From cf88f9dda13d15ab7f773f57c6e844691fd1a496 Mon Sep 17 00:00:00 2001 From: Himanshu Kapoor Date: Wed, 14 Aug 2019 15:25:40 +0530 Subject: [PATCH] Add new API method: projectUsers The new API method projectUsers gets all the users added to a particular project. --- app/assets/javascripts/api.js | 15 +++++++++++++ ...ers_select-vue-to-remove-approverusers.yml | 5 +++++ spec/frontend/api_spec.js | 22 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 changelogs/unreleased/ee-2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers.yml 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/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`;