mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
DEV: Update group moderator behavior to better mimic staff (#19618)
# Context When a topic is reviewable by a group we give those group moderators some admin abilities including the ability to delete a topic. # Problem There are two main problems: 1. Currently when a group moderator deletes a topic they are redirected to root (not the same for staff) 2. Viewing the categories deleted topics (`c/foo/1/?status=deleted`) does not display the deleted topic to the group moderator (not the same for staff). # Fix If the `deleted_by` user is part a group that matches the `reviewable_by_group` on a topic then don't redirect. This is the default interaction for staff to give them the ability to do things like restore the topic in case it was accidentally deleted. To render the deleted topics as expected for the group moderator I am utilizing [the guardian scope of `guardian.can_see_deleted_topics?` for said category](https://github.com/discourse/discourse/pull/19618/files#diff-288e61b8bacdb29d9c2e05b42da6837b0036dcf1867332d977ca7c5e74a44297R802-R803)
This commit is contained in:
parent
7e33cb3665
commit
e5349e43af
|
@ -467,7 +467,12 @@ const Topic = RestModel.extend({
|
|||
"details.can_permanently_delete":
|
||||
this.siteSettings.can_permanently_delete && deleted_by.admin,
|
||||
});
|
||||
if (!deleted_by.staff) {
|
||||
if (
|
||||
!deleted_by.staff &&
|
||||
!deleted_by.groups.some(
|
||||
(group) => group.name === this.category.reviewable_by_group_name
|
||||
)
|
||||
) {
|
||||
DiscourseURL.redirectTo("/");
|
||||
}
|
||||
})
|
||||
|
|
|
@ -799,8 +799,8 @@ class TopicQuery
|
|||
when 'unlisted'
|
||||
result = result.where('NOT topics.visible')
|
||||
when 'deleted'
|
||||
guardian = @guardian
|
||||
if guardian.is_staff?
|
||||
category = Category.find_by(id: options[:category])
|
||||
if @guardian.can_see_deleted_topics?(category)
|
||||
result = result.where('topics.deleted_at IS NOT NULL')
|
||||
require_deleted_clause = false
|
||||
end
|
||||
|
|
|
@ -226,10 +226,16 @@ RSpec.describe TopicQuery do
|
|||
|
||||
describe 'deleted filter' do
|
||||
it "filters deleted topics correctly" do
|
||||
_topic = Fabricate(:topic, deleted_at: 1.year.ago)
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
group_moderator = Fabricate(:user)
|
||||
group = Fabricate(:group)
|
||||
group.add(group_moderator)
|
||||
category = Fabricate(:category, reviewable_by_group: group)
|
||||
topic = Fabricate(:topic, category: category, deleted_at: 1.year.ago)
|
||||
|
||||
expect(TopicQuery.new(admin, status: 'deleted').list_latest.topics.size).to eq(1)
|
||||
expect(TopicQuery.new(moderator, status: 'deleted').list_latest.topics.size).to eq(1)
|
||||
expect(TopicQuery.new(group_moderator, status: 'deleted', category: category.id).list_latest.topics.size).to eq(1)
|
||||
expect(TopicQuery.new(user, status: 'deleted').list_latest.topics.size).to eq(0)
|
||||
expect(TopicQuery.new(nil, status: 'deleted').list_latest.topics.size).to eq(0)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user