Пример #1
0
    def _validate(self, doc):
        assignment = get_resource_service('assignments').find_one(
            req=None, _id=doc.get('assignment_id'))

        if not assignment:
            raise SuperdeskApiError.badRequestError('Assignment not found.')

        item = get_resource_service('archive').find_one(req=None,
                                                        _id=doc.get('item_id'))

        if not item:
            raise SuperdeskApiError.badRequestError('Content item not found.')

        if item.get('assignment_id'):
            raise SuperdeskApiError.badRequestError(
                'Content is already linked to an assignment. Cannot link assignment and content.'
            )

        if not is_assigned_to_a_desk(item):
            raise SuperdeskApiError.badRequestError(
                'Content not in workflow. Cannot link assignment and content.')

        if not item.get('rewrite_of'):
            delivery = get_resource_service('delivery').find_one(
                req=None, assignment_id=ObjectId(doc.get('assignment_id')))

            if delivery:
                raise SuperdeskApiError.badRequestError(
                    'Content already exists for the assignment. Cannot link assignment and content.'
                )
Пример #2
0
    def on_updated(self, updates, original):
        updated = copy(original)
        updated.update(updates)
        if self._stage_changed(updates, original):
            insert_into_versions(doc=updated)
        new_task = updates.get('task', {})
        old_task = original.get('task', {})
        if new_task.get('stage') != old_task.get('stage'):
            push_notification('task:stage',
                              new_stage=str(new_task.get('stage', '')),
                              old_stage=str(old_task.get('stage', '')),
                              new_desk=str(new_task.get('desk', '')),
                              old_desk=str(old_task.get('desk', '')))
        else:
            push_notification(self.datasource, updated=1)

        if is_assigned_to_a_desk(updated):
            if self.__is_content_assigned_to_new_desk(original, updates) and \
                    not self._stage_changed(updates, original):
                insert_into_versions(doc=updated)
            add_activity(ACTIVITY_UPDATE,
                         'updated task {{ subject }} for item {{ type }}',
                         self.datasource,
                         item=updated,
                         subject=get_subject(updated),
                         type=updated['type'])
Пример #3
0
    def on_updated(self, updates, original):
        updated = copy(original)
        updated.update(updates)
        if self._stage_changed(updates, original):
            insert_into_versions(doc=updated)
        new_task = updates.get("task", {})
        old_task = original.get("task", {})
        if new_task.get("stage") != old_task.get("stage"):
            push_notification(
                "task:stage",
                new_stage=str(new_task.get("stage", "")),
                old_stage=str(old_task.get("stage", "")),
                new_desk=str(new_task.get("desk", "")),
                old_desk=str(old_task.get("desk", "")),
            )
        else:
            push_notification(self.datasource, updated=1)

        if is_assigned_to_a_desk(updated):
            if self.__is_content_assigned_to_new_desk(original, updates) and not self._stage_changed(updates, original):
                insert_into_versions(doc=updated)
            add_activity(
                ACTIVITY_UPDATE,
                "updated task {{ subject }} for item {{ type }}",
                self.datasource,
                item=updated,
                subject=get_subject(updated),
                type=updated["type"],
            )
Пример #4
0
 def on_created(self, docs):
     push_notification(self.datasource, created=1)
     for doc in docs:
         insert_into_versions(doc['_id'])
         if is_assigned_to_a_desk(doc):
             add_activity(ACTIVITY_CREATE, 'added new task {{ subject }} of type {{ type }}', item=doc,
                          subject=get_subject(doc), type=doc['type'])
Пример #5
0
 def on_created(self, docs):
     push_notification(self.datasource, created=1)
     push_notification('task:new')
     for doc in docs:
         insert_into_versions(doc['_id'])
         if is_assigned_to_a_desk(doc):
             add_activity(ACTIVITY_CREATE, 'added new task {{ subject }} of type {{ type }}',
                          self.datasource, item=doc,
                          subject=get_subject(doc), type=doc[ITEM_TYPE])
Пример #6
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = updates.get('task', {}).get('stage', '')
     old_stage_id = original.get('task', {}).get('stage', '')
     new_user_id = updates.get('task', {}).get('user', '')
     if new_stage_id and new_stage_id != old_stage_id:
         send_to(doc=original, update=updates, desk_id=None, stage_id=new_stage_id, user_id=new_user_id)
     update_version(updates, original)
Пример #7
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = str(updates.get('task', {}).get('stage', ''))
     old_stage_id = str(original.get('task', {}).get('stage', ''))
     new_user_id = updates.get('task', {}).get('user', '')
     if new_stage_id and new_stage_id != old_stage_id:
         updates[ITEM_OPERATION] = ITEM_SEND
         send_to(doc=original, update=updates, desk_id=None, stage_id=new_stage_id, user_id=new_user_id)
         resolve_document_version(updates, ARCHIVE, 'PATCH', original)
     update_version(updates, original)
Пример #8
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = str(updates.get('task', {}).get('stage', ''))
     old_stage_id = str(original.get('task', {}).get('stage', ''))
     new_user_id = updates.get('task', {}).get('user', '')
     if new_stage_id and new_stage_id != old_stage_id:
         updates[ITEM_OPERATION] = ITEM_SEND
         send_to(doc=original, update=updates, desk_id=None, stage_id=new_stage_id, user_id=new_user_id)
         resolve_document_version(updates, ARCHIVE, 'PATCH', original)
     convert_task_attributes_to_objectId(updates)
     update_version(updates, original)
