def test_odd_userGroups(self, m_log): '''Test the odd case where a person has the ``GroupMember`` role, but the group is absent from the list of groups for the member.''' user = self.user(['GroupMember', ], ['other_member', ]) group = self.group('example') r = user_member_of_group(user, group) self.assertTrue(r) self.assertEqual(1, m_log.warn.call_count, 'Failed to raise a warning')
def test_odd_not_userGroups(self, m_log): '''Test the odd case where a person lacks the ``GroupMember`` role, but the group is in the list of groups for the member.''' user = self.user([], ['example_member', ]) group = self.group('example') r = user_member_of_group(user, group) self.assertFalse(r) self.assertEqual(1, m_log.warn.call_count, 'Failed to raise a warning')
def user_is_member(self): '''A user is a member of the group if the the user has the member role in the group context. While this may sound like I am stating the blindingly obvious, this was not always the case! ''' retval = user_member_of_group(self.userInfo, self.groupInfo) if retval: self.__status = u'a member' else: self.__status = u'not a member' self.__statusNum = 8 assert type(self.__status) == unicode assert type(retval) == bool 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 accept_invitations(self, groupInfos): assert type(groupInfos) == list gids = [g.id for g in groupInfos] acceptedInvites = [i for i in self.currentInvitations if (i.groupInfo.id in gids)] # Skip groups already member auditor = Auditor(self.siteInfo, self.userInfo) for acceptedInvite in acceptedInvites: acceptedInvite.accept() auditor.info(INVITE_RESPOND, acceptedInvite.groupInfo, acceptedInvite.adminInfo, INVITE_RESPOND_ACCEPT) groupInfo = acceptedInvite.groupInfo if not(user_member_of_group(self.userInfo, groupInfo)): join_group(acceptedInvite, self.request)
def check(self): if not self.s['checked']: if user_member_of_group(self.userInfo, self.groupInfo): self.s['canPost'] = True self.s['status'] = u'a member.' self.s['statusNum'] = 0 else: self.s['canPost'] = False self.s['status'] = u'not a member.' self.s['statusNum'] = self.weight self.s['checked'] = True assert self.s['checked'] assert type(self.s['canPost']) == bool assert type(self.s['status']) == unicode assert type(self.s['statusNum']) == int
def accept_invitations(self, groupInfos): assert type(groupInfos) == list gids = [g.id for g in groupInfos] acceptedInvites = [ i for i in self.currentInvitations if (i.groupInfo.id in gids) ] # Skip groups already member auditor = Auditor(self.siteInfo, self.userInfo) for acceptedInvite in acceptedInvites: acceptedInvite.accept() auditor.info(INVITE_RESPOND, acceptedInvite.groupInfo, acceptedInvite.adminInfo, INVITE_RESPOND_ACCEPT) groupInfo = acceptedInvite.groupInfo if not (user_member_of_group(self.userInfo, groupInfo)): join_group(acceptedInvite, self.request)
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 handle_accept(self, action, data): if self.invitationId != 'example': auditor = Auditor(self.siteInfo, self.userInfo) auditor.info(INVITE_RESPOND, self.invitation.groupInfo, self.invitation.adminInfo, INVITE_RESPOND_ACCEPT) self.verify_email_address() pu = IGSPasswordUser(self.userInfo) pu.set_password(data['password1']) self.invitation.accept() if not (user_member_of_group(self.userInfo, self.groupInfo)): join_group(self.invitation, self.request) uri = '%s?welcome=1' % self.groupInfo.relativeURL self.request.RESPONSE.redirect(uri)
def handle_accept(self, action, data): if self.invitationId != 'example': auditor = Auditor(self.siteInfo, self.userInfo) auditor.info(INVITE_RESPOND, self.invitation.groupInfo, self.invitation.adminInfo, INVITE_RESPOND_ACCEPT) self.verify_email_address() pu = IGSPasswordUser(self.userInfo) pu.set_password(data['password1']) self.invitation.accept() if not(user_member_of_group(self.userInfo, self.groupInfo)): join_group(self.invitation, self.request) uri = '%s?welcome=1' % self.groupInfo.relativeURL self.request.RESPONSE.redirect(uri)
def test_non_member(self): user = self.user([], ['other_member', ]) group = self.group('example') r = user_member_of_group(user, group) self.assertFalse(r)
def test_is_member(self): user = self.user(['GroupMember', ], ['example_member', ]) group = self.group('example') r = user_member_of_group(user, group) self.assertTrue(r)
def isMember(self): retval = user_member_of_group(self.userInfo, self.context) return retval