diff --git a/components/Group/Controller/Group.php b/components/Group/Controller/Group.php index 62508e2b30..3b72fda3d4 100644 --- a/components/Group/Controller/Group.php +++ b/components/Group/Controller/Group.php @@ -32,7 +32,9 @@ use App\Core\Log; use App\Entity\Actor; use App\Entity as E; use App\Util\Common; +use App\Util\Exception\ClientException; use App\Util\Exception\RedirectException; +use App\Util\Form\ActorForms; use App\Util\Nickname; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; @@ -123,4 +125,20 @@ class Group extends ActorController '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); + } + } } diff --git a/components/Group/Group.php b/components/Group/Group.php index 3733b3d748..8fcc4c21c8 100644 --- a/components/Group/Group.php +++ b/components/Group/Group.php @@ -22,10 +22,17 @@ declare(strict_types = 1); namespace Component\Group; use App\Core\Event; +use function App\Core\I18n\_m; use App\Core\Modules\Component; 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 Component\Group\Controller as C; +use Component\Tag\Controller\Tag as TagController; +use Symfony\Component\HttpFoundation\Request; 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_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; } public function onAppendCardProfile(array $vars, array &$res): bool { - $actor = $vars['actor']; - if ($actor->isGroup()) { - dd($actor); + $actor = Common::actor(); + $group = $vars['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; } diff --git a/components/Group/templates/group/settings.html.twig b/components/Group/templates/group/settings.html.twig new file mode 100644 index 0000000000..8a9115a325 --- /dev/null +++ b/components/Group/templates/group/settings.html.twig @@ -0,0 +1,22 @@ +{% extends 'base.html.twig' %} + +{% import 'settings/macros.html.twig' as macros %} + +{% block stylesheets %} + {{ parent() }} + + +{% endblock stylesheets %} + +{% block body %} + +{% endblock body %}