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.

security-hotspots.ts 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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 { getJSON, post } from 'sonar-ui-common/helpers/request';
  21. import throwGlobalError from '../app/utils/throwGlobalError';
  22. import { BranchParameters } from '../types/branch-like';
  23. import {
  24. Hotspot,
  25. HotspotAssignRequest,
  26. HotspotResolution,
  27. HotspotSearchResponse,
  28. HotspotSetStatusRequest,
  29. HotspotStatus
  30. } from '../types/security-hotspots';
  31. export function assignSecurityHotspot(
  32. hotspotKey: string,
  33. data: HotspotAssignRequest
  34. ): Promise<void> {
  35. return post('/api/hotspots/assign', { hotspot: hotspotKey, ...data }).catch(throwGlobalError);
  36. }
  37. export function setSecurityHotspotStatus(
  38. hotspotKey: string,
  39. data: HotspotSetStatusRequest
  40. ): Promise<void> {
  41. return post('/api/hotspots/change_status', { hotspot: hotspotKey, ...data }).catch(
  42. throwGlobalError
  43. );
  44. }
  45. export function getSecurityHotspots(
  46. data: {
  47. projectKey: string;
  48. p: number;
  49. ps: number;
  50. status?: HotspotStatus;
  51. resolution?: HotspotResolution;
  52. onlyMine?: boolean;
  53. sinceLeakPeriod?: boolean;
  54. } & BranchParameters
  55. ): Promise<HotspotSearchResponse> {
  56. return getJSON('/api/hotspots/search', data).catch(throwGlobalError);
  57. }
  58. export function getSecurityHotspotList(
  59. hotspotKeys: string[],
  60. data: {
  61. projectKey: string;
  62. } & BranchParameters
  63. ): Promise<HotspotSearchResponse> {
  64. return getJSON('/api/hotspots/search', { ...data, hotspots: hotspotKeys.join() }).catch(
  65. throwGlobalError
  66. );
  67. }
  68. export function getSecurityHotspotDetails(securityHotspotKey: string): Promise<Hotspot> {
  69. return getJSON('/api/hotspots/show', { hotspot: securityHotspotKey })
  70. .then((response: Hotspot & { users: T.UserBase[] }) => {
  71. const { users, ...hotspot } = response;
  72. if (users) {
  73. if (hotspot.assignee) {
  74. hotspot.assigneeUser = users.find(u => u.login === hotspot.assignee) || {
  75. active: true,
  76. login: hotspot.assignee
  77. };
  78. }
  79. hotspot.authorUser = users.find(u => u.login === hotspot.author) || {
  80. active: true,
  81. login: hotspot.author
  82. };
  83. hotspot.comment.forEach(c => {
  84. c.user = users.find(u => u.login === c.login) || { active: true, login: c.login };
  85. });
  86. }
  87. return hotspot;
  88. })
  89. .catch(throwGlobalError);
  90. }