DEV: Update rubocop-discourse to latest version

The lastest version of rubocop-discourse enables rules regarding
plugins.
This commit is contained in:
Loïc Guitaut 2024-02-01 17:28:10 +01:00 committed by Loïc Guitaut
parent 7a6ba47e7b
commit f7d7092a7a
27 changed files with 169 additions and 118 deletions

View File

@ -8,6 +8,30 @@ Discourse/NoAddReferenceOrAliasesActiveRecordMigration:
Discourse/NoResetColumnInformationInMigrations:
Enabled: true
Discourse/Plugins/CallRequiresPlugin:
Include:
- "plugins/*/app/controllers/**/*"
Discourse/Plugins/UsePluginInstanceOn:
Include:
- "plugins/**/*"
Discourse/Plugins/NamespaceMethods:
Include:
- "plugins/**/*"
Discourse/Plugins/NamespaceConstants:
Include:
- "plugins/**/*"
Discourse/Plugins/UseRequireRelative:
Include:
- "plugins/**/*"
Discourse/Plugins/NoMonkeyPatching:
Include:
- "plugins/**/*"
Lint/Debugger:
Exclude:
- script/**/*

View File

@ -305,6 +305,7 @@ GEM
racc
pg (1.5.4)
prettier_print (1.2.1)
prism (0.24.0)
progress (3.6.0)
pry (0.14.2)
coderay (~> 1.1)
@ -417,12 +418,16 @@ GEM
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
rubocop-ast (1.31.0)
parser (>= 3.3.0.4)
prism (>= 0.24.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-discourse (3.6.1)
rubocop-discourse (3.7.1)
activesupport (>= 6.1)
rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Chat::Api::CategoryChatablesController < ApplicationController
requires_plugin Chat::PLUGIN_NAME
def permissions
category = Category.find(params[:id])

View File

@ -1,13 +1,13 @@
# frozen_string_literal: true
CHANNEL_EDITABLE_PARAMS ||= %i[name description slug]
CATEGORY_CHANNEL_EDITABLE_PARAMS ||= %i[
auto_join_users
allow_channel_wide_mentions
threading_enabled
]
class Chat::Api::ChannelsController < Chat::ApiController
CHANNEL_EDITABLE_PARAMS ||= %i[name description slug]
CATEGORY_CHANNEL_EDITABLE_PARAMS ||= %i[
auto_join_users
allow_channel_wide_mentions
threading_enabled
]
def index
permitted = params.permit(:filter, :limit, :offset, :status)

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
MEMBERSHIP_EDITABLE_PARAMS = %i[muted desktop_notification_level mobile_notification_level]
class Chat::Api::ChannelsCurrentUserNotificationsSettingsController < Chat::Api::ChannelsController
MEMBERSHIP_EDITABLE_PARAMS = %i[muted desktop_notification_level mobile_notification_level]
def update
settings_params = params.require(:notifications_settings).permit(MEMBERSHIP_EDITABLE_PARAMS)
membership_from_params.update!(settings_params.to_h)

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Chat::Api::HintsController < ApplicationController
requires_plugin Chat::PLUGIN_NAME
before_action :ensure_logged_in
def check_group_mentions

View File

@ -2,18 +2,10 @@
module Chat
class ApiController < ::Chat::BaseController
before_action :ensure_logged_in
before_action :ensure_can_chat
include Chat::WithServiceHelper
private
def ensure_can_chat
raise Discourse::NotFound unless SiteSetting.chat_enabled
guardian.ensure_can_chat!
end
def default_actions_for_service
proc do
on_success { render(json: success_json) }

View File

@ -2,13 +2,14 @@
module Chat
class BaseController < ::ApplicationController
requires_plugin Chat::PLUGIN_NAME
before_action :ensure_logged_in
before_action :ensure_can_chat
private
def ensure_can_chat
raise Discourse::NotFound unless SiteSetting.chat_enabled
guardian.ensure_can_chat!
end

View File

@ -33,6 +33,10 @@ GlobalSetting.add_default(:allow_unsecure_chat_uploads, false)
module ::Chat
PLUGIN_NAME = "chat"
RETENTION_SETTINGS_TO_USER_OPTION_FIELDS = {
chat_channel_retention_days: :dismissed_channel_retention_reminder,
chat_dm_retention_days: :dismissed_dm_retention_reminder,
}
end
require_relative "lib/chat/engine"
@ -70,7 +74,7 @@ after_initialize do
Group.prepend Chat::GroupExtension
Jobs::UserEmail.prepend Chat::UserEmailExtension
Plugin::Instance.prepend Chat::PluginInstanceExtension
Jobs::ExportCsvFile.class_eval { prepend Chat::MessagesExporter }
Jobs::ExportCsvFile.prepend Chat::MessagesExporter
WebHook.prepend Chat::OutgoingWebHookExtension
end
@ -270,12 +274,8 @@ after_initialize do
include_condition: -> { SiteSetting.chat_enabled && SiteSetting.create_thumbnails },
) { object.thumbnail }
RETENTION_SETTINGS_TO_USER_OPTION_FIELDS = {
chat_channel_retention_days: :dismissed_channel_retention_reminder,
chat_dm_retention_days: :dismissed_dm_retention_reminder,
}
on(:site_setting_changed) do |name, old_value, new_value|
user_option_field = RETENTION_SETTINGS_TO_USER_OPTION_FIELDS[name.to_sym]
user_option_field = Chat::RETENTION_SETTINGS_TO_USER_OPTION_FIELDS[name.to_sym]
begin
if user_option_field && old_value != new_value && !new_value.zero?
UserOption.where(user_option_field => true).update_all(user_option_field => false)
@ -342,10 +342,9 @@ after_initialize do
nil
end
CHAT_NOTIFICATION_TYPES = [Notification.types[:chat_mention], Notification.types[:chat_message]]
register_push_notification_filter do |user, payload|
if user.user_option.only_chat_push_notifications && user.user_option.chat_enabled
CHAT_NOTIFICATION_TYPES.include?(payload[:notification_type])
payload[:notification_type].in?(::Notification.types.values_at(:chat_mention, :chat_message))
else
true
end

View File

@ -19,7 +19,7 @@ after_initialize do
POST_CUSTOM_FIELD ||= "local_dates".freeze
end
%w[../lib/discourse_local_dates/engine.rb].each { |path| load File.expand_path(path, __FILE__) }
require_relative "lib/discourse_local_dates/engine"
register_post_custom_field_type(DiscourseLocalDates::POST_CUSTOM_FIELD, :json)

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
module DiscourseNarrativeBot
module PostGuardianExtension
extend ActiveSupport::Concern
prepended do
alias_method :existing_can_create_post?, :can_create_post?
def can_create_post?(parent)
if SiteSetting.discourse_narrative_bot_enabled &&
parent.try(:subtype) == "system_message" &&
parent.try(:user) == ::DiscourseNarrativeBot::Base.new.discobot_user
return true
end
existing_can_create_post?(parent)
end
end
end
end

View File

@ -21,7 +21,7 @@ if Rails.env == "development"
Rails.configuration.autoload_paths << File.expand_path("../autoload/jobs", __FILE__)
end
require_relative "lib/discourse_narrative_bot/welcome_post_type_site_setting.rb"
require_relative "lib/discourse_narrative_bot/welcome_post_type_site_setting"
register_asset "stylesheets/discourse-narrative-bot.scss"
after_initialize do
@ -32,24 +32,23 @@ after_initialize do
Mime::Type.register "image/svg+xml", :svg
%w[
../autoload/jobs/regular/bot_input.rb
../autoload/jobs/regular/narrative_timeout.rb
../autoload/jobs/regular/narrative_init.rb
../autoload/jobs/regular/send_default_welcome_message.rb
../autoload/jobs/onceoff/discourse_narrative_bot/grant_badges.rb
../autoload/jobs/onceoff/discourse_narrative_bot/remap_old_bot_images.rb
../lib/discourse_narrative_bot/actions.rb
../lib/discourse_narrative_bot/base.rb
../lib/discourse_narrative_bot/new_user_narrative.rb
../lib/discourse_narrative_bot/advanced_user_narrative.rb
../lib/discourse_narrative_bot/track_selector.rb
../lib/discourse_narrative_bot/certificate_generator.rb
../lib/discourse_narrative_bot/dice.rb
../lib/discourse_narrative_bot/quote_generator.rb
../lib/discourse_narrative_bot/magic_8_ball.rb
../lib/discourse_narrative_bot/welcome_post_type_site_setting.rb
].each { |path| load File.expand_path(path, __FILE__) }
require_relative "autoload/jobs/regular/bot_input"
require_relative "autoload/jobs/regular/narrative_timeout"
require_relative "autoload/jobs/regular/narrative_init"
require_relative "autoload/jobs/regular/send_default_welcome_message"
require_relative "autoload/jobs/onceoff/discourse_narrative_bot/grant_badges"
require_relative "autoload/jobs/onceoff/discourse_narrative_bot/remap_old_bot_images"
require_relative "lib/discourse_narrative_bot/actions"
require_relative "lib/discourse_narrative_bot/base"
require_relative "lib/discourse_narrative_bot/new_user_narrative"
require_relative "lib/discourse_narrative_bot/advanced_user_narrative"
require_relative "lib/discourse_narrative_bot/track_selector"
require_relative "lib/discourse_narrative_bot/certificate_generator"
require_relative "lib/discourse_narrative_bot/dice"
require_relative "lib/discourse_narrative_bot/quote_generator"
require_relative "lib/discourse_narrative_bot/magic_8_ball"
require_relative "lib/discourse_narrative_bot/welcome_post_type_site_setting"
require_relative "lib/discourse_narrative_bot/post_guardian_extension"
RailsMultisite::ConnectionManagement.safe_each_connection do
if SiteSetting.discourse_narrative_bot_enabled
@ -315,16 +314,5 @@ after_initialize do
end
end
PostGuardian.class_eval do
alias_method :existing_can_create_post?, :can_create_post?
def can_create_post?(parent)
if SiteSetting.discourse_narrative_bot_enabled && parent.try(:subtype) == "system_message" &&
parent.try(:user) == ::DiscourseNarrativeBot::Base.new.discobot_user
return true
end
existing_can_create_post?(parent)
end
end
PostGuardian.prepend(DiscourseNarrativeBot::PostGuardianExtension)
end

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
module DiscoursePoll
module PostExtension
extend ActiveSupport::Concern
prepended do
attr_accessor :extracted_polls
has_many :polls, dependent: :destroy
after_save do
polls = self.extracted_polls
self.extracted_polls = nil
next if polls.blank? || !polls.is_a?(Hash)
post = self
::Poll.transaction do
polls.values.each { |poll| DiscoursePoll::Poll.create!(post.id, poll) }
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
post.save_custom_fields(true)
end
end
end
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
module DiscoursePoll
module UserExtension
extend ActiveSupport::Concern
prepended { has_many :poll_votes, dependent: :delete_all }
end
end

