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

AO3-6565 Move admin user search to Elasticsearch, add past emails and username search #4801

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
AO3-6565 Appease dog somewhat
weeklies committed Apr 28, 2024
commit 801e175169054a5cc63c53efe5761a4ce6465a6a
3 changes: 1 addition & 2 deletions app/models/indexing/scheduled_reindex_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ScheduledReindexJob
MAIN_CLASSES = %w(Pseud Tag Work Bookmark Series ExternalWork User).freeze
MAIN_CLASSES = %w[Pseud Tag Work Bookmark Series ExternalWork User].freeze

def self.perform(reindex_type)
classes = case reindex_type
@@ -16,4 +16,3 @@ def self.run_queue(klass, reindex_type)
end

end

9 changes: 4 additions & 5 deletions app/models/pseud.rb
Original file line number Diff line number Diff line change
@@ -81,9 +81,12 @@
validates_length_of :icon_comment_text, allow_blank: true, maximum: ArchiveConfig.ICON_COMMENT_MAX,
too_long: ts("must be less than %{max} characters long.", max: ArchiveConfig.ICON_COMMENT_MAX)

after_create :reindex_user
after_update :check_default_pseud
after_update :expire_caches
after_update :reindex_user, if: :name_changed?
after_commit :reindex_creations, :touch_comments
after_destroy :reindex_user

Check warning on line 89 in app/models/pseud.rb

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 `after_destroy` is supposed to appear before `after_commit`. Raw Output: app/models/pseud.rb:89:3: C: Rails/ActiveRecordCallbacksOrder: `after_destroy` is supposed to appear before `after_commit`.

scope :alphabetical, -> { order(:name) }
scope :default_alphabetical, -> { order(is_default: :desc).alphabetical }
@@ -419,7 +422,7 @@

def clear_icon
return unless delete_icon?

self.icon = nil unless icon.dirty?
self.icon_alt_text = nil
end
@@ -450,10 +453,6 @@
IndexQueue.enqueue_ids(Series, series.pluck(:id), :main)
end

after_create :reindex_user
after_update :reindex_user, if: :name_changed?
after_destroy :reindex_user

def reindex_user
user.enqueue_to_index
end
13 changes: 7 additions & 6 deletions app/models/roles_user.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,14 @@ class RolesUser < ApplicationRecord
belongs_to :user
belongs_to :role

delegate :enqueue_to_index, to: :user

after_create :log_role_addition
after_create :enqueue_to_index
after_destroy :log_role_removal
after_destroy :destroy_last_wrangling_activity
after_destroy :enqueue_to_index

def log_role_addition
admin = User.current_user
note = "Change made by #{admin&.login}"
@@ -12,7 +19,6 @@ def log_role_addition
role_id: role_id })
end

after_destroy :log_role_removal
def log_role_removal
admin = User.current_user
note = "Change made by #{admin&.login}"
@@ -24,14 +30,9 @@ def log_role_removal

# After removing the tag_wrangler role, remove the
# user's last wrangling activity as well.
after_destroy :destroy_last_wrangling_activity
def destroy_last_wrangling_activity
return unless role.name == "tag_wrangler"

user.last_wrangling_activity&.destroy
end

delegate :enqueue_to_index, to: :user
after_create :enqueue_to_index
after_destroy :enqueue_to_index
end
6 changes: 3 additions & 3 deletions app/models/search/user_query.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UserQuery < Query
def klass
'User'
"User"
end

def index_name
@@ -38,15 +38,15 @@ def role_filter
end

def name_filter
return unless options[:name].present?
return if options[:name].blank?

field = options[:search_past].present? ? :all_names : :names

{ wildcard: { field => options[:name] } }
end

def email_filter
return unless options[:email].present?
return if options[:email].blank?

field = options[:search_past].present? ? :all_emails : :email


Unchanged files with check annotations Beta

normalizer: {
keyword_normalizer: {
type: "custom",
filter: ["lowercase", "asciifolding"]

Check warning on line 43 in app/models/search/user_indexer.rb

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Use `%w` or `%W` for an array of words. Raw Output: app/models/search/user_indexer.rb:43:21: C: Style/WordArray: Use `%w` or `%W` for an array of words.
}
}
}
<%= ts("Search for user with exact ID.") %>
</p>
</dd>
<dt><%= label_tag "role_id", ts("Role") %></dt>

Check failure on line 25 in app/views/admin/admin_users/index.html.erb

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/views/admin/admin_users/index.html.erb:25:35: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
<dd><%= select_tag "role_id", "<option></option>".html_safe + options_for_select(@role_values, params[:role_id].to_i) %></dd>
<dt><%= label_tag "status", ts("Status") %></dt>
<dd>
<%= label_tag "inactive", ts("Not yet activated") %>
</dd>
<% if policy(User).can_view_past? %>
<dt><%= label_tag "settings", ts("Search settings") %></dt>

Check failure on line 33 in app/views/admin/admin_users/index.html.erb

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/views/admin/admin_users/index.html.erb:33:38: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
<dd>
<ul>
<li>
<%= check_box_tag "search_past", "1", params[:search_past].present? %>
<%= label_tag "search_past", ts("Include past usernames and emails") %>

Check failure on line 38 in app/views/admin/admin_users/index.html.erb

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/views/admin/admin_users/index.html.erb:38:45: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts`: the latter is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
</li>
</ul>
</dd>