Skip to content
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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ The best practice is to use an initializer:

```ruby
# config/initializers/alchemy.rb
Alchemy.user_class_name = 'YourUserClass' # Defaults to 'User'
Alchemy.current_user_method = 'current_admin_user' # Defaults to 'current_user'
Alchemy.signup_path = '/your/signup/path' # Defaults to '/signup'
Alchemy.login_path = '/your/login/path' # Defaults to '/login'
Alchemy.logout_path = '/your/logout/path' # Defaults to '/logout'
Alchemy.logout_method = 'http_verb_for_logout' # Defaults to 'delete'
Alchemy.unauthorized_path = '/some/public/page' # Defaults to '/'
Alchemy.configure do |config|
config.user_class = 'YourUserClass' # This has to be configured
config.current_user_method = 'current_admin_user' # Defaults to 'current_user'
config.signup_path = '/your/signup/path' # Defaults to '/signup'
config.login_path = '/your/login/path' # Defaults to '/login'
config.logout_path = '/your/logout/path' # Defaults to '/logout'
config.logout_method = 'http_verb_for_logout' # Defaults to 'delete'
config.unauthorized_path = '/some/public/page' # Defaults to '/'
end
```

The only thing Alchemy needs to know from your user class is the `alchemy_roles` method.
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/alchemy/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def show_error_notice(error)
end

def set_stamper
if Alchemy.user_class < ActiveRecord::Base
Alchemy.user_class.stamper = current_alchemy_user
if Alchemy.config.user_class.respond_to?(:stamper=)
Alchemy.config.user_class.stamper = current_alchemy_user
end
end

def reset_stamper
if Alchemy.user_class < ActiveRecord::Base
Alchemy.user_class.reset_stamper
if Alchemy.config.user_class.respond_to?(:reset_stamper)
Alchemy.config.user_class.reset_stamper
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/alchemy/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class DashboardController < Alchemy::Admin::BaseController
def index
@last_edited_pages = Page.all_last_edited_from(current_alchemy_user)
@all_locked_pages = Page.locked
if Alchemy.user_class.respond_to?(:logged_in)
@online_users = Alchemy.user_class.logged_in.to_a - [current_alchemy_user]
if Alchemy.config.user_class.respond_to?(:logged_in)
@online_users = Alchemy.config.user_class.logged_in.to_a - [current_alchemy_user]
end
if current_alchemy_user.respond_to?(:sign_in_count) && current_alchemy_user.respond_to?(:last_sign_in_at)
@last_sign_at = current_alchemy_user.last_sign_in_at
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/alchemy/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def handle_redirect_for_user
if can?(:index, :alchemy_admin_dashboard)
redirect_or_render_notice
else
redirect_to Alchemy.unauthorized_path
redirect_to Alchemy.config.unauthorized_path
end
end

Expand Down Expand Up @@ -95,7 +95,7 @@ def handle_redirect_for_guest
render :permission_denied
else
store_location
redirect_to Alchemy.login_path
redirect_to Alchemy.config.login_path
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/alchemy/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def caching_options
end

def signup_required?
if Alchemy.user_class.respond_to?(:admins)
Alchemy.user_class.admins.empty?
if Alchemy.config.user_class.respond_to?(:admins)
Alchemy.config.user_class.admins.empty?
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Attachment < BaseRecord

include Alchemy.storage_adapter.attachment_class_methods

stampable stamper_class_name: Alchemy.user_class_name
stampable stamper_class_name: Alchemy.config.user_class_name

scope :by_file_type, ->(*file_type) do
Alchemy.storage_adapter.by_file_type_scope(file_type)
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Element < BaseRecord
#
acts_as_list scope: [:page_version_id, :fixed, :parent_element_id]

stampable stamper_class_name: Alchemy.user_class_name
stampable stamper_class_name: Alchemy.config.user_class_name

before_destroy :delete_all_nested_elements

Expand Down
4 changes: 2 additions & 2 deletions app/models/alchemy/folded_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
module Alchemy
class FoldedPage < BaseRecord
belongs_to :page, inverse_of: :folded_pages
belongs_to :user, inverse_of: :folded_pages, class_name: Alchemy.user_class_name
belongs_to :user, inverse_of: :folded_pages, class_name: Alchemy.config.user_class_name

def self.folded_for_user(user)
return none unless Alchemy.user_class < ActiveRecord::Base
return none unless Alchemy.config.user_class.respond_to?(:where)

where(user: user, folded: true)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Node < BaseRecord
before_destroy :check_if_related_node_ingredients_present

acts_as_nested_set scope: "language_id", touch: true
stampable stamper_class_name: Alchemy.user_class_name
stampable stamper_class_name: Alchemy.config.user_class_name

belongs_to :language, class_name: "Alchemy::Language"
belongs_to :page, class_name: "Alchemy::Page", optional: true, inverse_of: :nodes
Expand Down
14 changes: 7 additions & 7 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ class Page < BaseRecord

