1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +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
: publishedApps.filter(app => { : publishedApps.filter(app => {
return userGroups.find(group => { return userGroups.find(group => {
return Object.keys(group.roles) return groups.actions
.getGroupApps(group)
.map(role => apps.extractAppId(role)) .map(role => apps.extractAppId(role))
.includes(app.appId) .includes(app.appId)
}) })

View file

@ -41,7 +41,9 @@
$: fetchUsers(page, searchTerm) $: fetchUsers(page, searchTerm)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
$: filtered = $users.data $: 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) { if (loaded && !group?._id) {
$goto("./") $goto("./")

View file

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

View file

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

View file

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

View file

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