From 873d6af8bc843c6eea6049ace2f5218a371f01d4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 27 Feb 2018 17:02:40 +0100 Subject: [roomplanner] Add permissions --- modules-available/locations/page.inc.php | 4 +- .../locations/templates/location-subnets.html | 6 +- .../roomplanner/hooks/runmode/config.json | 3 +- modules-available/roomplanner/js/grid.js | 85 ++--- modules-available/roomplanner/page.inc.php | 45 ++- .../roomplanner/permissions/permissions.json | 11 +- modules-available/roomplanner/style.css | 3 + .../roomplanner/templates/footer.html | 59 ++++ .../roomplanner/templates/header.html | 49 +++ .../roomplanner/templates/item-selector.html | 314 ++++++++++++++++++ .../roomplanner/templates/main-roomplan.html | 18 + modules-available/roomplanner/templates/page.html | 369 --------------------- 12 files changed, 534 insertions(+), 432 deletions(-) create mode 100644 modules-available/roomplanner/templates/footer.html create mode 100644 modules-available/roomplanner/templates/header.html create mode 100644 modules-available/roomplanner/templates/item-selector.html create mode 100644 modules-available/roomplanner/templates/main-roomplan.html delete mode 100644 modules-available/roomplanner/templates/page.html diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 08f9b518..0a6fdb10 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -495,9 +495,7 @@ class Page_Locations extends Page { $locationId = Request::any('locationid', 0, 'integer'); - if (!User::hasPermission("location.view", $locationId)) { - die('Permission denied'); - } + User::assertPermission("location.view", $locationId); $loc = Database::queryFirst('SELECT locationid, parentlocationid, locationname FROM location WHERE locationid = :lid', array('lid' => $locationId)); diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index 9db75f0b..db94be0a 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -75,9 +75,11 @@
{{#roomplanner}} - - {{lang_editRoomplan}} + + {{^perms.roomplanner.edit.disabled}}{{lang_editRoomplan}}{{/perms.roomplanner.edit.disabled}} + {{#perms.roomplanner.edit.disabled}}{{lang_showRoomplan}}{{/perms.roomplanner.edit.disabled}} {{/roomplanner}}
diff --git a/modules-available/roomplanner/hooks/runmode/config.json b/modules-available/roomplanner/hooks/runmode/config.json index 27c601fd..3cbf4a6c 100644 --- a/modules-available/roomplanner/hooks/runmode/config.json +++ b/modules-available/roomplanner/hooks/runmode/config.json @@ -3,5 +3,6 @@ "isClient": false, "configHook": "PvsGenerator::runmodeConfigHook", "allowGenericEditor": false, - "deleteUrlSnippet": "locationid=" + "deleteUrlSnippet": "locationid=", + "permission": ".roomplanner.edit" } \ No newline at end of file diff --git a/modules-available/roomplanner/js/grid.js b/modules-available/roomplanner/js/grid.js index 466e42aa..ced76678 100644 --- a/modules-available/roomplanner/js/grid.js +++ b/modules-available/roomplanner/js/grid.js @@ -1,5 +1,9 @@ +var $gridInner = $('#draw-element-area'); +var $gridFrame = $('#drawpanel'); +var $grid = $('#drawarea'); + if (!roomplanner) var roomplanner = { - + getScaleFactor: function() { return this.settings.scale/100; }, @@ -280,7 +284,7 @@ if (!roomplanner) var roomplanner = { "computers": [] }; - var furniture = $('#draw-element-area div[itemtype="furniture"]'); + var furniture = $gridInner.find('div[itemtype="furniture"]'); furniture.each(function(idx,el) { objects.furniture.push({ "gridRow" : $(el).attr('gridRow'), @@ -291,7 +295,7 @@ if (!roomplanner) var roomplanner = { }); }); - var computers = $('#draw-element-area div[itemtype="pc"]'); + var computers = $gridInner.find('div[itemtype="pc"]'); computers.each(function(idx,el) { var object = { @@ -326,7 +330,7 @@ if (!roomplanner) var roomplanner = { var objects = object; } - $('#draw-element-area').html(''); + $gridInner.html(''); function itemToHtml(item, itemtype, obstacle) { var html = '
maxX) return; - var width = (maxX - minX) / $('#drawpanel .panel-body').width(); - var height = (maxY - minY) / $('#drawpanel .panel-body').height(); + var width = (maxX - minX) / $gridFrame.find('.panel-body').width(); + var height = (maxY - minY) / $gridFrame.find('.panel-body').height(); var scale; if (width > height) { scale = Math.floor(100 / width); @@ -461,7 +470,7 @@ roomplanner.fitContent = function() { top: -(minY * (scale / 100)) + "px" }; - $('#drawarea').css(opts); + $grid.css(opts); }; $(document).ready(function(){ @@ -480,12 +489,12 @@ $(document).ready(function(){ change: update, slide: update, stop: function(e, ui) { - $('#drawarea').trigger('checkposition'); + $grid.trigger('checkposition'); } }); - $('#drawarea').bind('checkposition', function() { + $grid.bind('checkposition', function() { if ($(this).offset().left > 0) { $(this).css('left',0); } @@ -502,7 +511,7 @@ $(document).ready(function(){ } }); - $('#drawarea').draggable({ + $grid.draggable({ stop: function() { $(this).trigger('checkposition'); } @@ -512,7 +521,7 @@ $(document).ready(function(){ * adds droppable functionality to the draw area for the elements. * drop event is only fired for elements added to the board from the toolbar. */ - $('#draw-element-area').droppable({ + $gridInner.droppable({ accept: ".draggable", drop: function(event, ui) { @@ -528,8 +537,8 @@ $(document).ready(function(){ if (ui.helper != ui.draggable) { - var leftPos = parseInt($(el).css('left'))-parseInt($('#drawarea').css('left'))-$('#drawpanel').offset().left; - var topPos = parseInt($(el).css('top'))-parseInt($('#drawarea').css('top'))-($('#drawpanel').offset().top + $('#drawpanel .panel-heading').height()); + var leftPos = parseInt($(el).css('left'))-parseInt($grid.css('left'))-$gridFrame.offset().left; + var topPos = parseInt($(el).css('top'))-parseInt($grid.css('top'))-($gridFrame.offset().top + $gridFrame.find('.panel-heading').height()); var cp = roomplanner.getCellPositionFromPixels(leftPos,topPos); leftPos = cp[0]; topPos = cp[1]; @@ -575,8 +584,8 @@ $(document).ready(function(){ $(el).css('opacity',1); if (ui.helper != ui.draggable) { - var l = parseInt($(el).css('left'))-parseInt($('#drawarea').css('left'))-$('#drawpanel').offset().left; - var t = parseInt($(el).css('top'))-parseInt($('#drawarea').css('top'))-($('#drawpanel').offset().top + $('#drawpanel .panel-heading').height()); + var l = parseInt($(el).css('left'))-parseInt($grid.css('left'))-$gridFrame.offset().left; + var t = parseInt($(el).css('top'))-parseInt($grid.css('top'))-($gridFrame.offset().top + $gridFrame.find('.panel-heading').height()); var cp = roomplanner.getCellPositionFromPixels(l,t); $(el).css('left',cp[0]); $(el).css('top',cp[1]); @@ -596,7 +605,7 @@ $(document).ready(function(){ if ($(el).attr('itemtype') == "pc") { var uuids = []; - var computers = $('#draw-element-area div[itemtype="pc"]'); + var computers = $gridInner.find('div[itemtype="pc"]'); computers.each(function(idx,el) { if ($(el).attr('muuid')) { uuids.push($(el).attr('muuid')); diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index 764d5cdb..2712560a 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -30,7 +30,7 @@ class Page_Roomplanner extends Page { User::load(); - if (!User::hasPermission('superadmin')) { + if (!User::isLoggedIn()) { Message::addError('main.no-permission'); Util::redirect('?do=Main'); } @@ -79,13 +79,22 @@ class Page_Roomplanner extends Page $subnetMachines = $this->getPotentialMachines(); $machinesOnPlan = $this->getMachinesOnPlan($config['tutoruuid']); $roomConfig = array_merge($furniture, $machinesOnPlan); - Render::addTemplate('page', [ + $canEdit = User::hasPermission('edit', $this->locationid); + $params = [ 'location' => $this->location, 'managerip' => $managerIp, 'dediMgrChecked' => $dediMgr, 'subnetMachines' => json_encode($subnetMachines), 'locationid' => $this->locationid, - 'roomConfiguration' => json_encode($roomConfig)]); + 'roomConfiguration' => json_encode($roomConfig), + 'edit_disabled' => $canEdit ? '' : 'disabled' + ]; + Render::addTemplate('header', $params); + if ($canEdit) { + Render::addTemplate('item-selector', $params); + } + Render::addTemplate('main-roomplan', $params); + Render::addTemplate('footer', $params); } else { Message::addError('main.invalid-action', $this->action); } @@ -97,16 +106,30 @@ class Page_Roomplanner extends Page $this->action = Request::any('action', false, 'string'); if ($this->action === 'getmachines') { + + $locations = User::getAllowedLocations('edit'); + if (empty($locations)) { + die('{"machines":[]}'); + } + $query = Request::get('query', false, 'string'); $aquery = preg_replace('/[^\x01-\x7f]+/', '%', $query); + if (strlen(str_replace('%', '', $aquery)) < 2) { + $aquery = $query; + } + + $condition = 'locationid IN (:locations)'; + if (in_array(0, $locations)) { + $condition .= ' OR locationid IS NULL'; + } - $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid ' - . 'FROM machine ' - . 'WHERE machineuuid LIKE :aquery ' - . ' OR macaddr LIKE :aquery ' - . ' OR clientip LIKE :aquery ' - . ' OR hostname LIKE :query ' - . ' LIMIT 100', ['query' => "%$query%", 'aquery' => "%$aquery%"]); + $result = Database::simpleQuery("SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid + FROM machine + WHERE ($condition) AND machineuuid LIKE :aquery + OR macaddr LIKE :aquery + OR clientip LIKE :aquery + OR hostname LIKE :query + LIMIT 100", ['query' => "%$query%", 'aquery' => "%$aquery%", 'locations' => $locations]); $returnObject = ['machines' => []]; @@ -134,7 +157,7 @@ class Page_Roomplanner extends Page private function handleSaveRequest($isAjax) { - /* save */ + User::assertPermission('edit', $this->locationid); $machinesOnPlan = $this->getMachinesOnPlan('invalid'); $config = Request::post('serializedRoom', null, 'string'); $config = json_decode($config, true); diff --git a/modules-available/roomplanner/permissions/permissions.json b/modules-available/roomplanner/permissions/permissions.json index f7bc3479..6a520a89 100644 --- a/modules-available/roomplanner/permissions/permissions.json +++ b/modules-available/roomplanner/permissions/permissions.json @@ -1,10 +1,5 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "sourceMap": true - }, - "exclude": [ - "node_modules" - ] + "edit": { + "location-aware": true + } } \ No newline at end of file diff --git a/modules-available/roomplanner/style.css b/modules-available/roomplanner/style.css index 6a68a444..9359f82b 100644 --- a/modules-available/roomplanner/style.css +++ b/modules-available/roomplanner/style.css @@ -715,6 +715,9 @@ div.draggable:hover .deleteHandle { display:inline; cursor: pointer;} +.draggable.disabled { + pointer-events: none; +} [itemtype="furniture"], [itemtype="furniture_drag"] { z-index: 99; diff --git a/modules-available/roomplanner/templates/footer.html b/modules-available/roomplanner/templates/footer.html new file mode 100644 index 00000000..6e4e0783 --- /dev/null +++ b/modules-available/roomplanner/templates/footer.html @@ -0,0 +1,59 @@ +
+
+
{{lang_managerIp}}
+ +
+ + +
+
+
+
+ + +
+
+ + + diff --git a/modules-available/roomplanner/templates/header.html b/modules-available/roomplanner/templates/header.html new file mode 100644 index 00000000..5706c970 --- /dev/null +++ b/modules-available/roomplanner/templates/header.html @@ -0,0 +1,49 @@ + + + + +

{{lang_roomplanner}} – {{location.locationname}}

+ + + + \ No newline at end of file diff --git a/modules-available/roomplanner/templates/item-selector.html b/modules-available/roomplanner/templates/item-selector.html new file mode 100644 index 00000000..72607e7c --- /dev/null +++ b/modules-available/roomplanner/templates/item-selector.html @@ -0,0 +1,314 @@ +
+
+ +
+
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
+
+ + +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
+ +
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • + +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • + +
+
+
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+
+
    +
  • +
    +
  • +
+
+ +
+
+
\ No newline at end of file diff --git a/modules-available/roomplanner/templates/main-roomplan.html b/modules-available/roomplanner/templates/main-roomplan.html new file mode 100644 index 00000000..1fc49bea --- /dev/null +++ b/modules-available/roomplanner/templates/main-roomplan.html @@ -0,0 +1,18 @@ +
+
+

{{lang_roomplan}}

+
+
+
+
+
+
+ +
+
+ + +
+
+
+
\ No newline at end of file diff --git a/modules-available/roomplanner/templates/page.html b/modules-available/roomplanner/templates/page.html deleted file mode 100644 index e8544ce8..00000000 --- a/modules-available/roomplanner/templates/page.html +++ /dev/null @@ -1,369 +0,0 @@ - - - - -

{{lang_roomplanner}} – {{location.locationname}}

- - - - - -
-
- -
-
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
-
- - -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
- -
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • - -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • - -
-
-
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
-
-
    -
  • -
    -
  • -
-
- -
-
-
- - - -
-
-

{{lang_roomplan}}

-
-
-
-
-
-
- -
-
- - -
-
-
- - -
- -
-
-
{{lang_managerIp}}
- -
-
-
-
- - -
-
- - - -- cgit v1.2.3-55-g7522