def test_sql_task_is_updated_on_plone_object_update(self):
        self.task.responsible_client = 'asd'
        self.task.title = u'Gopf, iz mach mau'
        notify(ObjectModifiedEvent(self.task))

        self.assertEqual(1, Session.query(Task).count())
        task = Session.query(Task).one()

        self.assertEqual('asd', task.assigned_org_unit)
        self.assertEqual(u'dossier > subdossier > Gopf, iz mach mau',
                         task.breadcrumb_title)
        self.assertEqual(u'Gopf, iz mach mau', task.title)

        self.assertEqual(get_current_org_unit().id(), task.issuing_org_unit)
        self.assertEqual(get_current_admin_unit().id(), task.admin_unit_id)
        self.assertEqual(self.user.userid, task.issuer)
        self.assertEqual(self.user.userid, task.responsible)
        self.assertEqual(u'task-state-open', task.review_state)
        self.assertEqual(u'dossier-1/dossier-2/task-1', task.physical_path)
        self.assertIsNotNone(task.icon)
        self.assertEqual(task.deadline, date(2010, 1, 1))
        self.assertIsNotNone(task.modified)
        self.assertEqual('direct-execution', task.task_type)
        self.assertFalse(task.is_subtask)
        self.assertEqual(1, task.sequence_number)
        self.assertEqual('Client1 / 1.1', task.reference_number)
        self.assertEqual('dossier', task.containing_dossier)
        self.assertEqual('subdossier', task.containing_subdossier)
        self.assertEqual(2, task.dossier_sequence_number)
        self.assertEqual('Lorem ipsum dolor sit amet, consectetur', task.text)
        self.assertSequenceEqual([TEST_USER_ID], task.principals)
        self.assertIsNone(task.predecessor)
    def test_sql_task_is_updated_when_container_is_moved(self):
        dossier2 = create(Builder('dossier')
                          .titled(u'Dossier 2'))

        api.content.move(source=self.subdossier, target=dossier2)

        task = Session.query(Task).one()
        self.assertEqual('subdossier', task.containing_subdossier)
        self.assertEqual(u'dossier-3/dossier-2/task-1', task.physical_path)
        self.assertEqual(2, task.dossier_sequence_number)
        self.assertEqual(u'Client1 / 2.1', task.reference_number)
Пример #3
0
    def __init__(self, obj, event):
        self.obj = obj
        self.event = event

        if not self.is_uninstalling_plone():
            self.admin_unit_id = get_current_admin_unit().id()
            self.current_org_unit_id = get_current_org_unit().id()
            self.sequence_number = self.obj.get_sequence_number()
            self.assigned_org_unit = obj.responsible_client
            self.obj_id = self.get_object_id()
            self.task_query = Session.query(Task).filter_by(
                admin_unit_id=self.admin_unit_id, int_id=self.obj_id)
Пример #4
0
    def get_sql_task(self):
        admin_unit_id = get_current_admin_unit().id()
        current_org_unit_id = get_current_org_unit().id()
        sequence_number = self.obj.get_sequence_number()
        assigned_org_unit = self.obj.responsible_client

        task = Session.query(Task).filter_by(
            admin_unit_id=admin_unit_id, int_id=self.obj_id).first()
        if task is None:
            task = Task(self.obj_id, admin_unit_id,
                        issuing_org_unit=current_org_unit_id,
                        assigned_org_unit=assigned_org_unit,
                        sequence_number=sequence_number,
                        created=self.obj.created().asdatetime())
            Session.add(task)
        return task
