Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files
backend_structured/routes.py
CHANGED
|
@@ -498,7 +498,7 @@ def get_org_users(current_user, org_id):
|
|
| 498 |
@auth_bp.route('/users/invite', methods=['POST'])
|
| 499 |
@token_required
|
| 500 |
def invite_user(current_user):
|
| 501 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 502 |
return jsonify({'message': 'Permission denied'}), 403
|
| 503 |
|
| 504 |
data = request.get_json()
|
|
@@ -556,7 +556,7 @@ def invite_user(current_user):
|
|
| 556 |
@auth_bp.route('/users/<user_id>/role', methods=['PUT'])
|
| 557 |
@token_required
|
| 558 |
def update_user_role(current_user, user_id):
|
| 559 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 560 |
return jsonify({'message': 'Permission denied'}), 403
|
| 561 |
|
| 562 |
user = db.session.get(User, user_id)
|
|
@@ -585,7 +585,7 @@ def update_user_role(current_user, user_id):
|
|
| 585 |
@auth_bp.route('/users/<user_id>/credentials', methods=['PUT'])
|
| 586 |
@token_required
|
| 587 |
def update_user_credentials(current_user, user_id):
|
| 588 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 589 |
return jsonify({'message': 'Permission denied'}), 403
|
| 590 |
|
| 591 |
user = db.session.get(User, user_id)
|
|
@@ -834,13 +834,13 @@ def manage_single_organization(current_user, org_id):
|
|
| 834 |
@auth_bp.route('/organizations/logo', methods=['POST', 'DELETE'])
|
| 835 |
@token_required
|
| 836 |
def upload_organization_logo(current_user):
|
| 837 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 838 |
return jsonify({'message': 'Permission denied'}), 403
|
| 839 |
|
| 840 |
org = None
|
| 841 |
if current_user.org_id:
|
| 842 |
org = db.session.get(Organization, current_user.org_id)
|
| 843 |
-
if not org and current_user.role
|
| 844 |
org = db.session.query(Organization).first()
|
| 845 |
if not org:
|
| 846 |
return jsonify({'message': 'Organization not found'}), 404
|
|
@@ -933,13 +933,13 @@ def serve_uploaded_logo(filename):
|
|
| 933 |
@auth_bp.route('/organizations/webhook', methods=['GET', 'PUT'])
|
| 934 |
@token_required
|
| 935 |
def manage_webhook(current_user):
|
| 936 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 937 |
return jsonify({'message': 'Permission denied'}), 403
|
| 938 |
|
| 939 |
org = None
|
| 940 |
if current_user.org_id:
|
| 941 |
org = db.session.get(Organization, current_user.org_id)
|
| 942 |
-
if not org and current_user.role
|
| 943 |
org = db.session.query(Organization).first()
|
| 944 |
if not org:
|
| 945 |
return jsonify({'message': 'Organization not found'}), 404
|
|
@@ -1361,7 +1361,7 @@ def update_user(current_user, user_id):
|
|
| 1361 |
if not target:
|
| 1362 |
return jsonify({'message': 'User not found!'}), 404
|
| 1363 |
|
| 1364 |
-
if current_user.role not in ('org_admin', 'super_admin'):
|
| 1365 |
return jsonify({'message': 'Permission denied'}), 403
|
| 1366 |
|
| 1367 |
if current_user.role == 'org_admin' and target.org_id != current_user.org_id:
|
|
@@ -1397,7 +1397,7 @@ def delete_user(current_user, user_id):
|
|
| 1397 |
target = db.session.get(User, user_id)
|
| 1398 |
if not target:
|
| 1399 |
return jsonify({'message': 'User not found!'}), 404
|
| 1400 |
-
if current_user.role
|
| 1401 |
return jsonify({'message': 'Unauthorized to delete this user!'}), 403
|
| 1402 |
|
| 1403 |
log = AuditLog(admin_id=current_user.id, action=f"Deleted user {target.email}", target_id=target.org_id)
|
|
|
|
| 498 |
@auth_bp.route('/users/invite', methods=['POST'])
|
| 499 |
@token_required
|
| 500 |
def invite_user(current_user):
|
| 501 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 502 |
return jsonify({'message': 'Permission denied'}), 403
|
| 503 |
|
| 504 |
data = request.get_json()
|
|
|
|
| 556 |
@auth_bp.route('/users/<user_id>/role', methods=['PUT'])
|
| 557 |
@token_required
|
| 558 |
def update_user_role(current_user, user_id):
|
| 559 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 560 |
return jsonify({'message': 'Permission denied'}), 403
|
| 561 |
|
| 562 |
user = db.session.get(User, user_id)
|
|
|
|
| 585 |
@auth_bp.route('/users/<user_id>/credentials', methods=['PUT'])
|
| 586 |
@token_required
|
| 587 |
def update_user_credentials(current_user, user_id):
|
| 588 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 589 |
return jsonify({'message': 'Permission denied'}), 403
|
| 590 |
|
| 591 |
user = db.session.get(User, user_id)
|
|
|
|
| 834 |
@auth_bp.route('/organizations/logo', methods=['POST', 'DELETE'])
|
| 835 |
@token_required
|
| 836 |
def upload_organization_logo(current_user):
|
| 837 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 838 |
return jsonify({'message': 'Permission denied'}), 403
|
| 839 |
|
| 840 |
org = None
|
| 841 |
if current_user.org_id:
|
| 842 |
org = db.session.get(Organization, current_user.org_id)
|
| 843 |
+
if not org and current_user.role in ('super_admin', 'admin'):
|
| 844 |
org = db.session.query(Organization).first()
|
| 845 |
if not org:
|
| 846 |
return jsonify({'message': 'Organization not found'}), 404
|
|
|
|
| 933 |
@auth_bp.route('/organizations/webhook', methods=['GET', 'PUT'])
|
| 934 |
@token_required
|
| 935 |
def manage_webhook(current_user):
|
| 936 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 937 |
return jsonify({'message': 'Permission denied'}), 403
|
| 938 |
|
| 939 |
org = None
|
| 940 |
if current_user.org_id:
|
| 941 |
org = db.session.get(Organization, current_user.org_id)
|
| 942 |
+
if not org and current_user.role in ('super_admin', 'admin'):
|
| 943 |
org = db.session.query(Organization).first()
|
| 944 |
if not org:
|
| 945 |
return jsonify({'message': 'Organization not found'}), 404
|
|
|
|
| 1361 |
if not target:
|
| 1362 |
return jsonify({'message': 'User not found!'}), 404
|
| 1363 |
|
| 1364 |
+
if current_user.role not in ('org_admin', 'super_admin', 'admin'):
|
| 1365 |
return jsonify({'message': 'Permission denied'}), 403
|
| 1366 |
|
| 1367 |
if current_user.role == 'org_admin' and target.org_id != current_user.org_id:
|
|
|
|
| 1397 |
target = db.session.get(User, user_id)
|
| 1398 |
if not target:
|
| 1399 |
return jsonify({'message': 'User not found!'}), 404
|
| 1400 |
+
if current_user.role not in ('super_admin', 'admin') and target.org_id != current_user.org_id:
|
| 1401 |
return jsonify({'message': 'Unauthorized to delete this user!'}), 403
|
| 1402 |
|
| 1403 |
log = AuditLog(admin_id=current_user.id, action=f"Deleted user {target.email}", target_id=target.org_id)
|