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

Failed to get user roles #22

Open
cyberkostyan opened this issue Mar 2, 2017 · 7 comments
Open

Failed to get user roles #22

cyberkostyan opened this issue Mar 2, 2017 · 7 comments

Comments

@cyberkostyan
Copy link

cyberkostyan commented Mar 2, 2017

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
Copy link
Author

cyberkostyan commented Mar 2, 2017

Seems like it should be spree_role_users

@cyberkostyan cyberkostyan changed the title Failed to Failed to get user roles Mar 2, 2017
@pikender
Copy link

pikender commented Mar 3, 2017

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

@vng1923
Copy link

vng1923 commented Jul 24, 2017

@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
Copy link

vng1923 commented Jul 24, 2017

image

@Anuragjain89
Copy link
Contributor

@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
Copy link

vng1923 commented Jul 25, 2017

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

The latest version you said is branch master?

@Anuragjain89
Copy link
Contributor

@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.

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

4 participants