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 1 commit
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
6 changes: 6 additions & 0 deletions decidim-core/lib/decidim/core/test/factories.rb
Expand Up @@ -600,6 +600,12 @@ def generate_localized_title
some_extra_data: "1"
}
end

trait :user_group_mentioned_notification do
andreslucena marked this conversation as resolved.
Show resolved Hide resolved
event_class { "Decidim::Comments::UserGroupMentionedEvent" }
event_name { "decidim.events.comments.user_group_mentioned" }
extra { { comment_id: create(:comment).id, group_id: create(:user_group).id } }
end
end

factory :action_log, class: "Decidim::ActionLog" do
Expand Down
10 changes: 8 additions & 2 deletions decidim-core/lib/decidim/events/user_group_event.rb
Expand Up @@ -35,9 +35,15 @@ def group_presenter
end

def group
return unless extra[:group].is_a?(Decidim::UserGroup)
@group ||= fetch_group
end

private

def fetch_group
return extra[:group] if extra[:group].is_a?(Decidim::UserGroup)
quinHD marked this conversation as resolved.
Show resolved Hide resolved

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

context "with user group mentioned notifications" do
andreslucena marked this conversation as resolved.
Show resolved Hide resolved
let!(:notification) { create :notification, :user_group_mentioned_notification, user: user }

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