From 7afb5fc481d14b2cb07761bc69ac5e83c16a13d7 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 7 Dec 2023 09:04:45 +1000 Subject: [PATCH] DEV: Use Discourse::SYSTEM_USER_ID in fixtures/009_users (#24743) I couldn't find where we created the system user and this is why -- everywhere else in the app we reference SYSTEM_USER_ID but here. --- app/models/group.rb | 2 +- db/fixtures/009_users.rb | 10 +++++----- db/fixtures/600_themes.rb | 2 +- lib/presence_channel.rb | 4 ++-- spec/helpers/application_helper_spec.rb | 8 ++++---- spec/jobs/correct_missing_dualstack_urls_spec.rb | 4 ++-- spec/models/category_spec.rb | 2 +- spec/requests/groups_controller_spec.rb | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index a9027401da7..70a5e3e99a5 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -474,7 +474,7 @@ class Group < ActiveRecord::Base group_users .pluck(:user_id, :notification_level) .each do |user_id, notification_level| - next if user_id == -1 + next if user_id == Discourse::SYSTEM_USER_ID next if user_id == topic.user_id next if ignore_existing && TopicUser.where(user_id: user_id, topic_id: topic.id).exists? diff --git a/db/fixtures/009_users.rb b/db/fixtures/009_users.rb index d362926bb45..a2869afe324 100644 --- a/db/fixtures/009_users.rb +++ b/db/fixtures/009_users.rb @@ -2,7 +2,7 @@ # kind of odd, but we need it, we also need to nuke usage of User from inside migrations # very poor form -user = User.find_by("id <> -1 and username_lower = 'system'") +user = User.find_by("id <> #{Discourse::SYSTEM_USER_ID} and username_lower = 'system'") if user user.username = UserNameSuggester.suggest("system") user.save @@ -12,11 +12,11 @@ UserEmail.seed do |ue| ue.id = -1 ue.email = "no_email" ue.primary = true - ue.user_id = -1 + ue.user_id = Discourse::SYSTEM_USER_ID end User.seed do |u| - u.id = -1 + u.id = Discourse::SYSTEM_USER_ID u.name = "system" u.username = "system" u.username_lower = "system" @@ -28,12 +28,12 @@ User.seed do |u| u.trust_level = TrustLevel[4] end -UserOption.where(user_id: -1).update_all( +UserOption.where(user_id: Discourse::SYSTEM_USER_ID).update_all( email_messages_level: UserOption.email_level_types[:never], email_level: UserOption.email_level_types[:never], ) -Group.user_trust_level_change!(-1, TrustLevel[4]) +Group.user_trust_level_change!(Discourse::SYSTEM_USER_ID, TrustLevel[4]) # User for the smoke tests if ENV["SMOKE"] == "1" diff --git a/db/fixtures/600_themes.rb b/db/fixtures/600_themes.rb index f58ddd69cbf..e2e2faefc32 100644 --- a/db/fixtures/600_themes.rb +++ b/db/fixtures/600_themes.rb @@ -25,7 +25,7 @@ if !Theme.exists? end name = I18n.t("color_schemes.default_theme_name") - default_theme = Theme.create!(name: name, user_id: -1) + default_theme = Theme.create!(name: name, user_id: Discourse::SYSTEM_USER_ID) default_theme.set_default! if SiteSetting.default_dark_mode_color_scheme_id == diff --git a/lib/presence_channel.rb b/lib/presence_channel.rb index 21da97d5b4d..6e54b422b58 100644 --- a/lib/presence_channel.rb +++ b/lib/presence_channel.rb @@ -516,7 +516,7 @@ class PresenceChannel #{UPDATE_GLOBAL_CHANNELS_LUA} -- Update the user session count in the channel hash - local val = redis.call('HINCRBY', hash_key, user_id, -1) + local val = redis.call('HINCRBY', hash_key, user_id, #{Discourse::SYSTEM_USER_ID}) if val <= 0 then redis.call('HDEL', hash_key, user_id) removed_users = 1 @@ -607,7 +607,7 @@ class PresenceChannel get_mutex() end - local val = redis.call('HINCRBY', hash_key, user_id, -1) + local val = redis.call('HINCRBY', hash_key, user_id, #{Discourse::SYSTEM_USER_ID}) if val <= 0 then table.insert(expired_user_ids, tonumber(user_id)) redis.call('HDEL', hash_key, user_id) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 113fff78d44..74bd9b17049 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -215,7 +215,7 @@ RSpec.describe ApplicationHelper do dark_theme = Theme.create( name: "Dark", - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id, ) helper.request.env[:resolved_theme_id] = dark_theme.id @@ -275,7 +275,7 @@ RSpec.describe ApplicationHelper do _dark_theme = Theme.create( name: "Dark", - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id, ) end @@ -300,7 +300,7 @@ RSpec.describe ApplicationHelper do dark_theme = Theme.create( name: "Dark", - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id, ) helper.request.env[:resolved_theme_id] = dark_theme.id @@ -798,7 +798,7 @@ RSpec.describe ApplicationHelper do dark_theme = Theme.create( name: "Dark", - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id, ) helper.request.env[:resolved_theme_id] = dark_theme.id diff --git a/spec/jobs/correct_missing_dualstack_urls_spec.rb b/spec/jobs/correct_missing_dualstack_urls_spec.rb index 7af8e9ece74..ae24b4059d4 100644 --- a/spec/jobs/correct_missing_dualstack_urls_spec.rb +++ b/spec/jobs/correct_missing_dualstack_urls_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Jobs::CorrectMissingDualstackUrls do url: "//custom-bucket.s3-us-east-1.amazonaws.com/somewhere/a.png", original_filename: "a.png", filesize: 100, - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, ) bad_upload = @@ -24,7 +24,7 @@ RSpec.describe Jobs::CorrectMissingDualstackUrls do url: "//custom-bucket.s3-us-west-1.amazonaws.com/somewhere/a.png", original_filename: "a.png", filesize: 100, - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, ) current_optimized = diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index eb2f017e32d..7944182bd96 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -1022,7 +1022,7 @@ RSpec.describe Category do topic = Topic.find_by_id(post1.topic_id) TopicTimer.create!( - user_id: -1, + user_id: Discourse::SYSTEM_USER_ID, topic: topic, execute_at: 1.hour.from_now, status_type: TopicTimer.types[:bump], diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb index 91974ea12ee..d6916d10f77 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -1931,7 +1931,7 @@ RSpec.describe GroupsController do end it "returns skipped_usernames response body when removing a valid user but is not a member of that group" do - delete "/groups/#{group.id}/members.json", params: { user_id: -1 } + delete "/groups/#{group.id}/members.json", params: { user_id: Discourse::SYSTEM_USER_ID } response_body = response.parsed_body expect(response.status).to eq(200)