mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Also ensure backwards compatibility for extensions that use the Zend framework but don't explicitly require it.
47 lines
1.2 KiB
PHP
47 lines
1.2 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.
|
|
*/
|
|
|
|
namespace Flarum\Api\Controller;
|
|
|
|
use Flarum\Group\Permission;
|
|
use Flarum\User\AssertPermissionTrait;
|
|
use Illuminate\Support\Arr;
|
|
use Laminas\Diactoros\Response\EmptyResponse;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
class SetPermissionController implements RequestHandlerInterface
|
|
{
|
|
use AssertPermissionTrait;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
|
{
|
|
$this->assertAdmin($request->getAttribute('actor'));
|
|
|
|
$body = $request->getParsedBody();
|
|
$permission = Arr::get($body, 'permission');
|
|
$groupIds = Arr::get($body, 'groupIds');
|
|
|
|
Permission::where('permission', $permission)->delete();
|
|
|
|
Permission::insert(array_map(function ($groupId) use ($permission) {
|
|
return [
|
|
'permission' => $permission,
|
|
'group_id' => $groupId
|
|
];
|
|
}, $groupIds));
|
|
|
|
return new EmptyResponse(204);
|
|
}
|
|
}
|