You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import throwGlobalError from '../app/utils/throwGlobalError';
  21. import { getJSON, post, postJSON } from '../helpers/request';
  22. export function getCurrentUser(): Promise<T.CurrentUser> {
  23. return getJSON('/api/users/current');
  24. }
  25. export function changePassword(data: {
  26. login: string;
  27. password: string;
  28. previousPassword?: string;
  29. }) {
  30. return post('/api/users/change_password', data).catch(throwGlobalError);
  31. }
  32. export interface UserGroup {
  33. default: boolean;
  34. description: string;
  35. id: number;
  36. name: string;
  37. selected: boolean;
  38. }
  39. export function getUserGroups(data: {
  40. login: string;
  41. p?: number;
  42. ps?: number;
  43. q?: string;
  44. selected?: string;
  45. }): Promise<{ paging: T.Paging; groups: UserGroup[] }> {
  46. return getJSON('/api/users/groups', data);
  47. }
  48. export function getIdentityProviders(): Promise<{ identityProviders: T.IdentityProvider[] }> {
  49. return getJSON('/api/users/identity_providers').catch(throwGlobalError);
  50. }
  51. export function searchUsers(data: {
  52. p?: number;
  53. ps?: number;
  54. q?: string;
  55. }): Promise<{ paging: T.Paging; users: T.User[] }> {
  56. data.q = data.q || undefined;
  57. return getJSON('/api/users/search', data).catch(throwGlobalError);
  58. }
  59. export function createUser(data: {
  60. email?: string;
  61. local?: boolean;
  62. login: string;
  63. name: string;
  64. password?: string;
  65. scmAccount: string[];
  66. }): Promise<void | Response> {
  67. return post('/api/users/create', data);
  68. }
  69. export function updateUser(data: {
  70. email?: string;
  71. login: string;
  72. name?: string;
  73. scmAccount: string[];
  74. }): Promise<T.User> {
  75. return postJSON('/api/users/update', {
  76. ...data,
  77. scmAccount: data.scmAccount.length > 0 ? data.scmAccount : ''
  78. });
  79. }
  80. export function deactivateUser(data: { login: string }): Promise<T.User> {
  81. return postJSON('/api/users/deactivate', data).catch(throwGlobalError);
  82. }
  83. export function setHomePage(homepage: T.HomePage): Promise<void | Response> {
  84. return post('/api/users/set_homepage', homepage).catch(throwGlobalError);
  85. }
  86. export function setUserSetting(setting: T.CurrentUserSetting): Promise<void | Response> {
  87. return post('/api/users/set_setting', setting).catch(throwGlobalError);
  88. }