Project

General

Profile

Feature #34242 ยป feature-34242.patch

Mizuki ISHIKAWA, 2020-11-11 07:43

View differences:

app/views/users/index.api.rsb
11 11
      api.updated_on user.updated_on
12 12
      api.last_login_on     user.last_login_on
13 13
      api.passwd_changed_on user.passwd_changed_on
14
      api.twofa_scheme user.twofa_scheme
14 15

  
15 16
      render_api_custom_values user.visible_custom_field_values, api
16 17
    end
app/views/users/show.api.rsb
9 9
  api.updated_on @user.updated_on
10 10
  api.last_login_on     @user.last_login_on
11 11
  api.passwd_changed_on @user.passwd_changed_on
12
  api.twofa_scheme      @user.twofa_scheme
12 13
  api.api_key    @user.api_key if User.current.admin? || (User.current == @user)
13 14
  api.status     @user.status if User.current.admin?
14 15

  
test/integration/api_test/users_test.rb
23 23
  fixtures :users, :email_addresses, :members, :member_roles, :roles, :projects
24 24

  
25 25
  test "GET /users.xml should return users" do
26
    users = User.active.order('login')
27
    users.last.update(twofa_scheme: 'totp')
26 28
    get '/users.xml', :headers => credentials('admin')
27 29

  
28 30
    assert_response :success
29 31
    assert_equal 'application/xml', response.media_type
30 32
    assert_select 'users' do
31
      users = User.active.order('login')
32 33
      assert_select 'user', :count => users.size do |nodeset|
33 34
        nodeset.zip(users) do |user_element, user|
34 35
          assert_select user_element, 'id', :text => user.id.to_s
35 36
          assert_select user_element, 'updated_on', :text => user.updated_on.iso8601
37
          assert_select user_element, 'twofa_scheme', :text => user.twofa_scheme.to_s
36 38

  
37 39
          # No one has changed password.
38 40
          assert_select user_element, 'passwd_changed_on', :text => ''
41

  
42
          if user == users.last
43
            assert_select user_element, 'twofa_scheme', :text => 'totp'
44
          else
45
            assert_select user_element, 'twofa_scheme', :text => ''
46
          end
39 47
        end
40 48
      end
41 49
    end
42 50
  end
43 51

  
44 52
  test "GET /users.json should return users" do
53
    users = User.active.order('login')
54
    users.last.update(twofa_scheme: 'totp')
45 55
    get '/users.json', :headers => credentials('admin')
46 56

  
47 57
    assert_response :success
......
58 68

  
59 69
      # No one has changed password.
60 70
      assert_nil user_json['passwd_changed_on']
71

  
72
      if user == users.last
73
        assert_equal 'totp', user_json['twofa_scheme']
74
      else
75
        assert_nil user_json['twofa_scheme']
76
      end
61 77
    end
62 78
  end
63 79

  
......
68 84
    assert_select 'user id', :text => '2'
69 85
    assert_select 'user updated_on', :text => Time.zone.parse('2006-07-19T20:42:15Z').iso8601
70 86
    assert_select 'user passwd_changed_on', :text => ''
87
    assert_select 'user twofa_scheme', :text => ''
71 88
  end
72 89

  
73 90
  test "GET /users/:id.json should return the user" do
......
80 97
    assert_equal 2, json['user']['id']
81 98
    assert_equal Time.zone.parse('2006-07-19T20:42:15Z').iso8601, json['user']['updated_on']
82 99
    assert_nil json['user']['passwd_changed_on']
100
    assert_nil json['user']['twofa_scheme']
83 101
  end
84 102

  
85 103
  test "GET /users/:id.xml with include=memberships should include memberships" do
    (1-1/1)