mirror of
https://github.com/friendica/friendica
synced 2025-05-18 01:04:16 +02:00
Create event for lockview_content hook
This commit is contained in:
parent
f08aef86f1
commit
ff3c4046e0
5 changed files with 76 additions and 7 deletions
|
@ -43,6 +43,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::NAV_INFO => 'nav_info',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
|
||||
ArrayFilterEvent::FEATURE_GET => 'get',
|
||||
ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT => 'lockview_content',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'post_local_start',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL => 'post_local',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'post_local_end',
|
||||
|
@ -127,6 +128,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT => 'onPermissionTooltipContentEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL => 'onInsertPostLocalEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onInsertPostLocalEndEvent',
|
||||
|
@ -215,6 +217,20 @@ final class HookEventBridge
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the PERMISSION_TOOLTIP_CONTENT event to `lockview_content` hook
|
||||
*/
|
||||
public static function onPermissionTooltipContentEvent(ArrayFilterEvent $event): void
|
||||
{
|
||||
$data = $event->getArray();
|
||||
|
||||
$model = (array) $data['model'] ?? [];
|
||||
|
||||
$data['model'] = static::callHook($event->getName(), $model);
|
||||
|
||||
$event->setArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the INSERT_POST_LOCAL event to `post_local` hook
|
||||
*/
|
||||
|
|
|
@ -24,6 +24,8 @@ final class ArrayFilterEvent extends Event
|
|||
|
||||
public const FEATURE_GET = 'friendica.data.feature_get';
|
||||
|
||||
public const PERMISSION_TOOLTIP_CONTENT = 'friendica.data.permission_tooltip_content';
|
||||
|
||||
public const INSERT_POST_LOCAL_START = 'friendica.data.insert_post_local_start';
|
||||
|
||||
public const INSERT_POST_LOCAL = 'friendica.data.insert_post_local';
|
||||
|
|
|
@ -7,14 +7,16 @@
|
|||
|
||||
namespace Friendica\Module\Privacy;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -23,21 +25,37 @@ use Friendica\Privacy\Entity;
|
|||
use Friendica\Security\PermissionSet\Repository\PermissionSet;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Outputs the permission tooltip HTML content for the provided item, photo or event id.
|
||||
*/
|
||||
class PermissionTooltip extends \Friendica\BaseModule
|
||||
class PermissionTooltip extends BaseModule
|
||||
{
|
||||
private Database $dba;
|
||||
private ACLFormatter $aclFormatter;
|
||||
private IHandleUserSessions $session;
|
||||
private IManageConfigValues $config;
|
||||
private PermissionSet $permissionSet;
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(PermissionSet $permissionSet, IManageConfigValues $config, IHandleUserSessions $session, ACLFormatter $aclFormatter, Database $dba, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
public function __construct(
|
||||
PermissionSet $permissionSet,
|
||||
IManageConfigValues $config,
|
||||
IHandleUserSessions $session,
|
||||
ACLFormatter $aclFormatter,
|
||||
Database $dba,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
L10n $l10n,
|
||||
BaseURL $baseUrl,
|
||||
Arguments $args,
|
||||
LoggerInterface $logger,
|
||||
Profiler $profiler,
|
||||
Response $response,
|
||||
array $server,
|
||||
array $parameters = [],
|
||||
) {
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->dba = $dba;
|
||||
|
@ -45,6 +63,7 @@ class PermissionTooltip extends \Friendica\BaseModule
|
|||
$this->session = $session;
|
||||
$this->config = $config;
|
||||
$this->permissionSet = $permissionSet;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
|
@ -87,8 +106,15 @@ class PermissionTooltip extends \Friendica\BaseModule
|
|||
throw new HttpException\NotFoundException($this->t('Model not found'));
|
||||
}
|
||||
|
||||
// Kept for backwards compatibility
|
||||
Hook::callAll('lockview_content', $model);
|
||||
$hook_data = [
|
||||
'model' => $model,
|
||||
];
|
||||
|
||||
$hook_data = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT, $hook_data),
|
||||
)->getArray();
|
||||
|
||||
$model = $hook_data['model'] ?? $model;
|
||||
|
||||
$aclReceivers = new Entity\AclReceivers();
|
||||
$addressedReceivers = new Entity\AddressedReceivers();
|
||||
|
|
|
@ -32,6 +32,7 @@ class HookEventBridgeTest extends TestCase
|
|||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT => 'onPermissionTooltipContentEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL => 'onInsertPostLocalEvent',
|
||||
ArrayFilterEvent::INSERT_POST_LOCAL_END => 'onInsertPostLocalEndEvent',
|
||||
|
@ -209,6 +210,28 @@ class HookEventBridgeTest extends TestCase
|
|||
HookEventBridge::onCollectRoutesEvent($event);
|
||||
}
|
||||
|
||||
public function testOnPermissionTooltipContentEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent(ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT, ['model' => ['uid' => -1]]);
|
||||
|
||||
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$reflectionProperty->setValue(null, function (string $name, array $data): array {
|
||||
$this->assertSame('lockview_content', $name);
|
||||
$this->assertSame(['uid' => -1], $data);
|
||||
|
||||
return ['uid' => 123];
|
||||
});
|
||||
|
||||
HookEventBridge::onPermissionTooltipContentEvent($event);
|
||||
|
||||
$this->assertSame(
|
||||
['model' => ['uid' => 123]],
|
||||
$event->getArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testOnInsertPostLocalEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL, ['item' => ['id' => -1]]);
|
||||
|
@ -230,6 +253,7 @@ class HookEventBridgeTest extends TestCase
|
|||
$event->getArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testOnInsertPostLocalEndEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL_END, ['item' => ['id' => -1]]);
|
||||
|
|
|
@ -29,6 +29,7 @@ class ArrayFilterEventTest extends TestCase
|
|||
[ArrayFilterEvent::NAV_INFO, 'friendica.data.nav_info'],
|
||||
[ArrayFilterEvent::FEATURE_ENABLED, 'friendica.data.feature_enabled'],
|
||||
[ArrayFilterEvent::FEATURE_GET, 'friendica.data.feature_get'],
|
||||
[ArrayFilterEvent::PERMISSION_TOOLTIP_CONTENT, 'friendica.data.permission_tooltip_content'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL_START, 'friendica.data.insert_post_local_start'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL, 'friendica.data.insert_post_local'],
|
||||
[ArrayFilterEvent::INSERT_POST_LOCAL_END, 'friendica.data.insert_post_local_end'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue