mirror of
https://github.com/flarum/core.git
synced 2025-08-10 18:35:56 +02:00
[mentions] feat: group mentions (#3658)
* wip: group mentions * Apply fixes from StyleCI * chore: format * group mention autocomplete * chore: format * remove console.log * implement notifications * prevent guest and member groups from being mentioned * Update extensions/mentions/less/forum.less Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * rename displayname to groupname * Update extensions/mentions/src/Formatter/FormatGroupMentions.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * remove redundant unparse * simplify migrations * add group deleted translation * Apply fixes from StyleCI * handle everything falsy * Include icon in group mention preview * remove box-shadow from autocomplete group results * Add color to preview * chore: format * Remove box shadow from group autocomplete results * Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * remove unneeded migration * prevent former group icon from beingdisplayed * add group searcher with permissions * Apply fixes from StyleCI * Search groups based on canSearchGroups permission * Don't include virtual groups in results * Add search groups translation * Revert "remove unneeded migration" This reverts commit9347665baa
. * Revert "Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php" This reverts commit8406d51df2
. * add searchGroups permission to tests * Apply fixes from StyleCI * Add default searchGroups permission * Apply fixes from StyleCI * Update extensions/mentions/js/src/forum/addComposerAutocomplete.js Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * remove unneeded migration, correct table table * correct table name in down migration * Remove group searcher * Apply fixes from StyleCI * Remove group searching from composer autocomplete * Add mentionGroups permission * Apply fixes from StyleCI * prevent post preview from rendering a group mention when user does not have permission * remove test changes * wip: expose ServerRequestInterface to textformatter parse() * Apply fixes from StyleCI * Set post content properly * php 7.x compatibility * begin adding groupmention tests * Apply fixes from StyleCI * test virtual groups don't mention * Apply fixes from StyleCI * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update extensions/mentions/extend.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update extensions/mentions/extend.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * requested changes * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/tests/integration/api/groups/ListTest.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/src/Search/SearchServiceProvider.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * Update framework/core/src/Extend/Formatter.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * remove default permission migration * try using datetime column instead of timestamp * Apply fixes from StyleCI * chore: remove commented code * add tests * Apply fixes from StyleCI * Pass actor to parser instead of ServerRequest * Allow for to be null * Update framework/core/src/Extend/Formatter.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * pass actor instead of request * Apply fixes from StyleCI * actor instead of request * remove serverrequest * Apply fixes from StyleCI * remove dupe actor * Update extensions/mentions/src/Formatter/CheckPermissions.php Co-authored-by: Sami Mazouz <sychocouldy@gmail.com> * fix type in comment * group does not have the relation, post does * test: invalid, deleted, fresh data mentions Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * fix: group mentions don't work when editing posts Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -12,10 +12,11 @@ namespace Flarum\Mentions;
|
||||
use Flarum\Api\Controller;
|
||||
use Flarum\Api\Serializer\BasicPostSerializer;
|
||||
use Flarum\Api\Serializer\BasicUserSerializer;
|
||||
use Flarum\Api\Serializer\CurrentUserSerializer;
|
||||
use Flarum\Api\Serializer\GroupSerializer;
|
||||
use Flarum\Api\Serializer\PostSerializer;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Mentions\Notification\PostMentionedBlueprint;
|
||||
use Flarum\Mentions\Notification\UserMentionedBlueprint;
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Post\Event\Deleted;
|
||||
use Flarum\Post\Event\Hidden;
|
||||
use Flarum\Post\Event\Posted;
|
||||
@@ -37,13 +38,16 @@ return [
|
||||
->configure(ConfigureMentions::class)
|
||||
->render(Formatter\FormatPostMentions::class)
|
||||
->render(Formatter\FormatUserMentions::class)
|
||||
->render(Formatter\FormatGroupMentions::class)
|
||||
->unparse(Formatter\UnparsePostMentions::class)
|
||||
->unparse(Formatter\UnparseUserMentions::class),
|
||||
->unparse(Formatter\UnparseUserMentions::class)
|
||||
->parse(Formatter\CheckPermissions::class),
|
||||
|
||||
(new Extend\Model(Post::class))
|
||||
->belongsToMany('mentionedBy', Post::class, 'post_mentions_post', 'mentions_post_id', 'post_id')
|
||||
->belongsToMany('mentionsPosts', Post::class, 'post_mentions_post', 'post_id', 'mentions_post_id')
|
||||
->belongsToMany('mentionsUsers', User::class, 'post_mentions_user', 'post_id', 'mentions_user_id'),
|
||||
->belongsToMany('mentionsUsers', User::class, 'post_mentions_user', 'post_id', 'mentions_user_id')
|
||||
->belongsToMany('mentionsGroups', Group::class, 'post_mentions_group', 'post_id', 'mentions_group_id'),
|
||||
|
||||
new Extend\Locales(__DIR__.'/locale'),
|
||||
|
||||
@@ -51,25 +55,28 @@ return [
|
||||
->namespace('flarum-mentions', __DIR__.'/views'),
|
||||
|
||||
(new Extend\Notification())
|
||||
->type(PostMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
||||
->type(UserMentionedBlueprint::class, PostSerializer::class, ['alert']),
|
||||
->type(Notification\PostMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
||||
->type(Notification\UserMentionedBlueprint::class, PostSerializer::class, ['alert'])
|
||||
->type(Notification\GroupMentionedBlueprint::class, PostSerializer::class, ['alert']),
|
||||
|
||||
(new Extend\ApiSerializer(BasicPostSerializer::class))
|
||||
->hasMany('mentionedBy', BasicPostSerializer::class)
|
||||
->hasMany('mentionsPosts', BasicPostSerializer::class)
|
||||
->hasMany('mentionsUsers', BasicUserSerializer::class),
|
||||
->hasMany('mentionsUsers', BasicUserSerializer::class)
|
||||
->hasMany('mentionsGroups', GroupSerializer::class),
|
||||
|
||||
(new Extend\ApiController(Controller\ShowDiscussionController::class))
|
||||
->addInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion'])
|
||||
->load([
|
||||
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user', 'posts.mentionedBy',
|
||||
'posts.mentionedBy.mentionsPosts', 'posts.mentionedBy.mentionsPosts.user', 'posts.mentionedBy.mentionsUsers',
|
||||
'posts.mentionsGroups'
|
||||
]),
|
||||
|
||||
(new Extend\ApiController(Controller\ListDiscussionsController::class))
|
||||
->load([
|
||||
'firstPost.mentionsUsers', 'firstPost.mentionsPosts', 'firstPost.mentionsPosts.user',
|
||||
'lastPost.mentionsUsers', 'lastPost.mentionsPosts', 'lastPost.mentionsPosts.user'
|
||||
'firstPost.mentionsUsers', 'firstPost.mentionsPosts', 'firstPost.mentionsPosts.user', 'firstPost.mentionsGroups',
|
||||
'lastPost.mentionsUsers', 'lastPost.mentionsPosts', 'lastPost.mentionsPosts.user', 'lastPost.mentionsGroups'
|
||||
]),
|
||||
|
||||
(new Extend\ApiController(Controller\ShowPostController::class))
|
||||
@@ -80,13 +87,16 @@ return [
|
||||
->load([
|
||||
'mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionedBy',
|
||||
'mentionedBy.mentionsPosts', 'mentionedBy.mentionsPosts.user', 'mentionedBy.mentionsUsers',
|
||||
'mentionsGroups'
|
||||
]),
|
||||
|
||||
(new Extend\ApiController(Controller\CreatePostController::class))
|
||||
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy']),
|
||||
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy'])
|
||||
->addOptionalInclude('mentionsGroups'),
|
||||
|
||||
(new Extend\ApiController(Controller\UpdatePostController::class))
|
||||
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy']),
|
||||
->addInclude(['mentionsPosts', 'mentionsPosts.mentionedBy'])
|
||||
->addOptionalInclude('mentionsGroups'),
|
||||
|
||||
(new Extend\ApiController(Controller\AbstractSerializeController::class))
|
||||
->prepareDataForSerialization(FilterVisiblePosts::class),
|
||||
@@ -103,4 +113,9 @@ return [
|
||||
|
||||
(new Extend\Filter(PostFilterer::class))
|
||||
->addFilter(Filter\MentionedFilter::class),
|
||||
|
||||
(new Extend\ApiSerializer(CurrentUserSerializer::class))
|
||||
->attribute('canMentionGroups', function (CurrentUserSerializer $serializer, User $user, array $attributes): bool {
|
||||
return $user->can('mentionGroups');
|
||||
})
|
||||
];
|
||||
|
Reference in New Issue
Block a user