1
0
Fork 0
mirror of synced 2024-06-22 16:10:40 +12:00

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 d80cd5042d
commit 99b8c269ea
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
}