From 36c6426a23bc54c7de27bd5c0eec76ee7c2fa287 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 28 Jul 2020 15:11:39 +0000 Subject: [PATCH] Include updated_on and passwd_changed_on columns in API response (#33592). Patch by vzvu 3k6k and Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@19940 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/users/index.api.rsb | 4 +++- app/views/users/show.api.rsb | 4 +++- test/integration/api_test/users_test.rb | 27 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/views/users/index.api.rsb b/app/views/users/index.api.rsb index 23e38398e..66b104f46 100644 --- a/app/views/users/index.api.rsb +++ b/app/views/users/index.api.rsb @@ -8,7 +8,9 @@ api.array :users, api_meta(:total_count => @user_count, :offset => @offset, :lim api.lastname user.lastname api.mail user.mail api.created_on user.created_on - api.last_login_on user.last_login_on + api.updated_on user.updated_on + api.last_login_on user.last_login_on + api.passwd_changed_on user.passwd_changed_on render_api_custom_values user.visible_custom_field_values, api end diff --git a/app/views/users/show.api.rsb b/app/views/users/show.api.rsb index 1a3041db3..3bc77e3be 100644 --- a/app/views/users/show.api.rsb +++ b/app/views/users/show.api.rsb @@ -6,7 +6,9 @@ api.user do api.lastname @user.lastname api.mail @user.mail if User.current.admin? || !@user.pref.hide_mail api.created_on @user.created_on - api.last_login_on @user.last_login_on + api.updated_on @user.updated_on + api.last_login_on @user.last_login_on + api.passwd_changed_on @user.passwd_changed_on api.api_key @user.api_key if User.current.admin? || (User.current == @user) api.status @user.status if User.current.admin? diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index 8320b4e0a..6322af2a1 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -28,7 +28,16 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_response :success assert_equal 'application/xml', response.media_type assert_select 'users' do - assert_select 'user', User.active.count + users = User.active.order('login') + assert_select 'user', :count => users.size do |nodeset| + nodeset.zip(users) do |user_element, user| + assert_select user_element, 'id', :text => user.id.to_s + assert_select user_element, 'updated_on', :text => user.updated_on.iso8601 + + # No one has changed password. + assert_select user_element, 'passwd_changed_on', :text => '' + end + end end end @@ -39,7 +48,17 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_equal 'application/json', response.media_type json = ActiveSupport::JSON.decode(response.body) assert json.key?('users') - assert_equal User.active.count, json['users'].size + + users = User.active.order('login') + assert_equal users.size, json['users'].size + + json['users'].zip(users) do |user_json, user| + assert_equal user.id, user_json['id'] + assert_equal user.updated_on.iso8601, user_json['updated_on'] + + # No one has changed password. + assert_nil user_json['passwd_changed_on'] + end end test "GET /users/:id.xml should return the user" do @@ -47,6 +66,8 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_response :success assert_select 'user id', :text => '2' + assert_select 'user updated_on', :text => '2006-07-19T20:42:15Z' + assert_select 'user passwd_changed_on', :text => '' end test "GET /users/:id.json should return the user" do @@ -57,6 +78,8 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_kind_of Hash, json assert_kind_of Hash, json['user'] assert_equal 2, json['user']['id'] + assert_equal '2006-07-19T20:42:15Z', json['user']['updated_on'] + assert_nil json['user']['passwd_changed_on'] end test "GET /users/:id.xml with include=memberships should include memberships" do -- 2.39.5