From 7305a725cb9e6aa0d1c0499c104224743d6debd3 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 28 Mar 2022 20:56:25 +0100 Subject: [PATCH] [PLUGIN][UnboundGroup] First steps on implementing AP FEP-2100 --- .../UnboundGroup/Controller/GroupSettings.php | 59 ++++++++++++++++++ plugins/UnboundGroup/UnboundGroup.php | 61 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 plugins/UnboundGroup/Controller/GroupSettings.php create mode 100644 plugins/UnboundGroup/UnboundGroup.php diff --git a/plugins/UnboundGroup/Controller/GroupSettings.php b/plugins/UnboundGroup/Controller/GroupSettings.php new file mode 100644 index 0000000000..7672a0537b --- /dev/null +++ b/plugins/UnboundGroup/Controller/GroupSettings.php @@ -0,0 +1,59 @@ +getActor(); + if (!$actor->canModerate($target)) { + throw new ClientException(_m('You don\'t have enough permissions to edit {nickname}\'s settings', ['{nickname}' => $target->getNickname()])); + } + + $form_definition = [ + ['new_link', TextType::class, ['label' => _m('Link to'), 'required' => true, 'help' => _m('Enter the URI.')]], + [$add_link_to_form_name = 'save_group_links', SubmitType::class, ['label' => _m('Add link')]], + ]; + + $add_link_to_form = Form::create($form_definition); + + if ($request->getMethod() === 'POST' && $request->request->has($add_link_to_form_name)) { + $add_link_to_form->handleRequest($request); + if ($add_link_to_form->isSubmitted() && $add_link_to_form->isValid()) { + if (Common::isValidHttpUrl($new_uri = $add_link_to_form->getData()['new_link'])) { + $new_link = Explorer::getOneFromUri($new_uri); + if (\is_null(Subscription::subscribe(subject: $target, object: $new_link, source: 'ActivityPub via FEP-2100'))) { + throw new ClientException(_m('This group is already linked from {nickname}', ['{nickname}' => $new_link->getNickname()])); + } + Subscription::refreshSubscriptionCount($target, $new_link); + Form::forceRedirect($add_link_to_form, $request); + } else { + throw new ClientException(_m('Invalid URI given.')); + } + } + } + + return [ + '_template' => 'self_tags_settings.fragment.html.twig', + 'add_self_tags_form' => $add_link_to_form->createView(), + ]; + } +} diff --git a/plugins/UnboundGroup/UnboundGroup.php b/plugins/UnboundGroup/UnboundGroup.php new file mode 100644 index 0000000000..15c676f414 --- /dev/null +++ b/plugins/UnboundGroup/UnboundGroup.php @@ -0,0 +1,61 @@ +. +// }}} + +/** + * ActivityPub implementation for GNU social + * + * @package GNUsocial + * @category Actor + * + * @author Diogo Peralta Cordeiro <@diogo.site> + * @copyright 2022 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace Plugin\UnboundGroup; + +use App\Core\Event; +use App\Core\Modules\Plugin; +use App\Entity\Actor; +use Plugin\UnboundGroup\Controller\GroupSettings; +use Symfony\Component\HttpFoundation\Request; + +/** + * When enabled, Adds ActivityPub "FEP-2100 Unbound Group and Organization" support to GNU social + * + * @copyright 2022 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class UnboundGroup extends Plugin +{ + public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool + { + if ($section === 'profile' && $request->get('_route') === 'group_actor_settings') { + $tabs[] = [ + 'title' => 'Linked', + 'desc' => 'Link to this Group from another Group.', + 'id' => 'settings-group-links-details', + 'controller' => GroupSettings::groupLinks($request, Actor::getById((int) $request->get('id')), 'settings-group-links-details'), + ]; + } + return Event::next; + } +}