[PLUGIN][UnboundGroup] First steps on implementing AP FEP-2100
This commit is contained in:
parent
fd4c3b0e68
commit
7305a725cb
59
plugins/UnboundGroup/Controller/GroupSettings.php
Normal file
59
plugins/UnboundGroup/Controller/GroupSettings.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Plugin\UnboundGroup\Controller;
|
||||||
|
|
||||||
|
use App\Core\Controller;
|
||||||
|
use App\Core\Form;
|
||||||
|
use function App\Core\I18n\_m;
|
||||||
|
use App\Entity as E;
|
||||||
|
use App\Util\Common;
|
||||||
|
use App\Util\Exception\ClientException;
|
||||||
|
use Component\Subscription\Subscription;
|
||||||
|
use Plugin\ActivityPub\Util\Explorer;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class GroupSettings extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Manage the linksTo collection of a Group or Organisation Actor
|
||||||
|
*/
|
||||||
|
public static function groupLinks(Request $request, E\Actor $target, string $details_id)
|
||||||
|
{
|
||||||
|
$actor = Common::ensureLoggedIn()->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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
61
plugins/UnboundGroup/UnboundGroup.php
Normal file
61
plugins/UnboundGroup/UnboundGroup.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user