[GROUP] Simplify logic by making Actor::Organisation a type of Actor::Group

Some minor bug fixes
This commit is contained in:
Diogo Peralta Cordeiro 2022-02-10 04:31:06 +00:00
parent 35e907f7b2
commit 1f1524c2b3
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0
12 changed files with 106 additions and 402 deletions

View File

@ -127,8 +127,7 @@ class Collection extends Component
foreach ( foreach (
[ [
Actor::PERSON => ['person', 'people'], Actor::PERSON => ['person', 'people'],
Actor::GROUP => ['group', 'groups'], Actor::GROUP => ['group', 'groups', 'org', 'orgs', 'organisation', 'organisations', 'organization', 'organizations'],
Actor::ORGANISATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'],
Actor::BOT => ['bot', 'bots'], Actor::BOT => ['bot', 'bots'],
] as $type => $match) { ] as $type => $match) {
if (array_intersect(explode(',', $term[1]), $match) !== []) { if (array_intersect(explode(',', $term[1]), $match) !== []) {

View File

@ -29,15 +29,18 @@ use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Log; use App\Core\Log;
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\ClientException;
use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\NicknameEmptyException; use App\Util\Exception\NicknameEmptyException;
use App\Util\Exception\NicknameException;
use App\Util\Exception\NicknameInvalidException; use App\Util\Exception\NicknameInvalidException;
use App\Util\Exception\NicknameNotAllowedException; use App\Util\Exception\NicknameNotAllowedException;
use App\Util\Exception\NicknameTakenException; use App\Util\Exception\NicknameTakenException;
use App\Util\Exception\NicknameTooLongException; use App\Util\Exception\NicknameTooLongException;
use App\Util\Exception\NoLoggedInUser; use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException; use App\Util\Exception\ServerException;
use App\Util\Form\ActorForms; use App\Util\Form\ActorForms;
@ -46,6 +49,7 @@ use Component\Collection\Util\Controller\FeedController;
use Component\Group\Entity\GroupMember; use Component\Group\Entity\GroupMember;
use Component\Group\Entity\LocalGroup; use Component\Group\Entity\LocalGroup;
use Component\Subscription\Entity\ActorSubscription; use Component\Subscription\Entity\ActorSubscription;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
@ -54,27 +58,14 @@ use Symfony\Component\HttpFoundation\Request;
class Group extends FeedController class Group extends FeedController
{ {
/** /**
* View a group feed by its nickname
*
* @param string $nickname The group's nickname to be shown
*
* @throws NicknameEmptyException
* @throws NicknameNotAllowedException
* @throws NicknameTakenException
* @throws NicknameTooLongException
* @throws ServerException * @throws ServerException
*
* @return array
*/ */
public function groupViewNickname(Request $request, string $nickname) public function handleGroup(Request $request, Actor $group): array
{ {
Nickname::validate($nickname, which: Nickname::CHECK_LOCAL_GROUP); // throws
$group = LocalGroup::getActorByNickname($nickname);
$actor = Common::actor(); $actor = Common::actor();
$subscribe_form = null; $subscribe_form = null;
if (!\is_null($group) if (!\is_null($actor)
&& !\is_null($actor)
&& \is_null(Cache::get( && \is_null(Cache::get(
ActorSubscription::cacheKeys($actor, $group)['subscribed'], ActorSubscription::cacheKeys($actor, $group)['subscribed'],
fn () => DB::findOneBy('actor_subscription', [ fn () => DB::findOneBy('actor_subscription', [
@ -97,35 +88,57 @@ class Group extends FeedController
} }
} }
$notes = !\is_null($group) ? DB::dql( $notes = DB::dql(<<<'EOF'
<<<'EOF' SELECT n FROM \App\Entity\Note AS n
select n from note n WHERE n.id IN (
join activity a with n.id = a.object_id SELECT act.object_id FROM \App\Entity\Activity AS act
join group_inbox gi with a.id = gi.activity_id WHERE act.object_type = 'note' AND act.id IN
where a.object_type = 'note' and gi.group_id = :group_id (SELECT att.activity_id FROM \Component\Notification\Entity\Notification AS att WHERE att.target_id = :id)
order by a.created desc, a.id desc )
EOF, EOF, ['id' => $group->getId()]);
['group_id' => $group->getId()],
) : [];
return [ return [
'_template' => 'group/view.html.twig', '_template' => 'group/view.html.twig',
'actor' => $group, 'actor' => $group,
'nickname' => $group?->getNickname() ?? $nickname, 'nickname' => $group->getNickname(),
'notes' => $notes, 'notes' => $notes,
'subscribe_form' => $subscribe_form?->createView(), 'subscribe_form' => $subscribe_form?->createView(),
]; ];
} }
public function groupViewId(Request $request, int $id): array
{
return $this->handleGroup($request, Actor::getById($id));
}
/**
* View a group feed by its nickname
*
* @param string $nickname The group's nickname to be shown
*
* @throws NicknameEmptyException
* @throws NicknameNotAllowedException
* @throws NicknameTakenException
* @throws NicknameTooLongException
* @throws ServerException
*/
public function groupViewNickname(Request $request, string $nickname): array
{
Nickname::validate($nickname, which: Nickname::CHECK_LOCAL_GROUP); // throws
$group = LocalGroup::getActorByNickname($nickname);
if (\is_null($group)) {
throw new NotFoundException(_m('Group not found.'));
}
return $this->handleGroup($request, $group);
}
/** /**
* Page that allows an actor to create a new group * Page that allows an actor to create a new group
* *
* @throws RedirectException * @throws RedirectException
* @throws ServerException * @throws ServerException
*
* @return array
*/ */
public function groupCreate(Request $request) public function groupCreate(Request $request): array
{ {
if (\is_null($actor = Common::actor())) { if (\is_null($actor = Common::actor())) {
throw new RedirectException('security_login'); throw new RedirectException('security_login');
@ -143,19 +156,19 @@ class Group extends FeedController
* Settings page for the group with the provided nickname, checks if the current actor can administrate given group * Settings page for the group with the provided nickname, checks if the current actor can administrate given group
* *
* @throws ClientException * @throws ClientException
* @throws DuplicateFoundException
* @throws NicknameEmptyException * @throws NicknameEmptyException
* @throws NicknameException
* @throws NicknameInvalidException * @throws NicknameInvalidException
* @throws NicknameNotAllowedException * @throws NicknameNotAllowedException
* @throws NicknameTakenException * @throws NicknameTakenException
* @throws NicknameTooLongException * @throws NicknameTooLongException
* @throws NoLoggedInUser * @throws NotFoundException
* @throws ServerException * @throws ServerException
*
* @return array
*/ */
public function groupSettings(Request $request, string $nickname) public function groupSettings(Request $request, int $id): array
{ {
$local_group = LocalGroup::getByNickname($nickname); $local_group = DB::findOneBy(LocalGroup::class, ['group_id' => $id]);
$group_actor = $local_group->getActor(); $group_actor = $local_group->getActor();
$actor = Common::actor(); $actor = Common::actor();
if (!\is_null($group_actor) && $actor->canAdmin($group_actor)) { if (!\is_null($group_actor) && $actor->canAdmin($group_actor)) {
@ -166,7 +179,7 @@ class Group extends FeedController
'open_details_query' => $this->string('open'), 'open_details_query' => $this->string('open'),
]; ];
} else { } else {
throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $nickname]), code: 404); throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $id]), code: 404);
} }
} }
@ -180,6 +193,10 @@ class Group extends FeedController
{ {
$create_form = Form::create([ $create_form = Form::create([
['group_nickname', TextType::class, ['label' => _m('Group nickname')]], ['group_nickname', TextType::class, ['label' => _m('Group nickname')]],
['group_type', ChoiceType::class, ['label' => _m('Type:'), 'multiple' => false, 'expanded' => false, 'choices' => [
_m('Group') => 'group',
_m('Organisation') => 'organisation',
]]],
['group_create', SubmitType::class, ['label' => _m('Create this group!')]], ['group_create', SubmitType::class, ['label' => _m('Create this group!')]],
]); ]);
@ -203,6 +220,7 @@ class Group extends FeedController
])); ]));
DB::persist(LocalGroup::create([ DB::persist(LocalGroup::create([
'group_id' => $group->getId(), 'group_id' => $group->getId(),
'type' => $data['group_type'],
'nickname' => $nickname, 'nickname' => $nickname,
])); ]));
DB::persist(ActorSubscription::create([ DB::persist(ActorSubscription::create([

View File

@ -1,100 +0,0 @@
<?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/>.
// }}}
namespace Component\Group\Entity;
use App\Core\Entity;
use DateTimeInterface;
/**
* Entity for Group Alias
*
* @category DB
* @package GNUsocial
*
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet Inc.
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class GroupAlias extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private string $alias;
private int $group_id;
private DateTimeInterface $modified;
public function setAlias(string $alias): self
{
$this->alias = mb_substr($alias, 0, 64);
return $this;
}
public function getAlias(): string
{
return $this->alias;
}
public function setGroupId(int $group_id): self
{
$this->group_id = $group_id;
return $this;
}
public function getGroupId(): int
{
return $this->group_id;
}
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getModified(): DateTimeInterface
{
return $this->modified;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
public static function schemaDef(): array
{
return [
'name' => 'group_alias',
'fields' => [
'alias' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'additional nickname for the group'],
'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'group id which this is an alias of'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['alias'],
'indexes' => [
'group_alias_group_id_idx' => ['group_id'],
],
];
}
}

View File

@ -1,110 +0,0 @@
<?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/>.
// }}}
namespace Component\Group\Entity;
use App\Core\Entity;
use DateTimeInterface;
/**
* Entity for Group Block
*
* @category DB
* @package GNUsocial
*
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet Inc.
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class GroupBlock extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $group_id;
private int $blocked_actor;
private int $blocker_user;
private DateTimeInterface $modified;
public function setGroupId(int $group_id): self
{
$this->group_id = $group_id;
return $this;
}
public function getGroupId(): int
{
return $this->group_id;
}
public function setBlockedActor(int $blocked_actor): self
{
$this->blocked_actor = $blocked_actor;
return $this;
}
public function getBlockedActor(): int
{
return $this->blocked_actor;
}
public function setBlockerUser(int $blocker_user): self
{
$this->blocker_user = $blocker_user;
return $this;
}
public function getBlockerUser(): int
{
return $this->blocker_user;
}
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getModified(): DateTimeInterface
{
return $this->modified;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
public static function schemaDef(): array
{
return [
'name' => 'group_block',
'fields' => [
'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'group actor is blocked from'],
'blocked_actor' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor that is blocked'],
'blocker_user' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'user making the block'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['group_id', 'blocked_actor'],
];
}
}

View File

@ -1,103 +0,0 @@
<?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/>.
// }}}
namespace Component\Group\Entity;
use App\Core\Entity;
use DateTimeInterface;
/**
* Entity for Group's inbox
*
* @category DB
* @package GNUsocial
*
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet Inc.
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class GroupInbox extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $group_id;
private int $activity_id;
private DateTimeInterface $created;
public function setGroupId(int $group_id): self
{
$this->group_id = $group_id;
return $this;
}
public function getGroupId(): int
{
return $this->group_id;
}
public function setActivityId(int $activity_id): self
{
$this->activity_id = $activity_id;
return $this;
}
public function getActivityId(): int
{
return $this->activity_id;
}
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCreated(): DateTimeInterface
{
return $this->created;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
public static function schemaDef(): array
{
return [
'name' => 'group_inbox',
'description' => 'Many-many table listing activities posted to a given group, or which groups a given activity was posted to',
'fields' => [
'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'name' => 'group_inbox_group_id_fkey', 'not null' => true, 'description' => 'group receiving the activity'],
'activity_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Activity.id', 'multiplicity' => 'many to one', 'name' => 'group_inbox_activity_id_fkey', 'not null' => true, 'description' => 'activity received'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
],
'primary key' => ['group_id', 'activity_id'],
'indexes' => [
'group_inbox_activity_id_idx' => ['activity_id'],
'group_inbox_group_id_created_activity_id_idx' => ['group_id', 'created', 'activity_id'],
'group_inbox_created_idx' => ['created'],
],
];
}
}

View File

@ -54,7 +54,8 @@ class LocalGroup extends Entity
// {{{ Autocode // {{{ Autocode
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
private int $group_id; private int $group_id;
private ?string $nickname = null; private string $nickname;
private string $type;
private DateTimeInterface $created; private DateTimeInterface $created;
private DateTimeInterface $modified; private DateTimeInterface $modified;
@ -69,17 +70,28 @@ class LocalGroup extends Entity
return $this->group_id; return $this->group_id;
} }
public function setNickname(?string $nickname): self public function setNickname(string $nickname): self
{ {
$this->nickname = \is_null($nickname) ? null : mb_substr($nickname, 0, 64); $this->nickname = mb_substr($nickname, 0, 64);
return $this; return $this;
} }
public function getNickname(): ?string public function getNickname(): string
{ {
return $this->nickname; return $this->nickname;
} }
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getType(): string
{
return $this->type;
}
public function setCreated(DateTimeInterface $created): self public function setCreated(DateTimeInterface $created): self
{ {
$this->created = $created; $this->created = $created;
@ -152,7 +164,8 @@ class LocalGroup extends Entity
'description' => 'Record for a user group on the local site, with some additional info not in user_group', 'description' => 'Record for a user group on the local site, with some additional info not in user_group',
'fields' => [ 'fields' => [
'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'name' => 'local_group_group_id_fkey', 'not null' => true, 'description' => 'group represented'], 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'name' => 'local_group_group_id_fkey', 'not null' => true, 'description' => 'group represented'],
'nickname' => ['type' => 'varchar', 'length' => 64, 'description' => 'group represented'], 'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'group represented'],
'type' => ['type' => 'varchar', 'not null' => true, 'default' => 'group', 'length' => 64, 'description' => 'Group or Organisation'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], 'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
], ],

View File

@ -40,8 +40,9 @@ class Group extends Component
public function onAddRoute(RouteLoader $r): bool public function onAddRoute(RouteLoader $r): bool
{ {
$r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']); $r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']);
$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_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']);
$r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]); $r->connect(id: 'group_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']);
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname']);
return Event::next; return Event::next;
} }
@ -53,7 +54,7 @@ class Group extends Component
$actor = Common::actor(); $actor = Common::actor();
$group = $vars['actor']; $group = $vars['actor'];
if (!\is_null($actor) && $group->isGroup() && $actor->canAdmin($group)) { if (!\is_null($actor) && $group->isGroup() && $actor->canAdmin($group)) {
$url = Router::url('group_settings', ['nickname' => $group->getNickname()]); $url = Router::url('group_settings', ['id' => $group->getId()]);
$res[] = HTML::html(['a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings'), 'class' => 'profile-extra-actions'], _m('Group settings')]]); $res[] = HTML::html(['a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings'), 'class' => 'profile-extra-actions'], _m('Group settings')]]);
} }
return Event::next; return Event::next;
@ -62,8 +63,8 @@ class Group extends Component
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs) public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs)
{ {
if ($section === 'profile' && $request->get('_route') === 'group_settings') { if ($section === 'profile' && $request->get('_route') === 'group_settings') {
$nickname = $request->get('nickname'); $group_id = $request->get('id');
$group = LocalGroup::getActorByNickname($nickname); $group = Actor::getById($group_id);
$tabs[] = [ $tabs[] = [
'title' => 'Self tags', 'title' => 'Self tags',
'desc' => 'Add or remove tags on this group', 'desc' => 'Add or remove tags on this group',
@ -95,7 +96,7 @@ class Group extends Component
{ {
$group = $this->getGroupFromContext($request); $group = $this->getGroupFromContext($request);
if (!\is_null($group)) { if (!\is_null($group)) {
$nick = '!' . $group->getNickname(); $nick = "!{$group->getNickname()}";
$targets[$nick] = $group->getId(); $targets[$nick] = $group->getId();
} }
return Event::next; return Event::next;

View File

@ -4,7 +4,7 @@
{% trans %}Create a group{% endtrans %} {% trans %}Create a group{% endtrans %}
</strong> </strong>
</summary> </summary>
<form method="GET" class="section-form"> <form method="POST" class="section-form">
{{ form(create_form) }} {{ form(create_form) }}
</form> </form>
</details> </details>

View File

@ -32,7 +32,6 @@ use App\Entity\Activity;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\LocalUser; use App\Entity\LocalUser;
use Component\FreeNetwork\FreeNetwork; use Component\FreeNetwork\FreeNetwork;
use Component\Group\Entity\GroupInbox;
use Component\Notification\Controller\Feed; use Component\Notification\Controller\Feed;
class Notification extends Component class Notification extends Component
@ -75,17 +74,9 @@ class Notification extends Component
$remote_targets = []; $remote_targets = [];
foreach ($targets as $target) { foreach ($targets as $target) {
if ($target->getIsLocal()) { if ($target->getIsLocal()) {
if ($target->isGroup()) { if ($target->hasBlocked($activity->getActor())) {
// FIXME: Make sure we check (for both local and remote) users are in the groups they send to! Log::info("Not saving reply to actor {$target->getId()} from sender {$sender->getId()} because of a block.");
DB::persist(GroupInbox::create([ continue;
'group_id' => $target->getId(),
'activity_id' => $activity->getId(),
]));
} else {
if ($target->hasBlocked($activity->getActor())) {
Log::info("Not saving reply to actor {$target->getId()} from sender {$sender->getId()} because of a block.");
continue;
}
} }
if (Event::handle('NewNotificationShould', [$activity, $target]) === Event::next) { if (Event::handle('NewNotificationShould', [$activity, $target]) === Event::next) {
// TODO: use https://symfony.com/doc/current/notifier.html // TODO: use https://symfony.com/doc/current/notifier.html

View File

@ -62,15 +62,14 @@ use Plugin\ActivityPub\Util\Model;
class Actor extends Model class Actor extends Model
{ {
private static array $_gs_actor_type_to_as2_actor_type = [ private static array $_gs_actor_type_to_as2_actor_type = [
GSActor::PERSON => 'Person', GSActor::PERSON => 'Person',
GSActor::GROUP => 'Group', GSActor::GROUP => 'Group',
GSActor::ORGANISATION => 'Organization', GSActor::BOT => 'Application',
GSActor::BOT => 'Application',
]; ];
private static array $_as2_actor_type_to_gs_actor_type = [ private static array $_as2_actor_type_to_gs_actor_type = [
'Person' => GSActor::PERSON, 'Person' => GSActor::PERSON,
'Group' => GSActor::GROUP, 'Group' => GSActor::GROUP,
'Organization' => GSActor::ORGANISATION, 'Organization' => GSActor::GROUP,
'Application' => GSActor::BOT, 'Application' => GSActor::BOT,
'Service' => null, 'Service' => null,
]; ];

View File

@ -29,6 +29,7 @@ use App\Entity\Actor;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\BugFoundException; use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
use App\Util\Exception\ServerException;
use Component\Collection\Util\Controller\CircleController; use Component\Collection\Util\Controller\CircleController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -39,8 +40,12 @@ class Directory extends CircleController
/** /**
* Function responsible for displaying a list of actors of a given * Function responsible for displaying a list of actors of a given
* $actor_type, sorted by the `order_by` GET parameter, if given * $actor_type, sorted by the `order_by` GET parameter, if given
*
* @throws BugFoundException
* @throws ClientException
* @throws ServerException
*/ */
private function impl(Request $request, int $actor_type, string $title, string $empty_message): array private function magic(Request $request, int $actor_type, string $title, string $empty_message): array
{ {
if ($actor_type !== Actor::PERSON && $actor_type !== Actor::GROUP) { if ($actor_type !== Actor::PERSON && $actor_type !== Actor::GROUP) {
throw new BugFoundException("Unimplemented for actor type: {$actor_type}"); throw new BugFoundException("Unimplemented for actor type: {$actor_type}");
@ -99,7 +104,7 @@ class Directory extends CircleController
'limit' => $limit, 'limit' => $limit,
'offset' => $offset, 'offset' => $offset,
], ],
['actr' => Actor::class], ['actor' => Actor::class],
); );
}; };
// -------- *** -------- // -------- *** --------
@ -114,22 +119,16 @@ class Directory extends CircleController
$query_fn = match ($order_by_field) { $query_fn = match ($order_by_field) {
'nickname', 'created' => $actor_query_fn, // select only from actors 'nickname', 'created' => $actor_query_fn, // select only from actors
'modified' => match ($actor_type) { // select by most/least recent activity // select by most/least recent activity
Actor::PERSON => $minmax_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), 'modified' => $minmax_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'),
Actor::GROUP => $minmax_query_fn(table: 'group_inbox', join_field: 'group_id', aggregate_field: 'created'),
},
'activity' => match ($actor_type) { // select by most/least activity amount // select by most/least activity amount
Actor::PERSON => $count_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), 'activity' => $count_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'),
Actor::GROUP => $count_query_fn(table: 'group_inbox', join_field: 'group_id', aggregate_field: 'created'),
},
'subscribers' => match ($actor_type) { // select by actors with most/least subscribers/members // select by actors with most/least subscribers/members
Actor::PERSON => $count_query_fn(table: 'subscription', join_field: 'subscribed_id', aggregate_field: 'subscriber_id'), 'subscribers' => $count_query_fn(table: 'subscription', join_field: 'subscribed_id', aggregate_field: 'subscriber_id'),
Actor::GROUP => $count_query_fn(table: 'group_member', join_field: 'group_id', aggregate_field: 'actor_id'),
},
default => throw new BugFoundException("Unkown order by found, but should have been validated: {$order_by_field}"), default => throw new BugFoundException("Unknown order by found, but should have been validated: {$order_by_field}"),
}; };
// -------- *** -------- // -------- *** --------
@ -154,11 +153,11 @@ class Directory extends CircleController
public function people(Request $request): array public function people(Request $request): array
{ {
return $this->impl($request, Actor::PERSON, title: _m('People'), empty_message: _m('No people here')); return $this->magic($request, Actor::PERSON, title: _m('People'), empty_message: _m('No people here'));
} }
public function groups(Request $request): array public function groups(Request $request): array
{ {
return $this->impl($request, Actor::GROUP, title: _m('Groups'), empty_message: _m('No groups here')); return $this->magic($request, Actor::GROUP, title: _m('Groups'), empty_message: _m('No groups here'));
} }
} }

View File

@ -243,8 +243,7 @@ class Actor extends Entity
public const PERSON = 1; public const PERSON = 1;
public const GROUP = 2; public const GROUP = 2;
public const ORGANISATION = 3; public const BOT = 3;
public const BOT = 4;
public static function cacheKeys(int|self $actor_id, mixed $other = null): array public static function cacheKeys(int|self $actor_id, mixed $other = null): array
{ {
@ -421,7 +420,6 @@ class Actor extends Entity
if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) { if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) {
switch ($this->type) { switch ($this->type) {
case self::PERSON: case self::PERSON:
case self::ORGANISATION:
case self::BOT: case self::BOT:
case self::GROUP: case self::GROUP:
$uri = Router::url('actor_view_id', ['id' => $this->getId()], $type); $uri = Router::url('actor_view_id', ['id' => $this->getId()], $type);
@ -447,7 +445,7 @@ class Actor extends Entity
$url = null; $url = null;
if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) { if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) {
$url = match ($this->type) { $url = match ($this->type) {
self::PERSON, self::ORGANISATION, self::BOT => Router::url('actor_view_nickname', ['nickname' => mb_strtolower($this->getNickname())], $type), self::PERSON, self::BOT => Router::url('actor_view_nickname', ['nickname' => mb_strtolower($this->getNickname())], $type),
self::GROUP => Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type), self::GROUP => Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type),
default => throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated'), default => throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated'),
}; };
@ -529,7 +527,6 @@ class Actor extends Entity
/** /**
* @method bool isPerson() * @method bool isPerson()
* @method bool isGroup() * @method bool isGroup()
* @method bool isOrganization()
* @method bool isBot() * @method bool isBot()
*/ */
public function __call(string $name, array $arguments): mixed public function __call(string $name, array $arguments): mixed