summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKushal Pandya <kushalspandya@gmail.com>2019-08-22 07:59:22 +0000
committerKushal Pandya <kushalspandya@gmail.com>2019-08-22 07:59:22 +0000
commit7b5708d1d944547dfea9bc8b6b8e1c6c6e22901b (patch)
tree4ca58265c0f350e8e22f3c62e2cd85899dab169d
parent11fd6bdf9972a9a890beb58ba48ebf2afe7d993c (diff)
parentcf88f9dda13d15ab7f773f57c6e844691fd1a496 (diff)
downloadgitlab-ce-7b5708d1d944547dfea9bc8b6b8e1c6c6e22901b.tar.gz
Merge branch 'ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers' into 'master'
Add a new method to `Api.js`: `projectUsers` See merge request gitlab-org/gitlab-ce!31801
-rw-r--r--app/assets/javascripts/api.js15
-rw-r--r--changelogs/unreleased/ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers.yml5
-rw-r--r--doc/api/projects.md1
-rw-r--r--lib/api/projects.rb2
-rw-r--r--spec/frontend/api_spec.js22
-rw-r--r--spec/requests/api/projects_spec.rb11
6 files changed, 56 insertions, 0 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js
index a649c521405..136ffdf8b9d 100644
--- a/app/assets/javascripts/api.js
+++ b/app/assets/javascripts/api.js
@@ -14,6 +14,7 @@ const Api = {
projectPath: '/api/:version/projects/:id',
forkedProjectsPath: '/api/:version/projects/:id/forks',
projectLabelsPath: '/:namespace_path/:project_path/-/labels',
+ projectUsersPath: '/api/:version/projects/:id/users',
projectMergeRequestsPath: '/api/:version/projects/:id/merge_requests',
projectMergeRequestPath: '/api/:version/projects/:id/merge_requests/:mrid',
projectMergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes',
@@ -108,6 +109,20 @@ const Api = {
});
},
+ projectUsers(projectPath, query = '', options = {}) {
+ const url = Api.buildUrl(this.projectUsersPath).replace(':id', encodeURIComponent(projectPath));
+
+ return axios
+ .get(url, {
+ params: {
+ search: query,
+ per_page: 20,
+ ...options,
+ },
+ })
+ .then(({ data }) => data);
+ },
+
// Return single project
project(projectPath) {
const url = Api.buildUrl(Api.projectPath).replace(':id', encodeURIComponent(projectPath));
diff --git a/changelogs/unreleased/ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers.yml b/changelogs/unreleased/ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers.yml
new file mode 100644
index 00000000000..dfa0f0cb593
--- /dev/null
+++ b/changelogs/unreleased/ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers.yml
@@ -0,0 +1,5 @@
+---
+title: 'Add new API method in Api.js: projectUsers'
+merge_request: 31801
+author:
+type: other
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 70df44ec0fd..373607f8f4b 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -855,6 +855,7 @@ GET /projects/:id/users
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `search` | string | no | Search for specific users |
+| `skip_users` | array[int] | no | Filter out users with the specified IDs |
```json
[
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 996205d4b7b..3073c14b341 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -489,11 +489,13 @@ module API
end
params do
optional :search, type: String, desc: 'Return list of users matching the search criteria'
+ optional :skip_users, type: Array[Integer], desc: 'Filter out users with the specified IDs'
use :pagination
end
get ':id/users' do
users = DeclarativePolicy.subject_scope { user_project.team.users }
users = users.search(params[:search]) if params[:search].present?
+ users = users.where_not_in(params[:skip_users]) if params[:skip_users].present?
present paginate(users), with: Entities::UserBasic
end
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js
index 7004373be0e..62ba0d36982 100644
--- a/spec/frontend/api_spec.js
+++ b/spec/frontend/api_spec.js
@@ -151,6 +151,28 @@ describe('Api', () => {
});
});
+ describe('projectUsers', () => {
+ it('fetches all users of a particular project', done => {
+ const query = 'dummy query';
+ const options = { unused: 'option' };
+ const projectPath = 'gitlab-org%2Fgitlab-ce';
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/users`;
+ mock.onGet(expectedUrl).reply(200, [
+ {
+ name: 'test',
+ },
+ ]);
+
+ Api.projectUsers('gitlab-org/gitlab-ce', query, options)
+ .then(response => {
+ expect(response.length).toBe(1);
+ expect(response[0].name).toBe('test');
+ })
+ .then(done)
+ .catch(done.fail);
+ });
+ });
+
describe('projectMergeRequests', () => {
const projectPath = 'abc';
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests`;
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 1d7ca85cdd2..5465fe0c366 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -1494,6 +1494,17 @@ describe API::Projects do
expect(response).to have_gitlab_http_status(404)
end
+
+ it 'filters out users listed in skip_users' do
+ other_user = create(:user)
+ project.team.add_developer(other_user)
+
+ get api("/projects/#{project.id}/users?skip_users=#{user.id}", user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(json_response.size).to eq(1)
+ expect(json_response[0]['id']).to eq(other_user.id)
+ end
end
end