filesafe/controllers/permissionController.js
Bobby Wibowo 02e2e402c3
!!! MASSIVE OVERHAUL !!!
As the title says, this commit is a massive overhaul.
I've rewritten/restrucuted almost everything in the controller scripts.
Because of that, there's a considerable possibility that I've broken
something somewhere.

Notable changes:

Added temporary uploads.

Removed file name length changer from dashboard,
in favor of an equivalent in homepage config tab.
This allows non-registered users to also set file name length.

A bunch of other undocmented stuff.
I don't know, I'm too tired to remember them all.
2019-09-08 08:56:29 +07:00

35 lines
870 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
}
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