diff --git a/src/octoprint/access/users.py b/src/octoprint/access/users.py index 9494e8ba8..0ec1ff54d 100644 --- a/src/octoprint/access/users.py +++ b/src/octoprint/access/users.py @@ -329,11 +329,11 @@ class FilebasedUserManager(UserManager): added_permissions = list(set(permissions) - set(user._permissions)) if len(removed_permissions) > 0: - user.remove_permissions_from_user(username, removed_permissions) + user.remove_permissions_from_user(removed_permissions) self._dirty = True if len(added_permissions) > 0: - user.add_permissions_to_user(username, added_permissions) + user.add_permissions_to_user(added_permissions) self._dirty = True if self._dirty: @@ -372,11 +372,11 @@ class FilebasedUserManager(UserManager): added_groups = list(set(groups) - set(user._groups)) if len(removed_groups) > 0: - user.remove_groups_from_user(username, removed_groups) + user.remove_groups_from_user(removed_groups) self._dirty = True if len(added_groups) > 0: - user.add_groups_to_user(username, added_groups) + user.add_groups_to_user(added_groups) self._dirty = True if self._dirty: diff --git a/src/octoprint/server/api/job.py b/src/octoprint/server/api/job.py index b9a739d5d..8da2adad9 100644 --- a/src/octoprint/server/api/job.py +++ b/src/octoprint/server/api/job.py @@ -31,7 +31,7 @@ def controlJob(): activePrintjob = printer.is_printing() or printer.is_paused() - with Permissions.PRINTING.require(403): + with Permissions.PRINT.require(403): if command == "start": if activePrintjob: return make_response("Printer already has an active print job, did you mean 'restart'?", 409) diff --git a/src/octoprint/static/js/app/viewmodels/access.js b/src/octoprint/static/js/app/viewmodels/access.js index 479fcb160..073314002 100644 --- a/src/octoprint/static/js/app/viewmodels/access.js +++ b/src/octoprint/static/js/app/viewmodels/access.js @@ -71,39 +71,9 @@ $(function() { }; self.fromResponse = function(response) { - _.each(response.users, function(user) { - user.groups = access.rereferenceGroupsList(user.groups); - user.permissions = access.rereferencePermissionsList(user.permissions); - }); - self.listHelper.updateItems(response.users); }; - - self.filterPermission = function(p) { - if (_.any(self.editorGroups(), function(p) { return access.loginState.checkNeeds(p, access.groups.ADMINS); })) { - return false; - } - - if (access.loginState.checkNeeds(p, access.permissions.ADMIN)) { - return true; - } - - return !_.any(self.editorPermissions(), function(p) { return access.loginState.checkNeeds(p, access.permissions.ADMIN); }); - }; - - self.filterGroup = function(p) { - if (_.any(self.editorPermissions(), function(p) { return access.loginState.checkNeeds(p, access.permissions.ADMIN); })) { - return false; - } - - if (access.loginState.checkNeeds(p, access.groups.ADMINS)) { - return true; - } - - return !_.any(self.editorGroups(), function(p) { return access.loginState.checkNeeds(p, access.groups.ADMINS); }); - }; - self.showAddUserDialog = function() { if (!CONFIG_ACCESS_CONTROL) return; @@ -352,10 +322,6 @@ $(function() { }; self.fromResponse = function(response) { - _.each(response.groups, function(group) { - group.permissions = access.rereferencePermissionsList(group.permissions); - }); - self.groupsList(response.groups); self.listHelper.updateItems(response.groups); }; @@ -404,14 +370,6 @@ $(function() { }); }; - self.filterPermission = function(p) { - if (access.loginState.checkNeeds(p, access.permissions.ADMIN)) { - return true; - } - - return !_.any(self.editorPermissions(), function(p) { return access.loginState.checkNeeds(p, access.permissions.ADMIN); }); - }; - //~~ Framework self.onStartup = function() { @@ -519,37 +477,12 @@ $(function() { return self; })(); - //~~ Shared Functions across the submenus - - ///////////////////////////////////////////////////////////////// - // // - // Rereference functions are taking e.g. the groups data // - // delivered with the user data and replacing them with // - // a reference to the groups data delivered by the // - // groups submenu. // - // // - // This is necessary for the editor to automatically check the // - // groups the user belongs to. // - // // - ///////////////////////////////////////////////////////////////// - access.rereferenceGroupsList = function(list) { - return _.filter(access.groups.groupsList(), function(group) { - return _.findWhere(list, group.name ) != undefined; - }); - }; - - access.rereferencePermissionsList = function(list) { - return _.filter(access.permissions.permissionsList(), function(permission) { - return _.findWhere(list, permission.name) != undefined; - }); - }; - // Maps the group names into a comma seperated list access.groupList = function(data) { if (data.groups === undefined) return ""; - return _.map(data.groups, function(p) { return p.name; }).join(", "); + return data.groups.join(", "); }; // Maps the permission names into a comma seperated list @@ -557,7 +490,7 @@ $(function() { if (data.permissions === undefined) return ""; - return _.map(data.permissions, function(p) { return p.name; }).join(", "); + return data.permissions.join(", "); }; //~~ API Calls diff --git a/src/octoprint/static/js/app/viewmodels/loginstate.js b/src/octoprint/static/js/app/viewmodels/loginstate.js index 1a4e85788..5274f5e7c 100644 --- a/src/octoprint/static/js/app/viewmodels/loginstate.js +++ b/src/octoprint/static/js/app/viewmodels/loginstate.js @@ -220,7 +220,7 @@ $(function() { // Shared checkNeeds function, also used inside the filter function of the access subs self.checkNeeds = function(needs, permissions) { - return _.every(permissions, function(permission) { return _.has(needs.needs, permission.method) && _.contains(needs.needs[permission.method], permission.value); }); + return _.any(permissions, function(permission) { return _.has(needs.needs, permission.method) && _.contains(needs.needs[permission.method], permission.value); }); }; }