mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 04:56:06 +08:00
FIX: group's mentions was broken (#27066)
In 1deeff2336
we changed the format of the results given by the API but we forgot to update the `#mentions` endpoint as well.
Context - https://meta.discourse.org/t/-/308044
This commit is contained in:
parent
501781c2e5
commit
07ecbb5a3b
|
@ -218,26 +218,43 @@ class GroupsController < ApplicationController
|
||||||
"#{SiteSetting.title} - #{I18n.t("rss_description.group_posts", group_name: group.name)}"
|
"#{SiteSetting.title} - #{I18n.t("rss_description.group_posts", group_name: group.name)}"
|
||||||
@link = Discourse.base_url
|
@link = Discourse.base_url
|
||||||
@description = I18n.t("rss_description.group_posts", group_name: group.name)
|
@description = I18n.t("rss_description.group_posts", group_name: group.name)
|
||||||
|
|
||||||
render "posts/latest", formats: [:rss]
|
render "posts/latest", formats: [:rss]
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentions
|
def mentions
|
||||||
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
||||||
|
|
||||||
group = find_group(:group_id)
|
group = find_group(:group_id)
|
||||||
|
guardian.ensure_can_see_group_members!(group)
|
||||||
|
|
||||||
posts =
|
posts =
|
||||||
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(20)
|
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(20)
|
||||||
render_serialized posts.to_a, GroupPostSerializer
|
|
||||||
|
response = { posts: serialize_data(posts, GroupPostSerializer) }
|
||||||
|
|
||||||
|
if guardian.can_lazy_load_categories?
|
||||||
|
category_ids = posts.map { |p| p.topic.category_id }.compact.uniq
|
||||||
|
categories = Category.secured(guardian).with_parents(category_ids)
|
||||||
|
response[:categories] = serialize_data(categories, CategoryBadgeSerializer)
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: response
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentions_feed
|
def mentions_feed
|
||||||
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
||||||
|
|
||||||
group = find_group(:group_id)
|
group = find_group(:group_id)
|
||||||
|
guardian.ensure_can_see_group_members!(group)
|
||||||
|
|
||||||
@posts =
|
@posts =
|
||||||
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(50)
|
group.mentioned_posts_for(guardian, params.permit(:before_post_id, :category_id)).limit(50)
|
||||||
@title =
|
@title =
|
||||||
"#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
|
"#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
|
||||||
@link = Discourse.base_url
|
@link = Discourse.base_url
|
||||||
@description = I18n.t("rss_description.group_mentions", group_name: group.name)
|
@description = I18n.t("rss_description.group_mentions", group_name: group.name)
|
||||||
|
|
||||||
render "posts/latest", formats: [:rss]
|
render "posts/latest", formats: [:rss]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -526,6 +526,46 @@ RSpec.describe GroupsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#mentions" do
|
||||||
|
it "ensures mentions are enabled" do
|
||||||
|
SiteSetting.enable_mentions = false
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ensures the group can be seen" do
|
||||||
|
sign_in(user)
|
||||||
|
group.update!(visibility_level: Group.visibility_levels[:owners])
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ensures the group members can be seen" do
|
||||||
|
sign_in(user)
|
||||||
|
group.update!(members_visibility_level: Group.visibility_levels[:owners])
|
||||||
|
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(403)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the right response" do
|
||||||
|
post = Fabricate(:post)
|
||||||
|
GroupMention.create!(post: post, group: group)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
get "/groups/#{group.name}/mentions.json"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response.parsed_body["posts"].first["id"]).to eq(post.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#posts" do
|
describe "#posts" do
|
||||||
it "ensures the group can be seen" do
|
it "ensures the group can be seen" do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user