mirror of
https://github.com/flarum/framework.git
synced 2025-06-03 14:33:07 +08:00
Move config/permission actions to API; clean up cache flushing
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
<?php namespace Flarum\Admin\Actions;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Support\Action;
|
||||
use Flarum\Core\Groups\Permission;
|
||||
use Exception;
|
||||
|
||||
class UpdateConfigAction extends Action
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepository
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param SettingsRepository $settings
|
||||
*/
|
||||
public function __construct(SettingsRepository $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(Request $request, array $routeParams = [])
|
||||
{
|
||||
$config = array_get($request->getAttributes(), 'config', []);
|
||||
|
||||
// TODO: throw HTTP status 400 or 422
|
||||
if (! is_array($config)) {
|
||||
throw new Exception;
|
||||
}
|
||||
|
||||
foreach ($config as $k => $v) {
|
||||
$this->settings->set($k, $v);
|
||||
}
|
||||
|
||||
$assetPath = public_path('assets');
|
||||
$manifest = file_get_contents($assetPath . '/rev-manifest.json');
|
||||
$revisions = json_decode($manifest, true);
|
||||
|
||||
foreach ($revisions as $file => $revision) {
|
||||
@unlink($assetPath . '/' . substr_replace($file, '-' . $revision, strrpos($file, '.'), 0));
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?php namespace Flarum\Admin\Actions;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Flarum\Support\Action;
|
||||
use Flarum\Core\Groups\Permission;
|
||||
|
||||
class UpdatePermissionAction extends Action
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(Request $request, array $routeParams = [])
|
||||
{
|
||||
$input = $request->getAttributes();
|
||||
$permission = array_get($input, 'permission');
|
||||
$groupIds = array_get($input, 'groupIds');
|
||||
|
||||
Permission::where('permission', $permission)->delete();
|
||||
|
||||
Permission::insert(array_map(function ($groupId) use ($permission) {
|
||||
return [
|
||||
'permission' => $permission,
|
||||
'group_id' => $groupId
|
||||
];
|
||||
}, $groupIds));
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
}
|
@ -50,18 +50,6 @@ class AdminServiceProvider extends ServiceProvider
|
||||
'flarum.admin.index',
|
||||
$this->action('Flarum\Admin\Actions\ClientAction')
|
||||
);
|
||||
|
||||
$routes->post(
|
||||
'/config',
|
||||
'flarum.admin.updateConfig',
|
||||
$this->action('Flarum\Admin\Actions\UpdateConfigAction')
|
||||
);
|
||||
|
||||
$routes->post(
|
||||
'/permission',
|
||||
'flarum.admin.updatePermission',
|
||||
$this->action('Flarum\Admin\Actions\UpdatePermissionAction')
|
||||
);
|
||||
}
|
||||
|
||||
protected function action($class)
|
||||
|
Reference in New Issue
Block a user