[COMPONENT][Group] Add group settings, with support for editing the group's personal info and self tags

This commit is contained in:
Hugo Sales 2021-12-23 17:13:08 +00:00 committed by Diogo Peralta Cordeiro
parent a36bdf9719
commit 333e71ed50
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 68 additions and 3 deletions

View File

@ -32,7 +32,9 @@ use App\Core\Log;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity as E; use App\Entity as E;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Form\ActorForms;
use App\Util\Nickname; use App\Util\Nickname;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -123,4 +125,20 @@ class Group extends ActorController
'notes' => $notes, 'notes' => $notes,
]; ];
} }
public function groupSettings(Request $request, string $nickname)
{
$group = Actor::getByNickname($nickname, type: Actor::GROUP);
$actor = Common::actor();
if (!\is_null($group) && $actor->canAdmin($group)) {
return [
'_template' => 'group/settings.html.twig',
'group' => $group,
'personal_info_form' => ActorForms::personalInfo($request, $group)->createView(),
'open_details_query' => $this->string('open'),
];
} else {
throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $nickname]), code: 404);
}
}
} }

View File

@ -22,10 +22,17 @@ declare(strict_types = 1);
namespace Component\Group; namespace Component\Group;
use App\Core\Event; use App\Core\Event;
use function App\Core\I18n\_m;
use App\Core\Modules\Component; use App\Core\Modules\Component;
use App\Core\Router\RouteLoader; use App\Core\Router\RouteLoader;
use App\Core\Router\Router;
use App\Entity\Actor;
use App\Util\Common;
use App\Util\HTML;
use App\Util\Nickname; use App\Util\Nickname;
use Component\Group\Controller as C; use Component\Group\Controller as C;
use Component\Tag\Controller\Tag as TagController;
use Symfony\Component\HttpFoundation\Request;
class Group extends Component class Group extends Component
{ {
@ -33,14 +40,32 @@ class Group extends Component
{ {
$r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']); $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']);
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]); $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]);
$r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]);
return Event::next; return Event::next;
} }
public function onAppendCardProfile(array $vars, array &$res): bool public function onAppendCardProfile(array $vars, array &$res): bool
{ {
$actor = $vars['actor']; $actor = Common::actor();
if ($actor->isGroup()) { $group = $vars['actor'];
dd($actor); if (!\is_null($actor) && $group->isGroup() && $actor->canAdmin($group)) {
$url = Router::url('group_settings', ['nickname' => $group->getNickname()]);
$res[] = HTML::html(['hr' => '', 'a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings')], 'p' => _m('Group settings')]]);
}
return Event::next;
}
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs)
{
if ($section === 'profile' && $request->get('_route') === 'group_settings') {
$nickname = $request->get('nickname');
$group = Actor::getByNickname($nickname, type: Actor::GROUP);
$tabs[] = [
'title' => 'Self tags',
'desc' => 'Add or remove tags on this group',
'id' => 'settings-self-tags',
'controller' => TagController::settingsSelfTags($request, $group, 'settings-self-tags-details'),
];
} }
return Event::next; return Event::next;
} }

View File

@ -0,0 +1,22 @@
{% extends 'base.html.twig' %}
{% import 'settings/macros.html.twig' as macros %}
{% block stylesheets %}
{{ parent() }}
<link rel="preload" href="{{ asset('assets/default_theme/css/pages/settings.css') }}" as="style" type="text/css">
<link rel="stylesheet" href="{{ asset('assets/default_theme/css/pages/settings.css') }}">
{% endblock stylesheets %}
{% block body %}
<nav class='section-settings'>
<h2>Settings</h2>
<ul>
<li>
{% set profile_tabs = [{'title': 'Personal Info', 'desc': 'Nickname, Homepage, Bio, Self Tags and more.', 'id': 'settings-personal-info', 'form': personal_info_form}] %}
{% set profile_tabs = profile_tabs|merge(handle_event('PopulateSettingsTabs', app.request, 'profile')) %}
{{ macros.settings_details_container('Profile', 'Personal Information, Avatar and Profile', 'settings-profile-details', profile_tabs, _context) }}
</li>
</ul>
</nav>
{% endblock body %}