示例#1
0
    def test_user_creation(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create a folder for covalent-members:
        members = helpers.create_memberfolder(self.portal)

        # create a user:
        utilities.add_member_object(members, member_id='m1',
            fullname=u"Hörbert M@ier", email="*****@*****.**")
        self.assertIn('m1', members)

        m1 = members['m1']
        message = self.mailhost.messages[0]
        expectedMessageText = '\n'.join([
            "Hello H=C3=B6rbert M@ier!",
            '',
            "Please follow this link to activate your account on Plone site:",
            m1.absolute_url() + '/activate?activation_code=3D' + m1.activation_code,
            '', '', ])

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'], u'Hörbert M[at]ier <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']),
            u"You've been invited to Plone site")
        self.assertEqual(message.get_payload(), expectedMessageText)
    def test_user_creation(self):
        """
        Test user creation by Site Admin with automatic approval.
        """

        setRoles(self.portal, TEST_USER_ID, ('Site Administrator',))

        # create a folder for covalent-members:
        members = helpers.create_memberfolder(self.portal)

        # create a user:
        utilities.add_member_object(members, member_id='m2',
            fullname=u"Ilse Pambrowski", email="*****@*****.**")
        self.assertIn('m2', members)

        member = members['m2']

        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(member, 'review_state'), 'pending')
        self.assertEqual(member.title, u"Ilse Pambrowski")
        self.assertEqual(member.emailAddress, "*****@*****.**")

        message = self.mailhost.messages[0]

        expectedMessageTpl = """Hello {name}!

You have been invited to the {site_title} site.

Please follow this link to activate your account on the {site_title} site:

{url}/activate?activation_code={activation_code}

This activation link is valid for {activation_period} days.

Your username is: {userId}

"""
        registry = getUtility(IRegistry)
        activation_period = registry['cnrd.vctypes.memberActivationTimeout']

        tplParams = {
            'url': member.absolute_url(),
            'activation_code': member.activation_code,
            'activation_period': activation_period,
            'userId': 'm2',
            'site_title': 'Plone site',
            'name': 'Ilse Pambrowski'
        }
        expectedMessageText = expectedMessageTpl.format(**tplParams)

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'], u'Ilse Pambrowski <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']),
            u"You've been invited to Plone site")
        self.assertEqual(message.get_payload(None, True), expectedMessageText)
    def test_user_self_registration(self):
        """
        Test user self registration by anonymous user.
        """

        # create a folder for covalent-members (temporarily become Manager):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))
        members = helpers.create_memberfolder(self.portal)

        # create a user (become Anonymous):
        setRoles(self.portal, TEST_USER_ID, ('Anonymous', 'Registrator'))
        utilities.add_member_object(members, member_id='m1',
            fullname=u"Hörbert M@ier", email="*****@*****.**")
        self.assertIn('m1', members)

        member = members['m1']

        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(member, 'review_state'), 'new')
        self.assertEqual(member.title, u"Hörbert M@ier")
        self.assertEqual(member.emailAddress, "*****@*****.**")

        message = self.mailhost.messages[0]

        expectedMessageTpl = """Hello!

{name} registered with username {userId} for the {site_title} site.

Please follow this link to review the new user: {expectedMemberUrl}

The membership of {name} has to be approved before he/she can start using the site.

You are receiving this e-mail because you are registered as site administrator of the {site_title} site.
"""

        tplParams = {
            'expectedMemberUrl': member.absolute_url(),
            'userId': 'm1',
            'site_title': 'Plone site',
            'name': 'Hörbert M@ier'
        }
        expectedMessageText = expectedMessageTpl.format(**tplParams)

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'], u' <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']),
            u"Please approve or reject new member Hörbert M@ier")
        self.assertEqual(message.get_payload(None, True), expectedMessageText)
    def test_user_activation(self):
        login(self.portal, testing.SITE_ADMIN)

        members = self.portal['people']

        # create a user:
        member = utilities.add_member_object(members, member_id='member',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        logout()

        password = '******'
        utilities.add_plone_member(member, password)
        utilities.activate_member_object(member)

        plone_member = self.portal.acl_users.authenticate(member.id, password,
            self.portal.REQUEST)
        self.assertNotEqual(plone_member, None)

        portal_membership = getToolByName(self.portal, 'portal_membership')
        plone_member = portal_membership.getMemberById(member.id)
        self.assertNotEqual(plone_member, None)

        self.assertEqual(unicode(plone_member.getProperty('fullname'), 'utf-8'),
            member.title)
        self.assertEqual(plone_member.getProperty('email'), member.emailAddress)

        login(self.portal, member.id)
    def test_user_activation(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create a folder for covalent-members:
        members = helpers.create_memberfolder(self.portal)

        # create a user:
        member = utilities.add_member_object(members, member_id='member',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        logout()

        password = '******'
        utilities.add_plone_member(member, 'secret')
        utilities.activate_member_object(member)

        plone_member = self.portal.acl_users.authenticate(member.id, password,
            self.portal.REQUEST)
        self.assertEqual(plone_member.getId(), member.id)

        portal_membership = getToolByName(self.portal, 'portal_membership')
        plone_member = portal_membership.getMemberById(member.id)
        self.assertEqual(plone_member.getId(), member.id)

        self.assertEqual(unicode(plone_member.getProperty('fullname'), 'utf-8'),
            member.title)
        self.assertEqual(plone_member.getProperty('email'), member.emailAddress)

        login(self.portal, member.id)
示例#6
0
def add_pending_cnrd_member(people_folder, name, role, uid=None, email=None):

    if uid is None:
        uid = utilities.find_possible_id(name)
    if email is None:
        email = uid + "@testing.meelogic.com"
    member = covalent_utils.add_member_object(people_folder, uid, name, email)
    member.role = role
    modified(member)
    covalent_utils.auto_approve_member_object(member)
    return member
示例#7
0
def add_activated_cnrd_member(people_folder, name, role, uid=None, email=None,
                              password='******'):
    if uid is None:
        uid = utilities.find_possible_id(name)
    if email is None:
        email = uid + "@testing.ixds.com"
    member = covalent_utils.add_member_object(people_folder, uid, name, email)
    member.role = role
    modified(member)
    covalent_utils.add_plone_member(member, password)
    covalent_utils.activate_member_object(member)
    return member
示例#8
0
    def test_get_member_by_id(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create a folder for covalent-members:
        members = helpers.create_memberfolder(self.portal)

        # create a user:
        member = utilities.add_member_object(members, member_id='member',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        self.assertEqual(member, utilities.get_member_by_id(member.id))
        self.assertEqual(None, utilities.get_member_by_id('no_such_id'))
    def save(self, action):
        data, errors = self.extractData()

        captcha = getMultiAdapter(
            (aq_inner(self.context), self.request),
            name='recaptcha'
        )
        if not captcha.verify():
            raise ActionExecutionError(Invalid(_(u"You must verify that you are no robot.")))

        if errors:
            self.status = self.formErrorsMessage
            return

        mtool = getToolByName(self.context, 'portal_membership')
        if mtool.isAnonymousUser():
            # Anonymous has the id None
            userId = None
        else:
            currentUser = mtool.getAuthenticatedMember()
            userId = currentUser.getId()

        # Check if the current user has 'Registrator' rights
        roles = list(self.context.get_local_roles_for_userid(userId))
        isRegistrator = 'Registrator' in roles or 'Manager' in roles or 'Site Administrator' in roles
        if not isRegistrator:
            roles.append('Registrator')
            self.context.manage_setLocalRoles(userId, roles)

        urltool = getToolByName(self.context, 'portal_url')
        portal = urltool.getPortalObject()

        member_folder = portal['people']
        member = add_member_object(member_folder, data['id'], data['title'], data['emailAddress'])
        member.role = data['role']
        member.recieveNotifications = data['recieveNotifications']
        if data['description'] is not None:
            member.description = data['description']
        if data['portrait'] is not None:
            member.portrait = data['portrait']
        if data['university'] is not None:
            member.university = relatify(data['university'])

        confirm = _(u"Thank you! Your registration request has been received " +
                    u"and we will respond as soon as possible.")
        IStatusMessage(self.request).add(confirm, type='info')
        self.request.response.redirect(portal.absolute_url())
        return u''
    def test_edit_member(self):
        driver = self.driver
        pat.setRoles(self.portal, pat.TEST_USER_ID, ('Manager',))
        members = helpers.create_memberfolder(self.portal)
        member = utilities.add_member_object(members, member_id='m1',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        login(driver, self.portal, username=testing.SITE_ADMIN,
            password=testing.PASSWORD)
        open(driver, '/'.join([self.portal.absolute_url(), members.id, member.id, "edit"]))

        email = driver.find_element_by_id(
            "form-widgets-ICovalentMember-emailAddress")
        email.clear()
        email.send_keys("*****@*****.**")

        driver.find_element_by_id("form-buttons-save").click()
    def test_user_self_registration(self):
        """
        Test user self registration by anonymous user.
        """
        logout()

        # create a user
        member_folder = self.portal['people']
        member = utilities.add_member_object(member_folder, member_id='ilse',
            fullname=u"Ilse Pambrowski", email="*****@*****.**")
        self.assertIn('ilse', member_folder)
        member = member_folder['ilse']

        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(member, 'review_state'), 'new')
        self.assertEqual(member.title, u"Ilse Pambrowski")
        self.assertEqual(member.emailAddress, "*****@*****.**")

        message = self.mailhost.messages[-1]
        expectedMessageTpl = """Hello!

{name} registered with username {userId} for the {site_title} site.

Please follow this link to review the new user: {expectedMemberUrl}

The membership of {name} has to be approved before he/she can start using the site.

You are receiving this e-mail because you are registered as site administrator of the {site_title} site.
"""

        tplParams = {
            'expectedMemberUrl': member.absolute_url(),
            'userId': 'ilse',
            'site_title': 'Plone site',
            'name': 'Ilse Pambrowski'
        }
        expectedMessageText = expectedMessageTpl.format(**tplParams)

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'], u' <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']), u"Please approve or reject new member Ilse Pambrowski")
        self.assertEqual(message.get_payload(None, True), expectedMessageText)
示例#12
0
def add_cnrd_member(site, userId, last, first, email, password, portrait=None):
    context = site["people"]

    if userId in context:
        print "Couldn't add %s, a vc-member with this id already exists." % (id)
        return

    member_obj = add_member_object(context, userId, u"%s %s" % (first, last), email.strip(), sendInvitation=False)
    add_plone_member(member_obj, password)
    activate_member_object(member_obj)
    mark(context[userId], IDemoContent)

    if portrait:
        context[userId].portrait = portrait

    context[userId].role = "student"

    notify(ObjectModifiedEvent(context[userId]))
    def test_user_creation(self):
        login(self.portal, testing.MEMBER)

        member_folder = self.portal['people']

        # become the owner of member_folder temporarily
        original_sm = getSecurityManager()
        member_folder_owner = member_folder.getOwner().getId()
        become_portal_user(self.portal, member_folder_owner)

        # create a user
        member = utilities.add_member_object(member_folder, member_id='member',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        # become the normal user again
        setSecurityManager(original_sm)

        self.assertIn('member', member_folder)

        member = member_folder['member']
        message = self.mailhost.messages[-1]
        expectedMessageText = '\n'.join([
            "Hello H=C3=B6rbert M@ier!",
            '',
            "Please follow this link to activate your account on Plone site:",
            member.absolute_url() + '/activate?activation_code=3D' +
                member.activation_code,
            '', '', ])

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'],
            u'Hörbert M[at]ier <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']),
            u"You've been invited to Plone site")
        self.assertEqual(message.get_payload(), expectedMessageText)
    def test_user_role_assignments(self):
        login(self.portal, testing.SITE_ADMIN)
        members = self.portal['people']
        member = utilities.add_member_object(members, member_id='member',
            fullname=u"Hörbert M@ier", email="*****@*****.**")
        logout()
        password = '******'
        utilities.add_plone_member(member, password)
        utilities.activate_member_object(member)

        self.assertEqual(getattr(member, 'role', None), None)
        groups = get_group_ids_by_user_id(self.portal, member.id)
        self.assertEqual(groups, ['AuthenticatedUsers'])
        roles = get_roles_by_user_id(self.portal, member.id)
        self.assertEqual(roles, ['Authenticated'])

        member.role = 'student'
        modified(member)
        groups = get_group_ids_by_user_id(self.portal, member.id)
        self.assertEqual(groups, ['AuthenticatedUsers', 'Students'])
        roles = get_roles_by_user_id(self.portal, member.id)
        self.assertEqual(roles, ['Authenticated', 'Member', 'Student'])

        member.role = 'teacher'
        modified(member)
        groups = get_group_ids_by_user_id(self.portal, member.id)
        self.assertEqual(groups, ['AuthenticatedUsers', 'Teachers'])
        roles = get_roles_by_user_id(self.portal, member.id)
        self.assertEqual(roles, ['Authenticated', 'Member', 'Teacher'])

        member.role = 'extern'
        modified(member)
        groups = get_group_ids_by_user_id(self.portal, member.id)
        self.assertEqual(groups, ['AuthenticatedUsers', 'Externs'])
        roles = get_roles_by_user_id(self.portal, member.id)
        self.assertEqual(roles, ['Authenticated', 'Extern'])
    def test_user_creation(self):
        """
        Test user creation by Site Admin with automatic approval.
        """

        login(self.portal, testing.SITE_ADMIN)

        member_folder = self.portal['people']

        # become the owner of member_folder temporarily
        original_sm = getSecurityManager()
        member_folder_owner = member_folder.getOwner().getId()
        become_portal_user(self.portal, member_folder_owner)

        # create a user
        member = utilities.add_member_object(member_folder, member_id='herbert',
            fullname=u"Hörbert M@ier", email="*****@*****.**")

        # become the normal user again
        setSecurityManager(original_sm)

        self.assertIn('herbert', member_folder)

        member = member_folder['herbert']

        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(member, 'review_state'), 'pending')
        self.assertEqual(member.title, u"Hörbert M@ier")
        self.assertEqual(member.emailAddress, "*****@*****.**")

        message = self.mailhost.messages[-1]

        expectedMessageTpl = """Hello {name}!

You have been invited to the {site_title} site.

Please follow this link to activate your account on the {site_title} site:

{url}/activate?activation_code={activation_code}

This activation link is valid for {activation_period} days.

Your username is: {userId}

"""
        registry = getUtility(IRegistry)
        activation_period = registry['cnrd.vctypes.memberActivationTimeout']

        tplParams = {
            'url': member.absolute_url(),
            'activation_code': member.activation_code,
            'activation_period': activation_period,
            'userId': 'herbert',
            'site_title': 'Plone site',
            'name': 'Hörbert M@ier'
        }
        expectedMessageText = expectedMessageTpl.format(**tplParams)

        self.assertEqual(message.get_charset(), 'utf-8')
        self.assertIsInstance(message['To'], basestring)
        self.assertEqual(message['To'], u'Hörbert M[at]ier <*****@*****.**>')
        self.assertIsInstance(message['From'], basestring)
        self.assertEqual(message['From'], u'Plone site <>')
        self.assertEqual(unicode(message['Subject']), u"You've been invited to Plone site")
        self.assertEqual(message.get_payload(None, True), expectedMessageText)