View File

@ -32,17 +32,19 @@ after_initialize do
end
end
require_relative "app/controllers/polls_controller.rb"
require_relative "app/models/poll_option.rb"
require_relative "app/models/poll_vote.rb"
require_relative "app/models/poll.rb"
require_relative "app/serializers/poll_option_serializer.rb"
require_relative "app/serializers/poll_serializer.rb"
require_relative "jobs/regular/close_poll.rb"
require_relative "lib/poll.rb"
require_relative "lib/polls_updater.rb"
require_relative "lib/polls_validator.rb"
require_relative "lib/post_validator.rb"
require_relative "app/controllers/polls_controller"
require_relative "app/models/poll_option"
require_relative "app/models/poll_vote"
require_relative "app/models/poll"
require_relative "app/serializers/poll_option_serializer"
require_relative "app/serializers/poll_serializer"
require_relative "jobs/regular/close_poll"
require_relative "lib/poll"
require_relative "lib/polls_updater"
require_relative "lib/polls_validator"
require_relative "lib/post_validator"
require_relative "lib/post_extension"
require_relative "lib/user_extension"
DiscoursePoll::Engine.routes.draw do
put "/vote" => "polls#vote"
@ -59,26 +61,8 @@ after_initialize do
topic_view_post_custom_fields_allowlister { [DiscoursePoll::HAS_POLLS] }
reloadable_patch do
Post.class_eval do
attr_accessor :extracted_polls
has_many :polls, dependent: :destroy
after_save do
polls = self.extracted_polls
self.extracted_polls = nil
next if polls.blank? || !polls.is_a?(Hash)
post = self
Poll.transaction do
polls.values.each { |poll| DiscoursePoll::Poll.create!(post.id, poll) }
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
post.save_custom_fields(true)
end
end
end
User.class_eval { has_many :poll_votes, dependent: :delete_all }
Post.prepend(DiscoursePoll::PostExtension)
User.prepend(DiscoursePoll::UserExtension)
end
validate(:post, :validate_polls) do |force = nil|

View File

@ -10,7 +10,7 @@ register_asset "stylesheets/styleguide.scss"
enabled_site_setting :styleguide_enabled
hide_plugin
load File.expand_path("../lib/styleguide/engine.rb", __FILE__)
require_relative "lib/styleguide/engine"
Discourse::Application.routes.append { mount ::Styleguide::Engine, at: "/styleguide" }

