def _seed(self):
        location_service = self._get_service()
        user_service = UserFormService()
        user_service.session = self._get_session()

        manager = user_service.find_model(
            pairs={'email': '*****@*****.**'})

        for location in locations:
            current_location = location_service.find_model(
                pairs={'google_map_id': location['google_map_id']})
            if current_location:
                location_service.update_model(_id=current_location.id,
                                              manager=manager)
Example #2
0
 def __create_meeting(self, *args, **kwargs):
     creator_id = kwargs.get('creator_id', 0)
     attendees = kwargs.pop('attendees', [])
     user_service = UserFormService()
     if creator_id:
         creator = user_service.get_model(_id=creator_id)
         attendees_creator = CreateMeetingAttendees()
         if creator:
             kwargs[
                 'associate_users'] = attendees_creator.create_associated_users(
                     creator_id, attendees)
             new_meeting = super().create_new_model(*args, **kwargs)
             self.commit()
             return new_meeting
         else:
             raise InvalidUserIdException()
 def create_attendees(self, attendees: list) -> list:
     meeting_users = list()
     user_service = UserFormService()
     for attendee in attendees:
         attendee_email = attendee.get('email', None)
         if attendee_email:
             user = user_service.find_model(pairs={'email': attendee_email})
             if user is None:
                 user = user_service.create_new_model(email=attendee_email,
                                                      is_activated=False)
                 user_service.session.commit()
             meeting_user = self._form_attendee(user_id=user.id,
                                                is_accepted=attendee.get('is_accepted', False),
                                                may_join=attendee.get('may_join', False))
             meeting_users.append(meeting_user)
     return meeting_users
Example #4
0
class AuthenticatedDecorator(BaseDecorator, ABC):
    def __init__(self):
        super().__init__()
        self._auth_user = None
        self.__user_service = UserFormService()

    def get_authenticated_user(self) -> User:
        """
        Get the user that uses this service. Retrieve data from Resource's authentication
        :return: User, raise Exception if self.__auth_user is None
        """
        if self._auth_user:
            return self._auth_user
        raise UnauthenticatedServiceLoginException()

    def set_authenticated_user(self, auth_user_id: dict):
        self._auth_user = self.__user_service.get_model(_id=auth_user_id)

    def _prepare_auth_service(self):
        """
        If decorator's delegated service is an instance of AuthenticatedDecorator, set auth_user for that service.
        :return:
        """
        service = self._get_service()
        if isinstance(service, AuthenticatedDecorator):
            service._auth_user = self._auth_user
            self.set_service(service)

    def update_model(self, *args, **kwargs) -> bool:
        self._prepare_auth_service()
        return super(AuthenticatedDecorator,
                     self).update_model(*args, **kwargs)

    def create_new_model(self, *args, **kwargs) -> Model:
        self._prepare_auth_service()
        return super(AuthenticatedDecorator,
                     self).create_new_model(*args, **kwargs)

    def delete_model(self, *args, **kwargs) -> bool:
        self._prepare_auth_service()
        return super(AuthenticatedDecorator,
                     self).delete_model(*args, **kwargs)
 def _retrieve_authenticated_user(self, user_id: int) -> User:
     user_service = self._prepared_service(base_service=UserFormService())
     auth_user = user_service.get_model(_id=user_id)
     if isinstance(auth_user, User):
         return auth_user
 def _create_service(self) -> BaseService:
     return UserFormService()
Example #7
0
 def _create_form_service(self) -> FormService:
     return UserFormService()
Example #8
0
 def __init__(self):
     super().__init__()
     self._auth_user = None
     self.__user_service = UserFormService()