Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# /home/anselm/code/alchemy-solidus/app/patches/controllers/alchemy/solidus/spree_admin_users_controller_patch.rb
Copy link
Member

Choose a reason for hiding this comment

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

we can remove this


module Alchemy
module Solidus
module SpreeAdminUsersControllerPatch
def self.prepended(base)
base.after_action :assign_admin_roles_to_first_user, only: :create
end

private

def assign_admin_roles_to_first_user
if Spree.user_class.count == 1
user = Spree.user_class.last
user.spree_roles = [Spree::Role.find_or_create_by(name: "admin")]
user.alchemy_roles = ["admin"]
user.save
end
end
end
end
end

::Spree::Admin::UsersController.prepend(Alchemy::Solidus::SpreeAdminUsersControllerPatch)
Copy link
Member

Choose a reason for hiding this comment

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

we probably want to safe guard?

22 changes: 22 additions & 0 deletions app/patches/models/alchemy/solidus/alchemy_devise_ability_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module AlchemyDeviseAbilityPatch
def initialize(user)
super

# Without these abilities, Alchemy's signup page does not work with Solidus' UsersController.
if Alchemy::User.count == 0
can :admin, Alchemy::User
can :update_password, Alchemy::User
can :update_email, Alchemy::User
end
end

if defined?(::Alchemy::Devise::Ability)
::Alchemy::Devise::Ability.prepend self
end
end
end
end
1 change: 1 addition & 0 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if defined?(Alchemy::Devise::Engine)
Spree.user_class = "Alchemy::User"
Spree::PermittedAttributes.user_attributes << :login
end

Rails.application.config.after_initialize do
Expand Down
3 changes: 3 additions & 0 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Engine < ::Rails::Engine
config.to_prepare do
Alchemy.register_ability ::Spree::Ability
::Spree::Ability.register_ability ::Alchemy::Permissions
Alchemy.registered_abilities.reject { _1 == Spree::Ability }.each do |ability|
::Spree::Ability.register_ability ability
end

if SolidusSupport.frontend_available?
# Allows to render Alchemy content within Solidus' controller views
Expand Down