Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix group mentions in notifications #8598

Merged
merged 3 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -56,7 +56,7 @@ def notify_mentioned_groups
affected_users = group.accepted_users - already_notified_users
@already_notified_users += affected_users

notify(:user_group_mentioned, affected_users: affected_users, extra: { group: group })
notify(:user_group_mentioned, affected_users: affected_users, extra: { group_id: group.id })
end
end

Expand Down
Expand Up @@ -10,7 +10,7 @@
let(:extra) do
{
comment_id: comment.id,
group: group
group_id: group.id
}
end

Expand Down
Expand Up @@ -146,7 +146,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)
expect(Decidim::EventsManager)
Expand Down Expand Up @@ -198,7 +198,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)
expect(Decidim::EventsManager)
Expand Down Expand Up @@ -232,7 +232,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)

Expand Down
4 changes: 1 addition & 3 deletions decidim-core/lib/decidim/events/user_group_event.rb
Expand Up @@ -35,9 +35,7 @@ def group_presenter
end

def group
return unless extra[:group].is_a?(Decidim::UserGroup)

extra[:group]
@group ||= Decidim::UserGroup.find_by(id: extra[:group_id]) if extra[:group_id]
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions decidim-core/spec/system/notifications_spec.rb
Expand Up @@ -111,4 +111,23 @@
end
end
end

context "with user group mentioned notifications" do
andreslucena marked this conversation as resolved.
Show resolved Hide resolved
let(:event_class) { "Decidim::Comments::UserGroupMentionedEvent" }
let(:event_name) { "decidim.events.comments.user_group_mentioned" }
let(:extra) { { comment_id: create(:comment).id, group_id: create(:user_group).id } }
let!(:notification) { create :notification, user: user, event_class: event_class, event_name: event_name, extra: extra }

before do
page.visit decidim.notifications_path
end

it "shows the notification with the group mentioned" do
group = Decidim::UserGroup.find(notification.extra["group_id"])
element = page.find(".card-data__item--expand")
notification_text = element.text

expect(notification_text).to end_with("as a member of #{group.name} @#{group.nickname}")
end
end
end