Skip to content

Commit

Permalink
Consolidate generated additions to the User class (#3341)
Browse files Browse the repository at this point in the history
Give the string_display_key a default value
  • Loading branch information
jcoyne authored Oct 5, 2024
1 parent b901630 commit 04e3cf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/blacklight/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Blacklight::User
# SEE ALSO: The lib/blacklight/generator/user_generator.rb class for where this
# is generated into the hosting application.
included do
class_attribute :string_display_key
class_attribute :string_display_key, default: :email

has_many :bookmarks, dependent: :destroy, as: :user
has_many :searches, dependent: :destroy, as: :user
Expand Down
19 changes: 9 additions & 10 deletions lib/generators/blacklight/user_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def generate_devise_assets
generate "devise", model_name.classify
generate "devise_guests", model_name.classify

# add the #to_s to the model.
insert_into_file("app/models/#{model_name}.rb", before: /end(\n| )*$/) do
"\n # Configuration added by Blacklight; Blacklight::User uses a method key on your\n" \
" # user class to get a user-displayable login/identifier for\n" \
" # the account.\n" \
" self.string_display_key ||= :email\n"
end
gsub_file("config/initializers/devise.rb", "config.sign_out_via = :delete", "config.sign_out_via = :get")
end

Expand All @@ -49,13 +42,19 @@ def inject_blacklight_user_behavior
file_path = "app/models/#{model_name.underscore}.rb"
if File.exist?(File.expand_path(file_path, destination_root))
inject_into_class file_path, model_name.classify do
"\n # Connects this user object to Blacklights Bookmarks." \
"\n include Blacklight::User\n"
<<~EOS
# Connects this user object to Blacklights Bookmarks.
include Blacklight::User
# Blacklight::User uses a method on your User class to get a user-displayable
# label (e.g. login or identifier) for the account. Blacklight uses `email' by default.
# self.string_display_key = :email
EOS
end
else
say_status "warning", <<~EOS, :yellow
Blacklight authenticated user functionality not installed, as a user model
could not be found at /app/models/user.rb. If you used a different name,
could not be found at #{file_path}. If you used a different name,
please re-run the migration and provide that name as an argument. E.g.:
`rails -g blacklight:user client`
Expand Down

0 comments on commit 04e3cf0

Please sign in to comment.