View File

@ -601,11 +601,9 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
describe "user api" do
fab! :user do
Fabricate(:user)
end
fab!(:user)
let :api_key do
let(:api_key) do
UserApiKey.create!(
application_name: "my app",
client_id: "1234",

View File

@ -445,7 +445,8 @@ RSpec.describe ComposerMessagesFinder do
end
context "when user can't send private messages" do
fab!(:group) { Fabricate(:group) }
fab!(:group)
before { SiteSetting.personal_message_enabled_groups = group.id }
it "does not show the message" do

View File

@ -3,7 +3,7 @@
RSpec.describe RejectionMailer do
describe "send_rejection" do
context "when sending rejection email" do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:template_args) do
{ former_title: "Mail Subject", destination: user.email, site_name: SiteSetting.title }
end

View File

@ -1,20 +1,19 @@
# frozen_string_literal: true
RSpec.describe Theme do
after { Theme.clear_cache! }
before { ThemeJavascriptCompiler.disable_terser! }
after { ThemeJavascriptCompiler.enable_terser! }
fab! :user do
Fabricate(:user)
end
fab!(:user)
fab!(:theme) { Fabricate(:theme, user: user) }
let(:guardian) { Guardian.new(user) }
fab!(:theme) { Fabricate(:theme, user: user) }
let(:child) { Fabricate(:theme, user: user, component: true) }
before { ThemeJavascriptCompiler.disable_terser! }
after do
Theme.clear_cache!
ThemeJavascriptCompiler.enable_terser!
end
it "can properly clean up color schemes" do
scheme = ColorScheme.create!(theme_id: theme.id, name: "test")
scheme2 = ColorScheme.create!(theme_id: theme.id, name: "test2")

View File

@ -4,7 +4,7 @@ RSpec.describe UserSearch do
before_all { SearchIndexer.enable } # Enable for prefabrication
before { SearchIndexer.enable } # Enable for each test
fab!(:topic) { Fabricate :topic }
fab!(:topic)
fab!(:topic2) { Fabricate :topic }
fab!(:topic3) { Fabricate :topic }
fab!(:topic4) { Fabricate :topic }
@ -29,7 +29,7 @@ RSpec.describe UserSearch do
fab!(:inactive) { Fabricate :user, username: "Ghost", active: false }
fab!(:admin) { Fabricate :admin, username: "theadmin" }
fab!(:moderator) { Fabricate :moderator, username: "themod" }
fab!(:staged) { Fabricate :staged }
fab!(:staged)
def search_for(*args)
# mapping "username" so it's easier to debug

View File

@ -4903,7 +4903,7 @@ RSpec.describe UsersController do
end
describe "#search_users" do
fab!(:topic) { Fabricate :topic }
fab!(:topic)
let(:user) { Fabricate :user, username: "joecabot", name: "Lawrence Tierney" }
let(:post1) { Fabricate(:post, user: user, topic: topic) }
let(:staged_user) { Fabricate(:user, staged: true) }

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe BasicUserSerializer do
fab!(:user) { Fabricate(:user) }
fab!(:user)
let(:serializer) { BasicUserSerializer.new(user, scope: Guardian.new(user), root: false) }
describe "#as_json" do
@ -30,7 +30,7 @@ RSpec.describe BasicUserSerializer do
end
describe "#status" do
fab!(:user_status) { Fabricate(:user_status) }
fab!(:user_status)
before { user.user_status = user_status }

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe UserStatusMixin do
fab!(:user_status) { Fabricate(:user_status) }
fab!(:user_status)
fab!(:user) { Fabricate(:user, user_status: user_status) }
class DummySerializer < ApplicationSerializer

View File

@ -28,7 +28,7 @@ RSpec.describe FoundUserSerializer do
end
describe "#status" do
fab!(:user_status) { Fabricate(:user_status) }
fab!(:user_status)
before { user.user_status = user_status }

View File

@ -364,7 +364,7 @@ RSpec.describe PostSerializer do
context "with mentions" do
fab!(:user_status)
fab!(:user) { Fabricate(:user) }
fab!(:user)
fab!(:user1) { Fabricate(:user, user_status: user_status) }
fab!(:post) { Fabricate(:post, user: user, raw: "Hey @#{user1.username}") }
let(:serializer) { described_class.new(post, scope: Guardian.new(user), root: false) }

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
describe "Group activity", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group) }
fab!(:user)
fab!(:group)
context "when on the posts activity page" do
let(:posts_page) { PageObjects::Pages::GroupActivityPosts.new }