From 7e2509c6afbaf2a89d8df747c8e9ad0f48172221 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Tue, 6 Feb 2018 16:16:20 +0100 Subject: [locationinfo] Fix styling of tooltip btns also made the style of two close btns consistent to the rest --- .../templates/ajax-config-location.html | 14 +++--- .../locationinfo/templates/ajax-config-server.html | 10 ++-- .../templates/page-config-panel-default.html | 54 +++++++++++----------- .../templates/page-config-panel-summary.html | 14 +++--- .../templates/page-config-panel-url.html | 18 ++++---- .../locationinfo/templates/page-locations.html | 4 +- .../locationinfo/templates/page-servers.html | 2 +- .../locationinfo/templates/server-prop-bool.html | 6 +-- .../templates/server-prop-dropdown.html | 6 +-- .../templates/server-prop-generic.html | 6 +-- 10 files changed, 68 insertions(+), 66 deletions(-) (limited to 'modules-available/locationinfo/templates') diff --git a/modules-available/locationinfo/templates/ajax-config-location.html b/modules-available/locationinfo/templates/ajax-config-location.html index b42ff98d..102a6ea4 100644 --- a/modules-available/locationinfo/templates/ajax-config-location.html +++ b/modules-available/locationinfo/templates/ajax-config-location.html @@ -110,9 +110,9 @@
- +

- +

@@ -124,9 +124,9 @@
- +

- +

@@ -137,9 +137,9 @@
- +

- +

