mirror of
https://github.com/flarum/framework.git
synced 2024-11-26 02:10:09 +08:00
a8777c6198
* refactor: json:api refactor iteration 1 * chore: delete dead code * fix: regressions * chore: move additions/changes to package * feat: AccessTokenResource * feat: allow dependency injection in resources * feat: `ApiResource` extender * feat: improve * feat: refactor tags extension * feat: refactor flags extension * fix: regressions * fix: drop bc layer * feat: refactor suspend extension * feat: refactor subscriptions extension * feat: refactor approval extension * feat: refactor sticky extension * feat: refactor nicknames extension * feat: refactor mentions extension * feat: refactor lock extension * feat: refactor likes extension * chore: merge conflicts * feat: refactor extension-manager extension * feat: context current endpoint helpers * chore: minor * feat: cleaner sortmap implementation * chore: drop old package * chore: not needed (auto scoping) * fix: actor only fields * refactor: simplify index endpoint * feat: eager loading * test: adapt * test: phpstan * test: adapt * fix: typing * fix: approving content * tet: adapt frontend tests * chore: typings * chore: review * fix: breaking change
77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* For detailed copyright and license information, please view the
|
|
* LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
use Flarum\Api\Context;
|
|
use Flarum\Api\Resource;
|
|
use Flarum\Api\Schema;
|
|
use Flarum\Discussion\Discussion;
|
|
use Flarum\Discussion\Search\DiscussionSearcher;
|
|
use Flarum\Extend;
|
|
use Flarum\Lock\Access;
|
|
use Flarum\Lock\Event\DiscussionWasLocked;
|
|
use Flarum\Lock\Event\DiscussionWasUnlocked;
|
|
use Flarum\Lock\Filter\LockedFilter;
|
|
use Flarum\Lock\Listener;
|
|
use Flarum\Lock\Notification\DiscussionLockedBlueprint;
|
|
use Flarum\Lock\Post\DiscussionLockedPost;
|
|
use Flarum\Search\Database\DatabaseSearchDriver;
|
|
|
|
return [
|
|
(new Extend\Frontend('forum'))
|
|
->js(__DIR__.'/js/dist/forum.js')
|
|
->css(__DIR__.'/less/forum.less'),
|
|
|
|
(new Extend\Frontend('admin'))
|
|
->js(__DIR__.'/js/dist/admin.js'),
|
|
|
|
new Extend\Locales(__DIR__.'/locale'),
|
|
|
|
(new Extend\Notification())
|
|
->type(DiscussionLockedBlueprint::class, ['alert']),
|
|
|
|
(new Extend\Model(Discussion::class))
|
|
->cast('is_locked', 'bool'),
|
|
|
|
(new Extend\ApiResource(Resource\DiscussionResource::class))
|
|
->fields(fn () => [
|
|
Schema\Boolean::make('isLocked')
|
|
->writable(fn (Discussion $discussion, Context $context) => $context->getActor()->can('lock', $discussion))
|
|
->set(function (Discussion $discussion, bool $isLocked, Context $context) {
|
|
$actor = $context->getActor();
|
|
|
|
if ($discussion->is_locked === $isLocked) {
|
|
return;
|
|
}
|
|
|
|
$discussion->is_locked = $isLocked;
|
|
|
|
$discussion->raise(
|
|
$discussion->is_locked
|
|
? new DiscussionWasLocked($discussion, $actor)
|
|
: new DiscussionWasUnlocked($discussion, $actor)
|
|
);
|
|
}),
|
|
Schema\Boolean::make('canLock')
|
|
->get(fn (Discussion $discussion, Context $context) => $context->getActor()->can('lock', $discussion)),
|
|
]),
|
|
|
|
(new Extend\Post())
|
|
->type(DiscussionLockedPost::class),
|
|
|
|
(new Extend\Event())
|
|
->listen(DiscussionWasLocked::class, Listener\CreatePostWhenDiscussionIsLocked::class)
|
|
->listen(DiscussionWasUnlocked::class, Listener\CreatePostWhenDiscussionIsUnlocked::class),
|
|
|
|
(new Extend\Policy())
|
|
->modelPolicy(Discussion::class, Access\DiscussionPolicy::class),
|
|
|
|
(new Extend\SearchDriver(DatabaseSearchDriver::class))
|
|
->addFilter(DiscussionSearcher::class, LockedFilter::class),
|
|
];
|