Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Update rubocop-discourse to latest version #145

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,47 +1,74 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
json (2.7.1)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.23.0)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.4)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
racc (1.7.3)
rainbow (3.1.1)
regexp_parser (2.9.0)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rubocop (1.60.0)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-discourse (3.6.0)
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)
rubocop-rspec (2.26.1)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
ruby-progressbar (1.13.0)
strscan (3.1.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)

PLATFORMS
Expand Down
18 changes: 18 additions & 0 deletions lib/discourse_translator/post_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module DiscourseTranslator
module PostExtension
extend ActiveSupport::Concern

prepended { before_update :clear_translator_custom_fields, if: :raw_changed? }

private

def clear_translator_custom_fields
return if !SiteSetting.translator_enabled

Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked in another PR but lost track of it 😄 - can we skip these checks in class extensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.custom_fields.delete(DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD)
self.custom_fields.delete(DiscourseTranslator::TRANSLATED_CUSTOM_FIELD)
end
end
end
18 changes: 18 additions & 0 deletions lib/discourse_translator/topic_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module DiscourseTranslator
module TopicExtension
extend ActiveSupport::Concern

prepended { before_update :clear_translator_custom_fields, if: :title_changed? }

private

def clear_translator_custom_fields
return if !SiteSetting.translator_enabled

self.custom_fields.delete(DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD)
self.custom_fields.delete(DiscourseTranslator::TRANSLATED_CUSTOM_FIELD)
end
end
end
42 changes: 7 additions & 35 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,6 @@ def translate
Post.register_custom_field_type(::DiscourseTranslator::TRANSLATED_CUSTOM_FIELD, :json)
Topic.register_custom_field_type(::DiscourseTranslator::TRANSLATED_CUSTOM_FIELD, :json)

class ::Post < ActiveRecord::Base
before_update :clear_translator_custom_fields, if: :raw_changed?

private

def clear_translator_custom_fields
return if !SiteSetting.translator_enabled

self.custom_fields.delete(DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD)
self.custom_fields.delete(DiscourseTranslator::TRANSLATED_CUSTOM_FIELD)
end
end

class ::Topic < ActiveRecord::Base
before_update :clear_translator_custom_fields, if: :title_changed?

private

def clear_translator_custom_fields
return if !SiteSetting.translator_enabled

self.custom_fields.delete(DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD)
self.custom_fields.delete(DiscourseTranslator::TRANSLATED_CUSTOM_FIELD)
end
end

module ::Jobs
class TranslatorMigrateToAzurePortal < ::Jobs::Onceoff
def execute_onceoff(args)
Expand Down Expand Up @@ -153,20 +127,18 @@ def execute(args)
end
end

def post_process(post)
return if !SiteSetting.translator_enabled
Jobs.enqueue(:detect_translation, post_id: post.id)
end
listen_for :post_process
on(:post_process) { |post| Jobs.enqueue(:detect_translation, post_id: post.id) }

topic_view_post_custom_fields_allowlister { [::DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] }

%w[../lib/discourse_translator/guardian_extension.rb].each do |path|
load File.expand_path(path, __FILE__)
end
require_relative "lib/discourse_translator/guardian_extension"
require_relative "lib/discourse_translator/post_extension"
require_relative "lib/discourse_translator/topic_extension"

reloadable_patch do |plugin|
Guardian.class_eval { prepend DiscourseTranslator::GuardianExtension }
Guardian.prepend(DiscourseTranslator::GuardianExtension)
Post.prepend(DiscourseTranslator::PostExtension)
Topic.prepend(DiscourseTranslator::TopicExtension)
end

add_to_serializer :post, :can_translate do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/guardian_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe DiscourseTranslator::GuardianExtension do
describe "anon user" do
let!(:guardian) { Guardian.new }
fab!(:post) { Fabricate(:post) }
fab!(:post)

before do
SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}"
Expand All @@ -26,7 +26,7 @@
end

describe "logged in user" do
fab!(:group) { Fabricate(:group) }
fab!(:group)
fab!(:user) { Fabricate(:user, groups: [group]) }
fab!(:post) { Fabricate(:post, user: user) }
let(:guardian) { Guardian.new(user) }
Expand Down