def subscribe(self, userInfo, email, request): assert self.groupVisibility.isPublic if userInfo and user_member_of_group(userInfo, self.groupInfo): raise GroupMember() ui = userInfo if userInfo else self.create_user(email['From']) addr = parseaddr(email['From'])[1] self.send_confirmation(email, addr, ui, request)
def handle_get_groups(self, action, data): '''The form action for the *Leave group* page. :param action: The button that was clicked. :param dict data: The form data.''' r = OrderedDict() groupInfo = createObject('groupserver.GroupInfo', self.context, data['groupId']) userInfo = createObject('groupserver.UserFromId', self.context, data['userId']) if groupInfo.groupObj is None: r['status'] = self.NO_GROUP r['message'] = 'No such group "{0}"'.format(data['groupId']) elif userInfo.anonymous: r['status'] = self.NO_USER r['message'] = 'No such user "{0}"'.format(data['userId']) elif user_member_of_group(userInfo, groupInfo): leave_group(groupInfo, userInfo, self.request) r['status'] = self.SUCCESS r['message'] = '{0} has left {1}'.format(userInfo.name, groupInfo.name) else: r['status'] = self.NOT_MEMBER r['message'] = '{0} is not a member {1}'.format(userInfo.name, groupInfo.name) r['groupId'] = data['groupId'] r['userId'] = data['userId'] retval = to_json(r) return retval
def groups(siteInfo, userInfo): groupsFolder = getattr(siteInfo.siteObj, 'groups') groups = [folder for folder in groupsFolder.objectValues(FOLDER_TYPES) if folder.getProperty('is_group', False)] retval = [group.getId() for group in groups if user_member_of_group(userInfo, group)] retval.sort() return retval
def process(self, data): """Attempt to invite a user to join a group based on the provided data. :param dict data: The data submitted to the form, assumed to be data used to invite a person to a group :returns: If successful, a 2-tuple of ``(status_code, userInfo)`` containing a status code indicating the result of processing the invite and an IGSUserInfo instance :rtype: tuple""" userInfo = None acl_users = self.context.acl_users toAddr = sanitise_address(data['toAddr']) emailChecker = NewEmailAddress(title='Email') emailChecker.context = self.context try: emailChecker.validate(toAddr) # Can handle a full address except EmailAddressExists: user = acl_users.get_userByEmail(toAddr) # Cannot assert user, 'User for address <%s> not found' % toAddr userInfo = IGSUserInfo(user) auditor, inviter = self.get_auditor_inviter(userInfo) if user_member_of_group(user, self.groupInfo): auditor.info(INVITE_EXISTING_MEMBER, toAddr) status_code = INVITE_EXISTING_MEMBER else: inviteId = inviter.create_invitation(data, False) auditor.info(INVITE_OLD_USER, toAddr) # TODO: a DMARC lookup on the From. If there is DMARC on # then construct a From from the support-email and the # group-administrator's name inviter.send_notification(data['subject'], data['message'], inviteId, data['fromAddr']) # No to-addr self.set_delivery(userInfo, data['delivery']) status_code = INVITE_OLD_USER else: # Email address does not exist, but it is a legitimate address user = create_user_from_email(self.context, toAddr) userInfo = IGSUserInfo(user) self.add_profile_attributes(userInfo, data) auditor, inviter = self.get_auditor_inviter(userInfo) inviteId = inviter.create_invitation(data, True) auditor.info(INVITE_NEW_USER, toAddr) inviter.send_notification(data['subject'], data['message'], inviteId, data['fromAddr'], toAddr) # Note the to-addr self.set_delivery(userInfo, data['delivery']) status_code = INVITE_NEW_USER assert status_code assert user, 'User not created or found' return (status_code, userInfo)
def can_confirm(addr, confirmationInfo): retval = ( bool(confirmationInfo) and (not confirmationInfo.hasResponse) and (confirmationInfo.email == addr) and not (user_member_of_group(confirmationInfo.userInfo, confirmationInfo.groupInfo))) assert type(retval) == bool return retval
def accept(self, userInfo): self.requestQuery.accept_request(userInfo.id, self.groupInfo.id, self.adminInfo.id) if user_member_of_group(userInfo, self.groupInfo): retval = '%s is already a member of the group, so '\ 'the request was ignored.' % userInfo_to_anchor(userInfo) else: joiningUser = IGSJoiningUser(userInfo) joiningUser.silent_join(self.groupInfo) retval = 'Accepted the request from %s' % userInfo_to_anchor(userInfo) return retval
def nonMembers(self): '''Get the members of the current site that are not a member of the group, and who have an email address.''' # OPTIMIZE: This could *mostly* be done with lists of IDs retval = [ EmailUser(self.context, ui) for ui in self.siteMembers.members if ((not user_member_of_group(ui, self.groupInfo)) and self.has_addr(ui)) ] retval.sort(key=lambda eu: eu.userInfo.name) assert type(retval) == list return retval
def subscribe(self, userInfo, email, request): assert self.groupVisibility.isPublicToSite siteInfo = self.groupInfo.siteInfo if ((not userInfo) or (not user_member_of_site(userInfo, siteInfo))): m = _('public-site-group-cannot-join', 'Only members of ${siteName} can join ${groupName}.', mapping={'siteName': siteInfo.name, 'groupName': self.groupInfo.name}) msg = translate(m) raise CannotJoin(msg) elif user_member_of_group(userInfo, self.groupInfo): raise GroupMember() addr = parseaddr(email['From'])[1] self.send_confirmation(email, addr, userInfo, request)
def join(self, confirmationInfo, request): if user_member_of_group(confirmationInfo.userInfo, confirmationInfo.groupInfo): raise GroupMember('Already a member of the group') auditor = SubscribeAuditor( confirmationInfo.site, confirmationInfo.userInfo, confirmationInfo.groupInfo) auditor.info(CONFIRM) self.verify_address(confirmationInfo.userInfo, confirmationInfo.email) join(confirmationInfo.groupInfo.groupObj, request, confirmationInfo.userInfo, confirmationInfo.groupInfo) self.query.clear_confirmations(confirmationInfo.userInfo.id, confirmationInfo.groupInfo.id)
def handle_get_groups(self, action, data): '''The form action for the list of members and their groups :param action: The button that was clicked. :param dict data: The form data.''' usergroups = [] for userId in self.siteMembers.memberIds: userInfo = createObject('groupserver.UserFromId', self.context, userId) r = user_info(self.siteInfo, userInfo) r['email'] = email_info(self.siteInfo, userInfo) # So the list of groups is cached r['groups'] = [group.getId() for group in self.groups if user_member_of_group(userInfo, group)] usergroups.append(r) retval = to_json(usergroups) return retval
def process(self, email, request): 'Process the email command ``digest``' components = self.get_command_components(email) if components[0] != 'digest': m = 'Not a digest command: {0}'.format(email['Subject']) raise ValueError(m) retval = CommandResult.notACommand addr = self.get_addr(email) userInfo = self.get_userInfo(addr) if ((len(components) == 2) and (userInfo is not None) and user_member_of_group(userInfo, self.group)): subcommand = components[1].lower() if (subcommand in ('on', 'off')): retval = CommandResult.commandStop auditor = SettingsAuditor( self.context, userInfo, userInfo, # Editing self self.groupInfo) if subcommand == 'on': auditor.info(DIGEST_COMMAND, addr) self.digest_on(userInfo) auditor.info(DIGEST) notifier = DigestOnNotifier(self.group, request) else: # 'off' auditor.info(EMAIL_COMMAND, addr) self.digest_off(userInfo) auditor.info(EMAIL) notifier = DigestOffNotifier(self.group, request) assert notifier, 'notifier not set.' notifier.notify(userInfo) # --=mpj17=-- If there is no extra parameter to "digest", or there # is no user for the From address in the email, or the user lacks # group membership then the message will be treated as a *normal* # *email*. This will almost certainly result in a "Not a member" # email going out, unless self.group is a support group. Confused? # Welcome to reality. assert isinstance(retval, CommandResult), \ 'retval not a command result' return retval
def process(self, email, request): 'Process the email command ``digest``' components = self.get_command_components(email) if components[0] != 'digest': m = 'Not a digest command: {0}'.format(email['Subject']) raise ValueError(m) retval = CommandResult.notACommand addr = self.get_addr(email) userInfo = self.get_userInfo(addr) if ((len(components) == 2) and (userInfo is not None) and user_member_of_group(userInfo, self.group)): subcommand = components[1].lower() if (subcommand in ('on', 'off')): retval = CommandResult.commandStop auditor = SettingsAuditor(self.context, userInfo, userInfo, # Editing self self.groupInfo) if subcommand == 'on': auditor.info(DIGEST_COMMAND, addr) self.digest_on(userInfo) auditor.info(DIGEST) notifier = DigestOnNotifier(self.group, request) else: # 'off' auditor.info(EMAIL_COMMAND, addr) self.digest_off(userInfo) auditor.info(EMAIL) notifier = DigestOffNotifier(self.group, request) assert notifier, 'notifier not set.' notifier.notify(userInfo) # --=mpj17=-- If there is no extra parameter to "digest", or there # is no user for the From address in the email, or the user lacks # group membership then the message will be treated as a *normal* # *email*. This will almost certainly result in a "Not a member" # email going out, unless self.group is a support group. Confused? # Welcome to reality. assert isinstance(retval, CommandResult), \ 'retval not a command result' return retval
def show(self): '''Determine if the group should be shown to the person. The group membership if tested three times, tested three times, tested three times because over time (and messing about with the ZMI) the group-membership info can be a become messed up. The ``show`` property is ``True`` iff the user is listed as a group member, the group is listed on the user-object, and the user has the correct role in the group.''' user = self.userInfo.user userGroups = user.getGroups() acl_users = user.site_root().acl_users userGroupId = member_id(self.groupObj.getId()) try: userGroup = acl_users.getGroupById(userGroupId) except KeyError: log.error('No user-group for %s', self.groupObj.getId()) return False groupUsers = userGroup.getUsers() retval = ((userGroupId in userGroups) and (self.userInfo.id in groupUsers) and user_member_of_group(self.userInfo, self.groupObj)) return retval
def isMember(self): # Deliberately not an @Lazy property (the membership will change). retval = user_member_of_group(self.userInfo, self.groupInfo) return retval
def isMember(self): # --=mpj17=-- Cut 'n' paste software engineering from # gs.group.member.viewlet.member.GroupMemberViewlet retval = ((not self.loggedInUser.anonymous) and user_member_of_group(self.loggedInUser, self.groupInfo)) return retval
def isMember(self): retval = ((not self.loggedInUser.anonymous) and user_member_of_group(self.loggedInUser, self.groupInfo)) return retval
def isMember(self): return user_member_of_group(self.loggedInUser, self.groupInfo)
def groups(self): retval = [g for g in self.get_all_groups() if user_member_of_group(self.loggedInUser, g)] return retval
def isMember(self): retval = user_member_of_group(self.userInfo, self.groupInfo) return retval
def member_group(self, g): '''Append a ``member`` property to the group''' g.member = user_member_of_group(self.loggedInUser, g) return g