summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-01-11 16:48:54 +0100
committerSimon Rettberg2019-01-11 16:48:54 +0100
commit856ff2fa8e9b103ee4033c8ceec3e80af87009bb (patch)
treea6fe34cf6aa1209d26feb7a2be89ea8173432e80
parentMerge branch 'master' into ipxe (diff)
downloadslx-admin-856ff2fa8e9b103ee4033c8ceec3e80af87009bb.tar.gz
slx-admin-856ff2fa8e9b103ee4033c8ceec3e80af87009bb.tar.xz
slx-admin-856ff2fa8e9b103ee4033c8ceec3e80af87009bb.zip
[serversetup-bwlp] Decouple location assigning from menu editing
-rw-r--r--modules-available/serversetup-bwlp/install.inc.php3
-rw-r--r--modules-available/serversetup-bwlp/page.inc.php133
-rw-r--r--modules-available/serversetup-bwlp/permissions/permissions.json3
-rw-r--r--modules-available/serversetup-bwlp/templates/menu-assign-location.html69
-rw-r--r--modules-available/serversetup-bwlp/templates/menu-edit.html51
5 files changed, 169 insertions, 90 deletions
diff --git a/modules-available/serversetup-bwlp/install.inc.php b/modules-available/serversetup-bwlp/install.inc.php
index 67d6693f..25579c13 100644
--- a/modules-available/serversetup-bwlp/install.inc.php
+++ b/modules-available/serversetup-bwlp/install.inc.php
@@ -54,7 +54,8 @@ $res[] = tableCreate('serversetup_localboot', "
// Add defaultentry override column
if (!tableHasColumn('serversetup_menu_location', 'defaultentryid')) {
- if (Database::exec('ALTER TABLE serversetup_menu_location ADD COLUMN `defaultentryid` int(11) DEFAULT NULL')) {
+ if (Database::exec('ALTER TABLE serversetup_menu_location ADD COLUMN `defaultentryid` int(11) DEFAULT NULL,
+ ADD KEY `defaultentryid` (`defaultentryid`)') !== false) {
$res[] = UPDATE_DONE;
} else {
$res[] = UPDATE_FAILED;
diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php
index f8a21227..004077dc 100644
--- a/modules-available/serversetup-bwlp/page.inc.php
+++ b/modules-available/serversetup-bwlp/page.inc.php
@@ -82,6 +82,12 @@ class Page_ServerSetup extends Page
$this->saveMenu();
}
+ if ($action === 'savelocation') {
+ // Permcheck in function
+ $this->saveLocationMenu();
+ Util::redirect('?do=locations');
+ }
+
if ($action === 'deleteMenu') {
// Permcheck in function
$this->deleteMenu();
@@ -158,6 +164,10 @@ class Page_ServerSetup extends Page
User::assertPermission('edit.address');
$this->showEditAddress();
break;
+ case 'assignlocation':
+ // Permcheck in function
+ $this->showEditLocation();
+ break;
default:
Util::redirect('?do=serversetup');
break;
@@ -294,19 +304,6 @@ class Page_ServerSetup extends Page
$entry['isdefault'] = ($entry['menuentryid'] == $menu['defaultentryid']);
// TODO: plainpass only when permissions
}
- // TODO: Make assigned locations editable
-
- $currentLocations = Database::queryColumnArray('SELECT locationid FROM serversetup_menu_location
- WHERE menuid = :menuid', array('menuid' => $id));
- $menu['locations'] = Location::getLocations($currentLocations);
-
- // if user has no permission to edit for this location, disable the location in the select
- $allowedEditLocations = User::getAllowedLocations('ipxe.menu.edit');
- foreach ($menu['locations'] as &$loc) {
- if (!in_array($loc["locationid"], $allowedEditLocations)) {
- $loc["disabled"] = "disabled";
- }
- }
Permission::addGlobalTags($menu['perms'], 0, ['ipxe.menu.edit']);
Render::addTemplate('menu-edit', $menu);
@@ -437,23 +434,6 @@ class Page_ServerSetup extends Page
return;
}
- $locationids = Request::post('locations', [], "ARRAY");
- // check if the user is allowed to edit the menu on the affected locations
- $allowedEditLocations = User::getAllowedLocations('ipxe.menu.edit');
- $currentLocations = Database::queryColumnArray('SELECT locationid FROM serversetup_menu_location
- WHERE menuid = :menuid', array('menuid' => $id));
- // permission denied if the user tries to assign or remove a menu to/from locations he has no edit rights for
- // or if the user tries to save a menu without locations but does not have the permission for the root location (0)
- if (!in_array(0, $allowedEditLocations)
- && (
- (!empty(array_diff($locationids, $allowedEditLocations)) && !empty(array_diff($currentLocations, $allowedEditLocations)))
- || empty($locationids)
- )
- ) {
- Message::addError('main.no-permission');
- Util::redirect('?do=serversetup');
- }
-
$insertParams = [
'title' => IPxe::sanitizeIpxeString(Request::post('title', '', 'string')),
'timeoutms' => abs(Request::post('timeout', 0, 'int') * 1000),
@@ -462,18 +442,13 @@ class Page_ServerSetup extends Page
Database::exec("INSERT INTO serversetup_menu (title, timeoutms, isdefault) VALUES (:title, :timeoutms, 0)", $insertParams);
$menu['menuid'] = $id = Database::lastInsertId();
} else {
- $menu = Database::queryFirst("SELECT m.menuid, GROUP_CONCAT(l.locationid) AS locations
+ $menu = Database::queryFirst("SELECT m.menuid
FROM serversetup_menu m
- LEFT JOIN serversetup_menu_location l USING (menuid)
WHERE menuid = :id", compact('id'));
if ($menu === false) {
Message::addError('no-such-menu', $id);
return;
}
- if (!$this->hasMenuPermission($id, 'ipxe.menu.edit')) {
- Message::addError('locations.no-permission-location', 'TODO');
- return;
- }
$insertParams['menuid'] = $id;
Database::exec('UPDATE serversetup_menu SET title = :title, timeoutms = :timeoutms
WHERE menuid = :menuid', $insertParams);
@@ -562,15 +537,6 @@ class Page_ServerSetup extends Page
Database::exec('UPDATE serversetup_menu SET defaultentryid = NULL WHERE menuid = :menuid', ['menuid' => $menu['menuid']]);
}
- Database::exec('DELETE FROM serversetup_menu_location WHERE menuid = :menuid', ['menuid' => $menu['menuid']]);
- if (!empty($locationids)) {
- Database::exec('DELETE FROM serversetup_menu_location WHERE locationid IN (:locationids)', ['locationids' => $locationids]);
- foreach ($locationids as $locationid) {
- Database::exec('INSERT INTO serversetup_menu_location (menuid, locationid) VALUES (:menuid, :locationid)',
- ['menuid' => $menu['menuid'], 'locationid' => $locationid]);
- }
- }
-
Message::addSuccess('menu-saved');
}
@@ -653,4 +619,81 @@ class Page_ServerSetup extends Page
Util::redirect('?do=serversetup&show=bootentry');
}
+ private function showEditLocation()
+ {
+ $locationId = Request::get('locationid', false, 'int');
+ $loc = Location::get($locationId);
+ if ($loc === false) {
+ Message::addError('locations.invalid-location-id', $locationId);
+ return;
+ }
+ User::assertPermission('ipxe.menu.assign', $locationId);
+ // List of menu entries
+ $res = Database::simpleQuery('SELECT menuentryid, title FROM serversetup_menuentry');
+ $menuEntries = $res->fetchAll(PDO::FETCH_KEY_PAIR);
+ // List of menus
+ $data = [
+ 'locationid' => $locationId,
+ 'locationName' => $loc['locationname'],
+ ];
+ $res = Database::simpleQuery('SELECT m.menuid, m.title, ml.locationid, ml.defaultentryid, GROUP_CONCAT(me.menuentryid) AS entries FROM serversetup_menu m
+ LEFT JOIN serversetup_menu_location ml ON (m.menuid = ml.menuid AND ml.locationid = :locationid)
+ INNER JOIN serversetup_menuentry me ON (m.menuid = me.menuid AND me.entryid IS NOT NULL)
+ GROUP BY menuid
+ ORDER BY m.title ASC', ['locationid' => $locationId]);
+ $menus = [];
+ $hasDefault = false;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $eids = explode(',', $row['entries']);
+ $row['entries'] = [];
+ foreach ($eids as $eid) {
+ $row['entries'][] = [
+ 'id' => $eid,
+ 'title' => $menuEntries[$eid],
+ 'selected' => ($eid == $row['defaultentryid'] ? 'selected' : ''),
+ ];
+ }
+ if ($row['locationid'] !== null) {
+ $hasDefault = true;
+ $row['menu_selected'] = 'checked';
+ }
+ $menus[] = $row;
+ }
+ if (!$hasDefault) {
+ $data['default_selected'] = 'checked';
+ }
+ $data['list'] = $menus;
+ Render::addTemplate('menu-assign-location', $data);
+ }
+
+ private function saveLocationMenu()
+ {
+ $locationId = Request::post('locationid', false, 'int');
+ $loc = Location::get($locationId);
+ if ($loc === false) {
+ Message::addError('locations.invalid-location-id', $locationId);
+ return;
+ }
+ User::assertPermission('ipxe.menu.assign', $locationId);
+ $menuId = Request::post('menuid', false, 'int');
+ if ($menuId === 0) {
+ Database::exec('DELETE FROM serversetup_menu_location WHERE locationid = :locationid',
+ ['locationid' => $locationId]);
+ Message::addSuccess('location-use-default', $loc['locationname']);
+ return;
+ }
+ $defaultEntryId = Request::post('defaultentryid-' . $menuId, 0, 'int');
+ if ($defaultEntryId === 0) {
+ $defaultEntryId = null;
+ }
+ Database::exec('INSERT INTO serversetup_menu_location (menuid, locationid, defaultentryid)
+ VALUES (:menuid, :locationid, :defaultentryid)
+ ON DUPLICATE KEY UPDATE menuid = :menuid, defaultentryid = :defaultentryid', [
+ 'menuid' => $menuId,
+ 'locationid' => $locationId,
+ 'defaultentryid' => $defaultEntryId
+ ]);
+ Message::addSuccess('location-menu-assigned', $loc['locationname']);
+ }
+
}
diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json
index aa2aa001..33cc9cea 100644
--- a/modules-available/serversetup-bwlp/permissions/permissions.json
+++ b/modules-available/serversetup-bwlp/permissions/permissions.json
@@ -18,6 +18,9 @@
"location-aware": false
},
"ipxe.menu.edit": {
+ "location-aware": false
+ },
+ "ipxe.menu.assign": {
"location-aware": true
},
"ipxe.localboot.edit": {
diff --git a/modules-available/serversetup-bwlp/templates/menu-assign-location.html b/modules-available/serversetup-bwlp/templates/menu-assign-location.html
new file mode 100644
index 00000000..077d137e
--- /dev/null
+++ b/modules-available/serversetup-bwlp/templates/menu-assign-location.html
@@ -0,0 +1,69 @@
+<h2>{{lang_assignMenuToLocation}}</h2>
+<h3>{{locationName}}</h3>
+
+<form method="post" action="?do=serversetup">
+
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="savelocation">
+ <input type="hidden" name="locationid" value="{{locationid}}">
+ <table class="table">
+ <thead>
+ <tr>
+ <th class="slx-smallcol"></th>
+ <th>{{lang_menuTitle}}</th>
+ <th class="slx-smallcol">{{lang_menuEntryOverride}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>
+ <div class="radio radio-inline">
+ <input type="radio" name="menuid" value="0" {{default_selected}}>
+ <label></label>
+ </div>
+ </td>
+ <td>
+ <i>{{lang_useDefaultMenu}}</i>
+ </td>
+ <td></td>
+ </tr>
+ {{#list}}
+ <tr>
+ <td>
+ <div class="radio radio-inline">
+ <input type="radio" name="menuid" value="{{menuid}}" {{menu_selected}}>
+ <label></label>
+ </div>
+ </td>
+ <td>
+ {{title}}
+ </td>
+ <td class="text-right">
+ <select name="defaultentryid-{{menuid}}" class="form-control">
+ <option value="0" style="font-style:italic">{{lang_useDefaultMenuEntry}}</option>
+ {{#entries}}
+ <option value="{{id}}" {{selected}}>{{title}}</option>
+ {{/entries}}
+ </select>
+ </td>
+ </tr>
+ {{/list}}
+ </tbody>
+ </table>
+
+ <div class="pull-right">
+ <button type="submit" class="btn btn-primary">
+ <span class="glyphicon glyphicon-floppy-disk"></span>
+ {{lang_save}}
+ </button>
+ </div>
+
+</form>
+
+<div class="clearfix"></div>
+
+<script>
+ function deleteMenu(menuid) {
+ $("#delete-menu-id").val(menuid);
+ }
+</script> \ No newline at end of file
diff --git a/modules-available/serversetup-bwlp/templates/menu-edit.html b/modules-available/serversetup-bwlp/templates/menu-edit.html
index 2141103f..21c6a30e 100644
--- a/modules-available/serversetup-bwlp/templates/menu-edit.html
+++ b/modules-available/serversetup-bwlp/templates/menu-edit.html
@@ -36,33 +36,18 @@
</div>
</div>
</div>
- <div class="row list-group-item">
- <div class="col-sm-3">
- <label for="panel-locations">{{lang_menuLocations}}</label>
- </div>
- <div class="col-sm-9">
- <select id="panel-locations" multiple name="locations[]">
- {{#locations}}
- <option value="{{locationid}}" {{disabled}} {{#selected}}selected{{/selected}}>{{locationpad}} {{locationname}}</option>
- {{/locations}}
- </select>
- {{#globalMenuWarning}}
- <span id="global-menu-warning" style="margin-left: 20px; color: red; display: none;">{{lang_globalMenuWarning}}</span>
- {{/globalMenuWarning}}
- </div>
- </div>
<div>
<table class="table">
<thead>
<tr>
- <th style="width: 10px"></th>
- <th style="width: 10px"></th>
- <th style="width: 10px">{{lang_entryId}}</th>
+ <th class="slx-smallcol"></th>
+ <th class="slx-smallcol"></th>
+ <th class="slx-smallcol">{{lang_entryId}}</th>
<th>{{lang_title}}</th>
- <th style="width: 150px">{{lang_hotkey}}</th>
- <th style="width: 200px">{{lang_password}}</th>
- <th style="width: 10px"><span class="glyphicon glyphicon-eye-close"></span></th>
- <th style="width: 10px"></th>
+ <th width="11%">{{lang_hotkey}}</th>
+ <th width="15%">{{lang_password}}</th>
+ <th class="slx-smallcol"><span class="glyphicon glyphicon-eye-close"></span></th>
+ <th class="slx-smallcol"></th>
</tr>
</thead>
<tbody id="table-body" style="overflow: auto;">
@@ -289,28 +274,6 @@
var spacerText = "{{lang_spacer}}";
document.addEventListener("DOMContentLoaded", function() {
- var locationSelect = $('#panel-locations');
- locationSelect.multiselect({numberDisplayed: 1});
- var globalMenuWarning = $('#global-menu-warning');
- if (globalMenuWarning.length) {
- var saveButton = $('#save-button');
- if (locationSelect.val() !== null) {
- saveButton.prop('disabled', false);
- globalMenuWarning.hide();
- } else {
- saveButton.prop('disabled', true);
- globalMenuWarning.show();
- }
- locationSelect.change(function () {
- if ($(this).val() !== null) {
- saveButton.prop('disabled', false);
- globalMenuWarning.hide();
- } else {
- saveButton.prop('disabled', true);
- globalMenuWarning.show();
- }
- });
- }
function reassignSortValues() {
var startValue = 1;