Ejemplo n.º 1
0
 def testGetForEmail_TestAccounts(self):
   self.mox.stubs.Set(users, '_EmailToGaeUserId', {}.get)
   # Accounts under ".test" should get their uids from the e-mail address.
   self.assertEquals('test1', users.GetForEmail('*****@*****.**').id)
   self.assertEquals('agablaga', users.GetForEmail('*****@*****.**').id)
   # User entities should have been stored as a side effect.
   self.assertEquals('*****@*****.**', users.Get('test1').email)
   self.assertEquals('*****@*****.**', users.Get('agablaga').email)
Ejemplo n.º 2
0
 def testGetForEmail_NonexistentGoogleAccounts(self):
     self.mox.stubs.Set(users, '_EmailToGaeUserId', {}.get)
     # Normal e-mail addresses should allocate uids sequentially.
     self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
     self.assertEquals('2', users.GetForEmail('*****@*****.**').id)
     # For an e-mail address we've seen before, we should get the matching User.
     self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
     # User entities should have been stored as a side effect.
     self.assertEquals('*****@*****.**', users.Get('1').email)
     self.assertEquals('*****@*****.**', users.Get('2').email)
Ejemplo n.º 3
0
 def testGetCurrent_AfterGetForEmailWithExistingGoogleAccount(self):
   self.mox.stubs.Set(users, '_EmailToGaeUserId', {
       '*****@*****.**': '123456789',
       '*****@*****.**': '123456789'
   }.get)
   # Introduce an e-mail address that's new to us but has a Google Account.
   # GetForEmail should associate the address with the Google Account.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
   # A sign-in with that Google Account ID should get the same UserModel,
   # even if the e-mail address is different.
   with test_utils.EnvContext(USER_ID='123456789',
                              USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
   # Any other e-mail address associated with the same Google Account should
   # yield the same UserModel.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
Ejemplo n.º 4
0
 def AddNewUserIfPresent(self, inputs, domain):
     """Grants domain roles to a new user."""
     new_email = inputs.pop('new_user').strip()
     new_role = inputs.pop('new_user.permission')
     if not new_email or not new_role:
         return
     if not utils.IsValidEmail(new_email):
         raise base_handler.Error(400,
                                  'Invalid e-mail address: %r.' % new_email)
     user = users.GetForEmail(new_email)
     perms.Grant(user.id, new_role, domain)
Ejemplo n.º 5
0
 def testGetCurrent_AfterGetForEmailWithNonexistentGoogleAccount(self):
   self.mox.stubs.Set(users, '_EmailToGaeUserId', {}.get)
   # Introduce a previously unseen e-mail address.
   self.assertEquals('1', users.GetForEmail('*****@*****.**').id)
   # A sign-in with that e-mail address should associate the Google Account.
   with test_utils.EnvContext(USER_ID='123456789', USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
   # Subsequent sign-ins with the same Google Account ID should also hook up.
   with test_utils.EnvContext(USER_ID='123456789',
                              USER_EMAIL='*****@*****.**'):
     self.assertEquals('1', users.GetCurrent().id)
Ejemplo n.º 6
0
    def Post(self, map_id, domain=None):  # pylint: disable=unused-argument
        """Adds the recipient to the appropriate permission areas."""
        map_object = model.Map.Get(map_id)
        if map_object is None:
            raise base_handler.Error(404, 'Map %r not found.' % map_id)
        role = self.request.get('role')
        recipient_email = self.request.get('recipient')
        message = self.request.get('message', '')

        # If these are empty or invalid, we shouldn't try to do anything.
        if role not in SHARING_ROLES:
            raise base_handler.Error(400, 'Invalid role parameter: %r.' % role)
        if not utils.IsValidEmail(recipient_email):
            raise base_handler.Error(
                400, 'Invalid e-mail address: %r.' % recipient_email)

        # Change the recipient's permission level as specified.
        recipient = users.GetForEmail(recipient_email)
        map_object.ChangePermissionLevel(role, recipient.id)
        # Send the recipient an email.
        self.SendPermissionChangeEmail(recipient_email, map_object, role,
                                       message)
        self.response.set_status(201)
Ejemplo n.º 7
0
def EmailToUid(email):
    if email:
        if email not in uids_by_email:
            uids_by_email[email] = users.GetForEmail(email).id
        return uids_by_email[email]