mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-15 08:21:28 +03:00
Fixed issue where roles were not properly initialized
This commit is contained in:
@@ -18,10 +18,19 @@ let JWT_EXPIRATION = null;
|
|||||||
let opts = null;
|
let opts = null;
|
||||||
let saltRounds = null;
|
let saltRounds = null;
|
||||||
|
|
||||||
exports.initialize = function() {
|
exports.initialize = function () {
|
||||||
/*************************
|
/*************************
|
||||||
* Authentication module
|
* Authentication module
|
||||||
************************/
|
************************/
|
||||||
|
|
||||||
|
if (db_api.database_initialized) {
|
||||||
|
setupRoles();
|
||||||
|
} else {
|
||||||
|
db_api.database_initialized_bs.subscribe(init => {
|
||||||
|
if (init) setupRoles();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
saltRounds = 10;
|
saltRounds = 10;
|
||||||
|
|
||||||
JWT_EXPIRATION = config_api.getConfigItem('ytdl_jwt_expiration');
|
JWT_EXPIRATION = config_api.getConfigItem('ytdl_jwt_expiration');
|
||||||
@@ -49,6 +58,41 @@ exports.initialize = function() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setupRoles = async () => {
|
||||||
|
const required_roles = {
|
||||||
|
admin: {
|
||||||
|
permissions: [
|
||||||
|
'filemanager',
|
||||||
|
'settings',
|
||||||
|
'subscriptions',
|
||||||
|
'sharing',
|
||||||
|
'advanced_download',
|
||||||
|
'downloads_manager'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
permissions: [
|
||||||
|
'filemanager',
|
||||||
|
'subscriptions',
|
||||||
|
'sharing'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const role_keys = Object.keys(required_roles);
|
||||||
|
for (let i = 0; i < role_keys.length; i++) {
|
||||||
|
const role_key = role_keys[i];
|
||||||
|
const role_in_db = await db_api.getRecord('roles', {key: role_key});
|
||||||
|
if (!role_in_db) {
|
||||||
|
// insert task metadata into table if missing
|
||||||
|
await db_api.insertRecordIntoTable('roles', {
|
||||||
|
key: role_key,
|
||||||
|
permissions: required_roles[role_key]['permissions']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.passport = require('passport');
|
exports.passport = require('passport');
|
||||||
|
|
||||||
exports.passport.serializeUser(function(user, done) {
|
exports.passport.serializeUser(function(user, done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user