Beispiel #1
0
 def post(self, username):
     """disable user account"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.user_all.value)
     qh.enable_user(username, False)
     return {}, 200
Beispiel #2
0
 def get(self, username, name):
     """Get user timezone by id"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.record_all.value,
         username=username)
     return qh.get_user_timezone(username, name)
Beispiel #3
0
 def delete(self, role):
     """Delete a user role"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.role.value)
     qh.delete_user_role(role)
     return {}, 200
Beispiel #4
0
 def get(self):
     """Get all timezones"""
     utils.check_user_enabled()
     data = qh.get_timezone_all()
     if not data["data"]:
         return {}, 404
     return data
Beispiel #5
0
 def get(self):
     """Get all users"""
     utils.check_user_enabled()
     username, perm = utils.get_user_permissions()
     users_data = qh.get_user_all(username, perm)
     if not users_data["data"]:
         return {}, 404
     return users_data
Beispiel #6
0
 def delete(self, username, name):
     """Delete user timezone"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.record_all.value,
         username=username)
     qh.delete_user_timezone(username, name)
     return {}, 200
Beispiel #7
0
 def get(self, username):
     """Get user by username"""
     utils.check_user_enabled()
     req_user, perm = utils.get_user_permissions()
     user = qh.get_user(username, req_user, perm)
     if not user:
         ns.abort(404)
     else:
         return user
Beispiel #8
0
 def get(self):
     """Get all user roles"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.role.value)
     roles = qh.get_user_roles()
     if not roles["data"]:
         return {}, 404
     return roles
Beispiel #9
0
 def get(self, username):
     """Get all timezones for a user"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.record_all.value,
         username=username)
     data = qh.get_user_timezone_all(username)
     if not data["data"]:
         return {}, 404
     return data
Beispiel #10
0
 def get(self, role):
     """Get user role"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.role.value)
     user_role = qh.get_user_role(role)
     if not user_role:
         return {}, 404
     else:
         return user_role
Beispiel #11
0
 def post(self):
     """Creates a new user role"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.role.value)
     args = request.get_json(force=True)
     try:
         return qh.create_user_role(role=args['role'],
                                    permissions=args['permissions'])
     except KeyError:
         raise ValueError('missing required input parameter')
Beispiel #12
0
 def post(self, username):
     """Creates a new timezone for a user"""
     utils.check_user_enabled()
     utils.validate_permissions(
         required_permission=UserRolesEnum.record_all.value,
         username=username)
     args = request.get_json(force=True)
     try:
         return qh.create_user_timezone(username,
                                        name=args['name'],
                                        timezone_id=args['timezone_id'])
     except KeyError:
         raise ValueError('missing required input parameter')
Beispiel #13
0
    def put(self, username):
        """Update user"""
        utils.check_user_enabled()
        args = request.get_json(force=True)

        update = {}
        for key in ['first_name', 'last_name', 'email', 'password', 'role']:
            try:
                val = args[key]
                if not val:
                    raise ValueError('invalid input')
                update[key] = val
            except KeyError:
                pass

        if not update:
            return {}, 200
        req_user, perm = utils.get_user_permissions()
        qh.update_user(username, req_user, perm, **update)
        return {}, 200
Beispiel #14
0
    def put(self, username, name):
        """Update user timezone"""
        utils.check_user_enabled()
        utils.validate_permissions(
            required_permission=UserRolesEnum.record_all.value,
            username=username)
        args = request.get_json(force=True)

        update = {}
        for key in ['name', 'timezone_id']:
            try:
                val = args[key]
                if not val:
                    raise ValueError('invalid input')
                update[key] = val
            except KeyError:
                pass

        if not update:
            return {}, 200

        qh.update_user_timezone(username, tz_name=name, **update)
        return {}, 200
Beispiel #15
0
 def delete(self, username):
     """Delete user"""
     utils.check_user_enabled()
     req_user, perm = utils.get_user_permissions()
     qh.delete_user(username, req_user, perm)
     return {}, 200