Пример #5
0
def index_task(obj, event):
    """Index the given task in opengever.globalindex.
    """
    # Skip this handler when trying to remove a Plone site. Otherwise the
    # component registry is already gone and we'll run into trouble.
    if IObjectRemovedEvent.providedBy(event) \
            and IPloneSiteRoot.providedBy(event.object):
        return None

    parent = aq_parent(aq_inner(obj))

    client_id = get_client_id()
    intids = getUtility(IIntIds)
    try:
        int_id = intids.getId(obj)
    except KeyError:
        try:
            # In some case (remote task updating etc)
            # only the base_object provides an intid.
            int_id = intids.getId(aq_base(obj))
        except KeyError:
            # The intid event handler didn' create a intid for this object
            # yet. The event will be fired again after creating the id.
            return

    session = Session()
    try:
        task = session.query(Task).filter(Task.client_id == client_id).filter(
            Task.int_id == int_id).one()
    except NoResultFound:
        task = Task(int_id, client_id)
        session.add(task)

    # title
    maximum_title_length = Task.title.property.columns[0].type.length
    title = obj.title
    if not isinstance(title, unicode):
        title = title.decode('utf-8')
    title = title[:maximum_title_length]
    task.title = title

    # Generate and store the breadcrumb tooltip
    breadcrumb_titles = []
    breadcrumbs_view = getMultiAdapter((obj, obj.REQUEST),
                                       name='breadcrumbs_view')
    for elem in breadcrumbs_view.breadcrumbs():
        if isinstance(elem.get('Title'), unicode):
            breadcrumb_titles.append(elem.get('Title'))
        else:
            breadcrumb_titles.append(elem.get('Title').decode('utf-8'))

    # we prevent to raise database-error, if we have a too long string
    # Shorten the breadcrumb_title to: mandant1 > repo1 > ...
    join_value = ' > '
    end_value = '...'

    maximum_length = Task.breadcrumb_title.property.columns[0].type.length
    maximum_length -= len(end_value)

    breadcrumb_title = breadcrumb_titles
    actual_length = 0

    for i, breadcrumb in enumerate(breadcrumb_titles):
        add_length = len(breadcrumb) + len(join_value) + len(end_value)
        if (actual_length + add_length) > maximum_length:
            breadcrumb_title = breadcrumb_titles[:i]
            breadcrumb_title.append(end_value)
            break

        actual_length += len(breadcrumb) + len(join_value)

    task.breadcrumb_title = join_value.join(breadcrumb_title)

    url_tool = obj.unrestrictedTraverse('@@plone_tools').url()
    task.physical_path = '/'.join(url_tool.getRelativeContentPath(obj))
    wftool = getToolByName(obj, 'portal_workflow')
    task.review_state = wftool.getInfoFor(obj, 'review_state')
    task.icon = obj.getIcon()
    task.responsible = obj.responsible
    task.issuer = obj.issuer

    # we need to have python datetime objects for make it work with sqlite etc.
    task.deadline = obj.deadline
    task.completed = obj.date_of_completion
    task.modified = obj.modified().asdatetime().replace(tzinfo=None)

    task.task_type = obj.task_type
    task.is_subtask = parent.portal_type == 'opengever.task.task'

    task.sequence_number = getUtility(ISequenceNumber).get_number(obj)
    task.reference_number = IReferenceNumber(obj).get_number()

    #get the containing_dossier value directly with the indexer
    catalog = getToolByName(obj, 'portal_catalog')
    task.containing_dossier = getMultiAdapter(
        (obj, catalog), IIndexer, name='containing_dossier')()

    # the dossier_sequence_number index is required for generating lists
    # of tasks as PDFs (LaTeX) as defined by the customer.
    task.dossier_sequence_number = get_dossier_sequence_number(obj)

    task.assigned_client = obj.responsible_client

    # index the predecessor
    if obj.predecessor:
        pred_client_id, pred_init_id = obj.predecessor.split(':', 1)
        try:
            predecessor = session.query(Task).filter_by(
                client_id=pred_client_id, int_id=pred_init_id).one()
        except NoResultFound:
            # For some reason the referenced predecessor doesn't exist
            predecessor = None

    else:
        predecessor = None

    task.predecessor = predecessor

    # index the principal which have View permission. This is according to the
    # allowedRolesAndUsers index but it does not car of global roles.
    allowed_roles = rolesForPermissionOn(View, obj)
    principals = []
    for principal, roles in _mergedLocalRoles(obj).items():
        for role in roles:
            if role in allowed_roles:
                principals.append(principal.decode('utf-8'))
                break

    task.principals = principals