Commit 13477658 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '2502-refactor-ee-app-assets-javascripts-approvals-components-approvers_select-vue-to-remove-approverusers' into 'master'

Refactor `ee/app/assets/javascripts/approvals/components/approvers_select.vue` to remove `approverUsers`

Closes #2502

See merge request gitlab-org/gitlab-ee!15146
parents 0fdf0484 06f9cc6c
......@@ -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));
......
---
title: 'Add new API method in Api.js: projectUsers'
merge_request: 31801
author:
type: other
......@@ -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
[
......
......@@ -8,25 +8,6 @@ export default {
subscriptionPath: '/api/:version/namespaces/:id/gitlab_subscription',
childEpicPath: '/api/:version/groups/:id/epics/:epic_iid/epics',
approverUsers(search, options, callback = () => {}) {
const url = Api.buildUrl('/autocomplete/users.json');
return axios
.get(url, {
params: Object.assign(
{
search,
per_page: 20,
},
options,
),
})
.then(({ data }) => {
callback(data);
return data;
});
},
userSubscription(namespaceId) {
const url = Api.buildUrl(this.subscriptionPath).replace(':id', encodeURIComponent(namespaceId));
......
......@@ -136,9 +136,8 @@ export default {
});
},
fetchUsers(term) {
return Api.approverUsers(term, {
return Api.projectUsers(this.projectId, term, {
skip_users: this.skipUserIds,
project_id: this.projectId,
});
},
onChange() {
......
......@@ -74,7 +74,7 @@ describe('Approvals ApproversSelect', () => {
beforeEach(() => {
jasmine.clock().install();
spyOn(Api, 'groups').and.returnValue(Promise.resolve(TEST_GROUPS));
spyOn(Api, 'approverUsers').and.returnValue(Promise.resolve(TEST_USERS));
spyOn(Api, 'projectUsers').and.returnValue(Promise.resolve(TEST_USERS));
});
afterEach(() => {
......@@ -127,9 +127,8 @@ describe('Approvals ApproversSelect', () => {
});
it('fetches users', () => {
expect(Api.approverUsers).toHaveBeenCalledWith(term, {
expect(Api.projectUsers).toHaveBeenCalledWith(TEST_PROJECT_ID, term, {
skip_users: [],
project_id: TEST_PROJECT_ID,
});
});
});
......@@ -161,9 +160,8 @@ describe('Approvals ApproversSelect', () => {
});
it('skips users', () => {
expect(Api.approverUsers).toHaveBeenCalledWith('', {
expect(Api.projectUsers).toHaveBeenCalledWith(TEST_PROJECT_ID, '', {
skip_users: skipUserIds,
project_id: TEST_PROJECT_ID,
});
});
});
......
......@@ -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
......
......@@ -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`;
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment