def _trace_achievement_action(action_name, description, username, async_process):
    try:
        if username:
            if action_name == "publish":  # Uses publish
                register_publish(username, BlockVersion.loads(description),
                                 async_process=async_process)
            elif action_name == "get_version_delta_info":  # User uses biicode
                register_get_version_delta_info(username, async_process=async_process)
    except Exception as e:
        logger.warning("Error sending to action to achievement: %s" % e)
def _trace_achievement_action(action_name, description, username,
                              async_process):
    try:
        if username:
            if action_name == "publish":  # Uses publish
                register_publish(username,
                                 BlockVersion.loads(description),
                                 async_process=async_process)
            elif action_name == "get_version_delta_info":  # User uses biicode
                register_get_version_delta_info(username,
                                                async_process=async_process)
    except Exception as e:
        logger.warning("Error sending to action to achievement: %s" % e)
Beispiel #3
0
    def publish(self, publish_request):
        '''Performs a publication
        TIP: If we add publish_request to transaction_definition we can easily have asynchronous
        publications

        private: Only for first publication
        '''
        from biicode.server.background.enqueuer import register_publish

        if publish_request.tag == DEV:
            if not publish_request:
                raise BiiRequestErrorException('Up to date, nothing to publish')
            if publish_request.versiontag is not None:
                raise PublishException('A DEV version cannot have tag %s' % publish_request.tag)

        assert publish_request.deptable is not None

        # by default it is public
        # TODO: BLock creation is not handled in the transaction
        target_version = publish_request.parent
        user = self._store.read_user(target_version.block.owner)
        # Look if user has the block already created, because the block
        # can exist with -1 version if it has been created in web
        if target_version.block not in user.blocks.keys():
            try:
                if target_version != publish_request.parent:  # Branching
                    user = self.create_block(target_version.block,
                                             publish_request.parent, private=False)
                else:
                    user = self.create_block(target_version.block, private=False)
            except DuplicateBlockException:
                pass  # Its ok, already created

        target_block = target_version.block
        self._store.requestBlockTransaction(target_block)
        try:
            # If we can't read the block, we can't know about his existence
            self.security.check_read_block(target_block)
            self.security.check_publish_block(target_block, publish_request)
            # biiresponse.debug('Read block "%s"' % brl_block)
            block = self._store.read_block(target_block)
            (cells, contents,
             old_cells_ids, old_content_ids) = self._in_memory_block_update(block, publish_request)
        except ForbiddenException:
            self._store.finishBlockTransaction(target_block)
            raise
        except PublishException as e:
            self._store.finishBlockTransaction(target_block)
            raise ServerInternalErrorException(e.message)
        except Exception as excp:
            logger.error("Exception in publish service!!: %s " % str(excp))
            tb = traceback.format_exc()
            logger.error(tb)
            self._store.finishBlockTransaction(target_block)
            raise ServerInternalErrorException()

        self._store.beginBlockTransaction(target_block, cells, contents)
        try:
            self._write_resources_to_db(cells, contents, old_cells_ids, old_content_ids)
            self._store.update_block(block)
            self._store.commitBlockTransaction(target_block)
            register_publish(self.auth_user, block.last_version())
            self._store.finishBlockTransaction(target_block)

            # Need to read user again, otherwise will raise MongoNotCurrentObjectException
            # because of double update of same memory object
            user = self._store.read_user(target_version.block.owner)
            user.add_block_size_bytes(target_version.block, publish_request.bytes)
            # Save user (with block bytes updated)
            self._store.update_user(user)

            return block.last_version()

        except Exception as excp:
            tb = traceback.format_exc()
            logger.debug(tb)
            self._rollback_transaction(excp, target_block)
            raise ServerInternalErrorException('Publish transaction failed. Please, retry')
    def publish(self, publish_request):
        '''Performs a publication
        TIP: If we add publish_request to transaction_definition we can easily have asynchronous
        publications

        private: Only for first publication
        '''
        from biicode.server.background.enqueuer import register_publish

        if publish_request.tag == DEV:
            if not publish_request:
                raise BiiRequestErrorException(
                    'Up to date, nothing to publish')
            if publish_request.versiontag is not None:
                raise PublishException('A DEV version cannot have tag %s' %
                                       publish_request.tag)

        assert publish_request.deptable is not None

        # by default it is public
        # TODO: BLock creation is not handled in the transaction
        target_version = publish_request.parent
        user = self._store.read_user(target_version.block.owner)
        # Look if user has the block already created, because the block
        # can exist with -1 version if it has been created in web
        if target_version.block not in user.blocks.keys():
            try:
                if target_version != publish_request.parent:  # Branching
                    user = self.create_block(target_version.block,
                                             publish_request.parent,
                                             private=False)
                else:
                    user = self.create_block(target_version.block,
                                             private=False)
            except DuplicateBlockException:
                pass  # Its ok, already created

        target_block = target_version.block
        self._store.requestBlockTransaction(target_block)
        try:
            # If we can't read the block, we can't know about his existence
            self.security.check_read_block(target_block)
            self.security.check_publish_block(target_block, publish_request)
            # biiresponse.debug('Read block "%s"' % brl_block)
            block = self._store.read_block(target_block)
            (cells, contents, old_cells_ids,
             old_content_ids) = self._in_memory_block_update(
                 block, publish_request)
        except ForbiddenException:
            self._store.finishBlockTransaction(target_block)
            raise
        except PublishException as e:
            self._store.finishBlockTransaction(target_block)
            raise ServerInternalErrorException(e.message)
        except Exception as excp:
            logger.error("Exception in publish service!!: %s " % str(excp))
            tb = traceback.format_exc()
            logger.error(tb)
            self._store.finishBlockTransaction(target_block)
            raise ServerInternalErrorException()

        self._store.beginBlockTransaction(target_block, cells, contents)
        try:
            self._write_resources_to_db(cells, contents, old_cells_ids,
                                        old_content_ids)
            self._store.update_block(block)
            self._store.commitBlockTransaction(target_block)
            register_publish(self.auth_user, block.last_version())
            self._store.finishBlockTransaction(target_block)

            # Need to read user again, otherwise will raise MongoNotCurrentObjectException
            # because of double update of same memory object
            user = self._store.read_user(target_version.block.owner)
            user.add_block_size_bytes(target_version.block,
                                      publish_request.bytes)
            # Save user (with block bytes updated)
            self._store.update_user(user)

            return block.last_version()

        except Exception as excp:
            tb = traceback.format_exc()
            logger.debug(tb)
            self._rollback_transaction(excp, target_block)
            raise ServerInternalErrorException(
                'Publish transaction failed. Please, retry')