summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/settings/api/access_dropdown_api.js
blob: 10f6c28a7bf1ba236a6f9903e763ef9aa648a3e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import axios from '~/lib/utils/axios_utils';

const USERS_PATH = '/-/autocomplete/users.json';
const GROUPS_PATH = '/-/autocomplete/project_groups.json';
const DEPLOY_KEYS_PATH = '/-/autocomplete/deploy_keys_with_owners.json';

const buildUrl = (urlRoot, url) => {
  let newUrl;
  if (urlRoot != null) {
    newUrl = urlRoot.replace(/\/$/, '') + url;
  }
  return newUrl;
};

export const getUsers = (query) => {
  return axios.get(buildUrl(gon.relative_url_root || '', USERS_PATH), {
    params: {
      search: query,
      per_page: 20,
      active: true,
      project_id: gon.current_project_id,
      push_code: true,
    },
  });
};

export const getGroups = () => {
  return axios.get(buildUrl(gon.relative_url_root || '', GROUPS_PATH), {
    params: {
      project_id: gon.current_project_id,
    },
  });
};

export const getDeployKeys = (query) => {
  return axios.get(buildUrl(gon.relative_url_root || '', DEPLOY_KEYS_PATH), {
    params: {
      search: query,
      per_page: 20,
      active: true,
      project_id: gon.current_project_id,
      push_code: true,
    },
  });
};