Conform to authorize

This commit is contained in:
Flavio Copes
2015-09-11 15:00:03 +02:00
parent 65efa010f6
commit d66ecd58fd
4 changed files with 26 additions and 26 deletions

View File

@@ -191,7 +191,7 @@ class Admin
} }
} }
return $this->authorise(); return $this->authorize();
} }
/** /**
@@ -201,12 +201,12 @@ class Admin
* *
* @return bool * @return bool
*/ */
public function authorise($action = 'admin.login') public function authorize($action = 'admin.login')
{ {
$action = (array)$action; $action = (array)$action;
foreach ($action as $a) { foreach ($action as $a) {
if ($this->user->authorise($a)) { if ($this->user->authorize($a)) {
return true; return true;
} }
} }

View File

@@ -325,7 +325,7 @@ class AdminController
*/ */
protected function taskClearCache() protected function taskClearCache()
{ {
if (!$this->authoriseTask('clear cache', ['admin.cache', 'admin.super'])) { if (!$this->authorizeTask('clear cache', ['admin.cache', 'admin.super'])) {
return; return;
} }
@@ -356,7 +356,7 @@ class AdminController
protected function taskBackup() protected function taskBackup()
{ {
$param_sep = $this->grav['config']->get('system.param_sep', ':'); $param_sep = $this->grav['config']->get('system.param_sep', ':');
if (!$this->authoriseTask('backup', ['admin.maintenance', 'admin.super'])) { if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
return; return;
} }
@@ -405,7 +405,7 @@ class AdminController
*/ */
protected function taskFilterPages() protected function taskFilterPages()
{ {
if (!$this->authoriseTask('filter pages', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('filter pages', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -492,7 +492,7 @@ class AdminController
*/ */
protected function taskListmedia() protected function taskListmedia()
{ {
if (!$this->authoriseTask('list media', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('list media', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -517,7 +517,7 @@ class AdminController
*/ */
protected function taskAddmedia() protected function taskAddmedia()
{ {
if (!$this->authoriseTask('add media', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('add media', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -584,7 +584,7 @@ class AdminController
*/ */
protected function taskDelmedia() protected function taskDelmedia()
{ {
if (!$this->authoriseTask('delete media', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('delete media', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -643,7 +643,7 @@ class AdminController
*/ */
protected function taskProcessMarkdown() protected function taskProcessMarkdown()
{ {
// if (!$this->authoriseTask('process markdown', ['admin.pages', 'admin.super'])) { // if (!$this->authorizeTask('process markdown', ['admin.pages', 'admin.super'])) {
// return; // return;
// } // }
@@ -674,7 +674,7 @@ class AdminController
*/ */
public function taskEnable() public function taskEnable()
{ {
if (!$this->authoriseTask('enable plugin', ['admin.plugins', 'admin.super'])) { if (!$this->authorizeTask('enable plugin', ['admin.plugins', 'admin.super'])) {
return; return;
} }
@@ -698,7 +698,7 @@ class AdminController
*/ */
public function taskDisable() public function taskDisable()
{ {
if (!$this->authoriseTask('disable plugin', ['admin.plugins', 'admin.super'])) { if (!$this->authorizeTask('disable plugin', ['admin.plugins', 'admin.super'])) {
return; return;
} }
@@ -722,7 +722,7 @@ class AdminController
*/ */
public function taskActivate() public function taskActivate()
{ {
if (!$this->authoriseTask('activate theme', ['admin.themes', 'admin.super'])) { if (!$this->authorizeTask('activate theme', ['admin.themes', 'admin.super'])) {
return; return;
} }
@@ -762,7 +762,7 @@ class AdminController
public function taskInstall() public function taskInstall()
{ {
$type = $this->view === 'plugins' ? 'plugins' : 'themes'; $type = $this->view === 'plugins' ? 'plugins' : 'themes';
if (!$this->authoriseTask('install ' . $type, ['admin.' . $type, 'admin.super'])) { if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
return; return;
} }
@@ -792,7 +792,7 @@ class AdminController
{ {
require_once __DIR__ . '/gpm.php'; require_once __DIR__ . '/gpm.php';
if (!$this->authoriseTask('install grav', ['admin.super'])) { if (!$this->authorizeTask('install grav', ['admin.super'])) {
return; return;
} }
@@ -835,7 +835,7 @@ class AdminController
} }
foreach ($permissions as $type => $p) { foreach ($permissions as $type => $p) {
if (!$this->authoriseTask('update ' . $type , $p)) { if (!$this->authorizeTask('update ' . $type , $p)) {
return; return;
} }
} }
@@ -871,7 +871,7 @@ class AdminController
public function taskUninstall() public function taskUninstall()
{ {
$type = $this->view === 'plugins' ? 'plugins' : 'themes'; $type = $this->view === 'plugins' ? 'plugins' : 'themes';
if (!$this->authoriseTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) {
return; return;
} }
@@ -899,7 +899,7 @@ class AdminController
*/ */
public function taskSave() public function taskSave()
{ {
if (!$this->authoriseTask('save', $this->dataPermissions())) { if (!$this->authorizeTask('save', $this->dataPermissions())) {
return; return;
} }
@@ -1026,7 +1026,7 @@ class AdminController
*/ */
protected function taskCopy() protected function taskCopy()
{ {
if (!$this->authoriseTask('copy page', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('copy page', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -1084,7 +1084,7 @@ class AdminController
*/ */
protected function taskReorder() protected function taskReorder()
{ {
if (!$this->authoriseTask('reorder pages', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('reorder pages', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -1105,7 +1105,7 @@ class AdminController
*/ */
protected function taskDelete() protected function taskDelete()
{ {
if (!$this->authoriseTask('delete page', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) {
return; return;
} }
@@ -1180,7 +1180,7 @@ class AdminController
* @return bool True if the action was performed. * @return bool True if the action was performed.
*/ */
protected function taskSaveas() { protected function taskSaveas() {
if (!$this->authoriseTask('save', $this->dataPermissions())) { if (!$this->authorizeTask('save', $this->dataPermissions())) {
return; return;
} }
@@ -1397,9 +1397,9 @@ class AdminController
* @param array $permissions The permissions given * @param array $permissions The permissions given
* @return bool True if authorized. False if not. * @return bool True if authorized. False if not.
*/ */
protected function authoriseTask($task = '', $permissions = []) protected function authorizeTask($task = '', $permissions = [])
{ {
if (!$this->admin->authorise($permissions)) { if (!$this->admin->authorize($permissions)) {
if ($this->grav['uri']->extension() === 'json') if ($this->grav['uri']->extension() === 'json')
$this->admin->json_response = ['status' => 'unauthorized', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.']; $this->admin->json_response = ['status' => 'unauthorized', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'];
else else

View File

@@ -3,7 +3,7 @@
<h3><a href="{{ base_url_relative }}">{{ "PLUGIN_ADMIN.GRAV_ADMIN"|tu }}</a> <a target="_blank" href="{{ base_url_relative_frontend }}"><i class="fa fa-fw fa-angle-double-right"></i></a></h3> <h3><a href="{{ base_url_relative }}">{{ "PLUGIN_ADMIN.GRAV_ADMIN"|tu }}</a> <a target="_blank" href="{{ base_url_relative_frontend }}"><i class="fa fa-fw fa-angle-double-right"></i></a></h3>
</div> </div>
{#{% if admin.authorise %}#} {#{% if admin.authorize %}#}
<div id="admin-user-details"> <div id="admin-user-details">
<a href="{{ base_url_relative }}/users/{{ admin.user.username }}"> <a href="{{ base_url_relative }}/users/{{ admin.user.username }}">
<img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=32" /> <img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=32" />

View File

@@ -8,7 +8,7 @@
Admin Admin
</h2> </h2>
{% if admin.authorise %} {% if admin.authorize %}
<span class="user-details"> <span class="user-details">
<img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=50" /><span class="badge">6</span><span class="hide-small">Hi, {{ admin.user.fullname }}<span> <a href="{{ base_url_relative }}/task{{ config.system.param_sep }}logout">{{ "PLUGIN_ADMIN.LOGOUT"|tu }}</a> <img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=50" /><span class="badge">6</span><span class="hide-small">Hi, {{ admin.user.fullname }}<span> <a href="{{ base_url_relative }}/task{{ config.system.param_sep }}logout">{{ "PLUGIN_ADMIN.LOGOUT"|tu }}</a>
</span> </span>