Skip to content

Commit

Permalink
🤖 Automatic code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
annda authored and github-actions[bot] committed Sep 19, 2024
1 parent c3ddeb3 commit f64afa7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 12 additions & 8 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\struct\meta\Schema;
use dokuwiki\plugin\struct\types\User;
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\struct\meta\StructException;
Expand All @@ -10,10 +15,10 @@
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Anna Dabrowska <[email protected]>
*/
class action_plugin_structacl extends \dokuwiki\Extension\ActionPlugin
class action_plugin_structacl extends ActionPlugin
{
/** @inheritDoc */
public function register(Doku_Event_Handler $controller)
public function register(EventHandler $controller)
{
$mode = $this->getConf('run');
$controller->register_hook('AUTH_ACL_CHECK', $mode, $this, 'handleAclCheck', $mode);
Expand All @@ -25,11 +30,11 @@ public function register(Doku_Event_Handler $controller)
* If current user is found in a configured struct field of the current page,
* upload permissions are granted.
*
* @param Doku_Event $event event object by reference
* @param Event $event event object by reference
* @param string $mode BEFORE|AFTER
* @return void
*/
public function handleAclCheck(Doku_Event $event, $mode)
public function handleAclCheck(Event $event, $mode)
{
global $ID;
global $REV;
Expand All @@ -52,12 +57,12 @@ public function handleAclCheck(Doku_Event $event, $mode)
continue;
}
try {
$schema = new \dokuwiki\plugin\struct\meta\Schema($schemaName);
$schema = new Schema($schemaName);
$schemaData = AccessTable::getPageAccess($schemaName, $ID, (int)$REV);
$data = $schemaData->getData();
foreach ($fields as $field) {
$col = $schema->findColumn($field);
if ($col && is_a($col->getType(), \dokuwiki\plugin\struct\types\User::class)) {
if ($col && is_a($col->getType(), User::class)) {
$value = $data[$field]->getValue();
if (empty($value)) continue;
// multivalue field?
Expand All @@ -74,7 +79,7 @@ public function handleAclCheck(Doku_Event $event, $mode)
}

// grant upload permissions if current user is found in struct field
if (!empty($users) && in_array($event->data['user'], $users)) {
if ($users !== [] && in_array($event->data['user'], $users)) {
$event->result = AUTH_UPLOAD;
}

Expand All @@ -84,4 +89,3 @@ public function handleAclCheck(Doku_Event $event, $mode)
}
}
}

12 changes: 7 additions & 5 deletions helper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

class helper_plugin_structacl extends DokuWiki_Plugin
use dokuwiki\Extension\Plugin;

class helper_plugin_structacl extends Plugin
{
const STRUCTACL_SEPCHAR = '.';
public const STRUCTACL_SEPCHAR = '.';
/**
* Convert config lines "schema.field name" into an array
*
Expand All @@ -11,7 +13,7 @@ class helper_plugin_structacl extends DokuWiki_Plugin
*/
public function getConfiguration($confValue)
{
$lines = explode(PHP_EOL , $confValue);
$lines = explode(PHP_EOL, $confValue);
$config = [];

foreach ($lines as $line) {
Expand All @@ -20,8 +22,8 @@ public function getConfiguration($confValue)
$line = trim($line);
if ($line === '' || strpos($line, self::STRUCTACL_SEPCHAR) === false) continue;

list($schema, $field) = explode(self::STRUCTACL_SEPCHAR, $line, 2);
$config[$schema] = $config[$schema] ?? [];
[$schema, $field] = explode(self::STRUCTACL_SEPCHAR, $line, 2);
$config[$schema] ??= [];
$config[$schema][] = $field;
}

Expand Down

0 comments on commit f64afa7

Please sign in to comment.