mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-13 16:06:21 +00:00
52d336cc45
No more enforced curly for if/else/for/while/do blocks w/ one statement. With that said, auto-fixed all JS files to follow the rule. I'd also like to apologize for the inconveniences this commit cause, after all it was me who intentionally enforced curly rule back then. Why the change of heart? After doing some more non-JS codes recently, I realized it was pretty stupid of me to enforce that.
33 lines
1009 B
JavaScript
33 lines
1009 B
JavaScript
const permissionController = {}
|
|
|
|
permissionController.permissions = {
|
|
user: 0, // upload & delete own files, create & delete albums
|
|
moderator: 50, // delete other user's files
|
|
admin: 80, // manage users (disable accounts) & create moderators
|
|
superadmin: 100 // create admins
|
|
// groups will inherit permissions from groups which have lower value
|
|
}
|
|
|
|
permissionController.is = (user, group) => {
|
|
// root bypass
|
|
if (user.username === 'root') return true
|
|
const permission = user.permission || 0
|
|
return permission >= permissionController.permissions[group]
|
|
}
|
|
|
|
permissionController.higher = (user, target) => {
|
|
const userPermission = user.permission || 0
|
|
const targetPermission = target.permission || 0
|
|
return userPermission > targetPermission
|
|
}
|
|
|
|
permissionController.mapPermissions = user => {
|
|
const map = {}
|
|
Object.keys(permissionController.permissions).forEach(group => {
|
|
map[group] = permissionController.is(user, group)
|
|
})
|
|
return map
|
|
}
|
|
|
|
module.exports = permissionController
|