diff --git a/doc/api/users.md b/doc/api/users.md index 228194f10faadde587cc2dbfcbffa2ae66ef1992..ac8fbe8492f9d590fea3a7af6e642b5eb5b117ac 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -190,7 +190,7 @@ GET /users ] ``` -Users on GitLab [Premium or higher](https://about.gitlab.com/pricing/) also see the `shared_runners_minutes_limit`, `extra_shared_runners_minutes_limit`, and `using_license_seat` parameters. +Users on GitLab [Premium or higher](https://about.gitlab.com/pricing/) also see the `shared_runners_minutes_limit`, `extra_shared_runners_minutes_limit`, `is_auditor`, and `using_license_seat` parameters. ```json [ @@ -199,6 +199,7 @@ Users on GitLab [Premium or higher](https://about.gitlab.com/pricing/) also see ... "shared_runners_minutes_limit": 133, "extra_shared_runners_minutes_limit": 133, + "is_auditor": false, "using_license_seat": true ... } @@ -359,12 +360,13 @@ NOTE: The `plan` and `trial` parameters are only available on GitLab Enterprise Edition. Users on GitLab [Premium or higher](https://about.gitlab.com/pricing/) also see -the `shared_runners_minutes_limit`, and `extra_shared_runners_minutes_limit` parameters. +the `shared_runners_minutes_limit`, `is_auditor`, and `extra_shared_runners_minutes_limit` parameters. ```json { "id": 1, "username": "john_smith", + "is_auditor": false, "shared_runners_minutes_limit": 133, "extra_shared_runners_minutes_limit": 133, ... @@ -628,6 +630,8 @@ GET /user } ``` +Users on GitLab [Premium or higher](https://about.gitlab.com/pricing/) also see the `shared_runners_minutes_limit`, `extra_shared_runners_minutes_limit`, `is_auditor`, and `using_license_seat` parameters. + ## User status Get the status of the currently signed in user. diff --git a/ee/changelogs/unreleased/expose-is-auditor.yml b/ee/changelogs/unreleased/expose-is-auditor.yml new file mode 100644 index 0000000000000000000000000000000000000000..4996c95774ca88bfe9ea50cb70786280e1f5fc35 --- /dev/null +++ b/ee/changelogs/unreleased/expose-is-auditor.yml @@ -0,0 +1,5 @@ +--- +title: Expose is_auditor user role via API +merge_request: 61058 +author: +type: changed diff --git a/ee/lib/ee/api/entities/user_with_admin.rb b/ee/lib/ee/api/entities/user_with_admin.rb index be7d9cc7e318c59fd808d29cab9b2ab2dba01707..6da3aadfa18e70470de61a1084940bae68cfa79c 100644 --- a/ee/lib/ee/api/entities/user_with_admin.rb +++ b/ee/lib/ee/api/entities/user_with_admin.rb @@ -8,6 +8,7 @@ module UserWithAdmin prepended do expose :using_license_seat?, as: :using_license_seat + expose :auditor, as: :is_auditor, if: ->(_instance, _opts) { ::License.feature_available?(:auditor_user) } end end end diff --git a/ee/spec/lib/ee/api/entities/user_with_admin_spec.rb b/ee/spec/lib/ee/api/entities/user_with_admin_spec.rb index 3b63b8ddb254220af7086a8331c86a551d013525..58dd8f3d63ee2d27fb8ac431b71216c3b07de21f 100644 --- a/ee/spec/lib/ee/api/entities/user_with_admin_spec.rb +++ b/ee/spec/lib/ee/api/entities/user_with_admin_spec.rb @@ -23,4 +23,30 @@ end end end + + context 'is_auditor' do + context 'when auditor_user is available' do + it 'returns false when user is not an auditor' do + expect(subject[:is_auditor]).to be false + end + + context 'when user is an auditor' do + let(:user) { create(:user, :auditor) } + + it 'returns true' do + expect(subject[:is_auditor]).to be true + end + end + end + + context 'when auditor_user is not available' do + before do + stub_licensed_features(auditor_user: false) + end + + it 'does not have the is_auditor param' do + expect(subject[:is_auditor]).to be nil + end + end + end end diff --git a/ee/spec/requests/api/users_spec.rb b/ee/spec/requests/api/users_spec.rb index f8cc250f85889d10a0ef4dc6603f54c831d60d00..2e1179dc317a06e1db2aef9c3c370ecf89d8e5c2 100644 --- a/ee/spec/requests/api/users_spec.rb +++ b/ee/spec/requests/api/users_spec.rb @@ -197,6 +197,12 @@ expect(json_response).to include('plan' => 'ultimate', 'trial' => true) end end + + it 'contains is_auditor parameter' do + get api("/users/#{user.id}", admin) + + expect(json_response).to have_key('is_auditor') + end end context 'and user has no plan' do @@ -215,6 +221,12 @@ expect(json_response).not_to have_key('plan') expect(json_response).not_to have_key('trial') end + + it 'does not contain is_auditor parameter' do + get api("/users/#{user.id}", user) + + expect(json_response).not_to have_key('is_auditor') + end end end