]> source.dussan.org Git - redmine.git/commitdiff
Include auth_source in /users API response if request includes auth_source (#23307).
authorMarius Balteanu <marius.balteanu@zitec.com>
Wed, 31 Jan 2024 03:24:44 +0000 (03:24 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Wed, 31 Jan 2024 03:24:44 +0000 (03:24 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@22666 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/users/index.api.rsb
test/integration/api_test/users_test.rb

index 6ce38a58d7b48361feb0798739f7bf40105468f7..8dd376e2515af61e8a4523c4e73ca3e40352a01e 100644 (file)
@@ -15,6 +15,11 @@ api.array :users, api_meta(:total_count => @user_count, :offset => @offset, :lim
       api.twofa_scheme user.twofa_scheme
       api.status user.status
 
+      api.auth_source do
+        api.id user.auth_source.id
+        api.name user.auth_source.name
+      end if include_in_api_response?('auth_source') && user.auth_source.present?
+
       render_api_custom_values user.visible_custom_field_values, api
     end
   end
index 89d1f9f86719c9ca3cd3b70f07981e3c7c1edb18..88f39bf20b293d7d8115827d1bc9a9206c4477a2 100644 (file)
@@ -128,6 +128,25 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
     assert_equal 0, json['users'].size
   end
 
+  test "GET /users.json with include=auth_source" do
+    user = User.find(2)
+    user.update(:auth_source_id => 1)
+    get '/users.json?include=auth_source', :headers => credentials('admin')
+
+    json = ActiveSupport::JSON.decode(response.body)
+    assert json.key?('users')
+
+    json['users'].each do | user_json |
+      if user_json['id'] == user.id
+        assert_kind_of Hash, user_json['auth_source']
+        assert_equal user.auth_source.id, user_json['auth_source']['id']
+        assert_equal user.auth_source.name, user_json['auth_source']['name']
+      else
+        assert_nil user_json['auth_source']
+      end
+    end
+  end
+
   test "GET /users.json with short filters" do
     get '/users.json', headers: credentials('admin'), params: { status: "1|3" }
     assert_response :success