diff --git a/backend/app.js b/backend/app.js
index 1fc0ac1..e9d92a3 100644
--- a/backend/app.js
+++ b/backend/app.js
@@ -68,7 +68,8 @@ db.defaults(
configWriteFlag: false,
downloads: {},
subscriptions: [],
- files_to_db_migration_complete: false
+ files_to_db_migration_complete: false,
+ tasks_manager_role_migration_complete: false
}).write();
users_db.defaults(
@@ -189,6 +190,15 @@ async function checkMigrations() {
else { logger.error('Migration failed: 4.2->4.3+'); }
}
+ const tasks_manager_role_migration_complete = db.get('tasks_manager_role_migration_complete').value();
+ if (!tasks_manager_role_migration_complete) {
+ logger.info('Checking if tasks manager role permissions exist for admin user...');
+ const success = await auth_api.changeRolePermissions('admin', 'tasks_manager', 'yes');
+ if (success) logger.info('Task manager permissions check complete!');
+ else logger.error('Failed to auto add tasks manager permissions to admin role!');
+ db.set('tasks_manager_role_migration_complete', true).write();
+ }
+
return true;
}
diff --git a/backend/authentication/auth.js b/backend/authentication/auth.js
index e6fa23c..92740d1 100644
--- a/backend/authentication/auth.js
+++ b/backend/authentication/auth.js
@@ -361,7 +361,6 @@ exports.userHasPermission = async function(user_uid, permission) {
logger.error('Invalid role ' + role);
return false;
}
- const role_permissions = (await db_api.getRecords('roles'))['permissions'];
const user_has_explicit_permission = user_obj['permissions'].includes(permission);
const permission_in_overrides = user_obj['permission_overrides'].includes(permission);
@@ -376,7 +375,8 @@ exports.userHasPermission = async function(user_uid, permission) {
}
// no overrides, let's check if the role has the permission
- if (role_permissions.includes(permission)) {
+ const role_has_permission = await exports.roleHasPermissions(role, permission);
+ if (role_has_permission) {
return true;
} else {
logger.verbose(`User ${user_uid} failed to get permission ${permission}`);
@@ -384,6 +384,16 @@ exports.userHasPermission = async function(user_uid, permission) {
}
}
+exports.roleHasPermissions = async function(role, permission) {
+ const role_obj = await db_api.getRecord('roles', {key: role})
+ if (!role) {
+ logger.error(`Role ${role} does not exist!`);
+ }
+ const role_permissions = role_obj['permissions'];
+ if (role_permissions && role_permissions.includes(permission)) return true;
+ else return false;
+}
+
exports.userPermissions = async function(user_uid) {
let user_permissions = [];
const user_obj = await db_api.getRecord('users', ({uid: user_uid}));
diff --git a/backend/consts.js b/backend/consts.js
index f473e07..bf1ed47 100644
--- a/backend/consts.js
+++ b/backend/consts.js
@@ -221,7 +221,8 @@ exports.AVAILABLE_PERMISSIONS = [
'subscriptions',
'sharing',
'advanced_download',
- 'downloads_manager'
+ 'downloads_manager',
+ 'tasks_manager'
];
exports.DETAILS_BIN_PATH = 'node_modules/youtube-dl/bin/details'
diff --git a/backend/utils.js b/backend/utils.js
index 3aac116..78d02f1 100644
--- a/backend/utils.js
+++ b/backend/utils.js
@@ -172,7 +172,7 @@ function getExpectedFileSize(input_info_jsons) {
const formats = info_json['format_id'].split('+');
let individual_expected_filesize = 0;
formats.forEach(format_id => {
- if(info_json.formats !== undefined) {
+ if (info_json.formats !== undefined) {
info_json.formats.forEach(available_format => {
if (available_format.format_id === format_id && (available_format.filesize || available_format.filesize_approx)) {
individual_expected_filesize += (available_format.filesize ? available_format.filesize : available_format.filesize_approx);
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 278b8fe..c2d79a2 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -44,7 +44,7 @@
Login
Subscriptions
Downloads
- Tasks
+ Tasks
Settings
diff --git a/src/app/components/manage-role/manage-role.component.ts b/src/app/components/manage-role/manage-role.component.ts
index dbe2511..2f13e0a 100644
--- a/src/app/components/manage-role/manage-role.component.ts
+++ b/src/app/components/manage-role/manage-role.component.ts
@@ -14,12 +14,13 @@ export class ManageRoleComponent implements OnInit {
permissions = null;
permissionToLabel = {
- 'filemanager': 'File manager',
- 'settings': 'Settings access',
- 'subscriptions': 'Subscriptions',
- 'sharing': 'Share files',
- 'advanced_download': 'Use advanced download mode',
- 'downloads_manager': 'Use downloads manager'
+ 'filemanager': $localize`File manager`,
+ 'settings': $localize`Settings access`,
+ 'subscriptions': $localize`Subscriptions`,
+ 'sharing': $localize`Share files`,
+ 'advanced_download': $localize`Use advanced download mode`,
+ 'downloads_manager': $localize`Use downloads manager`,
+ 'tasks_manager': $localize`Use tasks manager`,
}
constructor(public postsService: PostsService, private dialogRef: MatDialogRef,
diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts
index 9115437..8e74bed 100644
--- a/src/app/posts.services.ts
+++ b/src/app/posts.services.ts
@@ -4,7 +4,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { THEMES_CONFIG } from '../themes';
-import { Router, CanActivate } from '@angular/router';
+import { Router, CanActivate, ActivatedRouteSnapshot } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { BehaviorSubject } from 'rxjs';
import { MatSnackBar } from '@angular/material/snack-bar';
@@ -229,12 +229,15 @@ export class PostsService implements CanActivate {
}
}
- canActivate(route, state): Promise {
- return new Promise(resolve => {
- resolve(true);
- })
- console.log(route);
- throw new Error('Method not implemented.');
+ canActivate(route: ActivatedRouteSnapshot, state): Promise {
+ const PATH_TO_REQUIRED_PERM = {
+ settings: 'settings',
+ subscriptions: 'subscriptions',
+ downloads: 'downloads_manager',
+ tasks: 'tasks_manager'
+ }
+ const required_perm = PATH_TO_REQUIRED_PERM[route.routeConfig.path];
+ return required_perm ? this.hasPermission(required_perm) : true;
}
setTheme(theme) {
diff --git a/src/assets/i18n/messages.en.xlf b/src/assets/i18n/messages.en.xlf
index e561642..99b9861 100644
--- a/src/assets/i18n/messages.en.xlf
+++ b/src/assets/i18n/messages.en.xlf
@@ -645,6 +645,55 @@
Close
+
+ File manager
+
+ src/app/components/manage-role/manage-role.component.ts
+ 17
+
+
+
+ Settings access
+
+ src/app/components/manage-role/manage-role.component.ts
+ 18
+
+
+
+ Subscriptions
+
+ src/app/components/manage-role/manage-role.component.ts
+ 19
+
+
+
+ Share files
+
+ src/app/components/manage-role/manage-role.component.ts
+ 20
+
+
+
+ Use advanced download mode
+
+ src/app/components/manage-role/manage-role.component.ts
+ 21
+
+
+
+ Use downloads manager
+
+ src/app/components/manage-role/manage-role.component.ts
+ 22
+
+
+
+ Use tasks manager
+
+ src/app/components/manage-role/manage-role.component.ts
+ 23
+
+
Manage user