def get_responsible_widget_value(self, template): org_unit_id, responsible = self.replace_interactive_actors(template) actor_lookup = ActorLookup(responsible) if actor_lookup.is_inbox() or actor_lookup.is_team(): return (u'{}'.format(actor_lookup.identifier), ) else: return (u'{}:{}'.format(org_unit_id, actor_lookup.identifier), )
def getTerm(self, value, brain=None): # Contacts if ActorLookup(value).is_contact() and brain is None: catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults( portal_type=CONTACT_TYPE, contactid=value)[0] if brain and ActorLookup(value).is_contact(): actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title) # Inboxes if ActorLookup(value).is_inbox(): orgunit_id = value.split(':', 1)[1] orgunit = OrgUnit.query.filter(OrgUnit.unit_id == orgunit_id).one() value = token = orgunit.inbox().id() title = translate(_(u'inbox_label', default=u'Inbox: ${client}', mapping=dict(client=orgunit.label())), context=getRequest()) return SimpleTerm(value, token, title) user = self.base_query.filter(User.userid == value).one() token = value title = u'{} ({})'.format(user.fullname(), user.userid) return SimpleTerm(value, token, title)
def update_reponsible_field_data(self, data): """Extract responsible_client when a combined value is used (client, responsible separated by a colon). """ if not data.get('responsible'): return if isinstance(data['responsible'], dict): responsible = data['responsible']['token'] else: responsible = data['responsible'] # Skip values without the orgunit prefix if ':' not in responsible: return if ActorLookup(responsible).is_inbox(): responsible_client = responsible.split(':', 1)[1] elif ActorLookup(responsible).is_team(): team = Team.query.get_by_actor_id(responsible) responsible_client = team.org_unit.unit_id else: responsible_client, responsible = responsible.split(':', 1) data['responsible'] = responsible data['responsible_client'] = responsible_client
def get_responsible_widget_value(self, template): org_unit_id, responsible = self.replace_interactive_actors(template) actor_lookup = ActorLookup(responsible) if actor_lookup.is_inbox() or actor_lookup.is_team(): return (u'{}'.format(actor_lookup.identifier), ) else: return (u'{}:{}'.format(org_unit_id, actor_lookup.identifier), )
def get_user_ids(self): """Returns a list of userids which represents the given watcher: Means for a single user, a list with the user_id and for a inbox watcher, a list of the userids of all inbox_group users. """ actor_lookup = ActorLookup(self.actorid) if actor_lookup.is_inbox() or actor_lookup.is_team(): return [user.userid for user in Actor.lookup(self.actorid).representatives()] return [self.actorid]
def test_added_activity_is_recorded_when_a_disposition_is_created(self): self.login(self.regular_user) actor = ActorLookup(self.regular_user.getId()).lookup() create(Builder('disposition').titled(u'Angebot 13.49')) activity = Activity.query.one() self.assertEquals('disposition-added', activity.kind) self.assertEquals( u'New disposition added by {} on admin unit Hauptmandant'.format( actor.get_label(with_principal=False)), activity.summary) self.assertEquals(u'Disposition added', activity.label) self.assertIsNone(activity.description) self.assertEquals(u'Angebot 13.49', activity.title)
def test_appraise_activity_is_recorded(self): self.login(self.archivist) actor = ActorLookup(self.archivist.getId()).lookup() disposition = create(Builder('disposition')) api.content.transition(disposition, transition='disposition-transition-appraise') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-appraise', activity.kind) self.assertEquals( u'Appraisal finalized by {}'.format(actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-appraise', activity.label) self.assertIsNone(activity.description)
def test_added_activity_is_recorded_when_a_disposition_is_created(self): self.login(self.regular_user) actor = ActorLookup(self.regular_user.getId()).lookup() create(Builder('disposition').titled(u'Angebot 13.49')) activity = Activity.query.one() self.assertEquals('disposition-added', activity.kind) self.assertEquals( u'New disposition added by {} on admin unit Hauptmandant'.format( actor.get_label(with_principal=False)), activity.summary) self.assertEquals(u'Disposition added', activity.label) self.assertIsNone(activity.description) self.assertEquals(u'Angebot 13.49', activity.title)
def test_appraise_activity_is_recorded(self): self.login(self.archivist) actor = ActorLookup(self.archivist.getId()).lookup() disposition = create(Builder('disposition')) api.content.transition(disposition, transition='disposition-transition-appraise') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-appraise', activity.kind) self.assertEquals( u'Appraisal finalized by {}'.format(actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-appraise', activity.label) self.assertIsNone(activity.description)
def get_user_ids(self): """Returns a list of userids which represents the given watcher: Means for a single user, a list with the user_id and for a inbox watcher, a list of the userids of all inbox_group users. """ actor_lookup = ActorLookup(self.actorid) if actor_lookup.is_inbox() or actor_lookup.is_team(): return [ user.userid for user in Actor.lookup(self.actorid).representatives() ] return [self.actorid]
def test_close_activity_is_recorded(self): self.login(self.records_manager) actor = ActorLookup(self.records_manager.getId()).lookup() disposition = create(Builder('disposition') .in_state('disposition-state-archived')) api.content.transition(disposition, transition='disposition-transition-close') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-close', activity.kind) self.assertEquals( u'Disposition closed and all dossiers ' 'destroyed by {}'.format(actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-close', activity.label) self.assertIsNone(activity.description)
def test_close_activity_is_recorded(self): self.login(self.records_manager) actor = ActorLookup(self.records_manager.getId()).lookup() disposition = create( Builder('disposition').in_state('disposition-state-archived')) api.content.transition(disposition, transition='disposition-transition-close') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-close', activity.kind) self.assertEquals( u'Disposition closed and all dossiers ' 'destroyed by {}'.format(actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-close', activity.label) self.assertIsNone(activity.description)
def validate_no_teams(context, responsible): if responsible and not context.is_open(): if ActorLookup(responsible).is_team(): raise Invalid( _(u'error_no_team_responsible_in_progress_state', default=u'Team responsibles are only allowed if the task or ' u'forwarding is open.'))
def test_closed_activity_is_recorded_when_a_todo_is_closed(self, browser): self.login(self.workspace_owner, browser) browser.open(self.assigned_todo, method='PATCH', headers=self.api_headers, data=json.dumps({'completed': True})) activity = Activity.query.one() self.assertEquals('todo-modified', activity.kind) self.assertEquals(u'ToDo closed', activity.label) self.assertIsNone(activity.description) self.assertEquals(u'Go live', activity.title) user = ActorLookup(self.workspace_owner.getId()).lookup() self.assertEquals( u'Closed by {}'.format(user.get_label(with_principal=False)), activity.summary)
def get_user_ids(self): """Returns a list of userids which represents the given watcher: Means for a single user, a list with the user_id and for a inbox watcher, a list of the userids of all inbox_group users who have notify_inbox_actions set to True. """ actor_lookup = ActorLookup(self.actorid) if actor_lookup.is_inbox() or actor_lookup.is_team(): return [ user.userid for user in Actor.lookup(self.actorid).representatives() if UserSettings.get_setting_for_user(user.userid, 'notify_inbox_actions') ] return [self.actorid]
def getTerm(self, value): data = value.split(':', 1) if len(data) == 2: orgunit_id, userid = data else: userid = value orgunit_id = self.client_id # Handle special case - Inboxes: in form "inbox:unit_id" if ActorLookup(value).is_inbox(): orgunit_id = userid query = OrgUnit.query if self.only_current_inbox: orgunit = query.filter(OrgUnit.unit_id == self.client_id) \ .filter(OrgUnit.unit_id == orgunit_id) \ .one() else: orgunit = query.filter(OrgUnit.unit_id == orgunit_id) \ .one() value = token = orgunit.inbox().id() title = translate(_(u'inbox_label', default=u'Inbox: ${client}', mapping=dict(client=orgunit.label())), context=getRequest()) return SimpleTerm(value, token, title) if ActorLookup(value).is_team(): if not self.include_teams: raise LookupError team = Team.query.get_by_actor_id(value) return SimpleTerm(team.actor_id(), team.actor_id(), team.label()) user, orgunit = self.base_query.filter(OrgUnit.unit_id == orgunit_id) \ .filter(User.userid == userid).one() token = u'{}:{}'.format(orgunit_id, userid) title = u'{}: {} ({})'.format(orgunit.title, user.fullname(), user.userid) return SimpleTerm(value, token, title)
def test_dispose_activity_is_recorded(self): self.login(self.records_manager) actor = ActorLookup(self.records_manager.getId()).lookup() ILifeCycle(self.expired_dossier).archival_value = ARCHIVAL_VALUE_WORTHY disposition = create(Builder('disposition') .having(dossiers=[self.expired_dossier]) .in_state('disposition-state-appraised')) api.content.transition(disposition, transition='disposition-transition-dispose') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-dispose', activity.kind) self.assertEquals( u'Disposition disposed for the archive by {}'.format(actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-dispose', activity.label) self.assertIsNone(activity.description)
def update_reponsible_field_data(data): """The responsible field always contains the orgunit id and the userid separated by a colon. """ if ActorLookup(data['responsible']).is_inbox(): client = data['responsible'].split(':', 1)[1] data['responsible_client'] = client data['responsible'] = data['responsible'] elif ActorLookup(data['responsible']).is_team(): team = Team.query.get_by_actor_id(data['responsible']) data['responsible_client'] = team.org_unit.unit_id data['responsible'] = data['responsible'] else: client, user = data['responsible'].split(':', 1) data['responsible_client'] = client data['responsible'] = user
def test_dispose_activity_is_recorded(self): self.login(self.records_manager) actor = ActorLookup(self.records_manager.getId()).lookup() ILifeCycle(self.expired_dossier).archival_value = ARCHIVAL_VALUE_WORTHY disposition = create( Builder('disposition').having(dossiers=[self.expired_dossier]). in_state('disposition-state-appraised')) api.content.transition(disposition, transition='disposition-transition-dispose') activity = Activity.query.all()[-1] self.assertEquals('disposition-transition-dispose', activity.kind) self.assertEquals( u'Disposition disposed for the archive by {}'.format( actor.get_link()), activity.summary) self.assertEquals(u'disposition-transition-dispose', activity.label) self.assertIsNone(activity.description)
def test_commented_activity_is_recorded_when_a_todo_is_commented( self, browser): self.login(self.workspace_member, browser) url = '{}/@responses'.format(self.todo.absolute_url()) browser.open(url, method="POST", headers=self.api_headers, data=json.dumps({'text': u'Angebot \xfcberpr\xfcft'})) activity = Activity.query.one() self.assertEquals('todo-modified', activity.kind) self.assertEquals(u'ToDo commented', activity.label) self.assertIsNone(activity.description) self.assertEquals('Fix user login', activity.title) user = ActorLookup(self.workspace_member.getId()).lookup() self.assertEquals( u'Commented by {}'.format(user.get_label(with_principal=False)), activity.summary)
def getTerm(self, value, brain=None): if not ActorLookup(value).is_contact(): raise ValueError('Value is not a contact token') catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults(portal_type=CONTACT_TYPE, contactid=value)[0] actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title)
def update_reponsible_field_data(data): """The responsible field always contains the orgunit id and the userid separated by a colon. """ if ActorLookup(data['responsible']).is_inbox(): client = data['responsible'].split(':', 1)[1] data['responsible_client'] = client data['responsible'] = data['responsible'] else: client, user = data['responsible'].split(':', 1) data['responsible_client'] = client data['responsible'] = user
def test_assigned_activity_is_recorded_when_a_todo_with_responsible_is_created( self): self.login(self.workspace_owner) create( Builder('todo').titled(u'Test ToDos').having( responsible=self.workspace_member.getId()).within( self.workspace)) activity = Activity.query.one() self.assertEquals('todo-assigned', activity.kind) self.assertEquals(u'ToDo assigned', activity.label) self.assertIsNone(activity.description) self.assertEquals(u'Test ToDos', activity.title) user = ActorLookup(self.workspace_owner.getId()).lookup() responsible = ActorLookup(self.workspace_member.getId()).lookup() self.assertEquals( u'Assigned to {} by {}'.format( responsible.get_label(with_principal=False), user.get_label(with_principal=False)), activity.summary)
def test_assigned_activity_is_recorded_when_a_todo_is_reassigned( self, browser): self.login(self.workspace_owner, browser) browser.open(self.assigned_todo, method='PATCH', headers=self.api_headers, data=json.dumps( {'responsible': self.workspace_guest.getId()})) activity = Activity.query.one() self.assertEquals('todo-assigned', activity.kind) self.assertEquals(u'ToDo assigned', activity.label) self.assertIsNone(activity.description) self.assertEquals(u'Go live', activity.title) user = ActorLookup(self.workspace_owner.getId()).lookup() responsible = ActorLookup(self.workspace_guest.getId()).lookup() self.assertEquals( u'Assigned to {} by {}'.format( responsible.get_label(with_principal=False), user.get_label(with_principal=False)), activity.summary)
def current_user_link(self): userid = api.user.get_current().getId() actor = ActorLookup(userid).lookup() return actor.get_link()
def records_manager_label(self): userid = self.records_manager.getId() actor = ActorLookup(userid).lookup() return actor.get_label()
def archivist_label(self): userid = self.archivist.getId() actor = ActorLookup(userid).lookup() return actor.get_label()
def current_user_link(self): userid = api.user.get_current().getId() actor = ActorLookup(userid).lookup() return actor.get_link()
def records_manager_label(self): userid = self.records_manager.getId() actor = ActorLookup(userid).lookup() return actor.get_label()
def archivist_label(self): userid = self.archivist.getId() actor = ActorLookup(userid).lookup() return actor.get_label()
def is_team_task(self): """Is true if the task responsible is a team.""" return ActorLookup(self.responsible).is_team()