Ejemplo n.º 1
0
 def new_user_role(self, role_id, user_id, location_id, email):
     user_role = UserRole(role_id=role_id,
                          user_id=user_id,
                          location_id=location_id,
                          email=email)
     user_role.save()
     return user_role
Ejemplo n.º 2
0
 def init_user_role(user: User, role: Role):
     """
     Create User and Role mapping
     :param user: User object
     :param role: Role object
     """
     UserRole.create(user, role)
Ejemplo n.º 3
0
 def new_user_role(self, role_id, user_id, location_id, email):
     user_role = UserRole(role_id=role_id,
                          user_id=user_id,
                          location_id=location_id,
                          email=email)
     user_role.save()
     self.update_cache(user_role)
     return user_role
Ejemplo n.º 4
0
 def new_user_role(self, role_id, user_id):
     user_role = UserRole(role_id=role_id,
                          user_id=user_id,
                          is_active=True,
                          is_deleted=False)
     user_role.save()
     # self.update_cache(user_role)
     return user_role
Ejemplo n.º 5
0
 def view_roles():
     """
     Display the roles associated with current logged in user
     """
     roles = UserRole.get_roles(User.logged_in_user)
     if not roles:
         Log.log('No roles associated', color='red')
         return
     for role in UserRole.get_roles(User.logged_in_user):
         Log.log(role.name, color='green')
Ejemplo n.º 6
0
 def setUp(self):
     self.BaseSetUp()
     self.mock_role = Role(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         name="Mock role",
         help="Mock help",
     )
     self.mock_user_role = UserRole(
         id=1,
         role_id=1,
         user_id=1,
         is_active=True,
         is_deleted=False,
         created_at=datetime.now(),
         updated_at=datetime.now(),
     )
     self.mock_user = User(
         id=1,
         first_name="test",
         last_name="test",
         gender="male",
         password="******",
         is_active=True,
         is_deleted=False,
         created_at=datetime.now(),
         updated_at=datetime.now(),
     )
 def setUp(self):
     self.BaseSetUp()
     self.mock_user_role = UserRole(id=1,
                                    created_at=datetime.now(),
                                    updated_at=datetime.now(),
                                    role_id=1,
                                    user_id=1,
                                    is_active=True)
Ejemplo n.º 8
0
 def has_access(user: User, resource_name: str, action_type_name: str):
     """
     Check if the giver user has access to perform the given action type on given resource
     :param user: User object
     :param resource_name: Resource name
     :param action_type_name: Action Type name
     :return: True if user has access otherwise False
     """
     for role in UserRole.get_roles(user):
         for resource in RoleResource.get_resources(role, action_type_name):
             if resource.name == resource_name:
                 return True
     return False
Ejemplo n.º 9
0
 def setUp(self):
     self.BaseSetUp()
     self.mock_role = Role(id=1,
                           created_at=datetime.now(),
                           updated_at=datetime.now(),
                           name='Mock role',
                           help='Mock help')
     self.mock_user_role = UserRole(id=1,
                                    role_id=1,
                                    location_id=1,
                                    user_id=1,
                                    is_active=True,
                                    created_at=datetime.now(),
                                    updated_at=datetime.now())
Ejemplo n.º 10
0
 def add_role(user: User):
     """
     Assign a role to the given user
     :param user: User object
     """
     roles: list = UserRole.get_other_roles(user)
     if not roles:
         Log.log('No more roles available', color='red')
         return
     add_role_questions: list = [
         {
             'type': 'list',
             'name': 'role_name',
             'message': 'Choose Role',
             'choices': [role.name for role in roles]
         }
     ]
     answers: dict = prompt(add_role_questions, style=input_style)
     for role in roles:
         if role.name == answers['role_name']:
             UserRole.create(user, role)
             Log.log('Role assigned successfully', color='green')
             break
