def test_record_activity_when_open_next_task(self): self.login(self.regular_user) # create subtask subtask2 = create(Builder('task') .within(self.task) .having(responsible_client='fa', responsible=self.regular_user.getId(), issuer=self.dossier_responsible.getId(), task_type='correction', deadline=date(2016, 11, 1)) .in_state('task-state-planned')) self.set_workflow_state('task-state-in-progress', self.subtask) alsoProvides(self.subtask, IFromSequentialTasktemplate) alsoProvides(subtask2, IFromSequentialTasktemplate) self.task.set_tasktemplate_order([self.subtask, subtask2]) api.content.transition( obj=self.subtask, transition='task-transition-in-progress-resolved') self.assertEquals( 'task-state-resolved', api.content.get_state(self.subtask)) self.assertEquals( 'task-state-open', api.content.get_state(subtask2)) activities = Resource.query.get_by_oguid( Oguid.for_object(subtask2)).activities activity = activities[-1] self.assertEquals('task-added', activity.kind) self.assertEquals('Task opened', activity.label) self.assertEquals(u'New task opened by B\xe4rfuss K\xe4thi', activity.summary) self.assertEquals(Oguid.for_object(subtask2), activity.resource.oguid)
def setUp(self): super(TestNotificationHandling, self).setUp() self.center = NotificationCenter() self.peter = create(Builder('ogds_user').id('peter')) self.peter = create(Builder('watcher').having(actorid='peter')) self.hugo = create(Builder('ogds_user').id('hugo')) self.hugo = create(Builder('watcher').having(actorid='hugo')) self.resource_a = create( Builder('resource').oguid('fd:123').watchers( [self.hugo, self.peter])) self.resource_b = create( Builder('resource').oguid('fd:456').watchers([self.hugo])) self.resource_c = create( Builder('resource').oguid('fd:789').watchers([self.peter])) self.activity_1 = self.center.add_activity( Oguid('fd', '123'), 'task-added', { 'en': 'Kennzahlen 2014 erfassen' }, { 'en': 'Task added' }, { 'en': 'Task bla added by Peter' }, 'hugo.boss', { 'en': None }).get('activity') self.activity_2 = self.center.add_activity( Oguid('fd', '123'), 'task-transition-open-in-progress', { 'en': 'Kennzahlen 2015 erfassen' }, { 'en': 'Task accepted' }, { 'en': 'Task bla accepted by Peter' }, 'peter.mueller', { 'en': None }).get('activity') self.activity_3 = self.center.add_activity( Oguid('fd', '456'), 'task-added', { 'en': 'Besprechung Gesuch' }, { 'en': 'Task added' }, { 'en': 'Task for added by Peter' }, 'peter.mueller', { 'en': None }).get('activity') self.activity_4 = self.center.add_activity( Oguid('fd', '789'), 'task-added', { 'en': 'Vorbereitung Besprechung' }, { 'en': 'Task added' }, { 'en': 'Task bla accepted by Franz' }, 'franz.meier', { 'en': None }).get('activity')
def test_participations_are_copied_when_dossier_is_copied(self): dossier = create(Builder('dossier')) peter = create( Builder('person').having(firstname=u'peter', lastname=u'hans')) organization = create(Builder('organization').named('ACME')) org_role = create( Builder('org_role').having(person=peter, organization=organization, function=u'cheffe')) ogds_user = create( Builder('ogds_user').id('peter').having( firstname=u'Hans', lastname=u'Peter').as_contact_adapter()) create( Builder('ogds_user_participation').for_dossier( dossier).for_ogds_user(ogds_user)) create( Builder('contact_participation').having( contact=peter, dossier_oguid=Oguid.for_object(dossier))) create( Builder('contact_participation').having( contact=organization, dossier_oguid=Oguid.for_object(dossier))) create( Builder('org_role_participation').having( org_role=org_role, dossier_oguid=Oguid.for_object(dossier))) original_participations = Participation.query.by_dossier(dossier).all() copied_dossier = api.content.copy(source=dossier, target=self.portal) copied_participations = Participation.query.by_dossier( copied_dossier).all() self.assertEqual(4, len(copied_participations)) intersecting_elements = set(original_participations).intersection( set(copied_participations)) self.assertEqual(0, len(intersecting_elements))
def __call__(self): jsondata = self.request.get(REQUEST_KEY) data = encode_after_json(json.loads(jsondata)) committee = Oguid.parse(data['committee_oguid']).resolve_object() proposal_oguid = Oguid.parse(data['proposal_oguid']) proposal = meeting_service().fetch_proposal_by_oguid(proposal_oguid) with elevated_privileges(): submitted_proposal = SubmittedProposal.create(proposal, committee) # XXX use Transporter API? collector = getMultiAdapter((submitted_proposal, ), IDataCollector, name='field-data') data['field-data']['ISubmittedProposal'] = data['field-data'].pop( 'IProposal') collector.insert(data['field-data']) # XXX fix data types in transporter submitted_proposal.date_of_submission = date.today() # sync data to proposal after inserting field data submitted_proposal.sync_model(proposal_model=proposal) submitted_proposal.create_proposal_document( filename=data['file']['filename'], content_type=data['file']['contentType'].encode('utf-8'), data=base64.decodestring(data['file']['data'])) history_data = advancedjson.loads(self.request.get('history_data')) IHistory(submitted_proposal).append_record( u'submitted', uuid=history_data['uuid']) self.request.response.setHeader("Content-type", "application/json") return json.dumps( {'path': '/'.join(submitted_proposal.getPhysicalPath())})
def setUp(self): super(TestMarkAsRead, self).setUp() self.center = NotificationCenter() self.test_user = create( Builder('watcher').having(actorid=TEST_USER_ID)) self.resource_a = create( Builder('resource').oguid('fd:123').watchers([self.test_user])) with freeze(pytz.UTC.localize(datetime(2014, 5, 7, 12, 30))): self.activity_1 = self.center.add_activity( Oguid('fd', '123'), 'task-added', { 'en': 'Kennzahlen 2014 erfassen' }, { 'en': 'Task added' }, { 'en': 'Task bla added by Hugo' }, 'hugo.boss', { 'en': None }).get('activity') self.activity_2 = self.center.add_activity( Oguid('fd', '123'), 'task-transition-open-in-progress', { 'en': 'Kennzahlen 2014 erfassen' }, { 'en': 'Task accepted' }, { 'en': 'Task bla accepted' }, 'hugo.boss', { 'en': None }).get('activity') self.notifications = self.center.get_users_notifications( TEST_USER_ID)
def test_closing_direct_execution_task_does_not_revoke_roles_if_revoke_permission_is_false( self, browser): self.login(self.regular_user, browser=browser) self.subtask.revoke_permissions = False self.subtask.task_type = 'direct-execution' self.subtask.sync() self.set_workflow_state('task-state-in-progress', self.subtask) # close browser.open(self.subtask, view='tabbedview_view-overview') browser.click_on('task-transition-in-progress-tested-and-closed') browser.click_on('Save') storage = RoleAssignmentManager(self.subtask).storage self.assertEqual([{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.subtask), 'principal': self.regular_user.id }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.subtask), 'principal': 'fa_inbox_users' }], storage._storage())
def test_skip_task_does_not_revoke_roles_if_revoke_permission_is_false( self, browser): self.login(self.secretariat_user, browser=browser) self.seq_subtask_2.revoke_permissions = False storage = RoleAssignmentManager(self.seq_subtask_2).storage self.assertEqual([{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'kathi.barfuss' }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'fa_inbox_users' }], storage._storage()) # skip browser.open(self.seq_subtask_2, view='tabbedview_view-overview') browser.click_on('task-transition-planned-skipped') browser.click_on('Save') self.assertEqual([{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'kathi.barfuss' }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'fa_inbox_users' }], storage._storage())
def test_closing_a_task_revokes_responsible_roles_on_task(self, browser): self.login(self.dossier_responsible, browser=browser) self.set_workflow_state('task-state-tested-and-closed', self.subtask) self.set_workflow_state('task-state-resolved', self.task) storage = RoleAssignmentManager(self.task).storage self.assertEqual([{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'kathi.barfuss' }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'fa_inbox_users' }], storage._storage()) # close browser.open(self.task, view='tabbedview_view-overview') browser.click_on('task-transition-resolved-tested-and-closed') browser.fill({'Response': 'Done!'}) browser.click_on('Save') self.assertEqual([], storage._storage())
def test_record_activity_when_open_next_task(self): self.login(self.regular_user) # create subtask subtask2 = create( Builder('task').within(self.task).having( responsible_client='fa', responsible=self.regular_user.getId(), issuer=self.dossier_responsible.getId(), task_type='correction', deadline=date(2016, 11, 1)).in_state('task-state-planned')) self.set_workflow_state('task-state-in-progress', self.subtask) alsoProvides(self.subtask, IFromSequentialTasktemplate) alsoProvides(subtask2, IFromSequentialTasktemplate) self.task.set_tasktemplate_order([self.subtask, subtask2]) api.content.transition( obj=self.subtask, transition='task-transition-in-progress-resolved') self.assertEquals('task-state-resolved', api.content.get_state(self.subtask)) self.assertEquals('task-state-open', api.content.get_state(subtask2)) activities = Resource.query.get_by_oguid( Oguid.for_object(subtask2)).activities activity = activities[-1] self.assertEquals('task-added', activity.kind) self.assertEquals('Task opened', activity.label) self.assertEquals(u'New task opened by B\xe4rfuss K\xe4thi', activity.summary) self.assertEquals(Oguid.for_object(subtask2), activity.resource.oguid)
def test_redirects_to_portal_when_current_user_has_no_longer_view_permission( self, browser): self.login(self.regular_user, browser=browser) api.content.disable_roles_acquisition(obj=self.dossier) self.assign_task(self.secretariat_user, u'Thats a job for you.') manager = RoleAssignmentManager(self.task) self.assertEqual([{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task).id, 'principal': 'jurgen.konig' }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task).id, 'principal': u'fa_inbox_users' }], manager.storage._storage()) self.assertEqual(self.portal.absolute_url(), browser.url) self.assertEqual([ 'Task successfully reassigned. You are no longer permitted to ' 'access the task.' ], info_messages())
def test_oguid_url_different_admin_unit(self): self.login(self.regular_user) oguid = Oguid('foo', 1234) self.assertEqual( 'http://nohost/plone/@@resolve_oguid?oguid=foo:1234', oguid.get_url())
def test_check_for_notification_default(self): setting = create(Builder('notification_default_setting') .having(kind='task-added', mail_notification=False)) setting.set_mail_notification_roles( [WATCHER_ROLE, TASK_RESPONSIBLE_ROLE]) self.center.add_activity( Oguid('fd', '123'), 'task-added', {'en': 'Kennzahlen 2014 erfassen'}, {'en': 'Task added'}, {'en': 'Task bla accepted by Peter'}, 'hugo.boss', {'en': None}) self.assertEquals(0, len(self.dispatcher.notified)) setting.mail_notification = True self.center.add_activity( Oguid('fd', '123'), 'task-added', {'en': 'Kennzahlen 2014 erfassen'}, {'en': 'Task added'}, {'en': 'Task bla accepted by Peter'}, 'hugo.boss', {'en': None}) self.assertEquals(2, len(self.dispatcher.notified))
def test_closing_a_task_revokes_responsible_roles_on_related_documents(self, browser): self.login(self.dossier_responsible, browser=browser) self.set_workflow_state('task-state-tested-and-closed', self.subtask) self.set_workflow_state('task-state-resolved', self.task) storage = RoleAssignmentManager(self.document).storage expected_oguids = [ Oguid.for_object(task).id for task in ( self.task, self.task, self.subtask, self.subtask, self.info_task, self.info_task, self.private_task, self.inbox_task) ] self.assertEqual( expected_oguids, [item.get('reference') for item in storage._storage()], ) # close browser.open(self.task, view='tabbedview_view-overview') browser.click_on('task-transition-resolved-tested-and-closed') browser.fill({'Response': 'Done!'}) browser.click_on('Save') expected_oguids = [ Oguid.for_object(task).id for task in (self.subtask, self.subtask, self.info_task, self.info_task, self.private_task, self.inbox_task) ] self.assertEqual( expected_oguids, [item.get('reference') for item in storage._storage()], )
def test_participations_are_copied_when_dossier_is_copied(self): dossier = create(Builder('dossier')) peter = create(Builder('person').having( firstname=u'peter', lastname=u'hans')) organization = create(Builder('organization').named('ACME')) org_role = create(Builder('org_role').having( person=peter, organization=organization, function=u'cheffe')) ogds_user = create(Builder('ogds_user') .id('peter') .having(firstname=u'Hans', lastname=u'Peter') .as_contact_adapter()) create(Builder('ogds_user_participation') .for_dossier(dossier) .for_ogds_user(ogds_user)) create(Builder('contact_participation') .having(contact=peter, dossier_oguid=Oguid.for_object(dossier))) create(Builder('contact_participation') .having(contact=organization, dossier_oguid=Oguid.for_object(dossier))) create(Builder('org_role_participation') .having(org_role=org_role, dossier_oguid=Oguid.for_object(dossier))) original_participations = Participation.query.by_dossier(dossier).all() copied_dossier = api.content.copy(source=dossier, target=self.portal) copied_participations = Participation.query.by_dossier(copied_dossier).all() self.assertEqual(4, len(copied_participations)) intersecting_elements = set(original_participations).intersection( set(copied_participations)) self.assertEqual(0, len(intersecting_elements))
def __call__(self): jsondata = self.request.get(REQUEST_KEY) data = encode_after_json(json.loads(jsondata)) committee = Oguid.parse(data['committee_oguid']).resolve_object() proposal_oguid = Oguid.parse(data['proposal_oguid']) proposal = meeting_service().fetch_proposal_by_oguid(proposal_oguid) with elevated_privileges(): submitted_proposal = SubmittedProposal.create(proposal, committee) # XXX use Transporter API? collector = getMultiAdapter((submitted_proposal,), IDataCollector, name='field-data') data['field-data']['ISubmittedProposal'] = data['field-data'].pop( 'IProposal') collector.insert(data['field-data']) # XXX fix data types in transporter submitted_proposal.date_of_submission = date.today() # sync data to proposal after inserting field data submitted_proposal.sync_model(proposal_model=proposal) submitted_proposal.create_proposal_document( filename=data['file']['filename'], content_type=data['file']['contentType'].encode('utf-8'), data=base64.decodestring(data['file']['data'])) history_data = advancedjson.loads(self.request.get('history_data')) IHistory(submitted_proposal).append_record( u'submitted', uuid=history_data['uuid']) self.request.response.setHeader("Content-type", "application/json") return json.dumps( {'path': '/'.join(submitted_proposal.getPhysicalPath())})
def test_closing_a_task_revokes_responsible_roles_on_related_documents( self, browser): self.login(self.dossier_responsible, browser=browser) self.set_workflow_state('task-state-tested-and-closed', self.subtask) self.set_workflow_state('task-state-resolved', self.task) storage = RoleAssignmentManager(self.document).storage expected_oguids = [ Oguid.for_object(task).id for task in (self.task, self.task, self.subtask, self.subtask, self.info_task, self.info_task, self.private_task, self.inbox_task) ] self.assertEqual( expected_oguids, [item.get('reference') for item in storage._storage()], ) # close browser.open(self.task, view='tabbedview_view-overview') browser.click_on('task-transition-resolved-tested-and-closed') browser.fill({'Response': 'Done!'}) browser.click_on('Save') expected_oguids = [ Oguid.for_object(task).id for task in (self.subtask, self.subtask, self.info_task, self.info_task, self.private_task, self.inbox_task) ] self.assertEqual( expected_oguids, [item.get('reference') for item in storage._storage()], )
def test_skip_task_does_not_revoke_roles_if_revoke_permission_is_false(self, browser): self.login(self.secretariat_user, browser=browser) self.seq_subtask_2.revoke_permissions = False storage = RoleAssignmentManager(self.seq_subtask_2).storage self.assertEqual( [{'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'kathi.barfuss'}, {'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'fa_inbox_users'}], storage._storage()) # skip browser.open(self.seq_subtask_2, view='tabbedview_view-overview') browser.click_on('task-transition-planned-skipped') browser.click_on('Save') self.assertEqual( [{'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'kathi.barfuss'}, {'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.seq_subtask_2), 'principal': 'fa_inbox_users'}], storage._storage())
def test_closing_does_not_revoke_roles_on_task_if_revoke_permission_is_false(self, browser): self.login(self.dossier_responsible, browser=browser) self.set_workflow_state('task-state-tested-and-closed', self.subtask) self.set_workflow_state('task-state-resolved', self.task) self.task.revoke_permissions = False storage = RoleAssignmentManager(self.task).storage self.assertEqual( [{'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'kathi.barfuss'}, {'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'fa_inbox_users'}], storage._storage()) # close browser.open(self.task, view='tabbedview_view-overview') browser.click_on('task-transition-resolved-tested-and-closed') browser.fill({'Response': 'Done!'}) browser.click_on('Save') self.assertEqual( [{'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'kathi.barfuss'}, {'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Editor'], 'reference': Oguid.for_object(self.task), 'principal': 'fa_inbox_users'}], storage._storage())
def test_revokes_permissions_on_proposal(self): self.login(self.dossier_responsible) intids = getUtility(IIntIds) relation = RelationValue(intids.getId(self.proposaldocument)) ITask(self.subtask).relatedItems.append(relation) notify(ObjectModifiedEvent(self.subtask)) self.set_workflow_state('task-state-tested-and-closed', self.subtask) expected_assignments = [{ 'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Reader', 'Editor'], 'reference': Oguid.for_object(self.subtask), 'principal': self.regular_user.id }, { 'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Reader', 'Editor'], 'reference': Oguid.for_object(self.subtask), 'principal': u'fa_inbox_users' }] document_storage = RoleAssignmentManager(self.proposaldocument).storage self.assertEqual(expected_assignments, document_storage._storage()) proposal_storage = RoleAssignmentManager(self.proposal).storage self.assertEqual(expected_assignments, proposal_storage._storage()) RevokePermissions(self.subtask, self.request)() self.assertEqual([], proposal_storage._storage()) self.assertEqual([], document_storage._storage())
def test_closing_does_not_revoke_roles_on_proposal_if_revoke_permission_is_false(self, browser): self.login(self.dossier_responsible, browser=browser) self.task.revoke_permissions = False intids = getUtility(IIntIds) relation = RelationValue(intids.getId(self.proposaldocument)) ITask(self.task).relatedItems.append(relation) notify(ObjectModifiedEvent(self.task)) expected_assignments = [{'cause': ASSIGNMENT_VIA_TASK, 'roles': ['Reader', 'Editor'], 'reference': Oguid.for_object(self.task), 'principal': self.regular_user.id}, {'cause': ASSIGNMENT_VIA_TASK_AGENCY, 'roles': ['Reader', 'Editor'], 'reference': Oguid.for_object(self.task), 'principal': u'fa_inbox_users'}] document_storage = RoleAssignmentManager(self.proposaldocument).storage self.assertEqual(expected_assignments, document_storage._storage()) proposal_storage = RoleAssignmentManager(self.proposal).storage self.assertEqual(expected_assignments, proposal_storage._storage()) self.set_workflow_state('task-state-tested-and-closed', self.subtask) self.set_workflow_state('task-state-resolved', self.task) notify(ObjectModifiedEvent(self.task)) browser.open(self.task, view='tabbedview_view-overview') browser.click_on('task-transition-resolved-tested-and-closed') browser.click_on('Save') self.assertEqual(expected_assignments, proposal_storage._storage()) self.assertEqual(expected_assignments, document_storage._storage())
def test_adding_watcher_twice_to_resource_is_ignored(self): peter = create(Builder('watcher').having(actorid='peter')) resource = create(Builder('resource').oguid('fd:123')) self.center.add_watcher_to_resource(Oguid('fd', '123'), 'peter') self.center.add_watcher_to_resource(Oguid('fd', '123'), 'peter') self.assertEquals([peter], list(resource.watchers))
def test_adding(self): resource = self.center.add_resource(Oguid('fd', '123')) self.assertEquals(1, len(Resource.query.all())) resource = Resource.query.first() self.assertEquals(Oguid('fd', '123'), resource.oguid) self.assertEquals('fd', resource.admin_unit_id) self.assertEquals(123, resource.int_id)
def test_fetch_return_resource_by_means_of_oguid(self): resource_a = create(Builder('resource').oguid('fd:123')) resource_b = create(Builder('resource').oguid('fd:456')) self.assertEquals(resource_a, self.center.fetch_resource(Oguid('fd', '123'))) self.assertEquals(resource_b, self.center.fetch_resource(Oguid('fd', '456')))
def test_oguid_register_registers_intid(self): self.login(self.regular_user) copied_dossier = self.dossier._getCopy(self.leaf_repofolder) self.assertIsNone(Oguid.for_object(copied_dossier)) oguid = Oguid.for_object(copied_dossier, register=True) self.assertIsNotNone(oguid) self.assertEqual(oguid, Oguid.for_object(copied_dossier))
def sync_title_to_meeting_dossier(self, meeting): dossier_oguid = Oguid(meeting.dossier_admin_unit_id, meeting.dossier_int_id) dossier = dossier_oguid.resolve_object() if not dossier: return dossier.title = meeting.title dossier.reindexObject(idxs=['Title', 'SearchableText'])
def test_add_resource_if_not_exists(self): self.center.add_activity(Oguid('fd', '123'), 'task_added', {'en': 'Kennzahlen 2014 erfassen'}, {'en': 'Task added'}, {'en': 'Task bla added by Hugo'}, 'hugo.boss', {'en': None}) resource = self.center.fetch_resource(Oguid('fd', '123')) self.assertEquals('fd', resource.admin_unit_id) self.assertEquals(123, resource.int_id)
def sync_title_to_meeting_dossier(self, meeting): dossier_oguid = Oguid( meeting.dossier_admin_unit_id, meeting.dossier_int_id) dossier = dossier_oguid.resolve_object() if not dossier: return dossier.title = meeting.title dossier.reindexObject(idxs=['Title', 'SearchableText'])
def test_oguid_register_registers_intid(self): repo = create(Builder('repository')) dossier = create(Builder('dossier').within(repo)) copied_dossier = dossier._getCopy(repo) self.assertIsNone(Oguid.for_object(copied_dossier)) oguid = Oguid.for_object(copied_dossier, register=True) self.assertIsNotNone(oguid) self.assertEqual(oguid, Oguid.for_object(copied_dossier))
def setUp(self): super(TestMyNotifications, self).setUp() setting = NotificationDefault.query.filter_by(kind='task-added').one() setting.badge_notification_roles = [ WATCHER_ROLE, ] setting = NotificationDefault.query.filter_by( kind='task-transition-open-in-progress').one() setting.badge_notification_roles = [ WATCHER_ROLE, ] self.center = NotificationCenter(dispatchers=[BadgeIconDispatcher()]) self.test_watcher = create( Builder('watcher').having(actorid=self.regular_user.getId())) self.resource_a = create( Builder('resource').oguid('fd:123').watchers([self.test_watcher])) self.resource_b = create( Builder('resource').oguid('fd:456').watchers([self.test_watcher])) self.activity_1 = self.center.add_activity( Oguid('fd', '123'), u'task-added', { 'de': u'Kennzahlen 2014 \xfcbertragen' }, { 'de': u'Aufgabe hinzugef\xfcgt' }, { 'de': u'Neue Aufgabe hinzugef\xfcgt durch B\xf6ss' }, self.dossier_responsible.getId(), { 'de': None }).get('activity') self.activity_2 = self.center.add_activity( Oguid('fd', '123'), u'task-transition-open-in-progress', { 'de': u'Kennzahlen 2014 \xfcbertragen' }, { 'de': u'Aufgabe akzeptiert' }, { 'de': u'Aufgabe akzeptiert durch Hugo B\xf6ss' }, self.secretariat_user.getId(), { 'de': None }).get('activity') self.activity_3 = self.center.add_activity( Oguid('fd', '456'), u'task-added', { 'de': u'Kennzahlen 2014 \xfcbertragen' }, { 'de': u'Aufgabe hinzugef\xfcgt' }, { 'de': u'Neue Aufgabe hinzugef\xfcgt durch Peter M\xfcller' }, self.dossier_responsible.getId(), { 'de': None }).get('activity')
def test_get_watchers_returns_a_list_of_resource_watchers(self): peter = create(Builder('watcher').having(actorid='peter')) hugo = create(Builder('watcher').having(actorid='hugo')) fritz = create(Builder('watcher').having(actorid='fritz')) resource_1 = create(Builder('resource') .oguid('fd:123').watchers([hugo, fritz])) resource_2 = create(Builder('resource') .oguid('fd:456').watchers([peter])) self.assertEquals([hugo, fritz], self.center.get_watchers(Oguid('fd', '123'))) self.assertEquals([peter], self.center.get_watchers(Oguid('fd', '456')))
def render(self): jsondata = self.request.get(REQUEST_KEY) data = json.loads(jsondata) committee = Oguid.parse(data['committee_oguid']).resolve_object() proposal_oguid = Oguid.parse(data['proposal_oguid']) proposal = meeting_service().fetch_proposal_by_oguid(proposal_oguid) with elevated_privileges(): submitted_proposal = SubmittedProposal.create(proposal, committee) self.request.response.setHeader("Content-type", "application/json") return json.dumps( {'path': '/'.join(submitted_proposal.getPhysicalPath())})
def test_active_committeee_vocabulary_list_only_active_committees(self): self.login(self.committee_responsible) factory = getUtility( IVocabularyFactory, name='opengever.meeting.ActiveCommitteeVocabulary') self.assertItemsEqual([ Oguid.for_object(self.empty_committee).id, Oguid.for_object(self.committee).id ], [term.value for term in factory(context=None)]) self.empty_committee.load_model().deactivate() self.assertItemsEqual([Oguid.for_object(self.committee).id], [term.value for term in factory(context=None)])
def after_transition_hook(self, transition, disable_sync, transition_params): successor_task = self.create_successor_task(transition_params['dossier']) add_simple_response( self.context, transition=transition, text=transition_params.get('text'), successor_oguid=Oguid.for_object(successor_task).id) # set predecessor on successor task successor_tc_task = ISuccessorTaskController(successor_task) successor_tc_task.set_predecessor(Oguid.for_object(self.context).id) IYearfolderStorer(self.context).store_in_yearfolder() return successor_task
def migrate_proposal_fields_to_plone_objects(self, sql_proposal): oguid = Oguid(sql_proposal.admin_unit_id, sql_proposal.int_id) proposal = oguid.resolve_object() for field_name in PROPOSAL_FIELDS: setattr(proposal, field_name, getattr(sql_proposal, field_name)) submitted_oguid = Oguid(sql_proposal.submitted_admin_unit_id, sql_proposal.submitted_int_id) submitted_proposal = submitted_oguid.resolve_object() if not submitted_proposal: return for field_name in SUBMITTED_PROPOSAL_FIELDS: setattr(submitted_proposal, field_name, getattr(sql_proposal, field_name))
def test_comparison(self): self.assertEqual(Oguid('foo', 2), Oguid('foo', 2)) self.assertEqual('foo:2', Oguid('foo', 2)) self.assertNotEqual(None, Oguid('foo', 2)) self.assertNotEqual(Oguid('foo', 3), Oguid('foo', 2)) self.assertNotEqual(Oguid('bar', 2), Oguid('foo', 2))
def clear(self, cause, principal, reference, reindex=True): item = self.storage.get(principal, cause, Oguid.for_object(reference).id) if not item: return self.storage.clear(item) self._update_local_roles(reindex=reindex)
def by_oguid(self, oguid): """Returns the task identified by the given int_id and admin_unit_id or None """ if isinstance(oguid, basestring): oguid = Oguid.parse(oguid) return self.filter_by(oguid=oguid).first()
def by_oguid(self, oguid): """Returns the task identified by the given int_id and admin_unit_id or None """ if isinstance(oguid, basestring): oguid = Oguid.parse(oguid) return self.filter_by(oguid=oguid).first()
def _get_oguid_for(self, item): """Helper which returns a oguid for a given item. If the item is already an oguid, this oguid is returned.""" if not isinstance(item, Oguid): return Oguid.for_object(item) return item
def setUp(self): super(TestMarkAsRead, self).setUp() with self.login(self.regular_user): self.center = NotificationCenter() self.watcher = create( Builder('watcher').having(actorid=self.regular_user.id)) oguid = Oguid.for_object(self.task) self.resource = create( Builder('resource').oguid(oguid.id).watchers([self.watcher])) # XXX - something is wonky with the builder for activities with freeze(FREEZE_TIME_FIRST): self.activity_1 = create( Builder('activity').having(resource=self.resource, created=FREEZE_TIME_FIRST)) create( Builder('notification').id(1).having( activity=self.activity_1, userid=self.regular_user.id, )) # XXX - something is wonky with the builder for activities with freeze(FREEZE_TIME_SECOND): self.activity_2 = create( Builder('activity').having(resource=self.resource, created=FREEZE_TIME_SECOND)) create( Builder('notification').id(2).having( activity=self.activity_2, userid=self.regular_user.id, )) self.notifications = self.center.get_users_notifications( self.regular_user.id)
def test_assign_to_dossier_stores_and_close_forwarding(self, browser): self.login(self.secretariat_user, browser=browser) url = '{}/@workflow/forwarding-transition-assign-to-dossier'.format( self.inbox_forwarding.absolute_url()) dossier_uid = obj2brain(self.empty_dossier).UID data = {'dossier': dossier_uid} browser.open(url, method='POST', data=json.dumps(data), headers=self.api_headers) self.assertEqual(200, browser.status_code) yearfolder = get_current_yearfolder(context=self.inbox) self.assertEqual(1, len(yearfolder.objectValues())) forwarding = yearfolder.objectValues()[0] self.assertEqual( 'forwarding-state-closed', api.content.get_state(forwarding)) response = IResponseContainer(forwarding)[-1] task = self.empty_dossier.objectValues()[-1] self.assertEqual( 'forwarding-transition-assign-to-dossier', response.transition) self.assertEqual(Oguid.for_object(task).id, response.successor_oguid)
def test_adding_already_existing_favorite_returns_409_and_existing_representation(self, browser): self.login(self.administrator, browser=browser) create(Builder('favorite') .for_user(self.administrator) .for_object(self.document)) oguid = Oguid.for_object(self.document) url = '{}/@favorites/{}'.format( self.portal.absolute_url(), self.administrator.getId()) data = json.dumps({'oguid': oguid.id}) with browser.expect_http_error(409): browser.open(url, data=data, method='POST', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}) self.assertEqual( {u'@id': u'http://nohost/plone/@favorites/nicole.kohler/1', u'portal_type': u'opengever.document.document', u'admin_unit': u'Hauptmandant', u'favorite_id': 1, u'icon_class': u'icon-docx', u'oguid': u'plone:1014073300', u'position': None, u'target_url': u'http://nohost/plone/resolve_oguid/plone:1014073300', u'title': u'Vertr\xe4gsentwurf', u'tooltip_url': u'http://nohost/plone/resolve_oguid/plone:1014073300/tooltip'}, browser.json) self.assertEqual(1, Favorite.query.count())
def test_proposal_can_be_added(self): proposal = create(Builder('proposal').within(self.dossier)) self.assertEqual('proposal-1', proposal.getId()) model = proposal.load_model() self.assertIsNotNone(model) self.assertEqual(Oguid.for_object(proposal), model.oguid)
def test_responsible_has_reader_role_on_related_items_of_information_task(self): self.login(self.regular_user) # info_task is unidirectional by value manager = RoleAssignmentManager(self.document) assignment = manager.storage.get_by_reference(Oguid.for_object(self.info_task).id)[0] self.assertEqual(['Reader'], assignment.get('roles'))
def create_database_entry(self, meeting, document): excerpt = GeneratedExcerpt( oguid=Oguid.for_object(document), generated_version=document.get_current_version()) meeting.excerpt_documents.append(excerpt) return excerpt
def test_preserves_local_roles_from_invitation(self, browser): assignment_type = ASSIGNMENT_VIA_INVITATION assignment_class = RoleAssignment.registry[assignment_type] self.login(self.administrator, browser=browser) manager = RoleAssignmentManager(self.subdossier) manager.add_or_update_assignment( assignment_class(self.regular_user.id, ['Reader', 'Editor', 'Contributor'], self.workspace)) manager = RoleAssignmentManager(self.subdossier) assignments = manager.get_assignments_by_cause(assignment_type) self.assertEqual(1, len(assignments)) browser.open(self.dossier, data=self.make_path_param(self.subdossier), view="copy_items") with self.observe_children(self. empty_repofolder) as children: browser.open(self.empty_repofolder) browser.click_on('Paste') self.assertEqual(1, len(children.get('added'))) subdossier_copy = children.get('added').pop() manager = RoleAssignmentManager(subdossier_copy) assignments = manager.get_assignments_by_cause(assignment_type) self.assertEqual(1, len(assignments), "{} should get copied".format(assignment_class)) assignment = assignments[0] expected_assignment = {'cause': assignment_type, 'roles': ['Reader', 'Editor', 'Contributor'], 'reference': Oguid.for_object(self.workspace).id, 'principal': self.regular_user.id} self.assertEqual(expected_assignment, assignment)
def by_source(self, document): """Return all submitted documents where document is on the source side. """ oguid = Oguid.for_object(document) return self.filter(SubmittedDocument.oguid == oguid)
def assert_submitted_document_created(self, proposal, document, submitted_version=0): portal = api.portal.get() submitted_document_model = SubmittedDocument.query.get_by_source( proposal, document, ) submitted_document = portal.restrictedTraverse( submitted_document_model.submitted_physical_path.encode('utf-8'), ) self.assertIsNotNone(submitted_document_model) self.assertEqual( Oguid.for_object(submitted_document), submitted_document_model.submitted_oguid, ) self.assertEqual( submitted_version, submitted_document_model.submitted_version, ) self.assertEqual( proposal.load_model(), submitted_document_model.proposal, )
def test_check_permissions_fails_with_nobody(self, browser): self.login(self.regular_user) url = ResolveOGUIDView.url_for( Oguid.for_object(self.task), get_current_admin_unit()) with browser.expect_unauthorized(): browser.open(url)
def by_source(self, document): """Return all submitted documents where document is on the source side. """ oguid = Oguid.for_object(document) return self.filter(SubmittedDocument.oguid == oguid)
def test_proposal_creation_from_docx_template(self, browser): self.login(self.meeting_user, browser) committee_oguid = Oguid.for_object(self.committee).id payload = { u'@type': u'opengever.meeting.proposal', u'title': u'Sanierung B\xe4rengraben 2016', u'proposal_document_type': 'existing', u'proposal_document': IUUID(self.document), u"committee_oguid": committee_oguid, u'issuer': self.meeting_user.getId(), } response = browser.open(self.dossier.absolute_url(), data=json.dumps(payload), method='POST', headers=self.api_headers) self.assertEqual(201, response.status_code) new_object_id = str(response.json['id']) proposal = self.dossier.restrictedTraverse(new_object_id) self.assertEqual(u'Sanierung B\xe4rengraben 2016', proposal.title) self.assertEqual(self.meeting_user.getId(), proposal.issuer) proposal_doc = proposal.get_proposal_document() self.assertIsNotNone(proposal_doc) self.assertEqual(u'Sanierung B\xe4rengraben 2016', proposal_doc.title) self.assertEqual(u'Sanierung Baerengraben 2016.docx', proposal_doc.get_filename()) checksum = IBumblebeeDocument(proposal_doc).get_checksum() self.assertIsNotNone(checksum) self.assertEqual( IBumblebeeDocument(self.document).get_checksum(), checksum)
def journal_entry_factory(context, action, title, visible=True, comment='', actor=None, documents=None): if actor is None: actor = api.user.get_current().getId() comment = comment == '' and get_change_note(getRequest(), '') or comment title = propper_string(title) action = propper_string(action) comment = propper_string(comment) action_entry = PersistentDict({'type': action, 'title': title, 'visible': visible}) if documents: action_documents = PersistentList() for doc in documents: action_documents.append(PersistentDict( {'id': Oguid.for_object(doc).id, 'title': doc.title})) action_entry['documents'] = action_documents entry = { 'obj': context, 'action': action_entry, 'actor': actor, 'comment': comment} notify(JournalEntryEvent(**entry))
def test_committee_can_be_added(self): committee = create(Builder('committee').within(self.container)) self.assertEqual('committee-1', committee.getId()) model = committee.load_model() self.assertIsNotNone(model) self.assertEqual(Oguid.for_object(committee), model.oguid)
def test_oguid_for_object(self): self.login(self.regular_user) intids = getUtility(IIntIds) self.assertEqual('plone:{}'.format(intids.getId(self.dossier)), Oguid.for_object(self.dossier))
def create_database_entry(self, meeting, document): if meeting.protocol_document is not None: raise ProtocolAlreadyGenerated() version = document.get_current_version_id(missing_as_zero=True) protocol_document = GeneratedProtocol( oguid=Oguid.for_object(document), generated_version=version) meeting.protocol_document = protocol_document return protocol_document
def test_oguid_for_object(self): intids = getUtility(IIntIds) obj = create(Builder('dossier')) int_id = intids.getId(obj) oguid = Oguid.for_object(obj) self.assertEqual('client1:{}'.format(int_id), oguid)