def get_sql_task(self): task = self.task_query.first() if task is None: task = Task(self.obj_id, self.admin_unit_id, issuing_org_unit=self.current_org_unit_id, assigned_org_unit=self.assigned_org_unit, sequence_number=self.sequence_number) Session.add(task) return task
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
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
def test_accept_forwarding_with_successor_with_dossier(self): create_client('plone') set_current_client_id(self.portal, 'plone') # create fake predecessor predecessor = Task(FAKE_INTID, 'client2') predecessor.physical_path = 'eingangskorb/forwarding-1' predecessor.issuer = 'testuser2' predecessor.responsible_client = 'plone' predecessor.responsible = TEST_USER_ID predecessor.deadline = datetime.now() remote_request = self.mocker.replace('opengever.ogds.base.utils.remote_request') self.expect(remote_request( 'client2', '@@transporter-extract-object-json', path='eingangskorb/forwarding-1', data={}, headers={})).result(FakeResponse(FORWARDING_EXTRACTION)) self.expect(remote_request( 'client2', '@@task-documents-extract', path='eingangskorb/forwarding-1', data={'documents': 'null'}, headers={})).result(FakeResponse(DOCUMENT_EXTRACTION)) # TODO replace any with the realy expected data self.expect(remote_request( 'client2', '@@task-responses-extract', path='eingangskorb/forwarding-1', data=ANY)).result(FakeResponse('[]')) self.expect(remote_request( 'client2', '@@store_forwarding_in_yearfolder', path='eingangskorb/forwarding-1', # data={'response_text': 'This is a message', # 'successor_oguid': u'plone:1231066935', # 'transition': 'forwarding-transition-accept'} data=ANY, )).result(FakeResponse('OK')) self.replay() wft = getToolByName(self.portal, 'portal_workflow') intids = getUtility(IIntIds) session = Session() session.add(predecessor) accept_forwarding_with_successor( self.portal, 'client2:%s' % FAKE_INTID, u'This is a message', dossier=self.dossier) # CHECKS # --------------------- # yearfolder: current_year = datetime.now().year yearfolder = self.inbox.get(str(current_year), None) self.assertTrue(yearfolder) self.assertEquals(yearfolder.title, u'Closed %s' % current_year) # forwarding ... # is stored in the yearfolder forwarding = yearfolder.get('forwarding-1', None) self.assertTrue(forwarding) # and closed self.assertEquals(wft.getInfoFor(forwarding, 'review_state'), 'forwarding-state-closed') # attributes are correctly moved self.assertEquals(forwarding.responsible, u'inbox:plone') # the issuer should be changed to the local inbox group self.assertEquals(forwarding.issuer, u'inbox:plone') # also the response is correctly added response = IResponseContainer(forwarding)[0] self.assertEquals(response.transition, 'forwarding-transition-accept') # task (succesor of the forwarding) task = self.dossier.get('task-1') self.assertTrue(task) self.assertEquals( ISuccessorTaskController(forwarding).get_successors()[0].int_id, intids.getId(task)) # the succesor link is also in the response correctly self.assertEquals( response.successor_oguid, ISuccessorTaskController(task).get_oguid())