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

Solidus nav items (modules) not appearing in Alchemy CMS #32

Closed
itanywhere opened this issue Mar 8, 2019 · 15 comments
Closed

Solidus nav items (modules) not appearing in Alchemy CMS #32

itanywhere opened this issue Mar 8, 2019 · 15 comments

Comments

@itanywhere
Copy link

Alchemy-Solidus is not creating the tabs in the Alchemy main nav

Environment:
Rails 5.2.2
ruby 2.6.1p33 (2019-01-30 revision 66950)
Ubuntu 18.04

Installed Alchemy with Alchemy Devise, then Solidus and Solidus-Reports and Alchemy-Solidus. Installation steps as follows:

bin/rake alchemy_devise:install
bin/rake alchemy_devise:install:migrations
bin/rake alchemy:install
bundle exec rails g spree:install --sample=false
bundle exec rails g spree:custom_user Alchemy::User
bundle exec rails g solidus_reports:install
bundle exec rake alchemy_solidus:install:migrations

Verified that alchemy-solidus gem is creating the config/initializers/alchemy.rb file with the module correctly defined

@tvdeyen
Copy link
Member

tvdeyen commented Mar 8, 2019

Which version of Solidus and Alchemy are you using?

@itanywhere
Copy link
Author

Sorry forgot to paste these in the original post

Solidus 2.8.2
Alchemy 4.1.0 (specified 'master' in the Gemfile)

Thanks for the fast reply

@itanywhere
Copy link
Author

itanywhere commented Mar 9, 2019

I should also mention, these are the routes - I placed Alchemy and Solidus at the top level, but I've also tried placing Solidus at /shop. Originally I didn't have the "scope" section below, and I had to add this to get the admin section to appear (based on Issue #14).

scope :admin do
get '/' => redirect("#{Alchemy.admin_path}/dashboard"), as: :admin
end
mount Spree::Core::Engine => '/'
mount Alchemy::Engine => '/'

Also:
I'm not sure if this might be related, but the homepage was throwing this error:
ActionView::Template::Error (undefined local variable or method `meta_data_tags' ...
which I fixed by adding Alchemy::BaseController.send :helper, Spree::BaseHelper to alchemy-solidus/lib/alchemy/solidus/use_solidus_layout.rb.

After fixing this issue it then threw:
ActionView::Template::Error (undefined method `store_menu?'
Which I fixed by adding Alchemy::BaseController.send :helper, Spree::StoreHelper to the same file alchemy-solidus/lib/alchemy/solidus/use_solidus_layout.rb.

I'm assuming this was not limited to the homepage and would have appeared on all other pages as well, but I only have one page in the CMS so far.

I just thought I'd mention this in case it might be of use to anyone, or in case the fact that those lines needed to be added might indicate an issue in my setup or in the gem itself.

Thanks

@itanywhere
Copy link
Author

I just checked the Alchemy::User object for my admin account and found that spree_roles is empty, and Spree::Role is empty too. Is the user supposed to have Spree roles assigned? Alternatively, are we supposed to define cancan abilities anywhere?

I'm just thinking it might be a permissions issue, as when I'm in the Alchemy backend and go to admin/users, it redirects to a Solidus page (with Solidus logo and page layout) and says "Authorization failure". This tells me that Solidus isn't seeing the account as an admin, although it's signed in successfully in the Alchemy backend

@tvdeyen
Copy link
Member

tvdeyen commented Mar 9, 2019

From your notes above it seams you didn’t follow the setup guide from the README. What happens if you follow it?

@itanywhere
Copy link
Author

I did follow the readme several times over (creating and destroying the installation and I wasn't able to get around this particular issue) but I'll repeat the installation from the start and report back, thanks

@itanywhere
Copy link
Author

itanywhere commented Mar 10, 2019

Hi Thomas, I'd just like to confirm whether I'm following the steps correctly:

Note that I'm trying to set it up with Alchemy Devise as the user model

I tried the automated install by adding gem 'alchemy-solidus', github: 'AlchemyCMS/alchemy-solidus', branch: 'master' and then running bin/rails g alchemy:solidus:install. This complained about not having a User object so I added alchemy-devise gem and the alchemy:solidus:install proceeded to the stage where I enter the admin credentials. Immediately after entering the credentials, it failed with Table '_development.spree_roles' doesn't exist (Mysql2::Error).

So instead I decided to follow the manual instructions Option 2, existing Alchemy CMS installation with Alchemy Devise, as follows:

  1. Add alchemy-solidus gem and run bundle exec rails g alchemy:devise:install. All the migrations worked but then it stopped at "vendor/assets/stylesheets/alchemy/admin/all.css does not appear to exist". I assume this is because there isn't an Alchemy installation yet. I then proceeded with the instructions:

  2. bundle exec rails g spree:install --sample=false

  3. bundle exec rails g spree:custom_user Alchemy::User

  4. modifying lib/spree/authentication_helpers.rb

  5. bundle exec rake alchemy_solidus:install:migrations

  6. bundle exec rake alchemy:install

  7. Modified routes.rb (put both engines at root level)

I then went to /admin and it redirected to /unauthorized and gave a 404 error - I'm assuming this is because Solidus caught the /admin route and has no /unauthorized route, but I was able to go to /admin/signup and /admin/login etc successfully (just not /admin itself).

I can fix the /admin route issue, however the original issue remains where I can't see any links in the main Alchemy nav which point to Solidus.

Are the steps followed correct at all?

Just a side note:
I also tried adding Alchemy-Solidus to a completely fresh installation of Alchemy CMS+Devise, it reached a point where it threw "undefined local variable or method `definition_hash' for Alchemy::Modules:Module". I edited the alchemy-solidus gem file config/initializers/alchemy.rb and commented out the last line which says "Alchemy::Modules.register_module(alchemy_module)", this allowed the installation to proceed but when I returned that line to normal, the definition_hash error returned.

I appreciate your help

tvdeyen added a commit to tvdeyen/alchemy-solidus that referenced this issue Mar 11, 2019
If someone just requests '/admin' without being logged in Solidus
renders '/unauthorized'. In solidus_auth_devise there is a redirect
handler for this case that redirects to '/login'. In case we do not
have solidus_auth_devise we need to provide a handler that redirects
to Alchemy.login_path.

Refs AlchemyCMS#32
tvdeyen added a commit to tvdeyen/alchemy-solidus that referenced this issue Mar 11, 2019
If someone just requests '/admin' without being logged in Solidus
renders '/unauthorized'. In solidus_auth_devise there is a redirect
handler for this case that redirects to '/login'. In case we do not
have solidus_auth_devise we need to provide a handler that redirects
to Alchemy.login_path.

Refs AlchemyCMS#32
@tvdeyen
Copy link
Member

tvdeyen commented Mar 11, 2019

@itanywhere thanks for reporting. I investigated and found some issues. They should all be fixed by #34. Could you please upgrade to latest master in your project after I merged it?

Immediately after entering the credentials, it failed with Table '_development.spree_roles' doesn't exist (Mysql2::Error).

This happens if you did not ran the Solidus installer yet (rails g spree:install). After doing that the installer should run just fine.

it threw "undefined local variable or method `definition_hash' for Alchemy::Modules:Module".

Fixed by removing the "Reports" tab from the alchemy module. Solidus moved this into an extension. I also moved the initialiser into a file that gets generated in the host app, so one can easily make changes to that file.

Please re-run the rails g alchemy:solidus:install generator and replace alchemy.xx_path with Alchemy.xx_path in lib/spree/authentication_helpers.rb in order to fix the problems with the /admin route.

I could not reproduce the problems with the Solidus nav items not appearing in Alchemy admin, though. But maybe this is fixed for you as well with all the fixes I made recently. Fingers crossed.

@tvdeyen
Copy link
Member

tvdeyen commented Mar 11, 2019

@itanywhere #34 has now be merged. Please update to latest master and try again.

@itanywhere
Copy link
Author

Thanks, I'll give it a test now

@itanywhere
Copy link
Author

itanywhere commented Mar 12, 2019

@tvdeyen Just an update

I created a new project and changed the paths in authentication_helpers.rb, however these threw some errors about the routes until I ran rake routes and found that the only change in Alchemy was in "admin_signup" (the login_path and logout_path remained the same).

So I changed authentication_helpers.rb to:

def spree_signup_path
  alchemy.admin_signup_path
end

and left spree_login_path and spree_logout_path as alchemy.login_path and alchemy.logout_path respectively.

Alchemy CMS itself now appears to work normally

I also noticed the routes.rb file now looks like this:

Rails.application.routes.draw do
  # Let AlchemyCMS handle the root route
  Spree::Core::Engine.routes.draw do
    root to: '/alchemy/pages#index'
  end

  mount Alchemy::Engine => '/'
end

instead of the README which says:

# Make Alchemy's root page have higher priority than Spree's root page
root to: 'alchemy/pages#show'

mount Spree::Core::Engine => '/'

# Must be last so it's catch-all route can render undefined paths
mount Alchemy::Engine => '/'

Should the routes.rb remain as above, or should I change it to the one in the readme? I'm trying to mount Alchemy and Spree at root level

Also I have these in my Gemfile:

gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: 'master'
gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: 'master'
gem 'alchemy-solidus', github: 'AlchemyCMS/alchemy-solidus', branch: 'master'

Are these correct? Or should I just have Alchemy-Solidus and Alchemy-Devise?

Unfortunately the Solidus nav issue still persists, the Alchemy menu has Dashboard Pages Languages Sites Users Tags Library but nothing linking it to Solidus. I noticed your changes in config/initializers/alchemy.rb for the Reports tab - actually I did some research on Solidus last week and found that they had moved Reports to its own standalone gem and I even installed the gem before my original post in the hope that it would fix this issue.

There's also another issue that I haven't raised yet (I was originally waiting to see if the fix for the nav would fix this too) - When going to the Users section in Alchemy, I get the following error:
ActionView::Template::Error undefined method `firstname_or_lastname_or_login_or_email_or_gender_or_language_or_encrypted_password_or_password_salt_or_current_sign_in_ip_or_last_sign_in_ip_or_cached_tag_list_or_reset_password_token_or_alchemy_roles_or_spree_api_key_cont' for #<Ransack::Search:0x0000555d2fb006a8>

Thanks for looking into these issues and for releasing the fix for the links issue

@itanywhere
Copy link
Author

itanywhere commented Mar 13, 2019

@tvdeyen Hey Thomas

Through some miracle, I got it to work - well I got a lot closer

The funny part is the Solidus menu item now appears twice in the CMS menu (image below). The Solidus admin section appears and works fine otherwise.

This is how I got it to work
After moving to production environment I hadn't run the rake db:seed (I had only run a db:create and db:migrate). It seems that without the seed, it won't place the Solidus menu in the CMS.

Just a side note, the Automated option requires Spree to be installed first, with rails g spree:install --sample=false. The mistake I made was I assumed the Alchemy-Solidus installer would install everything, and when it failed I proceeded to try the Manual options.

If these steps are required (and I haven't done something wrong) then it might be worth adding these two pointers into the Readme

The remaining issues

  1. The /admin/users page still displays the Ransack error message as mentioned in my previous post
  2. Having Spree and Alchemy at the root domain did not allow me to create the admin account, it just kept redirecting to the signup page. I tried changing alchemy.signup_path to alchemy.admin_signup_path as per my last post, but this time it kept failing. The only solution was to set the Solidus route to /shop and let Alchemy have full control of the root level. I don't mind leaving Solidus to a sub path like /shop as it will most likely be used this way in production, but I just wanted to point this out.
  3. The two Solidus menu items (it's not really a problem, I can live with this)

image

@tvdeyen
Copy link
Member

tvdeyen commented Mar 20, 2019

@itanywhere I really need an example application in order to help you any further. The projects I am using this in, work fine. Also a fresh install works fine for me. Please upload a fresh install that shows this problems you are having somewhere on GitHub, so I can have a look. Otherwise I am not able to help. Sorry

@itanywhere
Copy link
Author

@tvdeyen Thanks Thomas, I've create a private repository to which you're added as a collaborator.

Regarding the double Spree icon in the Alchemy menu, I fixed this by deleting config/initializers/alchemy.rb as I noticed this does the same job as the equivalent file in the gem folder.

It's using Spree for the User section, is this correct? I had to modify the routes file to redirect the Spree POST /admin/users (new user) to the /alchemy/admin/users#create path

Thanks for looking into it

@tvdeyen
Copy link
Member

tvdeyen commented Dec 17, 2019

Fixed by #57

@tvdeyen tvdeyen closed this as completed Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants