FEATURE: Allow group moderators to close/archive topics

FEATURE: Allow group moderators to close/archive topics

  • FEATURE: Allow group moderators to close/archive topics
diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.js
index 19ec24d..2f80877 100644
--- a/app/assets/javascripts/discourse/app/lib/transform-post.js
+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js
@@ -119,7 +119,9 @@ export default function transformPost(
   postAtts.canManage = currentUser && currentUser.get("canManageTopic");
   postAtts.canViewRawEmail =
     currentUser && (currentUser.id === post.user_id || currentUser.staff);
-  postAtts.canReplyAsNewTopic = details.can_reply_as_new_topic;
+  postAtts.canArchiveTopic = !!details.can_archive_topic;
+  postAtts.canCloseTopic = !!details.can_close_topic;
+  postAtts.canReplyAsNewTopic = !!details.can_reply_as_new_topic;
   postAtts.canReviewTopic = !!details.can_review_topic;
   postAtts.canPublishPage =
     !!details.can_publish_page && post.post_number === 1;
diff --git a/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
index 5520c04..7bac284 100644
--- a/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/edit-category-settings.hbs
@@ -81,7 +81,7 @@
 
 <section>
   <h3>{{i18n "category.settings_sections.moderation"}}</h3>
-  {{#if siteSettings.enable_category_group_review}}
+  {{#if siteSettings.enable_category_group_moderation}}
     <section class="field">
       <label for="reviewable-by-group">
         {{i18n "category.reviewable_by_group"}}
diff --git a/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js b/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
index 7c96830..ce74f3a 100644
--- a/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/topic-admin-menu.js
@@ -158,7 +158,9 @@ export default createWidget("topic-admin-menu", {
           label: "actions.recover"
         });
       }
+    }
 
+    if (this.currentUser && details.get("can_close_topic")) {
       if (topic.get("closed")) {
         this.addActionButton({
           className: "topic-admin-open",
@@ -176,7 +178,9 @@ export default createWidget("topic-admin-menu", {
           label: "actions.close"
         });
       }
+    }
 
+    if (this.currentUser && this.currentUser.get("canManageTopic")) {
       this.addActionButton({
         className: "topic-admin-status-update",
         buttonClass: "popup-menu-btn",
@@ -212,7 +216,9 @@ export default createWidget("topic-admin-menu", {
         icon: "anchor",
         label: "actions.reset_bump_date"
       });
+    }
 
+    if (this.currentUser && details.get("can_archive_topic")) {
       if (!isPrivateMessage) {
         this.addActionButton({
           className: "topic-admin-archive",
@@ -222,7 +228,9 @@ export default createWidget("topic-admin-menu", {
           label: topic.get("archived") ? "actions.unarchive" : "actions.archive"
         });
       }
+    }
 
+    if (this.currentUser && this.currentUser.get("canManageTopic")) {
       this.addActionButton({
         className: "topic-admin-visible",
         buttonClass: "popup-menu-btn",
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 20e02ab..24eb841 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -335,7 +335,7 @@ class CategoriesController < ApplicationController
         allowed_tags: [],
         allowed_tag_groups: []
       )
-      if SiteSetting.enable_category_group_review?
+      if SiteSetting.enable_category_group_moderation?
         result[:reviewable_by_group_id] = Group.find_by(name: params[:reviewable_by_group_name])&.id
       end
 
diff --git a/app/controllers/reviewable_claimed_topics_controller.rb b/app/controllers/reviewable_claimed_topics_controller.rb
index 21015c4..c822f35 100644
--- a/app/controllers/reviewable_claimed_topics_controller.rb
+++ b/app/controllers/reviewable_claimed_topics_controller.rb
@@ -40,7 +40,7 @@ class ReviewableClaimedTopicsController < ApplicationController
   def notify_users(topic, claimed_by)
     user_ids = User.staff.pluck(:id)
 
-    if SiteSetting.enable_category_group_review? && group_id = topic.category&.reviewable_by_group_id.presence
+    if SiteSetting.enable_category_group_moderation? && group_id = topic.category&.reviewable_by_group_id.presence
       user_ids.concat(GroupUser.where(group_id: group_id).pluck(:user_id))
       user_ids.uniq!
     end
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 22edbcf..6e6ce06 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -412,7 +412,16 @@ class TopicsController < ApplicationController
 
     check_for_status_presence(:status, status)
     @topic = Topic.find_by(id: topic_id)
-    guardian.ensure_can_moderate!(@topic)
+
+    case status
+    when 'closed'
+      guardian.ensure_can_close_topic!(@topic)
+    when 'archived'
+      guardian.ensure_can_archive_topic!(@topic)
+    else
+      guardian.ensure_can_moderate!(@topic)
+    end
+
     @topic.update_status(status, enabled, current_user, until: params[:until])
 
     render json: success_json.merge!(
diff --git a/app/jobs/regular/notify_reviewable.rb b/app/jobs/regular/notify_reviewable.rb
index 95fef84..c6b02c1 100644
--- a/app/jobs/regular/notify_reviewable.rb
+++ b/app/jobs/regular/notify_reviewable.rb
@@ -10,7 +10,7 @@ class Jobs::NotifyReviewable < ::Jobs::Base
 
     notify_admins
     notify_moderators if reviewable.reviewable_by_moderator?
-    if SiteSetting.enable_category_group_review? && reviewable.reviewable_by_group.present?
+    if SiteSetting.enable_category_group_moderation? && reviewable.reviewable_by_group.present?
       notify_group(reviewable.reviewable_by_group)
     end
   end
diff --git a/app/jobs/regular/toggle_topic_closed.rb b/app/jobs/regular/toggle_topic_closed.rb
index 246eda4..2cd0a31 100644
--- a/app/jobs/regular/toggle_topic_closed.rb
+++ b/app/jobs/regular/toggle_topic_closed.rb
@@ -16,7 +16,7 @@ module Jobs
 
       user = topic_timer.user
 
-      if Guardian.new(user).can_close?(topic)
+      if Guardian.new(user).can_close_topic?(topic)
         if state == false && topic.auto_close_threshold_reached?
           topic.set_or_create_timer(
             TopicTimer.types[:open],
diff --git a/app/models/category.rb b/app/models/category.rb
index cb51a03..7ba81fe 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -768,7 +768,7 @@ class Category < ActiveRecord::Base
   end
 
   def update_reviewables
-    if SiteSetting.enable_category_group_review? && saved_change_to_reviewable_by_group_id?
+    if SiteSetting.enable_category_group_moderation? && saved_change_to_reviewable_by_group_id?
       Reviewable.where(category_id: id).update_all(reviewable_by_group_id: reviewable_by_group_id)
     end
   end
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 8e8cbd4..d867962 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -281,7 +281,7 @@ class Reviewable < ActiveRecord::Base
   end
 
   def apply_review_group
-    return unless SiteSetting.enable_category_group_review? &&
+    return unless SiteSetting.enable_category_group_moderation? &&
       category.present? &&
       category.reviewable_by_group_id
 
@@ -419,7 +419,7 @@ class Reviewable < ActiveRecord::Base
     end
     return result if user.admin?
 
-    group_ids = SiteSetting.enable_category_group_review? ? user.group_users.pluck(:group_id) : []
+    group_ids = SiteSetting.enable_category_group_moderation? ? user.group_users.pluck(:group_id) : []
 
     result.where(
       '(reviewables.reviewable_by_moderator AND :staff) OR (reviewables.reviewable_by_group_id IN (:group_ids))',

[... diff too long, it was truncated ...]

GitHub sha: 06073fe8

2 Likes

This commit appears in #10217 which was approved by eviltrout. It was merged by jbrw.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/category-group-review-moderation/116478/56