Merge py23 from devel
This commit is contained in:
commit
bf16bd1180
19 files changed
+347
-86
No files matched your search
@@ -11,6 +11,7 @@ install:
|
||||
- pip install -e .[develop]
|
||||
script:
|
||||
- nosetests --with-doctest
|
||||
- flake8 --ignore=D,E,W,F401 src/ tests setup.py
|
||||
sudo: false
|
||||
git:
|
||||
depth: 250
|
||||
@@ -25,11 +25,11 @@ INSTALL_REQUIRES = [
|
||||
# guarantee backwards compatibility for plugins and such with that
|
||||
# version, hence we need to pin to a lower version for now. See #1697
|
||||
"tornado==4.5.3", # a memory leak was observed in tornado >= 5, see #2585
|
||||
"Flask-Login>=0.2.11,<0.3", # some functions changed to properties in 0.3
|
||||
"regex!=2018.11.6", # avoid broken 2018.11.6. See #2874
|
||||
|
||||
# anything below this should be checked on releases for new versions
|
||||
|
||||
"Flask-Login>=0.4.1,<0.5",
|
||||
"Flask-Principal>=0.4,<0.5",
|
||||
"Flask-Babel>=0.12,<0.13",
|
||||
"Flask-Assets>=0.12,<0.13",
|
||||
@@ -75,6 +75,9 @@ EXTRA_REQUIRES = dict(
|
||||
"nose>=1.3.7,<1.4",
|
||||
"ddt",
|
||||
|
||||
# linter
|
||||
"flake8",
|
||||
|
||||
# Documentation dependencies
|
||||
"sphinx>=1.6,<1.7",
|
||||
"sphinxcontrib-httpdomain",
|
||||
|
||||
@@ -4,3 +4,4 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
ADMIN_GROUP = "admins"
|
||||
USER_GROUP = "users"
|
||||
GUEST_GROUP = "guests"
|
||||
READONLY_GROUP = "readonly"
|
||||
+133
-36
@@ -16,7 +16,7 @@ from past.builtins import basestring
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.util import atomic_write
|
||||
from octoprint.access import ADMIN_GROUP, USER_GROUP, GUEST_GROUP
|
||||
from octoprint.access import ADMIN_GROUP, USER_GROUP, GUEST_GROUP, READONLY_GROUP
|
||||
from octoprint.access.permissions import Permissions, OctoPrintPermission
|
||||
from flask_principal import Need, Permission
|
||||
|
||||
@@ -91,6 +91,7 @@ class GroupManager(object):
|
||||
"Admins",
|
||||
"Administrators",
|
||||
self.default_permissions_for_group(ADMIN_GROUP),
|
||||
[],
|
||||
changeable=False,
|
||||
removable=False,
|
||||
save=False)
|
||||
@@ -98,6 +99,7 @@ class GroupManager(object):
|
||||
"Users",
|
||||
"All logged in users",
|
||||
self.default_permissions_for_group(USER_GROUP),
|
||||
[],
|
||||
default=True,
|
||||
removable=False,
|
||||
toggleable=False,
|
||||
@@ -106,8 +108,17 @@ class GroupManager(object):
|
||||
"Guests",
|
||||
"Anyone who is not currently logged in",
|
||||
self.default_permissions_for_group(GUEST_GROUP),
|
||||
[],
|
||||
removable=False,
|
||||
toggleable=False,
|
||||
save=False),
|
||||
self.add_group(READONLY_GROUP,
|
||||
"Read-only Access",
|
||||
"Group to gain read-only access",
|
||||
self.default_permissions_for_group(READONLY_GROUP),
|
||||
[],
|
||||
changeable=False,
|
||||
removable=False,
|
||||
save=False)
|
||||
|
||||
def register_listener(self, listener):
|
||||
@@ -116,10 +127,11 @@ class GroupManager(object):
|
||||
def unregister_listener(self, listener):
|
||||
self._group_change_listeners.remove(listener)
|
||||
|
||||
def add_group(self, key, name, description, permissions, default=False, removable=True, changeable=True, toggleable=True, save=True, notify=True):
|
||||
def add_group(self, key, name, description, permissions, subgroups,
|
||||
default=False, removable=True, changeable=True, toggleable=True, save=True, notify=True):
|
||||
pass
|
||||
|
||||
def update_group(self, key, description=None, permissions=None, default=None, save=True, notify=True):
|
||||
def update_group(self, key, description=None, permissions=None, subgroups=None, default=None, save=True, notify=True):
|
||||
pass
|
||||
|
||||
def remove_group(self, key, save=True, notify=True):
|
||||
@@ -135,6 +147,13 @@ class GroupManager(object):
|
||||
def _from_permissions(self, *permissions):
|
||||
return [permission.key for permission in permissions]
|
||||
|
||||
def _from_groups(self, *groups):
|
||||
return [group.key for group in groups]
|
||||
|
||||
def _to_groups(self, *groups):
|
||||
return filter(lambda x: x is not None,
|
||||
[self._to_group(g) for g in groups])
|
||||
|
||||
def _to_group(self, group):
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(group, Group):
|
||||
@@ -165,6 +184,9 @@ class GroupChangeListener(object):
|
||||
def on_group_permissions_changed(self, group, added=None, removed=None):
|
||||
pass
|
||||
|
||||
def on_group_subgroups_changed(self, group, added=None, removed=None):
|
||||
pass
|
||||
|
||||
|
||||
class FilebasedGroupManager(GroupManager):
|
||||
def __init__(self, path=None):
|
||||
@@ -187,41 +209,49 @@ class FilebasedGroupManager(GroupManager):
|
||||
with io.open(self._groupfile, 'rt', encoding='utf-8') as f:
|
||||
data = yaml.safe_load(f)
|
||||
|
||||
if not "groups" in data:
|
||||
groups = data
|
||||
data = dict(groups=groups)
|
||||
if not "groups" in data:
|
||||
groups = data
|
||||
data = dict(groups=groups)
|
||||
|
||||
groups = data.get("groups", dict())
|
||||
tracked_permissions = data.get("tracked", list())
|
||||
groups = data.get("groups", dict())
|
||||
tracked_permissions = data.get("tracked", list())
|
||||
|
||||
for key, attributes in groups.items():
|
||||
if key in self._groups:
|
||||
# group is already there (from the defaults most likely)
|
||||
if not self._groups[key].is_changeable():
|
||||
# group may not be changed -> bail
|
||||
continue
|
||||
for key, attributes in groups.items():
|
||||
if key in self._groups:
|
||||
# group is already there (from the defaults most likely)
|
||||
if not self._groups[key].is_changeable():
|
||||
# group may not be changed -> bail
|
||||
continue
|
||||
|
||||
removable = self._groups[key].is_removable()
|
||||
changeable = self._groups[key].is_changeable()
|
||||
toggleable = self._groups[key].is_toggleable()
|
||||
else:
|
||||
removable = True
|
||||
changeable = True
|
||||
toggleable = True
|
||||
removable = self._groups[key].is_removable()
|
||||
changeable = self._groups[key].is_changeable()
|
||||
toggleable = self._groups[key].is_toggleable()
|
||||
else:
|
||||
removable = True
|
||||
changeable = True
|
||||
toggleable = True
|
||||
|
||||
permissions = self._to_permissions(*attributes.get("permissions", []))
|
||||
default_permissions = self.default_permissions_for_group(key)
|
||||
for permission in default_permissions:
|
||||
if not permission.key in tracked_permissions and not permission in permissions:
|
||||
permissions.append(permission)
|
||||
permissions = self._to_permissions(*attributes.get("permissions", []))
|
||||
default_permissions = self.default_permissions_for_group(key)
|
||||
for permission in default_permissions:
|
||||
if not permission.key in tracked_permissions and not permission in permissions:
|
||||
permissions.append(permission)
|
||||
|
||||
subgroups = attributes.get("subgroups", [])
|
||||
|
||||
group = Group(key, attributes.get("name", ""),
|
||||
description=attributes.get("description", ""),
|
||||
permissions=permissions,
|
||||
subgroups=subgroups,
|
||||
default=attributes.get("default", False),
|
||||
removable=removable,
|
||||
changeable=changeable,
|
||||
toggleable=toggleable)
|
||||
self._groups[key] = group
|
||||
|
||||
for group in self._groups.values():
|
||||
group._subgroups = self._to_groups(*group._subgroups)
|
||||
|
||||
self._groups[key] = Group(key, attributes.get("name", ""),
|
||||
description=attributes.get("description", ""),
|
||||
permissions=permissions,
|
||||
default=attributes.get("default", False),
|
||||
removable=removable,
|
||||
changeable=changeable,
|
||||
toggleable=toggleable)
|
||||
except Exception:
|
||||
self._logger.exception("Error while loading groups from file {}".format(self._groupfile))
|
||||
|
||||
@@ -236,6 +266,7 @@ class FilebasedGroupManager(GroupManager):
|
||||
name=group._name,
|
||||
description=group._description,
|
||||
permissions=self._from_permissions(*group._permissions),
|
||||
subgroups=self._from_groups(*group._subgroups),
|
||||
default=group._default
|
||||
)
|
||||
|
||||
@@ -261,7 +292,7 @@ class FilebasedGroupManager(GroupManager):
|
||||
return None
|
||||
return self._groups.get(key)
|
||||
|
||||
def add_group(self, key, name, description, permissions, default=False, removable=True,
|
||||
def add_group(self, key, name, description, permissions, subgroups, default=False, removable=True,
|
||||
changeable=True, toggleable=True, overwrite=False, notify=True, save=True):
|
||||
if key in self._groups and not overwrite:
|
||||
raise GroupAlreadyExists(key)
|
||||
@@ -272,9 +303,13 @@ class FilebasedGroupManager(GroupManager):
|
||||
permissions = self._to_permissions(*permissions)
|
||||
assert(all(map(lambda p: isinstance(p, OctoPrintPermission), permissions)))
|
||||
|
||||
subgroups = self._to_groups(*subgroups)
|
||||
assert(all(map(lambda g: isinstance(g, Group), subgroups)))
|
||||
|
||||
group = Group(key, name,
|
||||
description=description,
|
||||
permissions=permissions,
|
||||
subgroups=subgroups,
|
||||
default=default,
|
||||
changeable=changeable,
|
||||
removable=removable,
|
||||
@@ -306,7 +341,7 @@ class FilebasedGroupManager(GroupManager):
|
||||
if notify:
|
||||
self._notify_listeners("removed", group)
|
||||
|
||||
def update_group(self, key, description=None, permissions=None, default=None, save=True, notify=True):
|
||||
def update_group(self, key, description=None, permissions=None, subgroups=None, default=None, save=True, notify=True):
|
||||
group = self._to_group(key)
|
||||
if group is None:
|
||||
raise UnknownGroup(key)
|
||||
@@ -335,6 +370,21 @@ class FilebasedGroupManager(GroupManager):
|
||||
notifications.append((("permissions_changed", group),
|
||||
dict(added=added_permissions, removed=removed_permissions)))
|
||||
|
||||
if subgroups is not None:
|
||||
subgroups = self._to_groups(*subgroups)
|
||||
assert(all(map(lambda g: isinstance(g, Group), subgroups)))
|
||||
|
||||
removed_subgroups = list(set(group._subgroups) - set(subgroups))
|
||||
added_subgroups = list(set(subgroups) - set(group._subgroups))
|
||||
|
||||
if removed_subgroups:
|
||||
self._dirty = group.remove_subgroups_from_group(removed_subgroups)
|
||||
if added_subgroups:
|
||||
self._dirty = group.add_subgroups_to_group(added_subgroups)
|
||||
|
||||
notifications.append((("subgroups_changed", group),
|
||||
dict(added=added_subgroups, removed=removed_subgroups)))
|
||||
|
||||
if default is not None:
|
||||
group.change_default(default)
|
||||
self._dirty = True
|
||||
@@ -369,11 +419,12 @@ class GroupCantBeChanged(Exception):
|
||||
|
||||
|
||||
class Group(object):
|
||||
def __init__(self, key, name, description="", permissions=None, default=False, removable=True, changeable=True, toggleable=True):
|
||||
def __init__(self, key, name, description="", permissions=None, subgroups=None, default=False, removable=True, changeable=True, toggleable=True):
|
||||
self._key = key
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._permissions = permissions
|
||||
self._subgroups = subgroups
|
||||
self._default = default
|
||||
self._removable = removable
|
||||
self._changeable = changeable
|
||||
@@ -386,6 +437,7 @@ class Group(object):
|
||||
name=self.get_name(),
|
||||
description=self._description,
|
||||
permissions=list(map(lambda p: p.key, self._permissions)),
|
||||
subgroups=list(map(lambda g: g.key, self._subgroups)),
|
||||
needs=OctoPrintPermission.convert_needs_to_dict(self.needs),
|
||||
default=self._default,
|
||||
removable=self._removable,
|
||||
@@ -453,6 +505,45 @@ class Group(object):
|
||||
|
||||
return dirty
|
||||
|
||||
def add_subgroups_to_group(self, subgroups):
|
||||
"""Adds a list of subgroups to a group"""
|
||||
if not self.is_changeable():
|
||||
raise GroupCantBeChanged(self.key)
|
||||
|
||||
# Make sure the subgroups variable is of type list
|
||||
if not isinstance(subgroups, list):
|
||||
subgroups = [subgroups]
|
||||
|
||||
assert(all(map(lambda g: isinstance(g, Group), subgroups)))
|
||||
|
||||
dirty = False
|
||||
for group in subgroups:
|
||||
if group.is_toggleable() and group not in self._subgroups:
|
||||
self._subgroups.append(group)
|
||||
dirty = True
|
||||
|
||||
return dirty
|
||||
|
||||
def remove_subgroups_from_group(self, subgroups):
|
||||
"""Removes a list of subgroups from a group"""
|
||||
"""Adds a list of subgroups to a group"""
|
||||
if not self.is_changeable():
|
||||
raise GroupCantBeChanged(self.key)
|
||||
|
||||
# Make sure the subgroups variable is of type list
|
||||
if not isinstance(subgroups, list):
|
||||
subgroups = [subgroups]
|
||||
|
||||
assert (all(map(lambda g: isinstance(g, Group), subgroups)))
|
||||
|
||||
dirty = False
|
||||
for group in subgroups:
|
||||
if group.is_toggleable() and group in self._subgroups:
|
||||
self._subgroups.remove(group)
|
||||
dirty = True
|
||||
|
||||
return dirty
|
||||
|
||||
def change_default(self, default):
|
||||
"""Changes the default flag of a Group"""
|
||||
if not self.is_changeable():
|
||||
@@ -471,12 +562,18 @@ class Group(object):
|
||||
|
||||
return list(filter(lambda p: p is not None, self._permissions))
|
||||
|
||||
@property
|
||||
def subgroups(self):
|
||||
return filter(lambda g: g is not None, self._subgroups)
|
||||
|
||||
@property
|
||||
def needs(self):
|
||||
needs = set()
|
||||
needs.add(GroupNeed(self.key))
|
||||
for p in self.permissions:
|
||||
needs = needs.union(p.needs)
|
||||
for g in self.subgroups:
|
||||
needs = needs.union(g.needs)
|
||||
|
||||
return needs
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from collections import OrderedDict, defaultdict
|
||||
# noinspection PyCompatibility
|
||||
from past.builtins import basestring
|
||||
|
||||
from octoprint.access import ADMIN_GROUP, USER_GROUP, GUEST_GROUP
|
||||
from octoprint.access import ADMIN_GROUP, USER_GROUP, READONLY_GROUP
|
||||
|
||||
|
||||
class OctoPrintPermission(Permission):
|
||||
@@ -262,7 +262,7 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
gettext("Allows to gather status information, e.g. job progress, "
|
||||
"printer state, temperatures, ..."),
|
||||
RoleNeed("status"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
|
||||
CONNECTION = OctoPrintPermission("Connection",
|
||||
gettext("Allows to connect to and disconnect from a printer"),
|
||||
@@ -272,7 +272,7 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
WEBCAM = OctoPrintPermission("Webcam",
|
||||
gettext("Allows to watch the webcam stream"),
|
||||
RoleNeed("webcam"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
|
||||
SYSTEM = OctoPrintPermission("System",
|
||||
gettext("Allows to run system commands, e.g. restart OctoPrint, "
|
||||
@@ -284,7 +284,7 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
gettext("Allows to retrieve a list of all uploaded files, including"
|
||||
"their metadata (e.g. date, file size, analysis results, ...)"),
|
||||
RoleNeed("files_list"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
FILES_UPLOAD = OctoPrintPermission("File Upload",
|
||||
gettext("Allows users to upload new files"),
|
||||
RoleNeed("files_upload"),
|
||||
@@ -293,7 +293,7 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
gettext("Allows users to download files. The GCODE viewer is "
|
||||
"affected by this as well."),
|
||||
RoleNeed("files_download"), FILES_LIST,
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
FILES_DELETE = OctoPrintPermission("File Delete",
|
||||
gettext("Allows users to delete files"),
|
||||
RoleNeed("files_delete"), FILES_LIST,
|
||||
@@ -313,13 +313,13 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
gettext("Allows access to the GCODE viewer. Includes the \"File Download\""
|
||||
"permission."),
|
||||
RoleNeed("gcodeviewer"), FILES_DOWNLOAD,
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
|
||||
MONITOR_TERMINAL = OctoPrintPermission("Terminal",
|
||||
gettext("Allows to watch the terminal tab but not to send commands "
|
||||
"to the printer from it"),
|
||||
RoleNeed("monitor_terminal"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
|
||||
CONTROL = OctoPrintPermission("Control",
|
||||
gettext("Allows to control of the printer by using the temperature controls,"
|
||||
@@ -335,11 +335,11 @@ class Permissions(with_metaclass(PermissionsMetaClass)):
|
||||
TIMELAPSE_LIST = OctoPrintPermission("Timelapse List",
|
||||
gettext("Allows to list timelapse videos"),
|
||||
RoleNeed("timelapse_list"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
TIMELAPSE_DOWNLOAD = OctoPrintPermission("Timelapse Download",
|
||||
gettext("Allows to download timelapse videos"),
|
||||
RoleNeed("timelapse_download"),
|
||||
default_groups=[USER_GROUP, GUEST_GROUP])
|
||||
default_groups=[USER_GROUP, READONLY_GROUP])
|
||||
TIMELAPSE_DELETE = OctoPrintPermission("Timelapse Delete",
|
||||
gettext("Allows to delete timelapse videos and unrendered timelapses"),
|
||||
RoleNeed("timelapse_delete"),
|
||||
|
||||
@@ -264,6 +264,16 @@ class UserManager(GroupChangeListener, object):
|
||||
except Exception:
|
||||
self._logger.exception("Error in on_user_modified on {!r}".format(listener))
|
||||
|
||||
def on_group_subgroups_changed(self, group, added=None, removed=None):
|
||||
users = self.find_sessions_for(lambda u: group in u.groups)
|
||||
for listener in self._login_status_listeners:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
for user in users:
|
||||
listener.on_user_modified(user)
|
||||
except Exception:
|
||||
self._logger.exception("Error in on_user_modified on {!r}".format(listener))
|
||||
|
||||
def _trigger_on_user_modified(self, user):
|
||||
if isinstance(user, basestring):
|
||||
# user id
|
||||
@@ -768,6 +778,15 @@ class FilebasedUserManager(UserManager):
|
||||
# call parent
|
||||
UserManager.on_group_permissions_changed(self, group, added=added, removed=removed)
|
||||
|
||||
def on_group_subgroups_changed(self, group, added=None, removed=None):
|
||||
# refresh our group references
|
||||
for user in self.get_all_users():
|
||||
if group in user.groups:
|
||||
self._refresh_groups(user)
|
||||
|
||||
# call parent
|
||||
UserManager.on_group_subgroups_changed(self, group, added=added, removed=removed)
|
||||
|
||||
#~~ Helpers
|
||||
|
||||
def _to_groups(self, *groups):
|
||||
|
||||
@@ -22,6 +22,7 @@ import flask
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking, check_etag
|
||||
from octoprint.util import utmify, count
|
||||
@@ -52,11 +53,13 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
|
||||
dict(key="READ",
|
||||
name="Read announcements",
|
||||
description=gettext("Allows to read announcements"),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["read"]),
|
||||
dict(key="MANAGE",
|
||||
name="Manage announcement subscriptions",
|
||||
description=gettext("Allows to manage announcement subscriptions. Includes \"Read announcements\" "
|
||||
"permission"),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["manage"],
|
||||
permissions=["PLUGIN_ANNOUNCEMENTS_READ"])
|
||||
]
|
||||
|
||||
@@ -9,6 +9,7 @@ from octoprint.settings import settings
|
||||
|
||||
from octoprint.server import NO_CONTENT
|
||||
from octoprint.server.util.flask import redirect_to_tornado, no_firstrun_access
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
from flask import request, jsonify, url_for, make_response
|
||||
@@ -38,6 +39,7 @@ class LoggingPlugin(octoprint.plugin.AssetPlugin,
|
||||
dict(key="MANAGE",
|
||||
name="Logging management",
|
||||
description=gettext("Allows to download and delete log files and list and set log levels."),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["manage"])
|
||||
]
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import octoprint.plugin.core
|
||||
|
||||
from octoprint.settings import valid_boolean_trues
|
||||
from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking, check_etag
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.util.pip import LocalPipCaller
|
||||
from octoprint.util.version import get_octoprint_version_string, get_octoprint_version, is_octoprint_compatible
|
||||
@@ -136,10 +137,12 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
dict(key="MANAGE",
|
||||
name="Manage plugins",
|
||||
description=gettext("Allows to enable, disable and uninstall installed plugins."),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["manage"]),
|
||||
dict(key="INSTALL",
|
||||
name="Install new plugins",
|
||||
description=gettext("Allows to install new plugins. Includes the \"Manage plugins\" permission."),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["install"],
|
||||
permissions=["PLUGIN_PLUGINMANAGER_MANAGE"],
|
||||
dangerous=True)
|
||||
|
||||
@@ -27,7 +27,7 @@ from flask_babel import gettext
|
||||
|
||||
from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking, check_etag
|
||||
from octoprint.server import VERSION, REVISION, BRANCH
|
||||
from octoprint.access import USER_GROUP
|
||||
from octoprint.access import USER_GROUP, ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.util import dict_merge, to_unicode
|
||||
from octoprint.util.version import get_comparable_version
|
||||
@@ -103,6 +103,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
dict(key="UPDATE",
|
||||
name="Update",
|
||||
description=gettext("Allows to perform software updates"),
|
||||
default_groups=[ADMIN_GROUP],
|
||||
roles=["update"],
|
||||
dangerous=True)
|
||||
]
|
||||
|
||||
@@ -55,10 +55,11 @@ def add_group():
|
||||
name = data["name"]
|
||||
description = data.get("description", "")
|
||||
permissions = data["permissions"]
|
||||
subgroups = data["subgroups"]
|
||||
default = data.get("default", False)
|
||||
|
||||
try:
|
||||
groupManager.add_group(key, name, description=description, permissions=permissions, default=default)
|
||||
groupManager.add_group(key, name, description=description, permissions=permissions, subgroups=subgroups, default=default)
|
||||
except groups.GroupAlreadyExists:
|
||||
abort(409)
|
||||
return get_groups()
|
||||
@@ -93,6 +94,9 @@ def update_group(key):
|
||||
if "permissions" in data:
|
||||
kwargs["permissions"] = data["permissions"]
|
||||
|
||||
if "subgroups" in data:
|
||||
kwargs["subgroups"] = data["subgroups"]
|
||||
|
||||
if "default" in data:
|
||||
kwargs["default"] = data["default"] in valid_boolean_trues
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from octoprint.events import Events
|
||||
from octoprint.settings import settings
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.access.users import LoginStatusListener
|
||||
from octoprint.access.groups import GroupChangeListener
|
||||
from octoprint.util.json import JsonEncoding
|
||||
|
||||
import octoprint.printer
|
||||
@@ -69,7 +70,8 @@ class JsonEncodingSessionWrapper(wrapt.ObjectProxy):
|
||||
|
||||
class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
|
||||
octoprint.printer.PrinterCallback,
|
||||
LoginStatusListener):
|
||||
LoginStatusListener,
|
||||
GroupChangeListener):
|
||||
|
||||
_emit_permissions = {"connected": [],
|
||||
"reauthRequired": [],
|
||||
@@ -307,6 +309,10 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection,
|
||||
if self._user.is_anonymous and group == self._groupManager.guest_group:
|
||||
self._sendReauthRequired("modified")
|
||||
|
||||
def on_group_subgroups_changed(self, group, added=None, removed=None):
|
||||
if self._user.is_anonymous and group == self._groupManager.guest_group:
|
||||
self._sendReauthRequired("modified")
|
||||
|
||||
def _onEvent(self, event, payload):
|
||||
self.sendEvent(event, payload)
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
@@ -82,6 +82,7 @@
|
||||
var data = {
|
||||
description: group.description,
|
||||
permissions: group.permissions,
|
||||
subgroups: group.subgroups,
|
||||
default: group.default
|
||||
};
|
||||
return this.base.putJson(this.url(group.key), data, opts);
|
||||
|
||||
@@ -112,7 +112,7 @@ $(function() {
|
||||
if (!CONFIG_ACCESS_CONTROL) return;
|
||||
if (!access.loginState.hasPermissionKo(access.permissions.ADMIN)) return;
|
||||
|
||||
OctoPrint.access.users.list()
|
||||
return OctoPrint.access.users.list()
|
||||
.done(self.fromResponse);
|
||||
};
|
||||
|
||||
@@ -348,6 +348,7 @@ $(function() {
|
||||
name: ko.observable(undefined),
|
||||
description: ko.observable(undefined),
|
||||
permissions: ko.observableArray([]),
|
||||
subgroups: ko.observableArray([]),
|
||||
default: ko.observable(false),
|
||||
permissionSelected: function(permission) {
|
||||
var index = self.editor.permissions().indexOf(permission);
|
||||
@@ -363,6 +364,23 @@ $(function() {
|
||||
}
|
||||
self.editor.permissions(permissions);
|
||||
},
|
||||
subgroupSelected: function(subgroup) {
|
||||
var index = self.editor.subgroups().indexOf(subgroup);
|
||||
return index >= 0;
|
||||
},
|
||||
toggleSubgroup: function(subgroup) {
|
||||
var subgroups = self.editor.subgroups();
|
||||
var index = subgroups.indexOf(subgroup);
|
||||
if (index < 0) {
|
||||
subgroups.push(subgroup);
|
||||
} else {
|
||||
subgroups.splice(index, 1);
|
||||
}
|
||||
self.editor.subgroups(subgroups);
|
||||
},
|
||||
joinedGroupPermissions: function(group) {
|
||||
return access.permissionList(group);
|
||||
},
|
||||
header: ko.observable(undefined),
|
||||
new: ko.observable(true),
|
||||
confirm: undefined,
|
||||
@@ -420,6 +438,7 @@ $(function() {
|
||||
self.editor.name(undefined);
|
||||
self.editor.description(undefined);
|
||||
self.editor.permissions([]);
|
||||
self.editor.subgroups([]);
|
||||
self.editor.default(false);
|
||||
self.editor.header(gettext("Add group"));
|
||||
self.editor.new(true);
|
||||
@@ -430,6 +449,7 @@ $(function() {
|
||||
self.editor.name(newValue.name);
|
||||
self.editor.description(newValue.description);
|
||||
self.editor.permissions(newValue.permissions.slice(0));
|
||||
self.editor.subgroups(newValue.subgroups.slice(0));
|
||||
self.editor.default(newValue.default);
|
||||
self.editor.header(_.sprintf(gettext("Edit group \"%(name)s\""), {name: newValue.name}));
|
||||
self.editor.new(false);
|
||||
@@ -438,13 +458,11 @@ $(function() {
|
||||
});
|
||||
|
||||
self.requestData = function() {
|
||||
OctoPrint.access.groups.list()
|
||||
return OctoPrint.access.groups.list()
|
||||
.done(self.fromResponse);
|
||||
};
|
||||
|
||||
self.fromResponse = function(response) {
|
||||
self.listHelper.updateItems(response.groups);
|
||||
|
||||
var lookup = {};
|
||||
var defaults = [];
|
||||
_.each(response.groups, function(group) {
|
||||
@@ -455,11 +473,18 @@ $(function() {
|
||||
});
|
||||
self.lookup = lookup;
|
||||
self.defaults = defaults;
|
||||
self.listHelper.updateItems(response.groups);
|
||||
};
|
||||
|
||||
self.showAddGroupDialog = function() {
|
||||
self.currentGroup(undefined);
|
||||
self.groupEditorDialog.modal("show");
|
||||
$('ul.nav-pills a[data-toggle="tab"]:first', self.groupEditorDialog).tab("show");
|
||||
self.groupEditorDialog.modal({
|
||||
minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); }
|
||||
}).css({
|
||||
width: 'auto',
|
||||
'margin-left': function() { return -($(this).width() /2); }
|
||||
});
|
||||
};
|
||||
|
||||
self.confirmAddGroup = function() {
|
||||
@@ -468,6 +493,7 @@ $(function() {
|
||||
name: self.editor.name(),
|
||||
description: self.editor.description(),
|
||||
permissions: self.editor.permissions(),
|
||||
subgroups: self.editor.subgroups(),
|
||||
default: self.editor.default()
|
||||
};
|
||||
|
||||
@@ -483,7 +509,13 @@ $(function() {
|
||||
if (!group.changeable) return;
|
||||
|
||||
self.currentGroup(group);
|
||||
self.groupEditorDialog.modal("show");
|
||||
$('ul.nav-pills a[data-toggle="tab"]:first', self.groupEditorDialog).tab("show");
|
||||
self.groupEditorDialog.modal({
|
||||
minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); }
|
||||
}).css({
|
||||
width: 'auto',
|
||||
'margin-left': function() { return -($(this).width() /2); }
|
||||
});
|
||||
};
|
||||
|
||||
self.confirmEditGroup = function() {
|
||||
@@ -500,6 +532,11 @@ $(function() {
|
||||
data.permissions = editorPermissions;
|
||||
}
|
||||
|
||||
var editorSubgroups = self.editor.subgroups();
|
||||
if (!_.isEqual(group.subgroups.sort(), editorSubgroups.sort())) {
|
||||
data.subgroups = editorSubgroups;
|
||||
}
|
||||
|
||||
if (group.default !== self.editor.default()) {
|
||||
data.default = self.editor.default();
|
||||
}
|
||||
@@ -663,6 +700,18 @@ $(function() {
|
||||
}).join(", ");
|
||||
};
|
||||
|
||||
// Maps the sub group names into a comma separated list
|
||||
access.subgroupList = function(data) {
|
||||
if (data.subgroups === undefined)
|
||||
return "";
|
||||
|
||||
var mappedGroups = _.filter(_.map(data.subgroups, function(g) { return access.groups.lookup[g] }), function(g) { return g !== undefined });
|
||||
mappedGroups.sort(access.groupComparator);
|
||||
return _.map(mappedGroups, function(g) {
|
||||
return g.name;
|
||||
}).join(", ");
|
||||
};
|
||||
|
||||
// Maps the permission names into a comma separated list
|
||||
access.permissionList = function(data) {
|
||||
if (!data || data.permissions === undefined)
|
||||
@@ -691,8 +740,10 @@ $(function() {
|
||||
|
||||
access.onUserPermissionsChanged = access.onUserLoggedIn = access.onUserLoggedOut = function(user) {
|
||||
if (access.loginState.hasPermission(access.permissions.SETTINGS)) {
|
||||
access.groups.requestData();
|
||||
access.users.requestData();
|
||||
access.groups.requestData()
|
||||
.done(function() {
|
||||
access.users.requestData();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -383,6 +383,20 @@ table {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
table.settings_groups_details_table {
|
||||
font-size: 0.8em;
|
||||
margin-bottom: 0;
|
||||
|
||||
.settings_groups_details_key {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.settings_users_actions,
|
||||
&.settings_groups_actions {
|
||||
width: 60px;
|
||||
@@ -397,6 +411,10 @@ table {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
&.settings_accesscontrol_subgroups_list_checkbox {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
#settings-usersDialogAddUser, #settings-usersDialogEditUser {
|
||||
position: relative;
|
||||
top: 50%;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<tr>
|
||||
<th class="settings_groups_default"></th>
|
||||
<th class="settings_groups_name">{{ _('Name') }}</th>
|
||||
<th class="settings_groups_permissions">{{ _('Permissions') }}</th>
|
||||
<th class="settings_groups_details">{{ _('Details') }}</th>
|
||||
<th class="settings_groups_actions">{{ _('Action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -14,7 +14,18 @@
|
||||
<span data-bind="text: name"></span><br>
|
||||
<small class="muted" data-bind="text: description"></small>
|
||||
</td>
|
||||
<td class="settings_groups_permissions"><small><span data-bind="text: $root.access.permissionList($data)"></span></small></td>
|
||||
<td class="settings_groups_details">
|
||||
<table class="table settings_groups_details_table">
|
||||
<tr>
|
||||
<th class="settings_groups_details_key">{{ _('Permissions') }}</th>
|
||||
<td class="settings_groups_details_value" data-bind="text: $root.access.permissionList($data)"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="settings_groups_details_key">{{ _('Subgroups') }}</th>
|
||||
<td class="settings_groups_details_value" data-bind="text: $root.access.subgroupList($data)"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td class="settings_groups_actions">
|
||||
<a href="#" class="fa fa-pencil" title="{{ _('Update group') }}" data-bind="enable: changeable, css: {disabled: !changeable}, click: function() { $root.access.groups.showEditGroupDialog($data); }"></a> | <a href="#" class="fa fa-trash-o" title="{{ _('Delete group') }}" data-bind="enable: removable, css: {disabled: !removable}, click: function() { $root.access.groups.removeGroup($data); }"></a>
|
||||
</td>
|
||||
@@ -43,33 +54,59 @@
|
||||
<h3 data-bind="text: $root.access.groups.editor.header"></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-groupsDialogAddGroupName">{{ _('Name') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" id="settings-groupsDialogAddGroupName" data-bind="disable: !$root.access.groups.editor.new(), textInput: $root.access.groups.editor.name" required>
|
||||
<div class="full-sized-box">
|
||||
<ul class="nav nav-pills">
|
||||
<li id="settings_accesscontrol_groups_add_general_link" class="active">
|
||||
<a href="#settings_accesscontrol_groups_add_general" data-toggle="tab">{{ _('General') }}</a>
|
||||
</li>
|
||||
<li id="settings_accesscontrol_groups_add_permissions_link">
|
||||
<a href="#settings_accesscontrol_groups_add_permissions" data-toggle="tab">{{ _('Permissions') }}</a>
|
||||
</li>
|
||||
<li id="settings_accesscontrol_groups_add_subgroups_link">
|
||||
<a href="#settings_accesscontrol_groups_add_subgroups" data-toggle="tab">{{ _('Subgroups') }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div id="settings_accesscontrol_groups_add_general" class="tab-pane active">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-groupsDialogAddGroupName">{{ _('Name') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" id="settings-groupsDialogAddGroupName" data-bind="disable: !$root.access.groups.editor.new(), textInput: $root.access.groups.editor.name" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-groupsDialogAddGroupDescription">{{ _('Description') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" id="settings-groupsDialogAddGroupDescription" data-bind="value: $root.access.groups.editor.description">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" id="settings-groupsDialogEditDefault" data-bind="checked: $root.access.groups.editor.default"> {{ _('Default') }}
|
||||
</label>
|
||||
<span class="help-block">{{ _('Marking a group as default will make it get pre selected when creating new users.') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div id="settings_accesscontrol_groups_add_permissions" class="tab-pane">
|
||||
<!-- ko with: $root.access.groups -->
|
||||
<!-- ko with: $root.access.permissions -->
|
||||
{% include 'snippets/settings/accesscontrol/permission_list.jinja2' %}
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
<div id="settings_accesscontrol_groups_add_subgroups" class="tab-pane">
|
||||
<!-- ko with: $root.access.groups -->
|
||||
<!-- ko with: $root.access.groups -->
|
||||
{% include 'snippets/settings/accesscontrol/subgroup_list.jinja2' %}
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-groupsDialogAddGroupDescription">{{ _('Description') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" id="settings-groupsDialogAddGroupDescription" data-bind="value: $root.access.groups.editor.description">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" id="settings-groupsDialogEditDefault" data-bind="checked: $root.access.groups.editor.default"> {{ _('Default') }}
|
||||
</label>
|
||||
<span class="help-block">{{ _('Marking a group as default will make it be pre selected when creating new users.') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ko with: $root.access.groups -->
|
||||
<!-- ko with: $root.access.permissions -->
|
||||
{% include 'snippets/settings/accesscontrol/permission_list.jinja2' %}
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">{{ _('Abort') }}</button>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<table class="table table-condensed table-hover settings_accesscontrol_groups_list">
|
||||
<tbody data-bind="foreach: groupsList()">
|
||||
<tr>
|
||||
<td class="settings_accesscontrol_subgroups_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.subgroups, enable: toggleable"></td>
|
||||
<td class="settings_accesscontrol_subgroups_list_name" style="cursor: pointer" data-bind="click: function() { if ($data.toggleable) { $parents[1].editor.toggleSubgroup($data.key) } }, attr: {title: description}">
|
||||
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.subgroupSelected($data.name)) ? 'bold' : 'normal' }"></span> <small class="label label-info" data-bind="visible: !$data.toggleable" title="{{ _('Fixed groups can\'t be added or removed to other groups.') }}">{{ _('Fixed') }}</small><br>
|
||||
<small class="description" data-bind="text: description"></small><br>
|
||||
<small class="permissions muted" data-bind="text: $parents[1].editor.joinedGroupPermissions($data)"></small>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -35,7 +35,9 @@ def group_manager_with_temp_file():
|
||||
class GroupManagerTestCase(unittest.TestCase):
|
||||
def test_add_remove_group(self):
|
||||
with group_manager_with_temp_file() as group_manager:
|
||||
group_manager.add_group("fancy", "Fancy Group", "My Fancy New Group", permissions=[TEST_PERMISSION_1],
|
||||
group_manager.add_group("fancy", "Fancy Group", "My Fancy New Group",
|
||||
permissions=[TEST_PERMISSION_1],
|
||||
subgroups=[],
|
||||
save=False)
|
||||
self.assertIsNotNone(group_manager.find_group("fancy"))
|
||||
|
||||
|
||||
Reference in new issue
Block a user