Пример #9
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = updates.get('task', {}).get('stage', '')
     old_stage_id = original.get('task', {}).get('stage', '')
     if new_stage_id and new_stage_id != old_stage_id:
         new_stage = get_resource_service('stages').find_one(req=None, _id=new_stage_id)
         if not new_stage:
             raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % new_stage)
         updates['expiry'] = get_expiry(new_stage['desk'], new_stage_id)
         if new_stage.get('task_status'):
             updates['task']['status'] = new_stage['task_status']
Пример #10
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = str(updates.get("task", {}).get("stage", ""))
     old_stage_id = str(original.get("task", {}).get("stage", ""))
     new_user_id = updates.get("task", {}).get("user", "")
     if new_stage_id and new_stage_id != old_stage_id:
         updates[ITEM_OPERATION] = ITEM_SEND
         send_to(doc=original, update=updates, desk_id=None, stage_id=new_stage_id, user_id=new_user_id)
         resolve_document_version(updates, ARCHIVE, "PATCH", original)
     convert_task_attributes_to_objectId(updates)
     update_version(updates, original)
Пример #11
0
 def on_created(self, docs):
     push_notification(self.datasource, created=1)
     push_notification("task:new")
     for doc in docs:
         insert_into_versions(doc["_id"])
         if is_assigned_to_a_desk(doc):
             add_activity(
                 ACTIVITY_CREATE,
                 "added new task {{ subject }} of type {{ type }}",
                 self.datasource,
                 item=doc,
                 subject=get_subject(doc),
                 type=doc[ITEM_TYPE],
             )
Пример #12
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = updates.get('task', {}).get('stage', '')
     old_stage_id = original.get('task', {}).get('stage', '')
     if new_stage_id and new_stage_id != old_stage_id:
         new_stage = get_resource_service('stages').find_one(
             req=None, _id=new_stage_id)
         if not new_stage:
             raise SuperdeskApiError.notFoundError(
                 'Invalid stage identifier %s' % new_stage)
         updates['expiry'] = get_expiry(new_stage['desk'], new_stage_id)
         if new_stage.get('task_status'):
             updates['task']['status'] = new_stage['task_status']
Пример #13
0
    def on_updated(self, updates, original):
        new_stage = updates.get('task', {}).get('stage', '')
        old_stage = original.get('task', {}).get('stage', '')
        if new_stage != old_stage:
            push_notification('task:stage', new_stage=str(new_stage), old_stage=str(old_stage))
        else:
            push_notification(self.datasource, updated=1)
        updated = copy(original)
        updated.update(updates)

        if is_assigned_to_a_desk(updated):

            if self.__is_content_assigned_to_new_desk(original, updates):
                insert_into_versions(original['_id'])

            add_activity(ACTIVITY_UPDATE, 'updated task {{ subject }} for item {{ type }}',
                         item=updated, subject=get_subject(updated), type=updated['type'])
Пример #14
0
    def on_updated(self, updates, original):
        new_stage = updates.get('task', {}).get('stage', '')
        old_stage = original.get('task', {}).get('stage', '')
        if new_stage != old_stage:
            push_notification('task:stage',
                              new_stage=str(new_stage),
                              old_stage=str(old_stage))
        else:
            push_notification(self.datasource, updated=1)
        updated = copy(original)
        updated.update(updates)

        if is_assigned_to_a_desk(updated):

            if self.__is_content_assigned_to_new_desk(original, updates):
                insert_into_versions(original['_id'])

            add_activity(ACTIVITY_UPDATE,
                         'updated task {{ subject }} for item {{ type }}',
                         item=updated,
                         subject=get_subject(updated),
                         type=updated['type'])
Пример #15
0
    def _validate(self, doc):
        assignment = get_resource_service('assignments').find_one(
            req=None, _id=doc.get('assignment_id'))

        if not assignment:
            raise SuperdeskApiError.badRequestError('Assignment not found.')

        item = get_resource_service('archive').find_one(req=None,
                                                        _id=doc.get('item_id'))

        if not item:
            raise SuperdeskApiError.badRequestError('Content item not found.')

        if not doc.get('force') and item.get('assignment_id'):
            raise SuperdeskApiError.badRequestError(
                'Content is already linked to an assignment. Cannot link assignment and content.'
            )

        if not is_assigned_to_a_desk(item):
            raise SuperdeskApiError.badRequestError(
                'Content not in workflow. Cannot link assignment and content.')

        if not item.get('rewrite_of'):
            delivery = get_resource_service('delivery').find_one(
                req=None, assignment_id=ObjectId(doc.get('assignment_id')))

            if delivery:
                raise SuperdeskApiError.badRequestError(
                    'Content already exists for the assignment. Cannot link assignment and content.'
                )

            # scheduled update validation
            if assignment.get('scheduled_update_id'):
                raise SuperdeskApiError.badRequestError(
                    'Only updates can be linked to a scheduled update assignment'
                )

        coverage = get_coverage_for_assignment(assignment)
        allowed_states = [
            ASSIGNMENT_WORKFLOW_STATE.IN_PROGRESS,
            ASSIGNMENT_WORKFLOW_STATE.COMPLETED
        ]
        if (coverage and len(coverage.get('scheduled_updates')) > 0
                and str(assignment['_id']) != str(
                    (coverage.get('assigned_to') or {}).get('assignment_id'))):
            if (coverage.get('assigned_to')
                    or {}).get('state') not in allowed_states:
                raise SuperdeskApiError(
                    'Previous coverage is not linked to content.')

            # Check all previous scheduled updated to be linked/completed
            for s in coverage.get('scheduled_updates'):
                assigned_to = (s.get('assigned_to') or {})
                if str(assigned_to.get('assignment_id')) == str(
                        doc.get('assignment_id')):
                    break

                if assigned_to.get('state') not in allowed_states:
                    raise SuperdeskApiError(
                        'Previous scheduled-update pending content-linking/completion'
                    )