From 676bb4aebcbb65f6271f062d03aef2a48346f2e3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 9 Feb 2018 16:17:03 +0100 Subject: [backup] Use permission helpers --- modules-available/backup/page.inc.php | 14 ++++++++------ modules-available/backup/style.css | 7 ------- modules-available/backup/templates/_page.html | 14 +++++++------- script/slx-fixes.js | 10 ++++++---- style/default.css | 6 ++++++ 5 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 modules-available/backup/style.css diff --git a/modules-available/backup/page.inc.php b/modules-available/backup/page.inc.php index 949cd7f3..14522734 100644 --- a/modules-available/backup/page.inc.php +++ b/modules-available/backup/page.inc.php @@ -16,16 +16,18 @@ class Page_Backup extends Page Util::redirect('?do=Main'); } $this->action = Request::post('action'); - if ($this->action === 'backup' && User::hasPermission("create")) { + if ($this->action === 'backup') { + User::assertPermission("create"); $this->backup(); - } elseif ($this->action === 'restore' && User::hasPermission("restore")) { + } elseif ($this->action === 'restore') { + User::assertPermission("restore"); $this->restore(); } } protected function doRender() { - if ($this->action === 'restore' && User::hasPermission("restore")) { + if ($this->action === 'restore') { // TODO: We're in post mode, redirect with all the taskids first... Render::addTemplate('restore', $this->templateData); } else { $lastBackup = (int)Property::get(self::LAST_BACKUP_PROP, 0); @@ -34,9 +36,9 @@ class Page_Backup extends Page } else { $lastBackup = date('d.m.Y', $lastBackup); } - Render::addTemplate('_page', ['last_backup' => $lastBackup, - "createAllowed" => User::hasPermission("create"), - "restoreAllowed" => User::hasPermission("restore")]); + $params = ['last_backup' => $lastBackup]; + Permission::addGlobalTags($params['perms'], NULL, ['create', 'restore']); + Render::addTemplate('_page', $params); } } diff --git a/modules-available/backup/style.css b/modules-available/backup/style.css deleted file mode 100644 index 7b86af56..00000000 --- a/modules-available/backup/style.css +++ /dev/null @@ -1,7 +0,0 @@ -.disabledPanel { - cursor: not-allowed; -} -.disabledPanel > .panel-body { - pointer-events: none; - opacity: 0.8; -} diff --git a/modules-available/backup/templates/_page.html b/modules-available/backup/templates/_page.html index 41e73091..4c6cade4 100644 --- a/modules-available/backup/templates/_page.html +++ b/modules-available/backup/templates/_page.html @@ -3,16 +3,16 @@
-
+
{{lang_backup}}
-
+

{{lang_backupDescription}}

{{lang_lastBackup}}: {{^last_backup}}{{lang_unknown}}{{/last_backup}} {{last_backup}}

- +
@@ -20,15 +20,15 @@
-
+
{{lang_restore}}
-
+

{{lang_restoreDescription}}

- {{lang_browseForFile}}… + {{lang_browseForFile}}…
@@ -46,7 +46,7 @@

{{lang_dozmodExplanation}}

- +
\ No newline at end of file diff --git a/script/slx-fixes.js b/script/slx-fixes.js index 12db9c79..1ed71cb9 100644 --- a/script/slx-fixes.js +++ b/script/slx-fixes.js @@ -1,6 +1,8 @@ // Give file select dialogs a modern style and feel $(document).on('change', '.btn-file :file', function() { var input = $(this); + if (input.parents('.disabled').length !== 0) + return; var numFiles = input.get(0).files ? input.get(0).files.length : 1; var label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); input.trigger('fileselect', [numFiles, label]); @@ -15,23 +17,23 @@ $(document).ready(function() { }); }); $('.upload-ex :text').click(function () { - $(this).parents('.upload-ex').find(':file').click(); + var $this = $(this); + if ($this.parents('.disabled').length !== 0) + return; + $this.parents('.upload-ex').find(':file').click(); }); // Replace message query params in URL, so you won't see them again if you bookmark or share the link if (history && history.replaceState && window && window.location && window.location.search && window.location.search.indexOf('message[]=') !== -1) { var str = window.location.search; - console.log('TRUE: ' + str); do { var repl = str.match(/([\?&])message\[\]=[^&]+(&|$)/); - console.log(repl); if (!repl) break; if (repl[2].length === 0) { str = str.replace(repl[0], ''); } else { str = str.replace(repl[0], repl[1]); } - console.log('Replace: ' + str); } while (1); history.replaceState(null, null, window.location.pathname + str); } diff --git a/style/default.css b/style/default.css index 7273dba2..3b02ffdb 100644 --- a/style/default.css +++ b/style/default.css @@ -178,6 +178,7 @@ body { display: block; cursor: pointer; } + input[readonly] { background-color: white !important; cursor: text !important; @@ -598,3 +599,8 @@ table.slx-ellipsis td { text-overflow: ellipsis; white-space: nowrap; } + +div.disabled input, div.disabled label { + pointer-events: none; + cursor: not-allowed; +} \ No newline at end of file -- cgit v1.2.3-55-g7522