Skip to content

Commit

Permalink
The one with real people in the backend! - v1.0.6 #197
Browse files Browse the repository at this point in the history
The one with real people in the backend! - v1.0.6
  • Loading branch information
bardsley authored Oct 11, 2024
2 parents 164b41e + 8c8966f commit ff2ae44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions lib/authorise.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const superuser = "superadmin"

// These control access to various admin functionalities. Either direct path without querystring or regular expressions
const grantUsage = {
"all-admins": ["/admin"],
"all-admins": ["/admin"], // Everyone gets this set
"developer": ["#","/admin/users","/admin/stripe","/admin/import"],
"content-manager": ['/admin/content'],
"door-staff": ['/admin/ticketing','/admin/scan', '/admin/epos'],
"event-manager": ['/admin/ticketing.*'] // Everything under ticketing
}
// const grantView = {
// "developer": {
// "thing": ["create","update","read","delete"],
// "otherthing": ["create","update","read","delete"]
// }
// }


export const authUsage = (user,path) => {
// Check could ever be allowed to do anything
Expand All @@ -21,10 +17,12 @@ export const authUsage = (user,path) => {
const roles = user.publicMetadata.roles
// Superuser gets set to true always
if(roles.includes(superuser)) return true
// Check against all admins stuff
if(grantUsage['all-admins'].includes(pathWithoutQueryString)) return true
// check through roles to see if any of them allow access to path
return roles.some((role) => {
if(!grantUsage[role]) return false // Roles doesn't exist in permissions
return grantUsage[role] && grantUsage[role].includes(pathWithoutQueryString)
return grantUsage[role] && grantUsage[role].some((pattern) => { return pathWithoutQueryString == pattern || new RegExp(`^${pattern}$`).test(pathWithoutQueryString)})
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "congress-system",
"version": "0.3.1",
"version": "1.0.6",
"private": true,
"license": "Contact Adam & Connor for details",
"scripts": {
Expand Down

0 comments on commit ff2ae44

Please sign in to comment.