vinsol-spree-contrib / spree_admin_roles_and_access

Admin Roles And Access for Spree
BSD 3-Clause "New" or "Revised" License
43 stars 101 forks source link

Failed to get user roles #22

Open cyberkostyan opened 7 years ago

cyberkostyan commented 7 years ago

Hi, I'm using spree-3-1 and after installing this gem I can't enter admin area, it fails on this line with such error

Started GET "/admin/orders" for ::1 at 2017-03-02 21:58:18 +0300
  ActiveRecord::SchemaMigration Load (5.6ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Spree::Admin::OrdersController#index as HTML
  Spree::Preference Load (0.4ms)  SELECT  "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = $1 LIMIT 1  [["key", "spree/backend_configuration/locale"]]
  Spree::User Load (2.8ms)  SELECT  "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = $1  ORDER BY "spree_users"."id" ASC LIMIT 1  [["id", 1]]
Completed 500 Internal Server Error in 92ms (ActiveRecord: 9.6ms)

PG::UndefinedTable - ERROR:  relation "spree_roles_users" does not exist
LINE 5:                WHERE a.attrelid = '"spree_roles_users"'::reg...
                                          ^

I've tried in console

[6] pry(main)> user ||= Spree.user_class.new
[7] pry(main)> user.roles
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "spree_roles_users" does not exist
LINE 5:                WHERE a.attrelid = '"spree_roles_users"'::reg...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"spree_roles_users"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

but I can see such roles created after installing

[5] pry(main)> Spree::Role.all
  Spree::Role Load (0.5ms)  SELECT "spree_roles".* FROM "spree_roles"
=> [#<Spree::Role:0x007ff97664a768 id: 1, name: "admin", editable: true, is_default: false>,
 #<Spree::Role:0x007ff97664a4c0 id: 2, name: "user", editable: true, is_default: true>,
 #<Spree::Role:0x007ff97664a218 id: 3, name: "manager", editable: true, is_default: false>,
 #<Spree::Role:0x007ff976649f70 id: 4, name: "customer service", editable: true, is_default: false>,
 #<Spree::Role:0x007ff976649cc8 id: 5, name: "warehouse", editable: true, is_default: false>]
cyberkostyan commented 7 years ago

Seems like it should be spree_role_users

pikender commented 7 years ago

@cyberkostyan try running bundle exec rake spree_roles:permissions:populate and try opening the admin end again

vng1923 commented 7 years ago

@pikender I did like you suggested but still have the same error. I'm using Spree 3.2 and spree_admin_roles_and_access 2.0.0

Correct me if i'm wrong.

Thanks!

vng1923 commented 7 years ago

image

Anuragjain89 commented 7 years ago

@huyngvu

Any reason for not using the latest version of this extension ?

The latest version has a lot of improvements including a fancy UI for admin.

Regarding your error:

As can be seen in the shared screen print, the extension is looking for a table spree_roles_users which does not exist in your db.

This join table used to be there (hard coded) until recently. See this commit for details

P.S. I have used this extension in one of my projects and will be happy to share my experience.

vng1923 commented 7 years ago

@Anuragjain89 thanks bro, I fixed it yesterday by override User model.

The latest version you said is branch master?

Anuragjain89 commented 7 years ago

@huyngvu

Yep. That's the latest one.

In fact, there are some more improvements / bug fixes ( here's my PR ) lined up which are likely to be merged into the master.