diff --git a/components/Circle/Circle.php b/components/Circle/Circle.php index 591379cbc7..956711170e 100644 --- a/components/Circle/Circle.php +++ b/components/Circle/Circle.php @@ -97,7 +97,7 @@ class Circle extends Component public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool { - if ($section === 'profile' && $request->get('_route') === 'settings') { + if ($section === 'profile' && \in_array($request->get('_route'), ['person_actor_settings', 'group_actor_settings'])) { $tabs[] = [ 'title' => 'Self tags', 'desc' => 'Add or remove tags on yourself', diff --git a/components/Circle/Controller/SelfTagsSettings.php b/components/Circle/Controller/SelfTagsSettings.php index 813607104f..c8f347ec8e 100644 --- a/components/Circle/Controller/SelfTagsSettings.php +++ b/components/Circle/Controller/SelfTagsSettings.php @@ -23,6 +23,7 @@ class SelfTagsSettings extends Controller { /** * Generic settings page for an Actor's self tags + * TODO: We should have $actor->setSelfTags(), $actor->addSelfTags(), $actor->removeSelfTags() */ public static function settingsSelfTags(Request $request, E\Actor $target, string $details_id) { diff --git a/components/Group/Group.php b/components/Group/Group.php index bd163bca57..1daa7d41d0 100644 --- a/components/Group/Group.php +++ b/components/Group/Group.php @@ -31,7 +31,6 @@ use App\Entity\Actor; use App\Util\Common; use App\Util\HTML; use App\Util\Nickname; -use Component\Circle\Controller\SelfTagsSettings; use Component\Group\Controller as C; use Component\Group\Entity\LocalGroup; use Component\Notification\Notification; @@ -44,7 +43,7 @@ class Group extends Component $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']); $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']); $r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']); - $r->connect(id: 'group_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']); + $r->connect(id: 'group_actor_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']); return Event::next; } @@ -65,7 +64,7 @@ class Group extends Component } /** - * Add an to the profile card for groups, if the current actor can access them + * Add an to the profile card for groups, if the current actor can access them */ public function onAppendCardProfile(array $vars, array &$res): bool { @@ -73,7 +72,7 @@ class Group extends Component $group = $vars['actor']; if (!\is_null($actor) && $group->isGroup()) { if ($actor->canModerate($group)) { - $url = Router::url('group_settings', ['id' => $group->getId()]); + $url = Router::url('group_actor_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' => Router::url('blog_post', ['in' => $group->getId()]), 'title' => _m('Make a new blog post'), 'class' => 'profile-extra-actions'], _m('Post in blog')]]); @@ -81,21 +80,6 @@ class Group extends Component return Event::next; } - public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool - { - if ($section === 'profile' && $request->get('_route') === 'group_settings') { - $group_id = (int) $request->get('id'); - $group = Actor::getById($group_id); - $tabs[] = [ - 'title' => 'Self tags', - 'desc' => 'Add or remove tags on this group', - 'id' => 'settings-self-tags', - 'controller' => SelfTagsSettings::settingsSelfTags($request, $group, 'settings-self-tags-details'), - ]; - } - return Event::next; - } - /** * If in a group route, get the current group */ diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 42d39c24c7..98d69be1f3 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -36,6 +36,7 @@ use App\Util\Exception\NotImplementedException; use App\Util\Formatting; use App\Util\Nickname; use Component\Avatar\Avatar; +use Component\Circle\Entity\ActorTag; use Component\Group\Entity\GroupMember; use Component\Group\Entity\LocalGroup; use Component\Language\Entity\ActorLanguage; @@ -331,7 +332,7 @@ class Actor extends Entity { return Cache::getList( self::cacheKeys($this->getId())['self-tags'], - fn() => DB::findBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId()], order_by: ['modified' => 'DESC']), + fn() => DB::findBy(ActorTag::class, ['tagger' => $this->getId(), 'tagged' => $this->getId()], order_by: ['modified' => 'DESC']), ); } diff --git a/tests/Entity/ActorTest.php b/tests/Entity/ActorTest.php index 9ae66f56b7..b5e704be7f 100644 --- a/tests/Entity/ActorTest.php +++ b/tests/Entity/ActorTest.php @@ -21,10 +21,12 @@ declare(strict_types = 1); namespace App\Tests\Entity; +use App\Core\Cache; use App\Core\DB\DB; +use App\Entity\Actor; use App\Util\GNUsocialTestCase; use Component\Circle\Entity\ActorTag; -use Functional as F; +use Component\Tag\Tag as CompTag; use Jchook\AssertThrows\AssertThrows; class ActorTest extends GNUsocialTestCase @@ -33,20 +35,43 @@ class ActorTest extends GNUsocialTestCase public function testGetAvatarUrl() { - $actor = DB::findOneBy('actor', ['nickname' => 'taken_user']); + $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']); static::assertSame('/avatar/default', $actor->getAvatarUrl()); } public function testSelfTags() { - $actor = DB::findOneBy('actor', ['nickname' => 'taken_user']); - $tags = $actor->getSelfTags(); - $actor->setSelfTags(['foo'], $tags); + $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']); + // Start with no self-tags + static::assertSame( + expected: [], + actual: $actor->getSelfTags(), + ); + // Add one self-tag 'foo' + $tag = CompTag::sanitize('foo'); + DB::persist($actor_tag_foo = ActorTag::create([ + 'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag + 'tagged' => $actor->getId(), + 'tag' => $tag, + ])); DB::flush(); - $get_tags = fn ($tags) => F\map($tags, fn (ActorTag $t) => $t->getTag()); - static::assertSame(['foo'], $get_tags($tags = $actor->getSelfTags())); - $actor->setSelfTags(['bar'], $tags); + Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']); + static::assertSame( + expected: [$actor_tag_foo], + actual: $actor->getSelfTags(), + ); + // Add a second self-tag 'foo' + $tag = CompTag::sanitize('bar'); + DB::persist($actor_tag_bar = ActorTag::create([ + 'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag + 'tagged' => $actor->getId(), + 'tag' => $tag, + ])); DB::flush(); - static::assertSame(['bar'], $get_tags($tags = $actor->getSelfTags())); + Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']); + static::assertSame( + expected: [$actor_tag_bar, $actor_tag_foo], + actual: $actor->getSelfTags(), + ); } }