Skip to content

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

FIX: Do not show rewind for new users (#37205)

Martin Brennanee5abe0e7bf7
diff --git a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-preferences-nav/rewind-preferences.gjs b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-preferences-nav/rewind-preferences.gjs
index f71a1791b37..42a87080b6b 100644
--- a/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-preferences-nav/rewind-preferences.gjs
+++ b/plugins/discourse-rewind/assets/javascripts/discourse/connectors/user-preferences-nav/rewind-preferences.gjs
@@ -4,8 +4,13 @@ import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n";
export default class RewindPreferencesNav extends Component {
- static shouldRender(args, context) {
- return context.siteSettings.discourse_rewind_enabled;
+ static shouldRender(args, context, owner) {
+ const rewind = owner.lookup("service:rewind");
+
+ // This uses the rewind site setting rather than rewind.active
+ // from the service because if the user disables rewind,
+ // the preferences tab will disappear forever.
+ return context.siteSettings.discourse_rewind_enabled && rewind.active;
}
<template>
diff --git a/plugins/discourse-rewind/plugin.rb b/plugins/discourse-rewind/plugin.rb
index e393df9af8f..cce16924dd4 100644
--- a/plugins/discourse-rewind/plugin.rb
+++ b/plugins/discourse-rewind/plugin.rb
@@ -68,7 +68,9 @@ after_initialize do
end
add_to_serializer(:current_user, :is_rewind_active) do
- Rails.env.development? || Date.today.month == 1 || Date.today.month == 12
+ is_rewind_period = Rails.env.development? || Date.today.month == 1 || Date.today.month == 12
+ user_old_enough = scope.user.created_at <= 1.month.ago
+ is_rewind_period && user_old_enough
end
Discourse::Application.routes.append do
diff --git a/plugins/discourse-rewind/spec/serializers/current_user_serializer_spec.rb b/plugins/discourse-rewind/spec/serializers/current_user_serializer_spec.rb
new file mode 100644
index 00000000000..97c2dfb1b0d
--- /dev/null
+++ b/plugins/discourse-rewind/spec/serializers/current_user_serializer_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+RSpec.describe CurrentUserSerializer do
+ before { SiteSetting.discourse_rewind_enabled = true }
+
+ fab!(:user)
+
+ let(:serializer) { CurrentUserSerializer.new(user, scope: Guardian.new(user), root: false) }
+
+ describe "#is_rewind_active" do
+ context "when in December" do
+ before { freeze_time DateTime.parse("2024-12-15") }
+
+ it "returns true for users created more than a month ago" do
+ user.update!(created_at: 2.months.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(true)
+ end
+
+ it "returns false for users created less than a month ago" do
+ user.update!(created_at: 2.weeks.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(false)
+ end
+
+ it "returns true for users created exactly one month ago" do
+ user.update!(created_at: 1.month.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(true)
+ end
+ end
+
+ context "when in January" do
+ before { freeze_time DateTime.parse("2025-01-15") }
+
+ it "returns true for users created more than a month ago" do
+ user.update!(created_at: 2.months.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(true)
+ end
+
+ it "returns false for users created less than a month ago" do
+ user.update!(created_at: 2.weeks.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(false)
+ end
+ end
+
+ context "when outside rewind period (e.g., November)" do
+ before { freeze_time DateTime.parse("2024-11-15") }
+
+ it "returns false regardless of user age" do
+ user.update!(created_at: 2.years.ago)
+ expect(serializer.as_json[:is_rewind_active]).to eq(false)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-rewind/spec/system/dismiss_spec.rb b/plugins/discourse-rewind/spec/system/dismiss_spec.rb
index 891e61bd4c4..0fefc7ca691 100644
--- a/plugins/discourse-rewind/spec/system/dismiss_spec.rb
+++ b/plugins/discourse-rewind/spec/system/dismiss_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "DiscourseRewind | dismiss", type: :system do
- fab!(:user)
+ fab!(:user) { Fabricate(:user, created_at: DateTime.parse("2020-01-01")) }
let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
diff --git a/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
index efe3f1fd1d6..dcdfc13b4a2 100644
--- a/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
+++ b/plugins/discourse-rewind/spec/system/page_objects/pages/rewind.rb
@@ -130,6 +130,19 @@ module PageObjects
def has_rewind_loaded?
has_css?(".rewind__scroll-wrapper")
end
+
+ def visit_my_preferences
+ page.visit("/my/preferences")
+ self
+ end
+
+ def has_rewind_preferences_nav?
+ has_css?(".user-nav__preferences-rewind")
+ end
+
+ def has_no_rewind_preferences_nav?
+ has_no_css?(".user-nav__preferences-rewind")
+ end
end
end
end
diff --git a/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb b/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb
index 432725ca975..4bbc7fa6ba9 100644
--- a/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb
+++ b/plugins/discourse-rewind/spec/system/rewind_profile_tab_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "DiscourseRewind | rewind profile link", type: :system do
- fab!(:current_user, :user)
+ fab!(:current_user) { Fabricate(:user, created_at: DateTime.parse("2020-01-01")) }
let(:rewind_page) { PageObjects::Pages::Rewind.new }
let(:user_menu) { PageObjects::Components::UserMenu.new }
diff --git a/plugins/discourse-rewind/spec/system/rewind_sharing_spec.rb b/plugins/discourse-rewind/spec/system/rewind_sharing_spec.rb
index 0081f4e9f82..d77d5e199c7 100644
--- a/plugins/discourse-rewind/spec/system/rewind_sharing_spec.rb
+++ b/plugins/discourse-rewind/spec/system/rewind_sharing_spec.rb
@@ -1,9 +1,23 @@
# frozen_string_literal: true
describe "DiscourseRewind | rewind sharing", type: :system do
- fab!(:current_user) { Fabricate(:user, refresh_auto_groups: true, trust_level: 2) }
- fab!(:other_user) { Fabricate(:user, refresh_auto_groups: true, trust_level: 2) }
- fab!(:admin)
+ fab!(:current_user) do
+ Fabricate(
+ :user,
+ refresh_auto_groups: true,
+ trust_level: 2,
+ created_at: DateTime.parse("2020-01-01"),
+ )
+ end
+ fab!(:other_user) do
+ Fabricate(
+ :user,
+ refresh_auto_groups: true,
+ trust_level: 2,
+ created_at: DateTime.parse("2020-01-01"),
+ )
+ end
+ fab!(:admin) { Fabricate(:admin, created_at: DateTime.parse("2020-01-01")) }
let(:rewind_page) { PageObjects::Pages::Rewind.new }
let(:dialog) { PageObjects::Components::Dialog.new }
diff --git a/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb b/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
index 96fbfeb126b..aa5d8bb74cb 100644
--- a/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
+++ b/plugins/discourse-rewind/spec/system/rewind_tab_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "DiscourseRewind | rewind tab", type: :system do
- fab!(:current_user, :user)
+ fab!(:current_user) { Fabricate(:user, created_at: DateTime.parse("2020-01-01")) }
let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
@@ -35,4 +35,16 @@ describe "DiscourseRewind | rewind tab", type: :system do
expect(rewind_page).to have_no_rewind_tab
end
end
+
+ context "when user account is less than one month old" do
+ before do
+ freeze_time DateTime.parse("2022-12-05")
+ current_user.update!(created_at: DateTime.parse("2022-11-20"))
+ end
+
+ it "doesn't show the tab" do
+ rewind_page.visit_my_activity
+ expect(rewind_page).to have_no_rewind_tab
+ end
+ end
end
diff --git a/plugins/discourse-rewind/spec/system/user_preferences_spec.rb b/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
index a47331ad6c4..ce558a43bb2 100644
--- a/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
+++ b/plugins/discourse-rewind/spec/system/user_preferences_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe "DiscourseRewind | user preferences", type: :system do
- fab!(:current_user, :user)
+ fab!(:current_user) { Fabricate(:user, created_at: DateTime.parse("2020-01-01")) }
let(:rewind_page) { PageObjects::Pages::Rewind.new }
before do
@@ -24,6 +24,11 @@ describe "DiscourseRewind | user preferences", type: :system do
rewind_page.click_profile_tab
expect(rewind_page).to have_rewind_profile_link
end
+
+ it "shows the rewind preferences nav link" do
+ rewind_page.visit_my_preferences
+ expect(rewind_page).to have_rewind_preferences_nav
+ end
end
context "when discourse_rewind_enabled is false" do
@@ -41,5 +46,14 @@ describe "DiscourseRewind | user preferences", type: :system do
expect(rewind_page).to have_no_rewind_profile_link
end
end
+
+ context "when user account is less than one month old" do
+ before { current_user.update!(created_at: DateTime.parse("2022-11-20")) }
+
+ it "does not show the rewind preferences nav link" do
+ rewind_page.visit_my_preferences
+ expect(rewind_page).to have_no_rewind_preferences_nav
+ end
+ end
end
end