Example #1
0
    def get(self, project, document, group):
        if not project:
            raise HttpErrorException.bad_request('invalid project given')

        project = Project.get_by_id(project)
        if not project:
            raise HttpErrorException.bad_request('invalid project given')
        if not project.has_permission_read(self.user):
            raise HttpErrorException.forbidden()

        if not document:
            raise HttpErrorException.bad_request('invalid document given')

        document = Document.get_by_id(document)
        if not document:
            raise HttpErrorException.bad_request('invalid document given')
        if not document.has_permission_read(self.user):
            raise HttpErrorException.forbidden()

        if not group:
            raise HttpErrorException.bad_request('invalid group given')

        group = Group.get_by_id(group)
        if not group:
            raise HttpErrorException.bad_request('invalid group given')

        if document.key not in project.documents and document.key != project.distilled_document:
            raise HttpErrorException.bad_request(
                'document does not belong to project')

        temp_user = User()
        temp_user.groups = [group.key, Group.get_worldshare().key]
        org = self.user.organization if self.user.organization else None

        if org:
            temp_user.organization = org

        if not document.has_permission_read(temp_user):
            raise HttpErrorException.bad_request(
                'Group does not have permission to read the document')

        pubs = document.get_presentation_published(group=group)
        version_int = PublishDocument.get_largest_version(pubs)

        if version_int is None:
            version_int = 1
        else:
            version_int += 1

        version = self.request.get('version', str(version_int))
        if version == 'latest':
            raise HttpErrorException.bad_request('invalid version given')

        for pub in pubs:
            if pub.version == version:
                raise HttpErrorException.bad_request(
                    'version name already taken')

        try:
            slide_count = int(self.request.get('slide_count', 15))
        except ValueError:
            raise HttpErrorException.bad_request(
                'invalid slide count, must be integer')
        if slide_count < 1:
            raise HttpErrorException.bad_request(
                'invalid slide_count given min 1')
        if slide_count > 100:
            raise HttpErrorException.bad_request(
                'invalid slide_count given max 100')

        try:
            min_bullet = int(self.request.get('min_bullet', 4))
        except ValueError:
            raise HttpErrorException.bad_request(
                'invalid min bullet, must be integer')
        if min_bullet < 1:
            raise HttpErrorException.bad_request(
                'invalid min_bullet given min 1')
        if min_bullet > 15:
            raise HttpErrorException.bad_request(
                'invalid min_bullet given max 15')

        try:
            max_bullet = int(self.request.get('max_bullet', 6))
        except ValueError:
            raise HttpErrorException.bad_request(
                'invalid max bullet, must be integer')
        if max_bullet < 1:
            raise HttpErrorException.bad_request(
                'invalid max_bullet given min 1')
        if max_bullet > 15:
            raise HttpErrorException.bad_request(
                'invalid max_bullet given max 15')

        if min_bullet > max_bullet:
            raise HttpErrorException.bad_request(
                'min_bullet can not be greater than max_bullet')

        publisher = PresentationPublisherThread()
        publisher.id = server.create_uuid()
        publisher.request = self
        publisher.project = project
        publisher.document = document
        publisher.slide_count = slide_count
        publisher.min_bullet = min_bullet
        publisher.max_bullet = max_bullet
        publisher.group = group
        publisher.user = self.user
        publisher.version = version

        if publisher.is_lock():
            raise HttpErrorException.bad_request('publisher already running')
        publisher.start()

        self.write_json_response({'id': publisher.id})

        self.get_analytic_session()
        document.record_analytic('pres_publish',
                                 self.analytic_session,
                                 project=project.key)
Example #2
0
    def get(self, project, document, group):
        if not project:
            raise HttpErrorException.bad_request('invalid project given')

        project = Project.get_by_id(project)
        if not project:
            raise HttpErrorException.bad_request('invalid project given')
        if not project.has_permission_read(self.user):
            raise HttpErrorException.forbidden()

        if not document:
            raise HttpErrorException.bad_request('invalid document given')

        document = Document.get_by_id(document)
        if not document:
            raise HttpErrorException.bad_request('invalid document given')
        if not document.has_permission_read(self.user):
            raise HttpErrorException.forbidden()

        if not group:
            raise HttpErrorException.bad_request('invalid group given')

        group = Group.get_by_id(group)
        if not group:
            raise HttpErrorException.bad_request('invalid group given')

        temp_user = User()
        temp_user.groups = [group.key, Group.get_worldshare().key]
        org = self.user.organization if self.user.organization else None

        if org:
            temp_user.organization = org

        if not document.has_permission_read(temp_user):
            raise HttpErrorException.bad_request(
                'Group does not have permission to read the document')

        if document.key not in project.documents and document.key != project.distilled_document:
            raise HttpErrorException.bad_request(
                'document does not belong to project')

        pubs = document.get_published(group=group)
        version_int = PublishDocument.get_largest_version(pubs)

        if version_int is None:
            version_int = 1
        else:
            version_int += 1

        version = self.request.get('version', str(version_int))
        if version == 'latest':
            raise HttpErrorException.bad_request('invalid version given')

        pubs = document.get_published(group=group)
        for pub in pubs:
            if pub.version == version:
                raise HttpErrorException.bad_request(
                    'version name already taken')

        publisher = DocumentPublisherThread()
        publisher.id = server.create_uuid()
        publisher.request = self
        publisher.project = project
        publisher.document = document
        publisher.group = group
        publisher.user = self.user
        publisher.version = version

        if publisher.is_lock():
            raise HttpErrorException.bad_request('publisher already running')
        publisher.start()

        self.write_json_response({'id': publisher.id})

        self.get_analytic_session()
        document.record_analytic('doc_publish',
                                 self.analytic_session,
                                 project=project.key)