acts_as_nested_set(dependent: :destroy, scope: [:layoutpage, :language_id])

stampable stamper_class_name: Alchemy.user_class_name
stampable stamper_class_name: Alchemy.config.user_class_name

belongs_to :language

belongs_to :creator,
primary_key: Alchemy.user_class_primary_key,
class_name: Alchemy.user_class_name,
primary_key: Alchemy.config.user_class_primary_key,
class_name: Alchemy.config.user_class_name,
foreign_key: :creator_id,
optional: true

belongs_to :updater,
primary_key: Alchemy.user_class_primary_key,
class_name: Alchemy.user_class_name,
primary_key: Alchemy.config.user_class_primary_key,
class_name: Alchemy.config.user_class_name,
foreign_key: :updater_id,
optional: true

belongs_to :locker,
primary_key: Alchemy.user_class_primary_key,
class_name: Alchemy.user_class_name,
primary_key: Alchemy.config.user_class_primary_key,
class_name: Alchemy.config.user_class_name,
foreign_key: :locked_by,
optional: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/page/page_natures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def rootpage?
end

def folded?(user_id)
return unless Alchemy.user_class < ActiveRecord::Base
return unless Alchemy.config.user_class < ActiveRecord::Base

if folded_pages.loaded?
folded_pages.any? { |p| p.folded && p.user_id == user_id }
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def allowed_filetypes
validates_size_of :image_file, maximum: Alchemy.config.uploader.file_size_limit.megabytes
validate :image_file_type_allowed, if: -> { image_file.present? }

stampable stamper_class_name: Alchemy.user_class_name
stampable stamper_class_name: Alchemy.config.user_class_name

scope :named, ->(name) { where("#{table_name}.name LIKE ?", "%#{name}%") }
scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) }
Expand Down
2 changes: 1 addition & 1 deletion app/services/alchemy/page_tree_preloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def call

# Load folded page IDs for the user
def load_folded_page_ids
if user && Alchemy.user_class < ActiveRecord::Base
if user && Alchemy.config.user_class < ActiveRecord::Base
FoldedPage.folded_for_user(user).pluck(:page_id).to_set
else
Set.new
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/_menubar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</svg>
<%= Alchemy.t(:edit_page) %>
<% end %>
<%= form_tag Alchemy.logout_path, method: Alchemy.logout_method do %>
<%= form_tag Alchemy.config.logout_path, method: Alchemy.config.logout_method do %>
<%= button_tag class: "button" do %>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
<path d="M5 22C4.44772 22 4 21.5523 4 21V3C4 2.44772 4.44772 2 5 2H19C19.5523 2 20 2.44772 20 3V6H18V4H6V20H18V18H20V21C20 21.5523 19.5523 22 19 22H5ZM18 16V13H11V11H18V8L23 12L18 16Z"></path>
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/leave.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<label><%= Alchemy.t("Do you want to") %></label>
<%= link_to Alchemy.t('stay logged in'), alchemy.root_path, class: 'button secondary' %>
</p>
<%= form_tag Alchemy.logout_path, method: Alchemy.logout_method, class: 'buttons' do %>
<%= form_tag Alchemy.config.logout_path, method: Alchemy.config.logout_method, class: 'buttons' do %>
<label><%= Alchemy.t('or to completely') %></label>
<%= button_tag Alchemy.t(:logout), autofocus: true %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/base/permission_denied.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Alchemy.closeCurrentDialog(function() {
Turbo.visit('<%= Alchemy.login_path %>');
Turbo.visit('<%= Alchemy.config.login_path %>');
});
2 changes: 1 addition & 1 deletion app/views/alchemy/welcome.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<%= Alchemy.t("Before creating your first page you need an admin user") %>.
</p>
<p>
<%= link_to Alchemy.t("Create admin user"), Alchemy.signup_path, class: "button" %>
<%= link_to Alchemy.t("Create admin user"), Alchemy.config.signup_path, class: "button" %>
</p>
<h4><%= Alchemy.t("More resources") %></h4>
<ul>
Expand Down
5 changes: 1 addition & 4 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ class << self
def config
@_config ||= Alchemy::Configurations::Main.new
end

def configure(&blk)
yield config
end
delegate :configure, to: :config

enable_searchable_deprecation_msg = "Use `Alchemy.config.show_page_searchable_checkbox` instead."
def enable_searchable = config.show_page_searchable_checkbox
Expand Down
4 changes: 1 addition & 3 deletions lib/alchemy/ability_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ module Alchemy::AbilityHelper
def current_ability
@current_ability ||= begin
alchemy_permissions = Alchemy::Permissions.new(current_alchemy_user)
Alchemy.registered_abilities.each do |klass|
# Ensure to avoid issues with Rails constant lookup.
klass = "::#{klass}".constantize
Alchemy.config.abilities.each do |klass|
alchemy_permissions.merge(klass.new(current_alchemy_user))
end
alchemy_permissions
Expand Down
Loading
Loading