Project

General

Profile

Bug #9678

Can't update admin flag for users via API

Added by Tomáš Strachota over 6 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

Anytime a json containing "admin" is sent via PUT on users the request fails with:

undefined method `admin=' for nil:NilClass (NoMethodError)

The relevant backtrace is:

2015-03-09 09:57:27 [I] Started PUT "//api/users/13" for 127.0.0.1 at 2015-03-09 09:57:27 +0000
2015-03-09 09:57:27 [I] Processing by Api::V2::UsersController#update as JSON
2015-03-09 09:57:27 [I]   Parameters: {"user"=>{"admin"=>"false"}, "apiv"=>"v2", "id"=>"13"}
2015-03-09 09:57:27 [D]   ESC[1mESC[36mUser Load (0.2ms)ESC[0m  ESC[1mSELECT "users".* FROM "users" WHERE "users"."lower_login" = 'admin' LIMIT 1ESC[0m
2015-03-09 09:57:27 [D]   ESC[1mESC[35mAuthSource Load (0.1ms)ESC[0m  SELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."id" = 1 LIMIT 1
2015-03-09 09:57:27 [D]   ESC[1mESC[36mCACHE (0.0ms)ESC[0m  ESC[1mSELECT "users".* FROM "users" WHERE "users"."lower_login" = 'admin' LIMIT 1ESC[0m
2015-03-09 09:57:27 [D] Authenticated user Admin User against INTERNAL authentication source
2015-03-09 09:57:27 [D]   ESC[1mESC[35mUser Load (0.1ms)ESC[0m  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'foreman_admin' LIMIT 1
2015-03-09 09:57:27 [D] Setting current user thread-local variable to foreman_admin
2015-03-09 09:57:27 [D] Setting current user thread-local variable to nil
2015-03-09 09:57:27 [D]   ESC[1mESC[36mCACHE (0.0ms)ESC[0m  ESC[1mSELECT "users".* FROM "users" WHERE "users"."lower_login" = 'foreman_admin' LIMIT 1ESC[0m
2015-03-09 09:57:27 [D] Setting current user thread-local variable to foreman_admin
2015-03-09 09:57:27 [D]   ESC[1mESC[35m (0.0ms)ESC[0m  begin transaction
2015-03-09 09:57:27 [D]   ESC[1mESC[36m (0.2ms)ESC[0m  ESC[1mUPDATE "users" SET "last_login_on" = '2015-03-09 09:57:27.507351', "updated_at" = '2015-03-09 09:57:27.507910' WHERE "users"."id" = 1ESC[0m
2015-03-09 09:57:27 [D]   ESC[1mESC[35mRole Load (0.1ms)ESC[0m  SELECT "roles".* FROM "roles" WHERE "roles"."name" = 'Anonymous' LIMIT 1
2015-03-09 09:57:27 [D]   ESC[1mESC[36m (0.1ms)ESC[0m  ESC[1mSELECT "roles".id FROM "roles" INNER JOIN "user_roles" ON "roles"."id" = "user_roles"."role_id" WHERE "user_roles"."owner_id" = 1 AND "user_roles"."owner_type" = 'User'ESC[0m
2015-03-09 09:57:27 [D]   ESC[1mESC[35m (81.0ms)ESC[0m  commit transaction
2015-03-09 09:57:27 [D]   ESC[1mESC[36mCACHE (0.0ms)ESC[0m  ESC[1mSELECT "roles".* FROM "roles" WHERE "roles"."name" = 'Anonymous' LIMIT 1ESC[0m
2015-03-09 09:57:27 [D]   ESC[1mESC[35mRole Exists (0.1ms)ESC[0m  SELECT 1 AS one FROM "roles" INNER JOIN "user_roles" ON "roles"."id" = "user_roles"."role_id" WHERE "user_roles"."owner_id" = 1 AND "user_roles"."owner_type" = 'User' AND "r
oles"."id" = 8 LIMIT 1
2015-03-09 09:57:27 [D] Setting current user thread-local variable to nil
2015-03-09 09:57:27 [D] Setting current user thread-local variable to admin
2015-03-09 09:57:27 [D]   ESC[1mESC[36mAuthSourceHidden Load (0.1ms)ESC[0m  ESC[1mSELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."type" IN ('AuthSourceHidden')ESC[0m
2015-03-09 09:57:27 [D]   ESC[1mESC[35mUser Load (0.1ms)ESC[0m  SELECT "users".* FROM "users" WHERE "users"."lower_login" = 'admin' AND (users.auth_source_id <> 2) ORDER BY firstname LIMIT 1
2015-03-09 09:57:27 [I] Authorized user admin(Admin User)
2015-03-09 09:57:27 [D] Setting current user thread-local variable to admin
2015-03-09 09:57:27 [E] undefined method `admin=' for nil:NilClass (NoMethodError)
/root/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:46:in `update_admin_flag'

Associated revisions

Revision 1b1b3986 (diff)
Added by Tomáš Strachota over 6 years ago

Fixes #9678 - Can't update admin flag for users via API

find_resource needs to be defined prior to UsersMixin is included as it
requires the variable @user being set.

Revision ff3aabbb (diff)
Added by Tomáš Strachota over 6 years ago

Fixes #9678 - Can't update admin flag for users via API

find_resource needs to be defined prior to UsersMixin is included as it
requires the variable @user being set.

(cherry picked from commit 1b1b39861e485523b0cc0c6435fef30c38df7e07)

History

#1 Updated by The Foreman Bot over 6 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2231 added
  • Pull request deleted ()

#2 Updated by Tomáš Strachota over 6 years ago

  • Bugzilla link set to 1199990

#3 Updated by Anonymous over 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF