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

Fixes for Solidus 2.5 #30

Merged
merged 5 commits into from
Sep 10, 2018
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
- SOLIDUS_BRANCH=v2.2
- SOLIDUS_BRANCH=v2.3
- SOLIDUS_BRANCH=v2.4
- SOLIDUS_BRANCH=v2.5
- SOLIDUS_BRANCH=v2.6
- SOLIDUS_BRANCH=master
matrix:
fast_finish: true
Expand Down
6 changes: 0 additions & 6 deletions app/overrides/alchemy_solidus_tab.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/alchemy/admin/shared/_alchemy_solidus_tab.html.erb

This file was deleted.

23 changes: 23 additions & 0 deletions app/views/spree/admin/shared/_alchemy_sub_menu.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ul class="admin-subnav">
<% if can?(:index, :alchemy_admin_pages) %>
<%= tab :pages, label: :pages, url: alchemy.admin_pages_path %>
<% end %>
<% if can?(:index, :alchemy_admin_sites) %>
<%= tab :sites, label: :sites, url: alchemy.admin_sites_path %>
<% end %>
<% if can?(:index, :alchemy_admin_languages) %>
<%= tab :languages, label: :languages, url: alchemy.admin_languages_path %>
<% end %>
<% if can?(:index, :alchemy_admin_tags) %>
<%= tab :tags, label: :tags, url: alchemy.admin_tags_path %>
<% end %>
<% if defined?(Alchemy::User) && can?(:index, :alchemy_admin_users) %>
<%= tab :users, label: :users, url: alchemy.admin_users_path %>
<% end %>
<% if can?(:index, :alchemy_admin_pictures) %>
<%= tab :pictures, label: :pictures, url: alchemy.admin_pictures_path %>
<% end %>
<% if can?(:index, :alchemy_admin_attachments) %>
<%= tab :attachments, label: :attachments, url: alchemy.admin_attachments_path %>
<% end %>
</ul>
47 changes: 43 additions & 4 deletions config/initializers/alchemy.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
Alchemy::Modules.register_module({
alchemy_module = {
engine_name: 'spree',
name: 'solidus',
navigation: {
controller: 'spree/admin/orders',
action: 'index',
name: 'Shop',
image: 'alchemy/solidus/alchemy_module_icon.png'
name: 'Store',
image: 'alchemy/solidus/alchemy_module_icon.png',
sub_navigation: [
{
controller: 'spree/admin/orders',
action: 'index',
name: 'Orders'
},
{
controller: 'spree/admin/products',
action: 'index',
name: 'Products'
},
{
controller: 'spree/admin/reports',
action: 'index',
name: 'Reports'
},
{
controller: 'spree/admin/promotions',
action: 'index',
name: 'Promotions'
},
{
controller: 'spree/admin/stock_items',
action: 'index',
name: 'Stock'
}
]
}
})
}

if defined?(Spree::Auth::Engine)
alchemy_module[:navigation][:sub_navigation].push(
{
controller: 'spree/admin/users',
action: 'index',
name: 'Users'
}
)
end

Alchemy::Modules.register_module(alchemy_module)
9 changes: 8 additions & 1 deletion config/locales/alchemy_solidus_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ en:
spree:
admin:
tab:
cms: CMS
cms: CMS
pages: Pages
sites: Sites
languages: Languages
tags: Tags
users: Users
pictures: Pictures
attachments: Attachments
8 changes: 7 additions & 1 deletion config/locales/alchemy_solidus_it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ it:
spree:
admin:
tab:
cms: CMS
cms: CMS
pages: "Pagine"
sites: "Siti"
languages: "Lingue"
tags: "Tags"
pictures: "Immagini"
attachments: "File"
10 changes: 10 additions & 0 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class Engine < ::Rails::Engine
require 'alchemy/solidus/spree_install_generator_fix'
end
end

# Fix for +belongs_to :bill_address+ in {Spree::UserAddressBook}
# Solidus has this set to +false+ in {Spree::Base}, but {Alchemy::User} does not inherit from it.
initializer 'alchemy_solidus.belongs_bill_address_fix' do
if Alchemy.user_class_name == 'Alchemy::User'
ActiveSupport.on_load(:active_record) do
Alchemy::User.belongs_to_required_by_default = false
end
end
end
end
end
end
60 changes: 60 additions & 0 deletions lib/generators/alchemy/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class InstallGenerator < Rails::Generators::Base
desc: "Set true if you don't want to run the Alchemy Devise installer. NOTE: Automatically skipped if Alchemy::Devise is not available."
class_option :skip_spree_custom_user_generator, default: false, type: :boolean,
desc: "Set true if you don't want to run the Solidus custom user generator. NOTE: Automatically skipped if Alchemy::Devise is not available."
class_option :skip_alchemy_user_generator, default: false, type: :boolean,
desc: "Set true if you don't want to generate an admin user. NOTE: Automatically skipped if Alchemy::Devise is not available."
class_option :auto_accept, default: false, type: :boolean,
desc: 'Set true if run from a automated script (ie. on a CI)'

Expand Down Expand Up @@ -49,6 +51,44 @@ def run_spree_custom_user_generator
end
end

def inject_admin_tab
inject_into_file 'config/initializers/spree.rb', {after: "Spree::Backend::Config.configure do |config|\n"} do
<<~ADMIN_TAB
\ # AlchemyCMS admin tabs
\ config.menu_items << config.class::MenuItem.new(
\ [:pages, :sites, :languages, :tags, :users, :pictures, :attachments],
\ 'copy',
\ label: :cms,
\ condition: -> { can?(:index, :alchemy_admin_dashboard) },
\ partial: 'spree/admin/shared/alchemy_sub_menu',
\ url: '/admin/pages'
\ )
ADMIN_TAB
end
end

def create_admin_user
if Kernel.const_defined?('Alchemy::Devise') && !options[:skip_alchemy_user_generator] && Alchemy::User.count.zero?
login = ENV.fetch('ALCHEMY_ADMIN_USER_LOGIN', 'admin')
email = ENV.fetch('ALCHEMY_ADMIN_USER_EMAIL', 'admin@example.com')
password = ENV.fetch('ALCHEMY_ADMIN_USER_PASSWORD', 'test1234')
unless options[:auto_accept]
login = ask("\nEnter the username for the admin user", default: login)
email = ask("Enter the email for the admin user", default: email)
password = ask("Enter the password for the admin user", default: password)
end

Alchemy::User.create!(
login: login,
email: email,
password: password,
password_confirmation: password,
alchemy_roles: 'admin',
spree_roles: [Spree::Role.find_or_create_by!(name: 'admin')]
)
end
end

def inject_routes
routes_file_path = Rails.root.join('config', 'routes.rb')
mountpoint = '/'
Expand All @@ -64,6 +104,26 @@ def inject_routes
"\n mount Alchemy::Engine, at: '/#{mountpoint.chomp('/')}'\n"
end
end

def set_root_route
routes_file_path = Rails.root.join('config', 'routes.rb')
if options[:auto_accept] || ask("\nDo you want Alchemy to handle the root route ('/')?", default: true)
if File.read(routes_file_path).match SPREE_MOUNT_REGEXP
sentinel = SPREE_MOUNT_REGEXP
else
sentinel = "Rails.application.routes.draw do\n"
end
inject_into_file routes_file_path, {after: sentinel} do
<<~ROOT_ROUTE
\n
\ # Let AlchemyCMS handle the root route
\ Spree::Core::Engine.routes.draw do
\ root to: '/alchemy/pages#index'
\ end
ROOT_ROUTE
end
end
end
end
end
end
16 changes: 2 additions & 14 deletions spec/features/alchemy/alchemy_admin_integrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
require 'spree/testing_support/factories/address_factory'

RSpec.feature "Admin Integration", type: :feature do
let!(:admin) do
Alchemy::User.create!(
login: 'admin',
password: 'S3cre#t',
password_confirmation: 'S3cre#t',
email: 'email@example.com',
alchemy_roles: 'admin',
spree_roles: [Spree::Role.first_or_create!(name: 'admin')],
bill_address: FactoryBot.create(:address)
)
end

it 'it is possible to login and visit Alchemy admin' do
login!
visit '/admin/dashboard'
Expand All @@ -38,8 +26,8 @@ def login!
visit '/admin/login'

expect(page).to have_field 'user_login'
fill_in 'user_login', with: admin.login
fill_in 'user_password', with: admin.password
fill_in 'user_login', with: 'admin'
fill_in 'user_password', with: 'test1234'
click_button 'login'
end
end