def add_existing_user(self, toAddr): acl_users = self.context.acl_users user = acl_users.get_userByEmail(toAddr) if not user: m = 'User for address <{0}> not found'.format(toAddr) raise LookupError(m) # get the user object in the context of the group and site userInfo = createObject('groupserver.UserFromId', self.context, user.getId()) auditor = self.get_auditor(userInfo) e = '<code class="email">{0}</code>'.format(toAddr) if user_member_of_group(user, self.groupInfo): status = ADD_EXISTING_MEMBER auditor.info(status, toAddr) m = _('existing-member-msg', '<li>The person with the email address ${email} ' '― ${user} ― is already a member of ' '${group}. No changes to the profile of ${user} have ' 'been made.</li>', mapping={ 'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo) }) else: status = ADD_OLD_USER auditor.info(status, toAddr) joininguser = IGSJoiningUser(userInfo) joininguser.silent_join(self.groupInfo) # Verify the address <https://redmine.iopen.net/issues/4037> eu = EmailUser(self.context, userInfo) if not eu.is_address_verified(toAddr): evu = EmailVerificationUser(self.context, userInfo, toAddr) verificationId = evu.create_verification_id() evu.add_verification_id(verificationId) evu.verify_email(verificationId) m = _('existing-profile-msg', '<li>Adding the existing participant with the email ' 'address ${email} ― ${user} ― to ' '${group}.</li>', mapping={ 'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo) }) msg = translate(m) retval = (msg, userInfo, status) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-leave-command-%s' % self.code r = '<span class="{0}">Sent an email in to leave {1}, but you are not a member of the '\ 'group</span> ({2})' retval = r.format(cssClass, groupInfo_to_anchor(self.groupInfo), munge_date(self.context, self.date)) return retval
def add_new_user(self, toAddr, profileDict): # Email address does not exist, but it is a legitimate address user = create_user_from_email(self.context, toAddr) # force verify vid = '%s-%s-verified' % (toAddr, self.adminInfo.id) evu = createObject('groupserver.EmailVerificationUserFromEmail', self.context, toAddr) evu.add_verification_id(vid) evu.verify_email(vid) # get the user object in the context of the group and site userInfo = createObject('groupserver.UserFromId', self.context, user.id) self.add_profile_attributes(userInfo, profileDict) auditor = self.get_auditor(userInfo) status = ADD_NEW_USER auditor.info(status, toAddr) joininguser = IGSJoiningUser(userInfo) joininguser.silent_join(self.groupInfo) e = '<code class="email">{0}</code>'.format(toAddr) msg = _('new-profile-member', '<li>A profile for ${user} has been created, and given the ' 'email address ${email}.</li>\n' '<li>${user} has been joined to ${group}.</li>\n', mapping={'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo)}) retval = (msg, userInfo, status) return retval
def add_new_user(self, toAddr, profileDict): # Email address does not exist, but it is a legitimate address user = create_user_from_email(self.context, toAddr) # force verify vid = '%s-%s-verified' % (toAddr, self.adminInfo.id) evu = createObject('groupserver.EmailVerificationUserFromEmail', self.context, toAddr) evu.add_verification_id(vid) evu.verify_email(vid) # get the user object in the context of the group and site userInfo = createObject('groupserver.UserFromId', self.context, user.id) self.add_profile_attributes(userInfo, profileDict) auditor = self.get_auditor(userInfo) status = ADD_NEW_USER auditor.info(status, toAddr) joininguser = IGSJoiningUser(userInfo) joininguser.silent_join(self.groupInfo) e = '<code class="email">{0}</code>'.format(toAddr) msg = _('new-profile-member', '<li>A profile for ${user} has been created, and given the ' 'email address ${email}.</li>\n' '<li>${user} has been joined to ${group}.</li>\n', mapping={ 'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo) }) retval = (msg, userInfo, status) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-leave-command-%s' % self.code r = '<span class="{0}">Email-command to leave {1}, recieved from '\ '<code class="email">{2}</code> but no profile could be found ({3})' retval = r.format(cssClass, groupInfo_to_anchor(self.groupInfo), self.instanceDatum, munge_date(self.context, self.date)) return retval
def actual_add(self, data): retval = {} adder = Adder(self.context, self.groupInfo, self.loggedInUser) toAddr = sanitise_address(data['toAddr']) linked_groupname = groupInfo_to_anchor(self.groupInfo) msg, userInfo, status = adder.add(toAddr, data) linked_username = userInfo_to_anchor(userInfo) # Tell the user if status == ADD_NEW_USER: notifier = NotifyAdd(self.context, self.request) fromAddr = sanitise_address(data['fromAddr']) passwd = self.get_password_reset(userInfo, toAddr) notifier.notify(self.loggedInUser, userInfo, fromAddr, toAddr, passwd) retval['status'] = 1 m = [] m.append('A profile for {0} has been created, and given the ' 'email address <code>{1}</code>.') m.append('{0} has been added to {2}.') m = [i.format(linked_username, toAddr, linked_groupname) for i in m] retval['message'] = m elif status == ADD_OLD_USER: notifier = NotifyJoin(self.context, self.request) notifier.notify(userInfo) retval['status'] = 2 m = [] m.append('Added the existing person with the email address ' '<code>{0}</code> ({1}) to {2}.') m = [i.format(toAddr, linked_username, linked_groupname) for i in m] retval['message'] = m elif status == ADD_EXISTING_MEMBER: retval['status'] = 3 m = [] m.append('The person with the email address <code>{0}</code> ' '({1}) is already a member of {2}.') m.append('No changes to the profile of {1} have been made.') m = [i.format(toAddr, linked_username, linked_groupname) for i in m] retval['message'] = m else: retval['status'] = 100 retval['message'] = 'An unknown event occurred.' # Tell the administrator if status in (ADD_NEW_USER, ADD_OLD_USER): adminNotifier = NotifyAdmin(self.context, self.request) for adminInfo in self.groupInfo.group_admins: adminNotifier.notify(adminInfo, userInfo) retval = to_json(retval, indent=4) return retval
def add_existing_user(self, toAddr): acl_users = self.context.acl_users user = acl_users.get_userByEmail(toAddr) if not user: m = 'User for address <{0}> not found'.format(toAddr) raise LookupError(m) # get the user object in the context of the group and site userInfo = createObject('groupserver.UserFromId', self.context, user.getId()) auditor = self.get_auditor(userInfo) e = '<code class="email">{0}</code>'.format(toAddr) if user_member_of_group(user, self.groupInfo): status = ADD_EXISTING_MEMBER auditor.info(status, toAddr) m = _('existing-member-msg', '<li>The person with the email address ${email} ' '― ${user} ― is already a member of ' '${group}. No changes to the profile of ${user} have ' 'been made.</li>', mapping={'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo)}) else: status = ADD_OLD_USER auditor.info(status, toAddr) joininguser = IGSJoiningUser(userInfo) joininguser.silent_join(self.groupInfo) # Verify the address <https://redmine.iopen.net/issues/4037> eu = EmailUser(self.context, userInfo) if not eu.is_address_verified(toAddr): evu = EmailVerificationUser(self.context, userInfo, toAddr) verificationId = evu.create_verification_id() evu.add_verification_id(verificationId) evu.verify_email(verificationId) m = _('existing-profile-msg', '<li>Adding the existing participant with the email ' 'address ${email} ― ${user} ― to ' '${group}.</li>', mapping={'email': e, 'user': userInfo_to_anchor(userInfo), 'group': groupInfo_to_anchor(self.groupInfo)}) msg = translate(m) retval = (msg, userInfo, status) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-email-settings-%s'\ % self.code r = '<span class="{0}">Sent an email in to switch off digest mode '\ 'mode for {1}</span> ({2})' retval = r.format(cssClass, groupInfo_to_anchor(self.groupInfo), munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-%s' % self.code retval = '<span class="%s">Given the status of %s in %s</span>' % \ (cssClass, self.instanceDatum, groupInfo_to_anchor(self.groupInfo)) if self.instanceUserInfo.id != self.userInfo.id: retval = '%s — %s' % (retval, userInfo_to_anchor(self.userInfo)) retval = '%s (%s)' % (retval, munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-home-%s' %\ self.code retval = '<span class="%s">%s changed the About tab on the'\ 'homepage of %s</span>' % \ (cssClass, userInfo_to_anchor(self.instanceUserInfo), groupInfo_to_anchor(self.groupInfo)) retval = '%s (%s)' % \ (retval, munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event profile-invite-event-%s' % self.code retval = '<span class="%s">Withdrew the invitation to '\ 'join %s from %s.</span>' %\ (cssClass, groupInfo_to_anchor(self.groupInfo), userInfo_to_anchor(self.instanceUserInfo)) if ((self.instanceUserInfo.id != self.userInfo.id) and not(self.userInfo.anonymous)): retval = '%s — %s' %\ (retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): cssClass = 'audit-event profile-invite-event-%s' % self.code retval = '<span class="%s">Withdrew the invitation to '\ 'join %s from %s.</span>' %\ (cssClass, groupInfo_to_anchor(self.groupInfo), userInfo_to_anchor(self.instanceUserInfo)) if ((self.instanceUserInfo.id != self.userInfo.id) and not (self.userInfo.anonymous)): retval = '%s — %s' %\ (retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-email-settings-%s'\ % self.code r = '<span class="{0}">Switched to web-only mode in {1}' retval = r.format(cssClass, groupInfo_to_anchor(self.groupInfo)) if self.adminChanged: uu = userInfo_to_anchor(self.userInfo) retval = '{0} by {1}'.format(retval, uu) d = munge_date(self.context, self.date) retval = '{0}</span> ({1})'.format(retval, d) return retval
def xhtml(self): cssClass = 'audit-event profile-add-event-%s' % self.code retval = '<span class="%s">Tried to add the existing member '\ ' %s to join %s.</span>' %\ (cssClass, userInfo_to_anchor(self.instanceUserInfo), groupInfo_to_anchor(self.groupInfo)) if ((self.instanceUserInfo.id != self.userInfo.id) and not(self.userInfo.anonymous)): retval = '%s — %s' %\ (retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): cssClass = u'audit-event groupserver-profile-invite-%s' %\ self.code retval = u'<span class="%s">%s %s the invitation from %s to '\ u'join %s</span>' % \ (cssClass, userInfo_to_anchor(self.instanceUserInfo), self.instanceDatum.title(), userInfo_to_anchor(self.userInfo), groupInfo_to_anchor(self.groupInfo)) retval = u'%s (%s)' % \ (retval, munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event profile-add-event-{}'.format(self.code) m = '<span class="{cssClass}">Adding the existing user {user} '\ 'to {group}</span>' retval = m.format(cssClass=cssClass, user=userInfo_to_anchor(self.instanceUserInfo), group=groupInfo_to_anchor(self.groupInfo)) if ((self.instanceUserInfo.id != self.userInfo.id) and not(self.userInfo.anonymous)): retval = '{} — {}'.format(retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): cssClass = CSS_CLASS.format(self.code) email = EMAIL.format(self.instanceDatum) ua = userInfo_to_anchor(self.instanceUserInfo) ga = groupInfo_to_anchor(self.groupInfo) r = '<span class="{0}">Tried to invite the existing member '\ ' {1} (with email {2}) to join {3}.</span>' retval = r.format(cssClass, ua, email, ga) if ((self.instanceUserInfo.id != self.userInfo.id) and not (self.userInfo.anonymous)): retval = '%s — %s' %\ (retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): cssClass = CSS_CLASS.format(self.code) email = EMAIL.format(self.instanceDatum) ua = userInfo_to_anchor(self.instanceUserInfo) ga = groupInfo_to_anchor(self.groupInfo) r = '<span class="{0}">Tried to invite the existing member '\ ' {1} (with email {2}) to join {3}.</span>' retval = r.format(cssClass, ua, email, ga) if ((self.instanceUserInfo.id != self.userInfo.id) and not(self.userInfo.anonymous)): retval = '%s — %s' %\ (retval, userInfo_to_anchor(self.userInfo)) return retval
def xhtml(self): """Display the event as string, with XHTML markup, in such a way that it will be useful for the Web view of audit trails. """ cssClass = u'audit-event groupserver-bounce-event-%s' % \ self.code retval = u'<span class="%s">Email delivery from %s to '\ u'<code class="email">%s</code> failed' %\ (cssClass, groupInfo_to_anchor(self.groupInfo), self.instanceDatum) retval = u'%s (%s)' % \ (retval, munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event gs-group-type-set-{0}'.format(self.code) m = '<span class="{cssClass}">Changed the type of {group} '\ 'to {toType} from {fromType}.</span>' retval = m.format(cssClass=cssClass, group=groupInfo_to_anchor(self.groupInfo), toType=self.instanceDatum, fromType=self.supplementaryDatum) if ((self.instanceUserInfo.id != self.userInfo.id) and not (self.userInfo.anonymous)): u = userInfo_to_anchor(self.userInfo) retval = '{0} — {1}'.format(retval, u) return retval
def xhtml(self): cssClass = 'audit-event profile-add-event-{0}'.format(self.code) email = '<code class="email">{}</code>'.format(self.instanceDatum) m = '<span class="{cssClass}">Adding the new user {user} (with '\ 'the email address {email}) to join {group}.</span>' retval = m.format(cssClass=cssClass, email=email, user=userInfo_to_anchor(self.instanceUserInfo), group=groupInfo_to_anchor(self.groupInfo)) if ((self.instanceUserInfo.id != self.userInfo.id) and not(self.userInfo.anonymous)): u = userInfo_to_anchor(self.userInfo) retval = '{0} — {1}'.format(retval, u) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-%s' % self.code retval = '' # --=mpj17=-- Sometimes this is false. I do not know why. if self.groupInfo.id: retval = '<span class="%s">Left %s</span>' % \ (cssClass, groupInfo_to_anchor(self.groupInfo)) if self.adminRemoved: retval = '%s — removed by %s' % \ (retval, userInfo_to_anchor(self.userInfo)) retval = '%s (%s)' % \ (retval, munge_date(self.context, self.date)) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-email-settings-%s'\ % self.code addrs = ['<code class="email">{0}</code>'.format(a) for a in self.instanceDatum.split()] addrStr = comma_comma_and(addrs) r = '<span class="{0}">Switched to use the email addresses {1} in '\ '{2}' retval = r.format(cssClass, addrStr, groupInfo_to_anchor(self.groupInfo)) if self.adminChanged: uu = userInfo_to_anchor(self.userInfo) retval = '{0} by {1}'.format(retval, uu) d = munge_date(self.context, self.date) retval = '{0}</span> ({1})'.format(retval, d) return retval
def invite_user_success(self, action, data): # Zope's regular form validation system *should* take care of checking # on columns and what not. So here we just have to pass data on to the # actual invite code and package the result up as json inviteProcessor = InviteProcessor(self.context, self.request, self.siteInfo, self.groupInfo, self.loggedInUser, self.form_fields, self.inviteFields) result, userInfo = inviteProcessor.process(data) # Prep data for display addr = sanitise_address(data['toAddr']) linked_username = userInfo_to_anchor(userInfo) linked_groupname = groupInfo_to_anchor(self.groupInfo) retval = {} if result == INVITE_NEW_USER: retval['status'] = 1 m = [] m.append('A profile for {0} has been created, and given the ' 'email address <code>{1}</code>.') m.append('{0} has been sent an invitation to join {2}.') m = [i.format(linked_username, addr, linked_groupname) for i in m] retval['message'] = m elif result == INVITE_OLD_USER: retval['status'] = 2 m = [] m.append('Inviting the existing person with the email address ' '<code>{0}</code> ― {1} ― to join {2}.') m = [i.format(addr, linked_username, linked_groupname) for i in m] retval['message'] = m elif result == INVITE_EXISTING_MEMBER: retval['status'] = 3 m = [] m.append('The person with the email address <code>{0}</code> ― ' '{1} ― is already a member of {2}.') m.append('No changes to the profile of {1} have been made.') m = [i.format(addr, linked_username, linked_groupname) for i in m] retval['message'] = m else: retval['status'] = 100 retval['message'] = 'An unknown event occurred.' retval = json.dumps(retval, indent=4) return retval
def xhtml(self): cssClass = 'audit-event groupserver-group-member-email-settings-%s'\ % self.code addrs = [ '<code class="email">{0}</code>'.format(a) for a in self.instanceDatum.split() ] addrStr = comma_comma_and(addrs) r = '<span class="{0}">Switched to use the email addresses {1} in '\ '{2}' retval = r.format(cssClass, addrStr, groupInfo_to_anchor(self.groupInfo)) if self.adminChanged: uu = userInfo_to_anchor(self.userInfo) retval = '{0} by {1}'.format(retval, uu) d = munge_date(self.context, self.date) retval = '{0}</span> ({1})'.format(retval, d) return retval
def actual_handle_add(self, action, data): u = userInfo_to_anchor(self.userInfo) e = '<code class="email">%s</code>' % self.defaultToEmail g = groupInfo_to_anchor(self.groupInfo) auditor, inviter = self.get_auditor_inviter() fullMembers = FullMembers(self.groupInfo.groupObj) invitedMembers = InvitedMembers(self.groupInfo.groupObj) if self.userId in fullMembers: auditor.info(INVITE_EXISTING_MEMBER, self.defaultToEmail) self.status = self.already_a_member(u, e, g) elif self.userId in invitedMembers: self.status = self.resent(u, e, g) inviteId = inviter.create_invitation(data, False) auditor.info(INVITE_OLD_USER, self.defaultToEmail) inviter.send_notification(data['subject'], data['message'], inviteId, data['fromAddr'], data['toAddr']) else: self.status = self.issues(u, e, g) assert self.status
def handle_invite(self, action, data): inviteProcessor = InviteProcessor(self.context, self.request, self.siteInfo, self.groupInfo, self.loggedInUser, self.form_fields, self.inviteFields) result, userInfo = inviteProcessor.process(data) # Prep data for display addrName, addr = parseaddr(data['toAddr'].strip()) e = '<code class="email">%s</code>' % addr g = groupInfo_to_anchor(self.groupInfo) u = userInfo_to_anchor(userInfo) if result == INVITE_NEW_USER: m = '<li>A profile for {0} has been created, and given the '\ 'email address {1}.</li>\n'\ '<li>{0} has been sent an invitation to join {2}.</li>' self.status = m.format(u, e, g) elif result == INVITE_OLD_USER: m = '<li>Inviting the existing person with the email address '\ '{0} ― {1} ― to join {2}.</li>' self.status = m.format(e, u, g) elif result == INVITE_EXISTING_MEMBER: m = '<li>The person with the email address {0} ― {1} '\ '― is already a member of {2}.</li>\n'\ '<li>No changes to the profile of {1} have been made.</li>' self.status = m.format(e, u, g) else: # What happened? m = '<li>An unknown event occurred while attempting to invite '\ 'the person with the email address {0} ― {1} '\ '― is already a member of {2}.</li>\n'\ '<li>No changes to the profile of {1} have been made.</li>' self.status = m.format(e, u, g) self.status = '<ul>\n{0}\n</ul>'.format(self.status) assert userInfo, 'User not created or found' assert self.status
def actual_add(self, data): retval = {} adder = Adder(self.context, self.groupInfo, self.loggedInUser) toAddr = sanitise_address(data['toAddr']) linked_groupname = groupInfo_to_anchor(self.groupInfo) msg, userInfo, status = adder.add(toAddr, data) linked_username = userInfo_to_anchor(userInfo) # Tell the user if status == ADD_NEW_USER: notifier = NotifyAdd(self.context, self.request) fromAddr = sanitise_address(data['fromAddr']) passwd = self.get_password_reset(userInfo, toAddr) notifier.notify(self.loggedInUser, userInfo, fromAddr, toAddr, passwd) retval['status'] = 1 m = [] m.append('A profile for {0} has been created, and given the ' 'email address <code>{1}</code>.') m.append('{0} has been added to {2}.') m = [ i.format(linked_username, toAddr, linked_groupname) for i in m ] retval['message'] = m elif status == ADD_OLD_USER: notifier = NotifyJoin(self.context, self.request) notifier.notify(userInfo) retval['status'] = 2 m = [] m.append('Added the existing person with the email address ' '<code>{0}</code> ({1}) to {2}.') m = [ i.format(toAddr, linked_username, linked_groupname) for i in m ] retval['message'] = m elif status == ADD_EXISTING_MEMBER: retval['status'] = 3 m = [] m.append('The person with the email address <code>{0}</code> ' '({1}) is already a member of {2}.') m.append('No changes to the profile of {1} have been made.') m = [ i.format(toAddr, linked_username, linked_groupname) for i in m ] retval['message'] = m else: retval['status'] = 100 retval['message'] = 'An unknown event occurred.' # Tell the administrator if status in (ADD_NEW_USER, ADD_OLD_USER): adminNotifier = NotifyAdmin(self.context, self.request) for adminInfo in self.groupInfo.group_admins: adminNotifier.notify(adminInfo, userInfo) retval = to_json(retval, indent=4) return retval