more admin stuff 2
This commit is contained in:
@ -30,6 +30,7 @@ async def my_hosts(user: CurrentUser = Depends(get_current_user)):
|
||||
for h in hosts:
|
||||
h["can_connect"] = True
|
||||
h["can_file_transfer"] = True
|
||||
h["can_view_credentials"] = True
|
||||
return hosts
|
||||
|
||||
cursor = await conn.execute(
|
||||
@ -82,7 +83,26 @@ async def my_hosts(user: CurrentUser = Depends(get_current_user)):
|
||||
(user.id, user.id),
|
||||
)
|
||||
ft_groups = {row[0] for row in await ft_cursor.fetchall()}
|
||||
|
||||
cred_cursor = await conn.execute(
|
||||
"""
|
||||
SELECT uhr.host_group_id FROM user_hostgroup_roles uhr
|
||||
JOIN roles r ON r.id = uhr.role_id
|
||||
WHERE uhr.user_id = ? AND r.name IN ('credentials_view', 'credentials_manage')
|
||||
AND (uhr.expires_at IS NULL OR uhr.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
UNION
|
||||
SELECT ghr.host_group_id FROM group_hostgroup_roles ghr
|
||||
JOIN roles r ON r.id = ghr.role_id
|
||||
JOIN user_group_members ugm ON ugm.user_group_id = ghr.user_group_id
|
||||
WHERE ugm.user_id = ? AND r.name IN ('credentials_view', 'credentials_manage')
|
||||
AND (ghr.expires_at IS NULL OR ghr.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
""",
|
||||
(user.id, user.id),
|
||||
)
|
||||
cred_groups = {row[0] for row in await cred_cursor.fetchall()}
|
||||
|
||||
for h in hosts:
|
||||
h["can_connect"] = True
|
||||
h["can_file_transfer"] = h["host_group_id"] in ft_groups and bool(h["file_transfer_enabled"])
|
||||
h["can_view_credentials"] = h["host_group_id"] in cred_groups
|
||||
return hosts
|
||||
|
||||
Reference in New Issue
Block a user