Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Automatic code style fixes #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 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 Down
8 changes: 5 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class helper_plugin_structacl extends DokuWiki_Plugin
use dokuwiki\Extension\Plugin;

class helper_plugin_structacl extends Plugin
{
public const STRUCTACL_SEPCHAR = '.';
/**
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