예제 #1
0
파일: auth.py 프로젝트: nedemenang/Air-tech
            def decorated(*args, **kwargs):

                user_role_repo = UserRoleRepo()
                permission_repo = PermissionRepo()

                user_id = Auth.user('sub')
                user_role = user_role_repo.find_first(**{'user_id': user_id})

                if not user_id:
                    return make_response(jsonify({'msg': 'Missing user ID in token'})), 400

                if not user_role:
                    return make_response(jsonify({'msg': 'Access Error - No Role Granted'})), 400

                user_perms = permission_repo.get_unpaginated(**{'role_id': user_role.role_id})

                perms = [perm.name for perm in user_perms]

                if len(perms) == 0:
                    return make_response(jsonify({'msg': 'Access Error - No Permission Granted'})), 400

                if permission not in perms:
                    return make_response(jsonify({'msg': 'Access Error - Permission Denied'})), 400

                return f(*args, **kwargs)
예제 #2
0
            def decorated(*args, **kwargs):

                user_role_repo = UserRoleRepo()

                role_repo = RoleRepo()

                user_id = Auth.user('id')
                user_role = user_role_repo.find_first(**{'user_id': user_id})

                if not user_id:
                    return make_response(
                        jsonify({'msg': 'Missing User ID in token'})), 401

                if not user_role:
                    return make_response(
                        jsonify({'msg':
                                 'Access Error - No Role Granted'})), 401

                if role_repo.get(user_role.role_id).name != role:
                    return make_response(
                        jsonify({
                            'msg':
                            'Access Error - This role does not have the access rights'
                        })), 401

                return f(*args, **kwargs)