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

[BUG]: NoMethodError at /admin/users/6/edit undefined method `name' for nil:NilClass #4532

Closed
2 of 4 tasks
ruyrocha opened this issue Jul 15, 2024 · 2 comments
Closed
2 of 4 tasks
Labels

Comments

@ruyrocha
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

It's not possible to edit the user [email protected] while logged in as a super admin after a fresh installation.

Expected Behavior

The user can be edited without errors.

Steps To Reproduce

  1. Perform a fresh install
  2. Log in as [email protected]
  3. Go to Users > All Users, find user with email as [email protected] and click on Edit button
  4. Check you're seeing the NoMethodError on page

You can see on Rails console the resource name is missing for the first assigned role, e.g:

[14] pry(main)> user = User.find(6) ;
  User Load (1.6ms)  SELECT "users".* FROM "users" WHERE "users"."discarded_at" IS NULL AND "users"."id" = $1 LIMIT $2  [["id", 6], ["LIMIT", 1]]
[15] pry(main)> user.email
=> "[email protected]"
[16] pry(main)> user.roles.map { |role| [role.name, role.resource&.name || 'missing'] }
  Role Load (1.6ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1  [["user_id", 6]]
  Organization Load (4.1ms)  SELECT "organizations".* FROM "organizations" WHERE "organizations"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
=> [["super_admin", "missing"], ["org_user", "Pawnee Diaper Bank"]]
[17] pry(main)> 

Environment

- OS: Linux

Criteria for Completion

  • When a user clicks on the Edit button on Users page it should be able to edit that user without errors
  • Add tests covering the changes you're making

Anything else?

It seems that there is already a fix for cases where name is missing, displaying Name Not Provided on spec/models/user_spec.rb and spec/helpers/dashboard_helper_spec.rb.

Code of Conduct

  • I've read the Code of Conduct and understand my responsibilities as a member of the Ruby for Good community
@cielf
Copy link
Collaborator

cielf commented Jul 15, 2024

Looks to me like [email protected] is a super admin, and therefore would have no resource. So this is related to #4503.

@cielf
Copy link
Collaborator

cielf commented Jul 21, 2024

This is a subset of #4503. Closing this one (with a reference to it from the larger case).

@cielf cielf closed this as completed Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants