mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-15 08:56:21 +00:00
a28d862c14
Also better-ish scan results handling again, I guess Updated dependency knex: 0.20.0 -> 0.20.1
36 lines
920 B
JavaScript
36 lines
920 B
JavaScript
const self = {}
|
|
|
|
self.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
|
|
}
|
|
|
|
// returns true if user is in the group OR higher
|
|
self.is = (user, group) => {
|
|
// root bypass
|
|
if (user.username === 'root')
|
|
return true
|
|
|
|
const permission = user.permission || 0
|
|
return permission >= self.permissions[group]
|
|
}
|
|
|
|
self.higher = (user, target) => {
|
|
const userPermission = user.permission || 0
|
|
const targetPermission = target.permission || 0
|
|
return userPermission > targetPermission
|
|
}
|
|
|
|
self.mapPermissions = user => {
|
|
const map = {}
|
|
Object.keys(self.permissions).forEach(group => {
|
|
map[group] = self.is(user, group)
|
|
})
|
|
return map
|
|
}
|
|
|
|
module.exports = self
|