Skip to content

A platform for community discussion. Free, open, simple.

DEV: Introduce `reviewable_ui_refresh` site setting (#33404)

Alan Guo Xiang Tanbc29e5088eb2
diff --git a/app/assets/javascripts/discourse/app/components/reviewable-refresh/item.gjs b/app/assets/javascripts/discourse/app/components/reviewable-refresh/item.gjs
new file mode 100644
index 00000000000..1eed123ec58
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/reviewable-refresh/item.gjs
@@ -0,0 +1,13 @@
+import Component from "@glimmer/component";
+
+export default class ReviewableItem extends Component {
+ get reviewable() {
+ return this.args.reviewable;
+ }
+
+ <template>
+ <div class="review-container">
+ {{this.reviewable.type}}
+ </div>
+ </template>
+}
diff --git a/app/assets/javascripts/discourse/app/templates/review-show.gjs b/app/assets/javascripts/discourse/app/templates/review-show.gjs
index 9e133febde0..00ab83fa595 100644
--- a/app/assets/javascripts/discourse/app/templates/review-show.gjs
+++ b/app/assets/javascripts/discourse/app/templates/review-show.gjs
@@ -1,6 +1,29 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import RouteTemplate from "ember-route-template";
import ReviewableItem from "discourse/components/reviewable-item";
+import ReviewableItemRefresh from "discourse/components/reviewable-refresh/item";
export default RouteTemplate(
- <template><ReviewableItem @reviewable={{@controller.reviewable}} /></template>
+ class extends Component {
+ @service currentUser;
+ @service site;
+
+ /**
+ * Determines whether to use the refreshed reviewable UI component.
+ *
+ * @returns {boolean} True if both conditions are met: user has permission and component exists
+ */
+ get shouldUseRefreshUI() {
+ return this.currentUser.use_reviewable_ui_refresh;
+ }
+
+ <template>
+ {{#if this.shouldUseRefreshUI}}
+ <ReviewableItemRefresh @reviewable={{@controller.reviewable}} />
+ {{else}}
+ <ReviewableItem @reviewable={{@controller.reviewable}} />
+ {{/if}}
+ </template>
+ }
);
diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb
index 7b58cdb6588..bc921581421 100644
--- a/app/serializers/current_user_serializer.rb
+++ b/app/serializers/current_user_serializer.rb
@@ -78,7 +78,8 @@ class CurrentUserSerializer < BasicUserSerializer
:can_see_emails,
:use_glimmer_post_stream_mode_auto_mode,
:can_localize_content?,
- :effective_locale
+ :effective_locale,
+ :use_reviewable_ui_refresh
delegate :user_stat, to: :object, private: true
delegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat
@@ -342,4 +343,12 @@ class CurrentUserSerializer < BasicUserSerializer
def include_effective_locale?
SiteSetting.content_localization_enabled
end
+
+ def use_reviewable_ui_refresh
+ scope.can_see_reviewable_ui_refresh?
+ end
+
+ def include_use_reviewable_ui_refresh?
+ scope.can_see_review_queue?
+ end
end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index fdcf9b90702..1a6ec2ec58c 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2731,6 +2731,7 @@ en:
view_raw_email_allowed_groups: "Groups which can view the raw email content of a post if it was created by an incoming email. This includes email headers and other technical information."
rich_editor: "Enable the rich editor so all users can switch between the current Markdown mode and the new rich text editor for more intuitive and user-friendly composition. The rich text editor is under active development, so not all features are supported yet — <a href='https://meta.discourse.org/t/test-our-new-composer/352347' target='_blank'>see Meta for more details</a>."
viewport_based_mobile_mode: "EXPERIMENTAL: Disable the user-agent-based mobile/desktop modes and use viewport width instead."
+ reviewable_ui_refresh: "Groups that can use the experimental new UI in the review queue."
content_localization_enabled: "Displays localized content for users based on their browser or user language preferences. Such content may include categories, tags, posts, and topics. Supported locales are set in 'content localization supported locales'."
content_localization_supported_locales: "List of supported locales that user content can be translated to. Requires 'content localization enabled'."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 251c90ff074..9dea3d1fdc3 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4048,6 +4048,10 @@ experimental:
rich_editor:
client: true
default: false
+ reviewable_ui_refresh:
+ client: true
+ type: group_list
+ default: ""
experimental_system_themes:
type: list
default: "horizon"
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 8888c52d4ae..d6d98b44b1d 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -663,6 +663,11 @@ class Guardian
other && authenticated? && other.is_a?(User) && @user == other
end
+ def can_see_reviewable_ui_refresh?
+ SiteSetting.reviewable_ui_refresh_map.include?(Group::AUTO_GROUPS[:everyone]) ||
+ @user.in_any_groups?(SiteSetting.reviewable_ui_refresh_map)
+ end
+
private
def is_my_own?(obj)
diff --git a/spec/serializers/current_user_serializer_spec.rb b/spec/serializers/current_user_serializer_spec.rb
index a81a1fd612f..b9860c80e85 100644
--- a/spec/serializers/current_user_serializer_spec.rb
+++ b/spec/serializers/current_user_serializer_spec.rb
@@ -351,4 +351,34 @@ RSpec.describe CurrentUserSerializer do
)
end
end
+
+ describe "#use_reviewable_ui_refresh" do
+ fab!(:admin)
+ fab!(:user)
+ fab!(:group)
+
+ it "does not include the attribute if the user cannot see the reviewable UI refresh" do
+ serializer = described_class.new(user, scope: Guardian.new(user), root: false)
+
+ expect(serializer.as_json).not_to have_key(:use_reviewable_ui_refresh)
+ end
+
+ it "returns false if the user cannot see the reviewable UI refresh" do
+ SiteSetting.reviewable_ui_refresh = ""
+
+ serializer = described_class.new(admin, scope: Guardian.new(admin), root: false)
+
+ expect(serializer.as_json[:use_reviewable_ui_refresh]).to eq(false)
+ end
+
+ it "returns true if the user can see the reviewable UI refresh" do
+ SiteSetting.reviewable_ui_refresh = group.id
+
+ group.add(admin)
+
+ serializer = described_class.new(admin, scope: Guardian.new(admin), root: false)
+
+ expect(serializer.as_json[:use_reviewable_ui_refresh]).to eq(true)
+ end
+ end
end
diff --git a/spec/system/viewing_reviewable_spec.rb b/spec/system/viewing_reviewable_spec.rb
new file mode 100644
index 00000000000..50e8ddc6f2b
--- /dev/null
+++ b/spec/system/viewing_reviewable_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+describe "Viewing reviewable item", type: :system do
+ fab!(:admin)
+ fab!(:group)
+ fab!(:reviewable_flagged_post)
+
+ before { sign_in(admin) }
+
+ context "when user is not part of the groups list of the `reviewable_ui_refresh` site setting" do
+ before { SiteSetting.reviewable_ui_refresh = "" }
+
+ it "shows the old reviewable UI" do
+ visit "/review/#{reviewable_flagged_post.id}"
+
+ expect(page).to have_selector(".reviewable-item ")
+ end
+ end
+
+ context "when user is part of the groups list of the `reviewable_ui_refresh` site setting" do
+ before do
+ SiteSetting.reviewable_ui_refresh = group.name
+ group.add(admin)
+ end
+
+ it "shows the new reviewable UI" do
+ visit "/review/#{reviewable_flagged_post.id}"
+
+ expect(page).to have_selector(".review-container")
+ end
+ end
+end