mirror of
https://github.com/flarum/core.git
synced 2025-07-22 17:21:27 +02:00
Finish admin permissions page and clean up everything
This commit is contained in:
42
framework/core/src/Admin/Actions/UpdateConfigAction.php
Normal file
42
framework/core/src/Admin/Actions/UpdateConfigAction.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
}
|
29
framework/core/src/Admin/Actions/UpdatePermissionAction.php
Normal file
29
framework/core/src/Admin/Actions/UpdatePermissionAction.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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,6 +50,18 @@ 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)
|
||||
|
@@ -32,6 +32,7 @@ class ForumSerializer extends Serializer
|
||||
];
|
||||
|
||||
if ($this->actor->isAdmin()) {
|
||||
$attributes['adminUrl'] = Core::config('admin_url');
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
@@ -29,6 +29,10 @@ class DatabaseSettingsRepository implements SettingsRepository
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->database->table('config')->where('key', $key)->update(['value' => $value]);
|
||||
$query = $this->database->table('config')->where('key', $key);
|
||||
|
||||
$method = $query->exists() ? 'update' : 'insert';
|
||||
|
||||
$query->$method(compact('key', 'value'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user