fix: household leader selection and mobile monitoring experience v0.1.36

This commit is contained in:
Codex
2026-10-05 20:59:44 +08:00
parent 04d56d5aa2
commit 18d6613bb4
20 changed files with 206 additions and 28 deletions
+18 -4
View File
@@ -165,16 +165,30 @@ class Households:
reason = a.clean_text(data.get('reason', ''), 300, True)
if owner_id == successor_id:
raise a.Problem('备用负责人必须是另一位家庭管理员')
grant = data.get('grantManagement', False)
if type(grant) is not bool:
raise a.Problem('管理员授权确认格式不正确')
promotions = []
for uid in filter(None, (owner_id, successor_id)):
account = self.owns(user, a.get_object('users', uid))
if account['role'] != 'family_admin' or account['disabled']:
raise a.Problem('负责人须为本家庭已启用的家庭管理员')
if account['disabled'] or account['role'] not in ('family_admin', 'member'):
raise a.Problem('请选择本家庭已启用的成员或家庭管理员')
if account['role'] == 'member':
if not grant:
raise a.Problem('所选成员还不是家庭管理员,请确认授予本家庭管理权限')
promotions.append(dict(account, role='family_admin'))
record = dict(at=dt.datetime.now(dt.timezone.utc).isoformat(), actor=user['username'], reason=reason,
previousOwnerId=home.get('ownerId', ''), ownerId=owner_id, successorId=successor_id)
previousOwnerId=home.get('ownerId', ''), ownerId=owner_id, successorId=successor_id,
promotedUserIds=[u['id'] for u in promotions])
home.update(ownerId=owner_id, successorId=successor_id,
leadershipRevision=home.get('leadershipRevision', 0) + 1,
leadershipHistory=(home.get('leadershipHistory', []) + [record])[-50:])
a.save_object('households', home)
# Validate both choices first, then commit role grants and succession together.
with a.DB:
for account in promotions:
a.DB.execute('UPDATE users SET body=? WHERE id=?', (json.dumps(account), account['id']))
a.DB.execute('DELETE FROM sessions WHERE user_id=?', (account['id'],))
a.DB.execute('UPDATE households SET body=? WHERE id=?', (json.dumps(home), home['id']))
a.audit('家庭负责人交接', user['username'] + ' / ' + home['name'])
return {'ok': True}