@@ -170,7 +170,7 @@ setTimepicker($('#settings-outer').find('.timepicker2')); - $('a.helptext').tooltip(); + $('p.helptext').tooltip(); $('#new-openingtime').click(function (e) { e.preventDefault(); diff --git a/modules-available/locationinfo/templates/ajax-config-server.html b/modules-available/locationinfo/templates/ajax-config-server.html index 940bc55a..8c2cb3ba 100644 --- a/modules-available/locationinfo/templates/ajax-config-server.html +++ b/modules-available/locationinfo/templates/ajax-config-server.html @@ -12,9 +12,9 @@ form="form-{{currentbackend}}">
- +

- +

@@ -34,9 +34,9 @@
- +

- +

@@ -92,7 +92,7 @@ currentBackend = value; } - $('a.btn[title]').tooltip(); + $('p.btn[title]').tooltip(); $('#myModalSubmitButton').attr('form', 'form-' + currentBackend); $('.settings-bs-switch').bootstrapSwitch({size:'small'}); diff --git a/modules-available/locationinfo/templates/page-config-panel-default.html b/modules-available/locationinfo/templates/page-config-panel-default.html index b55e3d4d..41a8fd00 100644 --- a/modules-available/locationinfo/templates/page-config-panel-default.html +++ b/modules-available/locationinfo/templates/page-config-panel-default.html @@ -28,9 +28,9 @@
- +

- +

@@ -48,9 +48,9 @@
- +

- +

@@ -69,9 +69,9 @@
- +

- +

@@ -85,9 +85,9 @@
- +

- +

@@ -101,9 +101,9 @@
- +

- +

@@ -128,9 +128,9 @@ max="1440" value="{{calupdate}}" required>
- +

- +

@@ -145,9 +145,9 @@ max="86400" value="{{roomupdate}}" required>
- +

- +

@@ -177,9 +177,9 @@
- +

- +

@@ -193,9 +193,9 @@
- +

- +

@@ -217,9 +217,9 @@
- +

- +

@@ -238,9 +238,9 @@
- +

- +

@@ -255,9 +255,9 @@
- +

- +

@@ -272,9 +272,9 @@
- +

- +

@@ -338,7 +338,7 @@ document.addEventListener("DOMContentLoaded", function () { var $locInput = $('#locationids'); // Initialize fancy tooltips - $('a.helptext').tooltip(); + $('p.helptext').tooltip(); // Add listener to range sliders so their label can be updated $('input[type="range"]').change(function () { $(this).siblings().find('.range-display').text($(this).val()); diff --git a/modules-available/locationinfo/templates/page-config-panel-summary.html b/modules-available/locationinfo/templates/page-config-panel-summary.html index 2a968fc2..3dc93680 100644 --- a/modules-available/locationinfo/templates/page-config-panel-summary.html +++ b/modules-available/locationinfo/templates/page-config-panel-summary.html @@ -28,9 +28,9 @@
- +

- +

@@ -48,9 +48,9 @@
- +

- +

@@ -64,9 +64,9 @@
- +

- +

@@ -151,7 +151,7 @@ document.addEventListener("DOMContentLoaded", function () { var $locInput = $('#locationids'); // Initialize fancy tooltips - $('a.helptext').tooltip(); + $('p.helptext').tooltip(); // Add listener to range sliders so their label can be updated $('input[type="range"]').change(function () { $(this).siblings().find('.range-display').text($(this).val()); diff --git a/modules-available/locationinfo/templates/page-config-panel-url.html b/modules-available/locationinfo/templates/page-config-panel-url.html index cca81509..798ff55d 100644 --- a/modules-available/locationinfo/templates/page-config-panel-url.html +++ b/modules-available/locationinfo/templates/page-config-panel-url.html @@ -25,9 +25,9 @@
- +

- +

@@ -42,9 +42,9 @@ placeholder="http://www.bwlehrpool.de/" pattern=".*://.*" required>
- +

- +

@@ -61,9 +61,9 @@
- +

- +

@@ -77,9 +77,9 @@
- +

- +

@@ -95,6 +95,8 @@ \ No newline at end of file +//--> diff --git a/modules-available/locationinfo/templates/page-servers.html b/modules-available/locationinfo/templates/page-servers.html index eefb1ed5..dbf18b5f 100644 --- a/modules-available/locationinfo/templates/page-servers.html +++ b/modules-available/locationinfo/templates/page-servers.html @@ -60,7 +60,7 @@ diff --git a/modules-available/locationinfo/templates/server-prop-bool.html b/modules-available/locationinfo/templates/server-prop-bool.html index f430d02c..bd9dcc64 100644 --- a/modules-available/locationinfo/templates/server-prop-bool.html +++ b/modules-available/locationinfo/templates/server-prop-bool.html @@ -7,10 +7,10 @@
{{#helptext}} - +

- +

{{/helptext}}
- \ No newline at end of file + diff --git a/modules-available/locationinfo/templates/server-prop-dropdown.html b/modules-available/locationinfo/templates/server-prop-dropdown.html index 80667766..d1351551 100644 --- a/modules-available/locationinfo/templates/server-prop-dropdown.html +++ b/modules-available/locationinfo/templates/server-prop-dropdown.html @@ -10,10 +10,10 @@
{{#helptext}} - +

- +

{{/helptext}}
- \ No newline at end of file + diff --git a/modules-available/locationinfo/templates/server-prop-generic.html b/modules-available/locationinfo/templates/server-prop-generic.html index 9e94c23d..23ff1e4e 100644 --- a/modules-available/locationinfo/templates/server-prop-generic.html +++ b/modules-available/locationinfo/templates/server-prop-generic.html @@ -7,10 +7,10 @@
{{#helptext}} - +

- +

{{/helptext}}
- \ No newline at end of file + -- cgit v1.2.3-55-g7522 From da8870e85f59dc8e83d2c4f50432f688080cb1d1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 Mar 2018 14:17:36 +0100 Subject: [locationinfo] Add permissions --- .../locationinfo/inc/splittime.php.txt | 80 +++++++++++++ modules-available/locationinfo/page.inc.php | 128 +++++++++++++++++---- .../locationinfo/permissions/permissions.json | 20 ++++ .../locationinfo/templates/page-locations.html | 4 + .../locationinfo/templates/page-panels.html | 8 +- .../locationinfo/templates/page-servers.html | 9 +- .../locationinfo/templates/page-tabs.html | 6 +- 7 files changed, 221 insertions(+), 34 deletions(-) create mode 100644 modules-available/locationinfo/inc/splittime.php.txt create mode 100644 modules-available/locationinfo/permissions/permissions.json (limited to 'modules-available/locationinfo/templates') diff --git a/modules-available/locationinfo/inc/splittime.php.txt b/modules-available/locationinfo/inc/splittime.php.txt new file mode 100644 index 00000000..53510fee --- /dev/null +++ b/modules-available/locationinfo/inc/splittime.php.txt @@ -0,0 +1,80 @@ +(Unfinished) + + /* + error_log('Pre calendar: ' . print_r($calendar, true)); + $bad = array(); + for ($i = 0; $i < count($calendar); ++$i) { // Use for..count as we append while iterating + $entry =& $calendar[$i]; + // YYYY-MM-DDHH:MM:SS + $s = explode('T', $entry['start']); + $e = explode('T', $entry['end']); + if (count($s) !== 2 || count($e) !== 2) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + if ($e[0] === $s[0]) // Same day + continue; + $stime = explode(':', $s[1]); + $etime = explode(':', $e[1]); + if (count($stime) < 2 || count($etime) < 2) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + // Fix start + if ($stime[0] == 23 && $stime[1] >= 30) { + // clamp to next day + $day = strtotime($s[0] . ' 12:00 +1 day'); + if ($day === false || $day <= 0) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + $day = date('Y-m-d', $day); + $bad[] = $i; + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $day . 'T00:00:01', + 'end' => $entry['end'] + ); + continue; + } + + // Fix end + if ($etime[0] == 0 && $etime[1] <= 30) { + // clamp to next day + $day = strtotime($e[0] . ' 12:00 -1 day'); + if ($day === false || $day <= 0) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + $day = date('Y-m-d', $day); + $bad[] = $i; + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $day . 'T23:59:59', + 'end' => $entry['end'] + ); + continue; + } + // Split + $nextday = strtotime($s[0] . ' 12:00 +1 day'); + $nextday = date('Y-m-d', $nextday); + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $nextday . 'T00:00:01', + 'end' => $entry['end'] + ); + $entry['end'] = $s[0] . 'T23:59:59'; + } + unset($entry); + if (!empty($bad)) { + foreach ($bad as $i) { + unset($calendar[$i]); + } + $calendar = array_values($calendar); + } + */ + error_log('Post calendar: ' . print_r($calendar, true)); \ No newline at end of file diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index 777b84db..690012ea 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -2,16 +2,15 @@ class Page_LocationInfo extends Page { - - private $action; + private $show; /** * Called before any page rendering happens - early hook to check parameters etc. */ protected function doPreprocess() { - $show = Request::any('show', '', 'string'); - if ($show === 'panel') { + $this->show = Request::any('show', false, 'string'); + if ($this->show === 'panel') { $this->showPanel(); exit(0); } @@ -20,30 +19,39 @@ class Page_LocationInfo extends Page Message::addError('main.no-permission'); Util::redirect('?do=Main'); // does not return } - $this->action = Request::post('action'); - if ($this->action === 'writePanelConfig') { + $action = Request::post('action'); + if ($action === 'writePanelConfig') { $this->writePanelConfig(); - } elseif ($this->action === 'writeLocationConfig') { + } elseif ($action === 'writeLocationConfig') { $this->writeLocationConfig(); $show = 'locations'; - } elseif ($this->action === 'deleteServer') { + } elseif ($action === 'deleteServer') { $this->deleteServer(); - } elseif ($this->action === 'deletePanel') { + } elseif ($action === 'deletePanel') { $this->deletePanel(); - } elseif ($this->action === 'checkConnection') { + } elseif ($action === 'checkConnection') { $this->checkConnection(Request::post('serverid', 0, 'int')); $show = 'backends'; - } elseif ($this->action === 'updateServerSettings') { + } elseif ($action === 'updateServerSettings') { $this->updateServerSettings(); $show = 'backends'; } elseif (Request::isPost()) { - Message::addWarning('main.invalid-action', $this->action); + Message::addWarning('main.invalid-action', $action); } - if (Request::isPost()) { + if (Request::isPost() || $this->show === false) { if (!empty($show)) { - $show = '&show=' . $show; + // + } elseif (User::hasPermission('panel.list')) { + $show = 'panels'; + } elseif (User::hasPermission('location.*')) { + $show = 'locations'; + } elseif (User::hasPermission('backend.*')) { + $show = 'backends'; + } else { + Message::addError('main.no-permission'); + Util::redirect('?do=main'); } - Util::redirect('?do=locationinfo' . $show); + Util::redirect('?do=locationinfo&show=' . $show); } } @@ -53,10 +61,13 @@ class Page_LocationInfo extends Page protected function doRender() { // Do this here so we always see backend errors - $backends = $this->loadBackends(); - $show = Request::get('show', '', 'string'); - Render::addTemplate('page-tabs', array('class-' . $show => 'active')); - switch ($show) { + if (User::hasPermission('backend.*')) { + $backends = $this->loadBackends(); + } + $data = array('class-' . $this->show => 'active'); + Permission::addGlobalTags($data['perms'], null, ['backend.*', 'location.*', 'panel.list']); + Render::addTemplate('page-tabs', $data); + switch ($this->show) { case 'locations': $this->showLocationsTable(); break; @@ -66,7 +77,7 @@ class Page_LocationInfo extends Page case 'edit-panel': $this->showPanelConfig(); break; - case '': + case 'panels': $this->showPanelsTable(); break; default: @@ -79,6 +90,7 @@ class Page_LocationInfo extends Page */ private function deleteServer() { + User::assertPermission('backend.edit'); $id = Request::post('serverid', false, 'int'); if ($id === false) { Message::addError('server-id-missing'); @@ -97,6 +109,7 @@ class Page_LocationInfo extends Page Message::addError('main.parameter-missing', 'uuid'); return; } + $this->assertPanelPermission($id, 'panel.edit'); $res = Database::exec("DELETE FROM `locationinfo_panel` WHERE paneluuid = :id", array('id' => $id)); if ($res !== 1) { Message::addWarning('invalid-panel-id', $id); @@ -123,6 +136,8 @@ class Page_LocationInfo extends Page Message::addError('location.invalid-location-id', $locationid); return false; } + User::assertPermission('location.edit', $locationid); + $serverid = Request::post('serverid', 0, 'int'); if ($serverid === 0) { $serverid = null; @@ -304,6 +319,8 @@ class Page_LocationInfo extends Page Util::redirect('?do=locationinfo'); } + // Permission + $this->assertPanelPermission($paneluuid, 'panel.edit', $params['locationids']); if ($paneluuid === 'new') { $paneluuid = Util::randomUuid(); @@ -379,6 +396,7 @@ class Page_LocationInfo extends Page */ private function updateServerSettings() { + User::assertPermission('backend.edit'); $serverid = Request::post('id', -1, 'int'); $servername = Request::post('name', 'unnamed', 'string'); $servertype = Request::post('type', '', 'string'); @@ -423,6 +441,7 @@ class Page_LocationInfo extends Page if ($serverid === 0) { Util::traceError('checkConnection called with no server id'); } + User::assertPermission('backend.check'); $dbresult = Database::queryFirst("SELECT servertype, credentials FROM `locationinfo_coursebackend` @@ -482,14 +501,22 @@ class Page_LocationInfo extends Page */ private function showBackendsTable($serverlist) { - // Pass the data to the html and render it. - Render::addTemplate('page-servers', array( + User::assertPermission('backend.*'); + $data = array( 'serverlist' => $serverlist, - )); + ); + Permission::addGlobalTags($data['perms'], null, ['backend.edit', 'backend.check']); + // Pass the data to the html and render it. + Render::addTemplate('page-servers', $data); } private function showLocationsTable() { + $allowedLocations = User::getAllowedLocations('location.edit'); + if (empty($allowedLocations)) { + Message::addError('main.no-permission'); + return; + } $locations = Location::getLocations(0, 0, false, true); // Get hidden state of all locations @@ -499,7 +526,7 @@ class Page_LocationInfo extends Page while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { $locid = (int)$row['locationid']; - if (!isset($locations[$locid])) + if (!isset($locations[$locid]) || !in_array($locid, $allowedLocations)) continue; $glyph = !empty($row['openingtime']) ? 'ok' : ''; $backend = ''; @@ -517,6 +544,7 @@ class Page_LocationInfo extends Page $stack = array(); $depth = -1; foreach ($locations as &$location) { + $location['allowed'] = in_array($location['locationid'], $allowedLocations); while ($location['depth'] <= $depth) { array_pop($stack); $depth--; @@ -537,6 +565,13 @@ class Page_LocationInfo extends Page private function showPanelsTable() { + $visibleLocations = User::getAllowedLocations('panel.list'); + $editLocations = User::getAllowedLocations('panel.edit'); + $assignLocations = USer::getAllowedLocations('panel.assign-client'); + if (empty($visibleLocations)) { + Message::addError('main.no-permission'); + return; + } $res = Database::simpleQuery('SELECT p.paneluuid, p.panelname, p.locationids, p.panelconfig, p.paneltype FROM locationinfo_panel p ORDER BY panelname ASC'); @@ -550,8 +585,17 @@ class Page_LocationInfo extends Page if ($row['paneltype'] === 'URL') { $url = json_decode($row['panelconfig'], true)['url']; $row['locations'] = $row['locationurl'] = $url; + $row['edit_disabled'] = empty($editLocations) ? 'disabled' : ''; + $row['runmode_disabled'] = empty($assignLocations) ? 'disabled' : ''; } else { $lids = explode(',', $row['locationids']); + // Permissions + if (!empty(array_diff($lids, $visibleLocations))) { + continue; + } + $row['edit_disabled'] = !empty(array_diff($lids, $editLocations)) ? 'disabled' : ''; + $row['runmode_disabled'] = !empty(array_diff($lids, $assignLocations)) ? 'disabled' : ''; + // Locations $locs = array_map(function ($id) use ($locations) { return isset($locations[$id]) ? $locations[$id]['locationname'] : $id; }, $lids); @@ -594,6 +638,7 @@ class Page_LocationInfo extends Page */ private function ajaxServerSettings($id) { + User::assertPermission('backend.edit'); $oldConfig = Database::queryFirst('SELECT servername, servertype, credentials FROM `locationinfo_coursebackend` WHERE serverid = :id', array('id' => $id)); @@ -641,6 +686,7 @@ class Page_LocationInfo extends Page */ private function ajaxConfigLocation($id) { + User::assertPermission('location.edit', $id); $locConfig = Database::queryFirst("SELECT serverid, serverlocationid, openingtime FROM `locationinfo_locationconfig` WHERE locationid = :id", array('id' => $id)); if ($locConfig !== false) { $openingtimes = json_decode($locConfig['openingtime'], true); @@ -845,6 +891,9 @@ class Page_LocationInfo extends Page $config = json_decode($panel['panelconfig'], true); } + // Permission + $this->assertPanelPermission($panel, 'panel.edit'); + $def = LocationInfo::defaultPanelConfig($panel['paneltype']); if (!is_array($config)) { $config = $def; @@ -953,4 +1002,35 @@ class Page_LocationInfo extends Page die('Unknown panel type ' . $type); } + /** + * @param string|array $panelOrUuid UUID of panel, or array with keys paneltype and locationds + * @param string $permission + * @param null|int[] $additionalLocations + */ + private function assertPanelPermission($panelOrUuid, $permission, $additionalLocations = null) + { + if (is_array($panelOrUuid)) { + $panel = $panelOrUuid; + } else { + $panel = Database::queryFirst('SELECT paneltype, locationids FROM locationinfo_panel + WHERE paneluuid = :uuid', ['uuid' => $panelOrUuid]); + } + if ($panel === false || $panel['paneltype'] === 'URL' || empty($panel['locationids'])) { + if (empty($additionalLocations)) { + User::assertPermission($permission, null, '?do=locationinfo'); + } + } + $allowed = User::getAllowedLocations($permission); + if (!empty($allowed)) { + $locations = explode(',', $panel['locationids']); + if (!empty($additionalLocations)) { + $locations = array_merge($locations, $additionalLocations); + } + if (empty(array_diff($locations, $allowed))) + return; + } + Message::addError('main.no-permission'); + Util::redirect('?do=locationinfo'); + } + } diff --git a/modules-available/locationinfo/permissions/permissions.json b/modules-available/locationinfo/permissions/permissions.json new file mode 100644 index 00000000..be95a7bd --- /dev/null +++ b/modules-available/locationinfo/permissions/permissions.json @@ -0,0 +1,20 @@ +{ + "backend.edit": { + "location-aware": false + }, + "backend.check": { + "location-aware": false + }, + "location.edit": { + "location-aware": true + }, + "panel.list": { + "location-aware": true + }, + "panel.edit": { + "location-aware": true + }, + "panel.assign-client": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/locationinfo/templates/page-locations.html b/modules-available/locationinfo/templates/page-locations.html index 37d8dd96..94c4cd40 100644 --- a/modules-available/locationinfo/templates/page-locations.html +++ b/modules-available/locationinfo/templates/page-locations.html @@ -17,10 +17,14 @@
+ {{#allowed}} + {{/allowed}} {{locationname}} + {{#allowed}} + {{/allowed}} {{backend}} diff --git a/modules-available/locationinfo/templates/page-panels.html b/modules-available/locationinfo/templates/page-panels.html index e17b6584..2bccc796 100644 --- a/modules-available/locationinfo/templates/page-panels.html +++ b/modules-available/locationinfo/templates/page-panels.html @@ -34,19 +34,21 @@ {{#hasRunmode}} - + {{assignedMachineCount}} {{/hasRunmode}} - + - diff --git a/modules-available/locationinfo/templates/page-servers.html b/modules-available/locationinfo/templates/page-servers.html index dbf18b5f..3edb0e66 100644 --- a/modules-available/locationinfo/templates/page-servers.html +++ b/modules-available/locationinfo/templates/page-servers.html @@ -22,18 +22,19 @@ - - diff --git a/modules-available/locationinfo/templates/page-tabs.html b/modules-available/locationinfo/templates/page-tabs.html index ed3f01fd..743297e7 100644 --- a/modules-available/locationinfo/templates/page-tabs.html +++ b/modules-available/locationinfo/templates/page-tabs.html @@ -1,6 +1,6 @@
\ No newline at end of file -- cgit v1.2.3-55-g7522 From 0b12472b6ecb09b5053c50bca9e8f13e4f367af3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 5 Apr 2018 10:12:48 +0200 Subject: [locationinfo] Fix color of seat counter not updating properly --- modules-available/locationinfo/frontend/frontendscript.js | 2 +- modules-available/locationinfo/templates/frontend-default.html | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'modules-available/locationinfo/templates') diff --git a/modules-available/locationinfo/frontend/frontendscript.js b/modules-available/locationinfo/frontend/frontendscript.js index bad6a8ed..b5f59792 100644 --- a/modules-available/locationinfo/frontend/frontendscript.js +++ b/modules-available/locationinfo/frontend/frontendscript.js @@ -42,7 +42,7 @@ function toInt(str) { * computes the time difference between 2 Date objects * @param {Date} a * @param {Date} b - * @param {Array} globalConfig + * @param {Object} globalConfig * @returns {string} printable time */ function GetTimeDiferenceAsString(a, b, globalConfig) { diff --git a/modules-available/locationinfo/templates/frontend-default.html b/modules-available/locationinfo/templates/frontend-default.html index e457f68d..006d2661 100755 --- a/modules-available/locationinfo/templates/frontend-default.html +++ b/modules-available/locationinfo/templates/frontend-default.html @@ -369,7 +369,6 @@ optional: -