Separate system accounts and household people, add generation directory and consented member location sharing
This commit is contained in:
+39
-3
@@ -50,8 +50,8 @@ class Accounts:
|
||||
def save(self, data, actor):
|
||||
a = self.a
|
||||
with a.LOCK:
|
||||
if actor and not a.HOUSEHOLDS.manager(actor):
|
||||
raise a.Problem('需要家庭管理员权限', 403)
|
||||
if actor and actor.get('role') != 'admin':
|
||||
raise a.Problem('账号与登录资料由系统用户管理统一维护', 403)
|
||||
family = a.HOUSEHOLDS.prepare(actor, 'users', data)
|
||||
old = a.get_object('users', data.get('id'))
|
||||
if data.get('id') and not old:
|
||||
@@ -90,6 +90,8 @@ class Accounts:
|
||||
disabled = data.get('disabled', False)
|
||||
if not isinstance(disabled, bool):
|
||||
raise a.Problem('账号状态不正确')
|
||||
if old and disabled and any(uid in (h.get('ownerId'), h.get('successorId')) for h in a.objects('households')):
|
||||
raise a.Problem('请先交接该账号负责的家庭,再停用账号')
|
||||
if old and uid in (home.get('ownerId'), home.get('successorId')) and (disabled or role != 'family_admin'):
|
||||
raise a.Problem('请先交接家主或更换备用负责人,再停用或调整此账号')
|
||||
if old and old['role'] == 'admin' and (role != 'admin' or disabled):
|
||||
@@ -112,7 +114,7 @@ class Accounts:
|
||||
if person:
|
||||
if not a.get_object('people', person):
|
||||
raise a.Problem('家谱人物不存在')
|
||||
a.HOUSEHOLDS.owns(actor, a.get_object('people', person))
|
||||
a.HOUSEHOLDS.owns_person(actor, a.get_object('people', person))
|
||||
if any(u.get('personId') == person and u['id'] != uid for u in a.objects('users')):
|
||||
raise a.Problem('这个人物已经关联其他账号')
|
||||
password = data.get('password', '')
|
||||
@@ -123,6 +125,8 @@ class Accounts:
|
||||
role=role, disabled=disabled, familyId=family, siteIds=sorted(set(sites)), familyAccess=access, ptzControl=ptz_control,
|
||||
personId=person, relatedToId=related, includeSubspaces=descendants, heritageAccess=heritage_access,
|
||||
relationship=a.clean_text(data.get('relationship', ''), 40), **credentials)
|
||||
if old and 'familyGrants' in old:
|
||||
user['familyGrants'] = old['familyGrants']
|
||||
# Revoke sessions when credentials or authorization change, not for label edits.
|
||||
if old and any(old.get(k) != user.get(k) for k in ('hash', 'role', 'familyId', 'siteIds', 'includeSubspaces', 'familyAccess', 'heritageAccess', 'disabled', 'username', 'ptzControl', 'personId')):
|
||||
a.DB.execute('DELETE FROM sessions WHERE user_id=?', (uid,))
|
||||
@@ -130,6 +134,38 @@ class Accounts:
|
||||
a.audit('更新账号' if old else '建立账号', username)
|
||||
return self.public(user)
|
||||
|
||||
def grant_household(self, actor, data):
|
||||
a = self.a
|
||||
if actor['role'] != 'admin': raise a.Problem('家庭访问授权由平台用户管理统一设置', 403)
|
||||
with a.LOCK, a.DB:
|
||||
user = a.get_object('users', data.get('userId'))
|
||||
home = a.get_object('households', data.get('familyId'))
|
||||
if not user or not home or user['role'] == 'admin': raise a.Problem('请选择普通系统账号和有效家庭')
|
||||
if home['id'] == a.HOUSEHOLDS.family_of(user): raise a.Problem('主要家庭的权限请在账号档案中修改')
|
||||
role = data.get('role')
|
||||
if role not in ('none', 'member', 'family_admin'): raise a.Problem('家庭权限不正确')
|
||||
if role != 'family_admin' and user['id'] in (home.get('ownerId'), home.get('successorId')):
|
||||
raise a.Problem('请先交接负责人,再取消或降低本家庭管理权限')
|
||||
grants = dict(user.get('familyGrants', {}))
|
||||
if role == 'none':
|
||||
grants.pop(home['id'], None)
|
||||
else:
|
||||
previous = grants.get(home['id'], {})
|
||||
access = data.get('familyAccess', previous.get('familyAccess', 'none'))
|
||||
heritage = data.get('heritageAccess', previous.get('heritageAccess', 'none'))
|
||||
if access not in ('none','read','edit') or heritage not in ('none','read','edit'): raise a.Problem('资料权限不正确')
|
||||
sites = data.get('siteIds', previous.get('siteIds', []))
|
||||
if not isinstance(sites, list) or len(sites)>1000 or any(not isinstance(s, str) or not a.get_object('sites',s) or a.HOUSEHOLDS.family_of(a.get_object('sites',s)) != home['id'] for s in sites):
|
||||
raise a.Problem('空间必须属于所授权的家庭')
|
||||
grants[home['id']] = dict(role=role, siteIds=list(dict.fromkeys(sites)),
|
||||
includeSubspaces=previous.get('includeSubspaces', False),
|
||||
ptzControl=previous.get('ptzControl', False), familyAccess=access, heritageAccess=heritage)
|
||||
user['familyGrants'] = grants
|
||||
a.DB.execute('UPDATE users SET body=? WHERE id=?', (json.dumps(user), user['id']))
|
||||
a.DB.execute('DELETE FROM sessions WHERE user_id=?', (user['id'],))
|
||||
a.audit('调整账号家庭访问权限', actor['username']+' / '+user['username'])
|
||||
return {'ok': True}
|
||||
|
||||
def change_password(self, data, actor):
|
||||
a = self.a
|
||||
with a.LOCK:
|
||||
|
||||
Reference in New Issue
Block a user