fix(admin): 修改用户时,只有修改了密码才同步给casdoor
This commit is contained in:
1 parent
21b8c24815
commit
98481c7ea7
3 files changed
+43
-76
No files matched your search
@@ -596,11 +596,11 @@ def create_user():
|
||||
@require_admin
|
||||
def update_user(id):
|
||||
"""
|
||||
管理端编辑用户:本地变更 commit 前先同步 Casdoor update-user / set-password。
|
||||
核心逻辑:应用本地字段 → _sync_casdoor_update_user → commit;Casdoor 失败则 rollback。
|
||||
管理端编辑用户:资料仅写本地库;仅改密时同步 Casdoor set-password。
|
||||
核心逻辑:应用本地字段 →(有 new_password 时)_sync_casdoor_update_user → commit。
|
||||
Request JSON: email, department, role, status, password 等;password 为空表示不改密
|
||||
Returns:
|
||||
{ status: ok };Casdoor/唯一约束失败时抛出 AppError/ConflictError
|
||||
{ status: ok };Casdoor 改密/唯一约束失败时抛出 AppError/ConflictError
|
||||
"""
|
||||
from app.api import user as user_api
|
||||
user = db.session.get(User, id)
|
||||
@@ -611,8 +611,6 @@ def update_user(id):
|
||||
email = _empty_to_none(data.get('email'))
|
||||
if email is not None and (not _is_valid_email(email)):
|
||||
raise AppError(code='USER.EMAIL_INVALID', message='Invalid email format', http_status=400, details={'field': 'email'})
|
||||
profile_field_keys = {'email', 'department', 'status', 'real_name', 'phone_number'}
|
||||
sync_profile = any(k in data for k in profile_field_keys)
|
||||
new_password = _empty_to_none(data.get('password'))
|
||||
for k in ['email', 'department', 'role', 'status', 'real_name', 'employee_id', 'phone_number']:
|
||||
if k in data:
|
||||
@@ -626,12 +624,8 @@ def update_user(id):
|
||||
agents = db.session.query(Agent).filter(Agent.id.in_(data['agent_ids'])).all()
|
||||
user.agents = agents
|
||||
try:
|
||||
if sync_profile or new_password:
|
||||
user_api._sync_casdoor_update_user(
|
||||
user,
|
||||
new_password=new_password,
|
||||
sync_profile=sync_profile,
|
||||
)
|
||||
if new_password:
|
||||
user_api._sync_casdoor_update_user(user, new_password=new_password)
|
||||
db.session.commit()
|
||||
except IntegrityError as e:
|
||||
db.session.rollback()
|
||||
@@ -641,7 +635,7 @@ def update_user(id):
|
||||
raise
|
||||
except RuntimeError as e:
|
||||
db.session.rollback()
|
||||
user_api._raise_casdoor_update_user_error(e)
|
||||
user_api._raise_casdoor_set_password_error(e)
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
@admin_bp.route('/users/cleanup-rejected', methods=['POST'])
|
||||
|
||||
Reference in new issue
Block a user