Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change accessLevel to RoleId #145

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,21 @@ export function postReviews(collectionId, assetId, reviews) {
}

export async function getUser() {
cache.user = await apiRequest({endpoint: '/user'})
const user = await apiRequest({endpoint: '/user'})

user.collectionGrants = user.collectionGrants?.map(({ accessLevel, ...grant }) => ({
...grant,
roleId: grant.roleId ?? accessLevel
})) || []

cache.user = user
return cache.user
}

export function canUserAccept() {
const curUser = cache.user
const apiCollection = cache.collection
const userGrant = curUser.collectionGrants.find( i => i.collection.collectionId === apiCollection.collectionId )?.accessLevel
const userGrant = curUser.collectionGrants.find( i => i.collection.collectionId === apiCollection.collectionId )?.roleId
const allowAccept = apiCollection.settings.status.canAccept && (userGrant >= apiCollection.settings.status.minAcceptGrant)
return allowAccept
}
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function canUserAccept () {
if (!cache.user) return false

const apiCollection = cache.collection
const userGrant = cache.user.collectionGrants.find( i => i.collection.collectionId === apiCollection.collectionId )?.accessLevel
const userGrant = cache.user.collectionGrants.find( i => i.collection.collectionId === apiCollection.collectionId )?.roleId
return apiCollection.settings.status.canAccept && (userGrant >= apiCollection.settings.status.minAcceptGrant)
}

Expand Down
Loading