|  | @@ -7,7 +7,8 @@ from tracim.models.context_models import UserRoleWorkspaceInContext
 | 
	
		
			
			| 7 | 7 |  __author__ = 'damien'
 | 
	
		
			
			| 8 | 8 |  
 | 
	
		
			
			| 9 | 9 |  from sqlalchemy.orm import Session
 | 
	
		
			
			| 10 |  | -from tracim.models.auth import User, Group
 | 
	
		
			
			|  | 10 | +from sqlalchemy.orm import Query
 | 
	
		
			
			|  | 11 | +from tracim.models.auth import User
 | 
	
		
			
			| 11 | 12 |  from tracim.models.data import Workspace
 | 
	
		
			
			| 12 | 13 |  from tracim.models.data import UserRoleInWorkspace
 | 
	
		
			
			| 13 | 14 |  from tracim.models.data import RoleType
 | 
	
	
		
			
			|  | @@ -73,15 +74,17 @@ class RoleApi(object):
 | 
	
		
			
			| 73 | 74 |  
 | 
	
		
			
			| 74 | 75 |          return role
 | 
	
		
			
			| 75 | 76 |  
 | 
	
		
			
			| 76 |  | -    def __init__(self,
 | 
	
		
			
			| 77 |  | -                 session: Session,
 | 
	
		
			
			| 78 |  | -                 current_user: typing.Optional[User],
 | 
	
		
			
			| 79 |  | -                 config: CFG):
 | 
	
		
			
			|  | 77 | +    def __init__(
 | 
	
		
			
			|  | 78 | +        self,
 | 
	
		
			
			|  | 79 | +        session: Session,
 | 
	
		
			
			|  | 80 | +        current_user: typing.Optional[User],
 | 
	
		
			
			|  | 81 | +        config: CFG,
 | 
	
		
			
			|  | 82 | +    )-> None:
 | 
	
		
			
			| 80 | 83 |          self._session = session
 | 
	
		
			
			| 81 | 84 |          self._user = current_user
 | 
	
		
			
			| 82 | 85 |          self._config = config
 | 
	
		
			
			| 83 | 86 |  
 | 
	
		
			
			| 84 |  | -    def _get_one_rsc(self, user_id, workspace_id):
 | 
	
		
			
			|  | 87 | +    def _get_one_rsc(self, user_id: int, workspace_id: int) -> Query:
 | 
	
		
			
			| 85 | 88 |          """
 | 
	
		
			
			| 86 | 89 |          :param user_id:
 | 
	
		
			
			| 87 | 90 |          :param workspace_id:
 | 
	
	
		
			
			|  | @@ -91,16 +94,16 @@ class RoleApi(object):
 | 
	
		
			
			| 91 | 94 |              filter(UserRoleInWorkspace.workspace_id == workspace_id).\
 | 
	
		
			
			| 92 | 95 |              filter(UserRoleInWorkspace.user_id == user_id)
 | 
	
		
			
			| 93 | 96 |  
 | 
	
		
			
			| 94 |  | -    def get_one(self, user_id, workspace_id):
 | 
	
		
			
			|  | 97 | +    def get_one(self, user_id: int, workspace_id: int) -> UserRoleInWorkspace:
 | 
	
		
			
			| 95 | 98 |          return self._get_one_rsc(user_id, workspace_id).one()
 | 
	
		
			
			| 96 | 99 |  
 | 
	
		
			
			| 97 | 100 |      def create_one(
 | 
	
		
			
			| 98 |  | -            self,
 | 
	
		
			
			| 99 |  | -            user: User,
 | 
	
		
			
			| 100 |  | -            workspace: Workspace,
 | 
	
		
			
			| 101 |  | -            role_level: int,
 | 
	
		
			
			| 102 |  | -            with_notif: bool,
 | 
	
		
			
			| 103 |  | -            flush: bool=True
 | 
	
		
			
			|  | 101 | +        self,
 | 
	
		
			
			|  | 102 | +        user: User,
 | 
	
		
			
			|  | 103 | +        workspace: Workspace,
 | 
	
		
			
			|  | 104 | +        role_level: int,
 | 
	
		
			
			|  | 105 | +        with_notif: bool,
 | 
	
		
			
			|  | 106 | +        flush: bool=True
 | 
	
		
			
			| 104 | 107 |      ) -> UserRoleInWorkspace:
 | 
	
		
			
			| 105 | 108 |          role = self.create_role()
 | 
	
		
			
			| 106 | 109 |          role.user_id = user.user_id
 | 
	
	
		
			
			|  | @@ -111,34 +114,38 @@ class RoleApi(object):
 | 
	
		
			
			| 111 | 114 |              self._session.flush()
 | 
	
		
			
			| 112 | 115 |          return role
 | 
	
		
			
			| 113 | 116 |  
 | 
	
		
			
			| 114 |  | -    def delete_one(self, user_id, workspace_id, flush=True):
 | 
	
		
			
			|  | 117 | +    def delete_one(self, user_id: int, workspace_id: int, flush=True) -> None:
 | 
	
		
			
			| 115 | 118 |          self._get_one_rsc(user_id, workspace_id).delete()
 | 
	
		
			
			| 116 | 119 |          if flush:
 | 
	
		
			
			| 117 | 120 |              self._session.flush()
 | 
	
		
			
			| 118 | 121 |  
 | 
	
		
			
			| 119 |  | -    def _get_all_for_user(self, user_id):
 | 
	
		
			
			|  | 122 | +    def _get_all_for_user(self, user_id) -> typing.List[UserRoleInWorkspace]:
 | 
	
		
			
			| 120 | 123 |          return self._session.query(UserRoleInWorkspace)\
 | 
	
		
			
			| 121 | 124 |              .filter(UserRoleInWorkspace.user_id == user_id)
 | 
	
		
			
			| 122 | 125 |  
 | 
	
		
			
			| 123 |  | -    def get_all_for_user(self, user: User):
 | 
	
		
			
			|  | 126 | +    def get_all_for_user(self, user: User) -> typing.List[UserRoleInWorkspace]:
 | 
	
		
			
			| 124 | 127 |          return self._get_all_for_user(user.user_id).all()
 | 
	
		
			
			| 125 | 128 |  
 | 
	
		
			
			| 126 | 129 |      def get_all_for_user_order_by_workspace(
 | 
	
		
			
			| 127 |  | -            self,
 | 
	
		
			
			| 128 |  | -            user_id: int
 | 
	
		
			
			| 129 |  | -    ) -> UserRoleInWorkspace:
 | 
	
		
			
			|  | 130 | +        self,
 | 
	
		
			
			|  | 131 | +        user_id: int
 | 
	
		
			
			|  | 132 | +    ) -> typing.List[UserRoleInWorkspace]:
 | 
	
		
			
			| 130 | 133 |          return self._get_all_for_user(user_id)\
 | 
	
		
			
			| 131 | 134 |              .join(UserRoleInWorkspace.workspace).order_by(Workspace.label).all()
 | 
	
		
			
			| 132 | 135 |  
 | 
	
		
			
			| 133 |  | -    def get_all_for_workspace(self, workspace:Workspace):
 | 
	
		
			
			|  | 136 | +    def get_all_for_workspace(
 | 
	
		
			
			|  | 137 | +        self,
 | 
	
		
			
			|  | 138 | +        workspace:Workspace
 | 
	
		
			
			|  | 139 | +    ) -> typing.List[UserRoleInWorkspace]:
 | 
	
		
			
			| 134 | 140 |          return self._session.query(UserRoleInWorkspace)\
 | 
	
		
			
			| 135 | 141 |              .filter(UserRoleInWorkspace.workspace_id == workspace.workspace_id).all()  # nopep8
 | 
	
		
			
			| 136 | 142 |  
 | 
	
		
			
			| 137 |  | -    def save(self, role: UserRoleInWorkspace):
 | 
	
		
			
			|  | 143 | +    def save(self, role: UserRoleInWorkspace) -> None:
 | 
	
		
			
			| 138 | 144 |          self._session.flush()
 | 
	
		
			
			| 139 | 145 |  
 | 
	
		
			
			|  | 146 | +    # TODO - G.M - 07-06-2018 - [Cleanup] Check if this method is already needed
 | 
	
		
			
			| 140 | 147 |      @classmethod
 | 
	
		
			
			| 141 |  | -    def get_roles_for_select_field(cls):
 | 
	
		
			
			|  | 148 | +    def get_roles_for_select_field(cls) -> typing.List[RoleType]:
 | 
	
		
			
			| 142 | 149 |          """
 | 
	
		
			
			| 143 | 150 |  
 | 
	
		
			
			| 144 | 151 |          :return: list of DictLikeClass instances representing available Roles
 |