def mark_copy_im_as_read(context): if not context.readDataFile("imiodmsmail_singles_marker.txt"): return site = context.getSite() # adapted = ILabelJar(site['incoming-mail']); adapted.list() days_back = 5 start = datetime.datetime(1973, 2, 12) end = datetime.datetime.now() - datetime.timedelta(days=days_back) users = {} functions = { 'i': IM_READER_SERVICE_FUNCTIONS, 'o': OM_READER_SERVICE_FUNCTIONS } brains = site.portal_catalog.unrestrictedSearchResults( portal_type=['dmsincomingmail', 'dmsincoming_email'], created={ 'query': (start, end), 'range': 'min:max' }, sort_on='created') out = ["%d mails" % len(brains)] changed_mails = 0 related_users = set() for brain in brains: if not brain.recipient_groups: continue typ = brain.portal_type[3:4] user_ids = set() for org_uid in brain.recipient_groups: if org_uid not in users: users[org_uid] = {} if typ not in users[org_uid]: users[org_uid][typ] = [ u.id for u in get_selected_org_suffix_users( org_uid, functions[typ]) ] for userid in users[org_uid][typ]: user_ids.add(userid) if len(user_ids): related_users.update(user_ids) obj = brain._unrestrictedGetObject() labeling = ILabeling(obj) labeling.storage['lu'] = PersistentList(user_ids) obj.reindexObject(idxs=['labels']) changed_mails += 1 out.append('%d mails labelled with "lu"' % changed_mails) out.append('%d users are concerned' % len(related_users)) return '\n'.join(out)
def _apply(self, **data): if data['treating_group']: for brain in self.brains: # check if treating_groups is changed and assigned_user is no more in if (brain.treating_groups is not None and brain.assigned_user != EMPTY_STRING and data['treating_group'] != brain.treating_groups and brain.assigned_user not in [mb.getUserName() for mb in get_selected_org_suffix_users( data['treating_group'], IM_EDITOR_SERVICE_FUNCTIONS)]): # self.status not good here because it needs to stay on the same form api.portal.show_message(_(u'An assigned user is not in this new treating group. ' u'Mail "${mail}" !', mapping={'mail': brain.Title.decode('utf8')}), self.request, 'error') break else: # here if no break ! for brain in self.brains: obj = brain.getObject() obj.treating_groups = data['treating_group'] modified(obj, Attributes(IDmsDocument, 'treating_groups'))
def __call__(self, context): terms = [] users = {} titles = [] for uid in get_registry_organizations(): members = get_selected_org_suffix_users(uid, ['actioneditor']) for member in members: title = member.getUser().getProperty('fullname') or member.getUserName() if title not in titles: titles.append(title) users[title] = [member] elif member not in users[title]: users[title].append(member) for tit in sorted(titles): for mb in users[tit]: terms.append(SimpleTerm(mb.getMemberId(), mb.getMemberId(), tit)) # terms.insert(0, SimpleTerm(EMPTY_STRING, EMPTY_STRING, _('Empty value'))) return SimpleVocabulary(terms)
def validate(self, value, force=False): # we go out if assigned user is empty if value is None: return config = ( (IMEdit, { 'attr': 'treating_groups', 'schema': '', 'fcts': IM_EDITOR_SERVICE_FUNCTIONS }), (OMEdit, { 'attr': 'treating_groups', 'schema': '', 'fcts': OM_EDITOR_SERVICE_FUNCTIONS }), (TaskEdit, { 'attr': 'assigned_group', 'schema': 'ITask.', 'fcts': TASK_EDITOR_SERVICE_FUNCTIONS }), ) for klass, dic in config: if isinstance(self.view, klass): # check if group is changed and assigned_user is no more in form_widget = 'form.widgets.{}{}'.format( dic['schema'], dic['attr']) if (getattr(self.context, dic['attr']) is not None and self.context.assigned_user is not None and self.request.form.get(form_widget, False) and self.request.form[form_widget][0] != getattr( self.context, dic['attr']) and value not in [ mb.getUserName() for mb in get_selected_org_suffix_users( self.request.form[form_widget][0], dic['fcts']) ]): raise Invalid( _(u"The assigned user is not in the selected group !"))
def get_group_users(self, assigned_group): return get_selected_org_suffix_users(assigned_group, ASSIGNED_USER_FUNCTIONS)
def get_group_users(self, assigned_group): return get_selected_org_suffix_users(assigned_group, IM_EDITOR_SERVICE_FUNCTIONS)
def test_get_selected_org_suffix_users(self): self.assertListEqual(get_selected_org_suffix_users(self.uid, []), []) self.assertListEqual([ u.getUserName() for u in get_selected_org_suffix_users(self.uid, ['director']) ], [api.user.get(username=TEST_USER_ID).getUserName()])