Ejemplo n.º 11
0
    def setUp(self):
        self.BaseSetUp()
        self.mock_role = Role(
            id=1,
            name="Pass",
            help="help",
        )
        self.mock_user_role = UserRole(
            id=1,
            created_at=datetime.now(),
            updated_at=datetime.now(),
            role_id=1,
            role=self.mock_role,
            user_id=1,
            is_active=True,
            is_deleted=False,
        )

        self.mock_user = User(
            id=1,
            first_name="test",
            last_name="test",
            gender="male",
            password="******",
            email="*****@*****.**",
            is_active=True,
            is_deleted=False,
            created_at=datetime.now(),
            updated_at=datetime.now(),
        )
        self.mock_user2 = User(
            id=1,
            first_name="test",
            last_name="test",
            gender="male",
            password="******",
            email="*****@*****.**",
            is_active=True,
            is_deleted=False,
            created_at=datetime.now(),
            updated_at=datetime.now(),
        )
Ejemplo n.º 12
0
 def remove_role(user: User):
     """
     Remove a role associated with given user
     :param user: User object
     """
     user_roles: list = UserRole.get_user_roles(user)
     if not user_roles:
         Log.log('No roles assigned', color='red')
         return
     remove_role_questions: list = [
         {
             'type': 'list',
             'name': 'role_name',
             'message': 'Choose Role',
             'choices': [user_role.role.name for user_role in user_roles]
         }
     ]
     answers: dict = prompt(remove_role_questions, style=input_style)
     for index, user_role in enumerate(UserRole.user_roles):
         if user_role.user.id == user.id and user_role.role.name == answers['role_name']:
             UserRole.user_roles.pop(index)
             Log.log('Role unassigned successfully', color='green')
             break
Ejemplo n.º 13
0
 def setUp(self):
     super().setUp()
     self._role = "admin"
     self._alternate_role = UserRole()
     self._alternate_role_str = "user"
     self._user = AdminUser(self._username, self._password)
Ejemplo n.º 14
0
    def run():
        customer = User(
            id = 1, 
            ssnid = int(time.time()), 
            customerid = int(time.time()),
            password = generate_password_hash('password'),
            name = 'Customer',
            addrln1 = 'Address Line 1',
            addrln2 = 'Address Line 2',
            city = 'City ',
            state = 'State',
            pin = '12345')

        ace = User(
            id = 2, 
            ssnid = int(time.time()) + 2, 
            customerid = int(time.time()) + 2,
            password = generate_password_hash('password'),
            name = 'ACE',
            addrln1 = 'Address Line 1',
            addrln2 = 'Address Line 2',
            city = 'City ',
            state = 'State',
            pin = '12345')
        
        cashier = User(
            id = 3, 
            ssnid = int(time.time()) + 3, 
            customerid = int(time.time()) + 3,
            password = generate_password_hash('password'),
            name = 'Cashier',
            addrln1 = 'Address Line 1',
            addrln2 = 'Address Line 2',
            city = 'City ',
            state = 'State',
            pin = '12345')

        teller = User(
            id = 4, 
            ssnid = int(time.time()) + 4, 
            customerid = int(time.time()) + 4,
            password = generate_password_hash('password'),
            name = 'Teller',
            addrln1 = 'Address Line 1',
            addrln2 = 'Address Line 2',
            city = 'City ',
            state = 'State',
            pin = '12345')

        db.session.add(customer) 
        db.session.add(ace)  
        db.session.add(cashier)  
        db.session.add(teller)  

        customerRole = UserRole(id = 1, userid = 1, roleid = 1)
        aceRole = UserRole(id = 2, userid = 2, roleid = 2)
        cashierRole = UserRole(id = 3, userid = 3, roleid = 3)
        tellerRole = UserRole(id = 4, userid = 4, roleid = 4)

        db.session.add(customerRole)   
        db.session.commit()
Ejemplo n.º 15
0
    def create_user_role(self, role_id, user_id):
        user_role = UserRole(role_id=role_id, user_id=user_id)

        user_role.save()
        return user_role
Ejemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self._role = UserRole()
     self._role_str = "normal"