示例#1
0
    def testGrantAccessToOtherUser(self):
        ownerUser, shoppingList = self._createShoppingList()
        sharingUserEmail = '*****@*****.**'
        sharingUser = UserApi.UserApi.create(sharingUserEmail, 'asdfqwer')
        shoppingList = ShoppingListApi.ShoppingListApi.grantUserAccess(
            shoppingList, sharingUserEmail, ownerUser.id)

        self.assertEquals(1, len(shoppingList.allowed))
        self.assertEquals(
            Models.AllowedListUser(userId=sharingUser.id,
                                   username=sharingUser.email),
            shoppingList.allowed[0])
示例#2
0
 def grantUserAccess(cls, shoppingList: Models.ShoppingList,
                     emailAddress: str,
                     requestingId: str) -> Models.ShoppingList:
     if requestingId != shoppingList.owner:
         raise ApiExceptions.ForbiddenException
     userToAdd = UserApi.UserApi.getByUsername(emailAddress)
     if userToAdd is None:
         raise ApiExceptions.NotFoundException
     allowedUsers = shoppingList.allowed or []
     allowedUser: Models.AllowedListUser
     mappedIds = [allowedUser.userId for allowedUser in allowedUsers]
     if userToAdd.id not in mappedIds:
         allowedUser = Models.AllowedListUser(userId=userToAdd.id,
                                              username=userToAdd.email)
         allowedUsers.append(allowedUser)
         shoppingList.allowed = allowedUsers
         shoppingList.save()
         owner = Models.User.getById(shoppingList.owner)
         EmailSender.EmailSender.sendSharedShoppingList(
             emailAddress, owner.email, shoppingList.id)
         return shoppingList
     return shoppingList