Пример #1
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None):
    """Send item to given desk and stage.
    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """

    original_task = doc.setdefault('task', {})
    current_stage = None
    if original_task.get('stage'):
        current_stage = get_resource_service('stages').find_one(
            req=None, _id=original_task.get('stage'))
    desk = destination_stage = None
    task = {
        'desk': desk_id,
        'stage': stage_id,
        'user': original_task.get('user') if user_id is None else user_id
    }

    if current_stage:
        apply_stage_rule(doc, update, current_stage, is_incoming=False)

    if desk_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None,
                                                                _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError(
                'Invalid desk identifier %s' % desk_id)

        task['desk'] = desk_id
        if not stage_id:
            task['stage'] = desk.get('incoming_stage')
            destination_stage = get_resource_service('stages').find_one(
                req=None, _id=desk.get('incoming_stage'))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(
            req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError(
                'Invalid stage identifier %s' % stage_id)

        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, is_incoming=True)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update.setdefault('task', {})
        update['task'].update(task)
        update['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
    else:
        doc['task'].update(task)
        doc['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
Пример #2
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, default_stage='incoming_stage'):
    """Send item to given desk and stage.

    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    :param default_stage: if no stage_id is passed then it determines the stage in that desk the doc is assigned,
            either the the incomming stage or the working stage.
    """

    original_task = doc.setdefault('task', {})
    current_stage = None
    if original_task.get('stage'):
        current_stage = get_resource_service('stages').find_one(req=None, _id=original_task.get('stage'))
    desk = destination_stage = None
    task = {'desk': desk_id, 'stage': stage_id, 'user': original_task.get('user') if user_id is None else user_id}

    if current_stage:
        apply_stage_rule(doc, update, current_stage, MACRO_OUTGOING)

    if desk_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None, _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError('Invalid desk identifier %s' % desk_id)

        task['desk'] = desk_id
        if not stage_id:
            task['stage'] = desk.get(default_stage)
            destination_stage = get_resource_service('stages').find_one(req=None, _id=desk.get(default_stage))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % stage_id)

        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, MACRO_INCOMING, desk=desk)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update.setdefault('task', {})
        update['task'].update(task)
        update['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
    else:
        doc['task'].update(task)
        doc['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
        superdesk.get_resource_service('desks').apply_desk_metadata(doc, doc)
Пример #3
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None):
    """Send item to given desk and stage.
    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """

    original_task = doc.setdefault('task', {})
    current_stage = None
    if original_task.get('stage'):
        current_stage = get_resource_service('stages').find_one(req=None, _id=original_task.get('stage'))
    desk = destination_stage = None
    task = {'desk': desk_id, 'stage': stage_id, 'user': original_task.get('user') if user_id is None else user_id}

    if current_stage:
        apply_stage_rule(doc, update, current_stage, is_incoming=False)

    if desk_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None, _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError('Invalid desk identifier %s' % desk_id)

        task['desk'] = desk_id
        if not stage_id:
            task['stage'] = desk.get('incoming_stage')
            destination_stage = get_resource_service('stages').find_one(req=None, _id=desk.get('incoming_stage'))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % stage_id)

        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, is_incoming=True)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update.setdefault('task', {})
        update['task'].update(task)
        update['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
    else:
        doc['task'].update(task)
        doc['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
Пример #4
0
 def test_get_stage_content_expiry(self):
     stage = {"content_expiry": 10}
     calculated_minutes = get_item_expiry(self.app, stage)
     reference_minutes = get_expiry_date(10)
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #5
0
 def test_get_global_content_expiry(self):
     calculated_minutes = get_item_expiry(self.app, None)
     reference_minutes = get_expiry_date(99)
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #6
0
def send_to(doc,
            update=None,
            desk_id=None,
            stage_id=None,
            user_id=None,
            default_stage="incoming_stage"):
    """Send item to given desk and stage.

    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    :param default_stage: if no stage_id is passed then it determines the stage in that desk the doc is assigned,
            either the the incomming stage or the working stage.
    """

    original_task = doc.setdefault("task", {})
    current_stage = None
    if original_task.get("stage"):
        current_stage = get_resource_service("stages").find_one(
            req=None, _id=original_task.get("stage"))
    desk = destination_stage = None
    task = {
        "desk": desk_id,
        "stage": stage_id,
        "user": original_task.get("user") if user_id is None else user_id
    }

    if current_stage:
        apply_stage_rule(doc, update, current_stage, MACRO_OUTGOING)

    if desk_id:
        desk = superdesk.get_resource_service("desks").find_one(req=None,
                                                                _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError(
                _("Invalid desk identifier {desk_id}").format(desk_id=desk_id))

        if not current_user_has_privilege("move") and str(user_id) not in [
                str(x.get("user", "")) for x in desk.get("members", [])
        ]:
            raise SuperdeskApiError.forbiddenError(
                _("User is not member of desk: {desk_id}").format(
                    desk_id=desk_id))

        task["desk"] = desk_id
        if not stage_id:
            task["stage"] = desk.get(default_stage)
            destination_stage = get_resource_service("stages").find_one(
                req=None, _id=desk.get(default_stage))

    if stage_id:
        destination_stage = get_resource_service("stages").find_one(
            req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError(
                _("Invalid stage identifier {stage_id}").format(
                    stage_id=stage_id))

        task["desk"] = destination_stage["desk"]
        task["stage"] = stage_id

    if destination_stage:
        apply_stage_rule(doc,
                         update,
                         destination_stage,
                         MACRO_INCOMING,
                         desk=desk,
                         task=task)
        if destination_stage.get("task_status"):
            task["status"] = destination_stage["task_status"]

    if update:
        update.setdefault("task", {})
        update["task"].update(task)
        update["expiry"] = get_item_expiry(desk=desk, stage=destination_stage)
    else:
        doc["task"].update(task)
        doc["expiry"] = get_item_expiry(desk=desk, stage=destination_stage)
Пример #7
0
 def test_get_desk_content_expiry(self):
     desk = {"content_expiry": 10}
     calculated_minutes = get_item_expiry(desk=desk, stage=None)
     reference_minutes = get_expiry_date(10)
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #8
0
 def test_get_global_content_expiry(self):
     calculated_minutes = get_item_expiry(desk=None, stage=None)
     reference_minutes = get_expiry_date(self.ctx.app.config['CONTENT_EXPIRY_MINUTES'])
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #9
0
def send_to(doc,
            update=None,
            desk_id=None,
            stage_id=None,
            user_id=None,
            default_stage='incoming_stage'):
    """Send item to given desk and stage.

    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    :param default_stage: if no stage_id is passed then it determines the stage in that desk the doc is assigned,
            either the the incomming stage or the working stage.
    """

    original_task = doc.setdefault('task', {})
    current_stage = None
    if original_task.get('stage'):
        current_stage = get_resource_service('stages').find_one(
            req=None, _id=original_task.get('stage'))
    desk = destination_stage = None
    task = {
        'desk': desk_id,
        'stage': stage_id,
        'user': original_task.get('user') if user_id is None else user_id
    }

    if current_stage:
        apply_stage_rule(doc, update, current_stage, MACRO_OUTGOING)

    if desk_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None,
                                                                _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError(
                _('Invalid desk identifier {desk_id}').format(desk_id=desk_id))

        if not current_user_has_privilege('move') and \
                str(user_id) not in [str(x.get('user', '')) for x in desk.get('members', [])]:
            raise SuperdeskApiError.forbiddenError(
                _('User is not member of desk: {desk_id}').format(
                    desk_id=desk_id))

        task['desk'] = desk_id
        if not stage_id:
            task['stage'] = desk.get(default_stage)
            destination_stage = get_resource_service('stages').find_one(
                req=None, _id=desk.get(default_stage))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(
            req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError(
                _('Invalid stage identifier {stage_id}').format(
                    stage_id=stage_id))

        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc,
                         update,
                         destination_stage,
                         MACRO_INCOMING,
                         desk=desk,
                         task=task)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update.setdefault('task', {})
        update['task'].update(task)
        update['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
    else:
        doc['task'].update(task)
        doc['expiry'] = get_item_expiry(desk=desk, stage=destination_stage)
        superdesk.get_resource_service('desks').apply_desk_metadata(doc, doc)
Пример #10
0
 def test_get_stage_content_expiry(self):
     stage = {"content_expiry": 10}
     calculated_minutes = get_item_expiry(desk=None, stage=stage)
     reference_minutes = get_expiry_date(10)
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #11
0
 def test_get_global_content_expiry(self):
     calculated_minutes = get_item_expiry(desk=None, stage=None)
     reference_minutes = get_expiry_date(
         self.ctx.app.config["CONTENT_EXPIRY_MINUTES"])
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)
Пример #12
0
 def test_get_global_content_expiry(self):
     calculated_minutes = get_item_expiry(self.app, None)
     reference_minutes = get_expiry_date(99)
     self.assertEquals(calculated_minutes.hour, reference_minutes.hour)
     self.assertEquals(calculated_minutes.minute, reference_minutes.minute)