summaryrefslogtreecommitdiffstats
path: root/modules-available/permissionmanager
diff options
context:
space:
mode:
authorUdo Walter2017-04-25 14:50:37 +0200
committerUdo Walter2017-04-25 14:50:37 +0200
commit3e4c27599f920e6f630f048f494f5d196fc81b8e (patch)
tree77c61e2867f26fbbfe928266d433652a3248053e /modules-available/permissionmanager
parentMerge branches 'master' and 'permission-manager' of git.openslx.org:openslx-n... (diff)
downloadslx-admin-3e4c27599f920e6f630f048f494f5d196fc81b8e.tar.gz
slx-admin-3e4c27599f920e6f630f048f494f5d196fc81b8e.tar.xz
slx-admin-3e4c27599f920e6f630f048f494f5d196fc81b8e.zip
[permissionmanager] added possibility to get a list of allowed locations for a given permission + bugfixes
Diffstat (limited to 'modules-available/permissionmanager')
-rw-r--r--modules-available/permissionmanager/clientscript.js95
-rw-r--r--modules-available/permissionmanager/config.json2
-rw-r--r--modules-available/permissionmanager/inc/permissionutil.inc.php56
-rw-r--r--modules-available/permissionmanager/page.inc.php4
-rw-r--r--modules-available/permissionmanager/style.css6
-rw-r--r--modules-available/permissionmanager/templates/roleeditor.html16
6 files changed, 107 insertions, 72 deletions
diff --git a/modules-available/permissionmanager/clientscript.js b/modules-available/permissionmanager/clientscript.js
index edbd3eb9..927d2afa 100644
--- a/modules-available/permissionmanager/clientscript.js
+++ b/modules-available/permissionmanager/clientscript.js
@@ -1,54 +1,59 @@
document.addEventListener("DOMContentLoaded", function() {
- var table = $("table").stupidtable();
-
- // to show the sort-arrow next to the table header
- table.on("aftertablesort", function (event, data) {
- var th = $(this).find("th");
- th.find(".arrow").remove();
- var dir = $.fn.stupidtable.dir;
- var arrow = data.direction === dir.ASC ? "down" : "up";
- th.eq(data.column).append(' <span class="arrow glyphicon glyphicon-chevron-'+arrow+'"></span>');
- });
+ var table = $("table");
+ if (table.length) {
+ table = table.stupidtable();
+ // to show the sort-arrow next to the table header
+ table.on("aftertablesort", function (event, data) {
+ var th = $(this).find("th");
+ th.find(".arrow").remove();
+ var dir = $.fn.stupidtable.dir;
+ var arrow = data.direction === dir.ASC ? "down" : "up";
+ th.eq(data.column).append(' <span class="arrow glyphicon glyphicon-chevron-'+arrow+'"></span>');
+ });
+ }
- var selectize = $('#select-role').selectize({
- allowEmptyOption: false,
- maxItems: null,
- highlight: false,
- hideSelected: true,
- create: false,
- plugins: [ "remove_button" ]
- })[0].selectize;
+ var selectize = $('#select-role');
+ if (selectize.length) {
+ selectize = selectize.selectize({
+ allowEmptyOption: false,
+ maxItems: null,
+ highlight: false,
+ hideSelected: true,
+ create: false,
+ plugins: ["remove_button"]
+ })[0].selectize;
- // If Site gets refreshed, all data-selectizeCounts will be reset to 0, so delete the filters from the selectize
- selectize.clear();
+ // If Site gets refreshed, all data-selectizeCounts will be reset to 0, so delete the filters from the selectize
+ selectize.clear();
- selectize.on('item_add', function(value, $item) {
- // When first item gets added the filter isn't empty anymore, so hide all rows
- if (selectize.items.length === 1) {
- $('.dataTable tbody').find('tr').hide();
- }
- // Find all rows which shall be shown and increase their counter by 1
- $(".roleId-"+value).closest("tr").each(function() {
- $(this).data("selectizeCount", $(this).data("selectizeCount") + 1);
- $(this).show();
+ selectize.on('item_add', function (value, $item) {
+ // When first item gets added the filter isn't empty anymore, so hide all rows
+ if (selectize.items.length === 1) {
+ $('.dataTable tbody').find('tr').hide();
+ }
+ // Find all rows which shall be shown and increase their counter by 1
+ $(".roleId-" + value).closest("tr").each(function () {
+ $(this).data("selectizeCount", $(this).data("selectizeCount") + 1);
+ $(this).show();
+ });
});
- });
- selectize.on('item_remove', function(value, $item) {
- // When no items in the filter, show all rows again
- if (selectize.items.length === 0) {
- $('.dataTable tbody').find('tr').show();
- } else {
- // Find all rows which have the delete role, decrease their counter by 1
- $(".roleId-"+value).closest("tr").each(function() {
- $(this).data("selectizeCount", $(this).data("selectizeCount") - 1);
- // If counter is 0, hide the row (no filter given to show the row anymore)
- if ($(this).data("selectizeCount") === 0) {
- $(this).closest("tr").hide();
- }
- });
- }
- });
+ selectize.on('item_remove', function (value, $item) {
+ // When no items in the filter, show all rows again
+ if (selectize.items.length === 0) {
+ $('.dataTable tbody').find('tr').show();
+ } else {
+ // Find all rows which have the delete role, decrease their counter by 1
+ $(".roleId-" + value).closest("tr").each(function () {
+ $(this).data("selectizeCount", $(this).data("selectizeCount") - 1);
+ // If counter is 0, hide the row (no filter given to show the row anymore)
+ if ($(this).data("selectizeCount") === 0) {
+ $(this).closest("tr").hide();
+ }
+ });
+ }
+ });
+ }
$("form input").keydown(function(e) {
if (e.keyCode === 13) e.preventDefault();
diff --git a/modules-available/permissionmanager/config.json b/modules-available/permissionmanager/config.json
index 5089bdc9..c92e917a 100644
--- a/modules-available/permissionmanager/config.json
+++ b/modules-available/permissionmanager/config.json
@@ -1,4 +1,4 @@
{
"category":"main.content",
- "dependencies": [ "js_stupidtable", "bootstrap_switch", "js_selectize" ]
+ "dependencies": [ "locations", "js_stupidtable", "bootstrap_switch", "js_selectize" ]
}
diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php
index 8442f288..fe16f7ab 100644
--- a/modules-available/permissionmanager/inc/permissionutil.inc.php
+++ b/modules-available/permissionmanager/inc/permissionutil.inc.php
@@ -3,14 +3,28 @@
class PermissionUtil
{
public static function userHasPermission($userid, $permissionid, $locationid) {
- $locations = array();
- if (!is_null($locationid)) {
- $res = Database::simpleQuery("SELECT locationid, parentlocationid FROM location");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $locations[$row["locationid"]] = $row["parentlocationid"];
+ $locations = Location::getLocationRootChain($locationid);
+ if (count($locations) == 0) return false;
+ else $locations[] = 0;
+
+ $res = Database::simpleQuery("SELECT role_x_permission.permissionid as 'permissionid',
+ role_x_location.locid as 'locationid'
+ FROM user_x_role
+ INNER JOIN role_x_permission ON user_x_role.roleid = role_x_permission.roleid
+ LEFT JOIN role_x_location ON role_x_permission.roleid = role_x_location.roleid
+ WHERE user_x_role.userid = :userid", array("userid" => $userid));
+
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $userPermission = trim($row["permissionid"], "*");
+ if (substr($permissionid, 0, strlen($userPermission)) === $userPermission
+ && (is_null($locationid) || in_array($row["locationid"], $locations))) {
+ return true;
}
- if (!array_key_exists($locationid, $locations)) return false;
}
+ return false;
+ }
+
+ public static function getAllowedLocations($userid, $permissionid) {
$res = Database::simpleQuery("SELECT role_x_permission.permissionid as 'permissionid',
role_x_location.locid as 'locationid'
@@ -19,24 +33,36 @@ class PermissionUtil
LEFT JOIN role_x_location ON role_x_permission.roleid = role_x_location.roleid
WHERE user_x_role.userid = :userid", array("userid" => $userid));
+ $allowedLocations = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$userPermission = trim($row["permissionid"], "*");
if (substr($permissionid, 0, strlen($userPermission)) === $userPermission) {
- if (is_null($locationid) || $locationid == $row["locationid"]) {
- return true;
+ $allowedLocations[] = $row["locationid"];
+ }
+ }
+ $locations = Location::getTree();
+ if (count($allowedLocations) == 1 && $allowedLocations[0] == "0") {
+ $allowedLocations = Location::extractIds($locations);
+ } else {
+ $allowedLocations = self::getSublocations($locations, $allowedLocations);
+ }
+ return $allowedLocations;
+ }
+
+ private static function getSublocations($tree, $locations) {
+ $result = array_flip($locations);
+ foreach ($tree as $location) {
+ if (array_key_exists("children", $location)) {
+ if (in_array($location["locationid"], $locations)) {
+ $result += array_flip(Location::extractIds($location["children"]));
} else {
- $parentlocid = $locationid;
- while ($parentlocid != 0) {
- $parentlocid = $locations[$parentlocid];
- if ($parentlocid == $row["locationid"]) return true;
- }
+ $result += array_flip(self::getSublocations($location["children"], $locations));
}
}
}
- return false;
+ return array_keys($result);
}
-
public static function getPermissions()
{
$permissions = array();
diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php
index 326d5b24..7f288fd9 100644
--- a/modules-available/permissionmanager/page.inc.php
+++ b/modules-available/permissionmanager/page.inc.php
@@ -75,7 +75,7 @@ class Page_PermissionManager extends Page
$data["roleName"] = $roleData["name"];
if (count($roleData["locations"]) == 1 && $roleData["locations"][0] == 0) {
$data["allLocChecked"] = "checked";
- $data["selectizeClass"] = "disabled";
+ $data["selectizeClass"] = "faded unclickable";
} else {
$data["allLocChecked"] = "";
$data["selectizeClass"] = "";
@@ -83,7 +83,7 @@ class Page_PermissionManager extends Page
}
if (count($roleData["permissions"]) == 1 && $roleData["permissions"][0] == "*") {
$data["allPermChecked"] = "checked";
- $data["permissionsClass"] = "disabled";
+ $data["permissionsClass"] = "faded unclickable";
} else {
$data["allPermChecked"] = "";
$data["permissionsClass"] = "";
diff --git a/modules-available/permissionmanager/style.css b/modules-available/permissionmanager/style.css
index e1fac370..504df511 100644
--- a/modules-available/permissionmanager/style.css
+++ b/modules-available/permissionmanager/style.css
@@ -46,10 +46,14 @@
margin: 0;
}
-.disabled {
+.faded {
opacity: 0.6;
}
+.unclickable {
+ pointer-events: none;
+}
+
input[type='checkbox']:disabled {
cursor: inherit;
}
diff --git a/modules-available/permissionmanager/templates/roleeditor.html b/modules-available/permissionmanager/templates/roleeditor.html
index bfabf4af..d1535332 100644
--- a/modules-available/permissionmanager/templates/roleeditor.html
+++ b/modules-available/permissionmanager/templates/roleeditor.html
@@ -63,9 +63,9 @@
allLocations.on('switchChange.bootstrapSwitch', function(event, state) {
if (state) {
- $("#selectize-container").addClass("disabled");
+ $("#selectize-container").addClass("faded unclickable");
} else {
- $("#selectize-container").removeClass("disabled");
+ $("#selectize-container").removeClass("faded unclickable");
}
});
@@ -78,9 +78,9 @@
allPermissions.on('switchChange.bootstrapSwitch', function(event, state) {
if (state) {
- $(".permissions-container").addClass("disabled");
+ $(".permissions-container").addClass("faded unclickable");
} else {
- $(".permissions-container").removeClass("disabled");
+ $(".permissions-container").removeClass("faded unclickable");
}
});
@@ -102,16 +102,16 @@
var parent = $(this).parent().parent();
if (parent.hasClass("panel-heading")) parent = parent.parent();
parent = parent.find("ul:first");
- parent.find("ul").removeClass("disabled");
+ parent.find("ul").removeClass("faded");
var checkboxes = parent.find("input[type=checkbox]");
- if (parent.hasClass("disabled")) {
+ if (parent.hasClass("faded")) {
checkboxes.prop("disabled", false);
checkboxes.prop("checked", false);
- parent.removeClass("disabled");
+ parent.removeClass("faded");
} else {
checkboxes.prop("disabled", true);
checkboxes.prop("checked", true);
- parent.addClass("disabled");
+ parent.addClass("faded");
}
});