mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-28 08:46:45 +01:00
Conform to authorize
This commit is contained in:
@@ -191,7 +191,7 @@ class Admin
|
||||
}
|
||||
}
|
||||
|
||||
return $this->authorise();
|
||||
return $this->authorize();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,12 +201,12 @@ class Admin
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorise($action = 'admin.login')
|
||||
public function authorize($action = 'admin.login')
|
||||
{
|
||||
$action = (array)$action;
|
||||
|
||||
foreach ($action as $a) {
|
||||
if ($this->user->authorise($a)) {
|
||||
if ($this->user->authorize($a)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskClearCache()
|
||||
{
|
||||
if (!$this->authoriseTask('clear cache', ['admin.cache', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('clear cache', ['admin.cache', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ class AdminController
|
||||
protected function taskBackup()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskFilterPages()
|
||||
{
|
||||
if (!$this->authoriseTask('filter pages', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('filter pages', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskListmedia()
|
||||
{
|
||||
if (!$this->authoriseTask('list media', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('list media', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskAddmedia()
|
||||
{
|
||||
if (!$this->authoriseTask('add media', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('add media', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskDelmedia()
|
||||
{
|
||||
if (!$this->authoriseTask('delete media', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('delete media', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskProcessMarkdown()
|
||||
{
|
||||
// if (!$this->authoriseTask('process markdown', ['admin.pages', 'admin.super'])) {
|
||||
// if (!$this->authorizeTask('process markdown', ['admin.pages', 'admin.super'])) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
@@ -674,7 +674,7 @@ class AdminController
|
||||
*/
|
||||
public function taskEnable()
|
||||
{
|
||||
if (!$this->authoriseTask('enable plugin', ['admin.plugins', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('enable plugin', ['admin.plugins', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -698,7 +698,7 @@ class AdminController
|
||||
*/
|
||||
public function taskDisable()
|
||||
{
|
||||
if (!$this->authoriseTask('disable plugin', ['admin.plugins', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('disable plugin', ['admin.plugins', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -722,7 +722,7 @@ class AdminController
|
||||
*/
|
||||
public function taskActivate()
|
||||
{
|
||||
if (!$this->authoriseTask('activate theme', ['admin.themes', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('activate theme', ['admin.themes', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -762,7 +762,7 @@ class AdminController
|
||||
public function taskInstall()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -792,7 +792,7 @@ class AdminController
|
||||
{
|
||||
require_once __DIR__ . '/gpm.php';
|
||||
|
||||
if (!$this->authoriseTask('install grav', ['admin.super'])) {
|
||||
if (!$this->authorizeTask('install grav', ['admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -835,7 +835,7 @@ class AdminController
|
||||
}
|
||||
|
||||
foreach ($permissions as $type => $p) {
|
||||
if (!$this->authoriseTask('update ' . $type , $p)) {
|
||||
if (!$this->authorizeTask('update ' . $type , $p)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -871,7 +871,7 @@ class AdminController
|
||||
public function taskUninstall()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -899,7 +899,7 @@ class AdminController
|
||||
*/
|
||||
public function taskSave()
|
||||
{
|
||||
if (!$this->authoriseTask('save', $this->dataPermissions())) {
|
||||
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1026,7 +1026,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskCopy()
|
||||
{
|
||||
if (!$this->authoriseTask('copy page', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('copy page', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1084,7 +1084,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskReorder()
|
||||
{
|
||||
if (!$this->authoriseTask('reorder pages', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('reorder pages', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1105,7 +1105,7 @@ class AdminController
|
||||
*/
|
||||
protected function taskDelete()
|
||||
{
|
||||
if (!$this->authoriseTask('delete page', ['admin.pages', 'admin.super'])) {
|
||||
if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1180,7 +1180,7 @@ class AdminController
|
||||
* @return bool True if the action was performed.
|
||||
*/
|
||||
protected function taskSaveas() {
|
||||
if (!$this->authoriseTask('save', $this->dataPermissions())) {
|
||||
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1397,9 +1397,9 @@ class AdminController
|
||||
* @param array $permissions The permissions given
|
||||
* @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')
|
||||
$this->admin->json_response = ['status' => 'unauthorized', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'];
|
||||
else
|
||||
|
||||
@@ -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>
|
||||
</div>
|
||||
|
||||
{#{% if admin.authorise %}#}
|
||||
{#{% if admin.authorize %}#}
|
||||
<div id="admin-user-details">
|
||||
<a href="{{ base_url_relative }}/users/{{ admin.user.username }}">
|
||||
<img src="http://www.gravatar.com/avatar/{{ admin.user.email|md5 }}?s=32" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
Admin
|
||||
</h2>
|
||||
|
||||
{% if admin.authorise %}
|
||||
{% if admin.authorize %}
|
||||
<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>
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user