Updating group types to accurately reflect the state of the documents, as well as centralising the logic for getting the app IDs in a group.

This commit is contained in:
mike12345567 2022-09-22 13:55:52 +01:00
parent 6247f686e8
commit 25b8f0ca3b
6 changed files with 14 additions and 8 deletions

View File

@ -52,7 +52,8 @@
? publishedApps
: publishedApps.filter(app => {
return userGroups.find(group => {
return Object.keys(group.roles)
return groups.actions
.getGroupApps(group)
.map(role => apps.extractAppId(role))
.includes(app.appId)
})

View File

@ -41,7 +41,9 @@
$: fetchUsers(page, searchTerm)
$: group = $groups.find(x => x._id === groupId)
$: filtered = $users.data
$: groupApps = $apps.filter(app => group?.roles?.includes(app.appId))
$: groupApps = $apps.filter(app =>
groups.actions.getGroupApps(group).includes(app.appId)
)
$: {
if (loaded && !group?._id) {
$goto("./")

View File

@ -44,7 +44,7 @@
if (!group.roles) {
return false
}
return Object.keys(group.roles).includes(fixedAppId)
return groups.actions.getGroupApps(group).includes(fixedAppId)
})
async function removeUser(user) {
@ -114,7 +114,7 @@
autoWidth
quiet
value={group.roles[
Object.keys(group.roles).find(x => x === fixedAppId)
groups.actions.getGroupApps(group).find(x => x === fixedAppId)
]}
allowPublic={false}
/>

View File

@ -113,7 +113,7 @@
search = search?.toLowerCase()
return (allGroups || []).filter(group => {
// Filter out assigned groups
const appIds = Object.keys(group.roles || {})
const appIds = groups.actions.getGroupApps(group)
if (appIds.includes(appId)) {
return false
}

View File

@ -76,6 +76,10 @@ export function createGroupsStore() {
// refresh the group roles
await getGroup(groupId)
},
getGroupApps: group => {
return Object.keys(group?.roles || {})
},
}
return {

View File

@ -4,9 +4,8 @@ export interface UserGroup extends Document {
name: string
icon: string
color: string
users: GroupUser[]
apps: string[]
roles: UserGroupRoles
users?: GroupUser[]
roles?: UserGroupRoles
createdAt?: number
}