From: Stas Vilchik Date: Fri, 18 Aug 2017 17:28:04 +0000 (+0200) Subject: translate api/ to ts X-Git-Tag: 6.6-RC1~568 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b6f7557b705bee15f1b86d325b58dbc539a22245;p=sonarqube.git translate api/ to ts --- diff --git a/server/sonar-web/src/main/js/api/application.js b/server/sonar-web/src/main/js/api/application.js deleted file mode 100644 index 5aed51768a1..00000000000 --- a/server/sonar-web/src/main/js/api/application.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -/*:: -type GetApplicationLeakResponse = Array<{ - date: string, - project: string, - projectName: string -}>; -*/ - -export function getApplicationLeak( - application /*: string */ -) /*: Promise */ { - return getJSON('/api/views/show_leak', { application }).then(r => r.leaks, throwGlobalError); -} diff --git a/server/sonar-web/src/main/js/api/application.ts b/server/sonar-web/src/main/js/api/application.ts new file mode 100644 index 00000000000..c6bce86fbd6 --- /dev/null +++ b/server/sonar-web/src/main/js/api/application.ts @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +export interface IApplicationLeak { + date: string; + project: string; + projectName: string; +} + +export function getApplicationLeak(application: string): Promise> { + return getJSON('/api/views/show_leak', { application }).then(r => r.leaks, throwGlobalError); +} diff --git a/server/sonar-web/src/main/js/api/auth.js b/server/sonar-web/src/main/js/api/auth.js deleted file mode 100644 index 801e37189af..00000000000 --- a/server/sonar-web/src/main/js/api/auth.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { request } from '../helpers/request'; - -const basicCheckStatus = response => { - if (response.status >= 200 && response.status < 300) { - return response; - } else { - const error = new Error(response.status); - error.response = response; - throw error; - } -}; - -export const login = (login, password) => - request('/api/authentication/login') - .setMethod('POST') - .setData({ login, password }) - .submit() - .then(basicCheckStatus); - -export const logout = () => - request('/api/authentication/logout').setMethod('POST').submit().then(basicCheckStatus); diff --git a/server/sonar-web/src/main/js/api/auth.ts b/server/sonar-web/src/main/js/api/auth.ts new file mode 100644 index 00000000000..0c95f699127 --- /dev/null +++ b/server/sonar-web/src/main/js/api/auth.ts @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { request } from '../helpers/request'; + +export function login(login: string, password: string): Promise { + return request('/api/authentication/login') + .setMethod('POST') + .setData({ login, password }) + .submit() + .then(basicCheckStatus); +} + +export function logout(): Promise { + return request('/api/authentication/logout').setMethod('POST').submit().then(basicCheckStatus); +} + +function basicCheckStatus(response: Response): Promise { + if (response.status >= 200 && response.status < 300) { + return Promise.resolve(response); + } else { + return Promise.reject(response); + } +} diff --git a/server/sonar-web/src/main/js/api/ce.js b/server/sonar-web/src/main/js/api/ce.js deleted file mode 100644 index 3c426b0d0e6..00000000000 --- a/server/sonar-web/src/main/js/api/ce.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, post } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -export function getActivity(data /*: ?Object */) /*: Promise<*> */ { - return getJSON('/api/ce/activity', data); -} - -export function getStatus(componentId /*: ?string */) /*: Promise<*> */ { - const data = {}; - if (componentId) { - Object.assign(data, { componentId }); - } - return getJSON('/api/ce/activity_status', data); -} - -export function getTask( - id /*: string */, - additionalFields /*: ?Array */ -) /*: Promise<*> */ { - return getJSON('/api/ce/task', { id, additionalFields }).then(r => r.task); -} - -export function cancelTask(id /*: string */) /*: Promise<*> */ { - return post('/api/ce/cancel', { id }).then(() => getTask(id), () => getTask(id)); -} - -export function cancelAllTasks() /*: Promise<*> */ { - return post('/api/ce/cancel_all'); -} - -export function getTasksForComponent(componentKey /*: string */) /*: Promise<*> */ { - return getJSON('/api/ce/component', { componentKey }); -} - -export function getTypes() /*: Promise<*> */ { - return getJSON('/api/ce/task_types').then(r => r.taskTypes); -} - -export function getWorkers() /*: Promise<{ canSetWorkerCount: boolean, value: number }> */ { - return getJSON('/api/ce/worker_count').catch(throwGlobalError); -} - -export function setWorkerCount(count /*: number */) /*: Promise */ { - return post('/api/ce/set_worker_count', { count }).catch(throwGlobalError); -} diff --git a/server/sonar-web/src/main/js/api/ce.ts b/server/sonar-web/src/main/js/api/ce.ts new file mode 100644 index 00000000000..c0146360ada --- /dev/null +++ b/server/sonar-web/src/main/js/api/ce.ts @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +export function getActivity(data: RequestData): Promise { + return getJSON('/api/ce/activity', data); +} + +export function getStatus(componentId?: string): Promise { + const data = {}; + if (componentId) { + Object.assign(data, { componentId }); + } + return getJSON('/api/ce/activity_status', data); +} + +export function getTask(id: string, additionalFields?: string[]): Promise { + return getJSON('/api/ce/task', { id, additionalFields }).then(r => r.task); +} + +export function cancelTask(id: string): Promise { + return post('/api/ce/cancel', { id }).then(() => getTask(id), () => getTask(id)); +} + +export function cancelAllTasks(): Promise { + return post('/api/ce/cancel_all'); +} + +export function getTasksForComponent(componentKey: string): Promise { + return getJSON('/api/ce/component', { componentKey }); +} + +export function getTypes(): Promise { + return getJSON('/api/ce/task_types').then(r => r.taskTypes); +} + +export function getWorkers(): Promise<{ canSetWorkerCount: boolean; value: number } | Response> { + return getJSON('/api/ce/worker_count').catch(throwGlobalError); +} + +export function setWorkerCount(count: number): Promise { + return post('/api/ce/set_worker_count', { count }).catch(throwGlobalError); +} diff --git a/server/sonar-web/src/main/js/api/components.js b/server/sonar-web/src/main/js/api/components.js deleted file mode 100644 index 50f87afea82..00000000000 --- a/server/sonar-web/src/main/js/api/components.js +++ /dev/null @@ -1,252 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, postJSON, post } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -export function getComponents(data /*: ?Object */) { - const url = '/api/projects/search'; - return getJSON(url, data); -} - -export function getProvisioned(data /*: ?Object */) { - const url = '/api/projects/provisioned'; - return getJSON(url, data); -} - -export function getGhosts(data /*: ?Object */) { - const url = '/api/projects/ghosts'; - return getJSON(url, data); -} - -export function deleteComponents(data /*: { projects: string, organization?: string } */) { - const url = '/api/projects/bulk_delete'; - return post(url, data); -} - -export function deleteProject(project /*: string */) { - const url = '/api/projects/delete'; - const data = { project }; - return post(url, data); -} - -export function createProject( - data /*: { - branch?: string, - name: string, - project: string, - organization?: string -} */ -) { - const url = '/api/projects/create'; - return postJSON(url, data).catch(throwGlobalError); -} - -export function searchProjectTags(data /*: ?{ ps?: number, q?: string } */) { - const url = '/api/project_tags/search'; - return getJSON(url, data); -} - -export function setProjectTags(data /*: { project: string, tags: string } */) { - const url = '/api/project_tags/set'; - return post(url, data); -} - -export function getComponentTree( - strategy /*: string */, - componentKey /*: string */, - metrics /*: Array */ = [], - additional /*: ?Object */ = {} -) { - const url = '/api/measures/component_tree'; - const data = Object.assign({}, additional, { - baseComponentKey: componentKey, - metricKeys: metrics.join(','), - strategy - }); - return getJSON(url, data); -} - -export function getChildren( - componentKey /*: string */, - metrics /*: Array | void */, - additional /*: ?Object */ -) { - return getComponentTree('children', componentKey, metrics, additional); -} - -export function getComponentLeaves( - componentKey /*: string */, - metrics /*: Array | void */, - additional /*: ?Object */ -) { - return getComponentTree('leaves', componentKey, metrics, additional); -} - -export function getComponent(componentKey /*: string */, metrics /*: Array */ = []) { - const url = '/api/measures/component'; - const data = { componentKey, metricKeys: metrics.join(',') }; - return getJSON(url, data).then(r => r.component); -} - -export function getTree(component /*: string */, options /*: ?Object */ = {}) { - const url = '/api/components/tree'; - const data = { ...options, component }; - return getJSON(url, data); -} - -export function getComponentShow(component /*: string */) { - const url = '/api/components/show'; - return getJSON(url, { component }); -} - -export function getParents(component /*: string */) { - return getComponentShow(component).then(r => r.ancestors); -} - -export function getBreadcrumbs(component /*: string */) { - return getComponentShow(component).then(r => { - const reversedAncestors = [...r.ancestors].reverse(); - return [...reversedAncestors, r.component]; - }); -} - -export function getComponentData(component /*: string */) { - return getComponentShow(component).then(r => r.component); -} - -export function getMyProjects(data /*: ?Object */) { - const url = '/api/projects/search_my_projects'; - return getJSON(url, data); -} - -export function searchProjects(data /*: ?Object */) { - const url = '/api/components/search_projects'; - return getJSON(url, data); -} - -export function searchComponents(data /*: ?{ q?: string, qualifiers?: string, ps?: number } */) { - return getJSON('/api/components/search', data); -} - -/** - * Change component's key - * @param {string} from - * @param {string} to - * @returns {Promise} - */ -export function changeKey(from /*: string */, to /*: string */) { - const url = '/api/projects/update_key'; - const data = { from, to }; - return post(url, data); -} - -/** - * Bulk change component's key - * @param {string} project - * @param {string} from - * @param {string} to - * @param {boolean} dryRun - * @returns {Promise} - */ -export function bulkChangeKey( - project /*: string */, - from /*: string */, - to /*: string */, - dryRun /*: ?boolean */ = false -) { - const url = '/api/projects/bulk_update_key'; - const data = { project, from, to, dryRun }; - return postJSON(url, data); -} - -/*:: -export type SuggestionsResponse = { - organizations: Array<{ - key: string, - name: string - }>, - projects: Array<{ - key: string, - name: string - }>, - results: Array<{ - items: Array<{ - isFavorite: boolean, - isRecentlyBrowsed: boolean, - key: string, - match: string, - name: string, - organization: string, - project: string - }>, - more: number, - q: string - }>, - warning?: string -}; -*/ - -export function getSuggestions( - query /*: ?string */, - recentlyBrowsed /*: ?Array */, - more /*: ?string */ -) /*: Promise */ { - const data /*: Object */ = {}; - if (query) { - data.s = query; - } - if (recentlyBrowsed) { - data.recentlyBrowsed = recentlyBrowsed.join(); - } - if (more) { - data.more = more; - } - return getJSON('/api/components/suggestions', data); -} - -export function getComponentForSourceViewer(component /*: string */) /*: Promise<*> */ { - return getJSON('/api/components/app', { component }); -} - -export function getSources( - component /*: string */, - from /*: ?number */, - to /*: ?number */ -) /*: Promise> */ { - const data /*: Object */ = { key: component }; - if (from) { - Object.assign(data, { from }); - } - if (to) { - Object.assign(data, { to }); - } - return getJSON('/api/sources/lines', data).then(r => r.sources); -} - -export function getDuplications(component /*: string */) /*: Promise<*> */ { - return getJSON('/api/duplications/show', { key: component }); -} - -export function getTests(component /*: string */, line /*: number | string */) /*: Promise<*> */ { - return getJSON('/api/tests/list', { sourceFileKey: component, sourceFileLineNumber: line }).then( - r => r.tests - ); -} diff --git a/server/sonar-web/src/main/js/api/components.ts b/server/sonar-web/src/main/js/api/components.ts new file mode 100644 index 00000000000..5cd527da6ad --- /dev/null +++ b/server/sonar-web/src/main/js/api/components.ts @@ -0,0 +1,219 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, postJSON, post, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +export function getComponents(data: RequestData): Promise { + return getJSON('/api/projects/search', data); +} + +export function getProvisioned(data: RequestData): Promise { + return getJSON('/api/projects/provisioned', data); +} + +export function getGhosts(data: RequestData): Promise { + return getJSON('/api/projects/ghosts', data); +} + +export function deleteComponents(data: { projects: string; organization?: string }): Promise { + return post('/api/projects/bulk_delete', data); +} + +export function deleteProject(project: string): Promise { + return post('/api/projects/delete', { project }); +} + +export function createProject(data: { + branch?: string; + name: string; + project: string; + organization?: string; +}): Promise { + return postJSON('/api/projects/create', data).catch(throwGlobalError); +} + +export function searchProjectTags(data?: { ps?: number; q?: string }): Promise { + return getJSON('/api/project_tags/search', data); +} + +export function setProjectTags(data: { project: string; tags: string }): Promise { + return post('/api/project_tags/set', data); +} + +export function getComponentTree( + strategy: string, + componentKey: string, + metrics: string[] = [], + additional: RequestData = {} +): Promise { + const url = '/api/measures/component_tree'; + const data = Object.assign({}, additional, { + baseComponentKey: componentKey, + metricKeys: metrics.join(','), + strategy + }); + return getJSON(url, data); +} + +export function getChildren( + componentKey: string, + metrics: string[] = [], + additional: RequestData = {} +): Promise { + return getComponentTree('children', componentKey, metrics, additional); +} + +export function getComponentLeaves( + componentKey: string, + metrics: string[] = [], + additional: RequestData = {} +): Promise { + return getComponentTree('leaves', componentKey, metrics, additional); +} + +export function getComponent(componentKey: string, metrics: string[] = []): Promise { + const data = { componentKey, metricKeys: metrics.join(',') }; + return getJSON('/api/measures/component', data).then(r => r.component); +} + +export function getTree(component: string, options: RequestData = {}): Promise { + return getJSON('/api/components/tree', { ...options, component }); +} + +export function getComponentShow(component: string): Promise { + return getJSON('/api/components/show', { component }); +} + +export function getParents(component: string): Promise { + return getComponentShow(component).then(r => r.ancestors); +} + +export function getBreadcrumbs(component: string): Promise { + return getComponentShow(component).then(r => { + const reversedAncestors = [...r.ancestors].reverse(); + return [...reversedAncestors, r.component]; + }); +} + +export function getComponentData(component: string): Promise { + return getComponentShow(component).then(r => r.component); +} + +export function getMyProjects(data: RequestData): Promise { + const url = '/api/projects/search_my_projects'; + return getJSON(url, data); +} + +export function searchProjects(data: RequestData): Promise { + const url = '/api/components/search_projects'; + return getJSON(url, data); +} + +export function searchComponents(data?: { + q?: string; + qualifiers?: string; + ps?: number; +}): Promise { + return getJSON('/api/components/search', data); +} + +/** + * Change component's key + */ +export function changeKey(from: string, to: string): Promise { + const url = '/api/projects/update_key'; + const data = { from, to }; + return post(url, data); +} + +/** + * Bulk change component's key + */ +export function bulkChangeKey( + project: string, + from: string, + to: string, + dryRun: boolean = false +): Promise { + const url = '/api/projects/bulk_update_key'; + const data = { project, from, to, dryRun }; + return postJSON(url, data); +} + +export interface ISuggestionsResponse { + organizations: Array<{ key: string; name: string }>; + projects: Array<{ key: string; name: string }>; + results: Array<{ + items: Array<{ + isFavorite: boolean; + isRecentlyBrowsed: boolean; + key: string; + match: string; + name: string; + organization: string; + project: string; + }>; + more: number; + q: string; + }>; + warning?: string; +} + +export function getSuggestions( + query?: string, + recentlyBrowsed?: string[], + more?: string +): Promise { + const data: RequestData = {}; + if (query) { + data.s = query; + } + if (recentlyBrowsed) { + data.recentlyBrowsed = recentlyBrowsed.join(); + } + if (more) { + data.more = more; + } + return getJSON('/api/components/suggestions', data); +} + +export function getComponentForSourceViewer(component: string): Promise { + return getJSON('/api/components/app', { component }); +} + +export function getSources(component: string, from?: number, to?: number): Promise { + const data: RequestData = { key: component }; + if (from) { + Object.assign(data, { from }); + } + if (to) { + Object.assign(data, { to }); + } + return getJSON('/api/sources/lines', data).then(r => r.sources); +} + +export function getDuplications(component: string): Promise { + return getJSON('/api/duplications/show', { key: component }); +} + +export function getTests(component: string, line: number | string): Promise { + const data = { sourceFileKey: component, sourceFileLineNumber: line }; + return getJSON('/api/tests/list', data).then(r => r.tests); +} diff --git a/server/sonar-web/src/main/js/api/favorites.js b/server/sonar-web/src/main/js/api/favorites.js deleted file mode 100644 index 4b2683dcc59..00000000000 --- a/server/sonar-web/src/main/js/api/favorites.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/* @flow */ -import { post, getJSON } from '../helpers/request'; - -export function getFavorites() /*: Promise */ { - return getJSON('/api/favorites/search'); -} - -export function addFavorite(component /*: string */) { - return post('/api/favorites/add', { component }); -} - -export function removeFavorite(component /*: string */) { - return post('/api/favorites/remove', { component }); -} diff --git a/server/sonar-web/src/main/js/api/favorites.ts b/server/sonar-web/src/main/js/api/favorites.ts new file mode 100644 index 00000000000..40a097f9503 --- /dev/null +++ b/server/sonar-web/src/main/js/api/favorites.ts @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { post, getJSON } from '../helpers/request'; + +export function getFavorites(): Promise { + return getJSON('/api/favorites/search'); +} + +export function addFavorite(component: string): Promise { + return post('/api/favorites/add', { component }); +} + +export function removeFavorite(component: string): Promise { + return post('/api/favorites/remove', { component }); +} diff --git a/server/sonar-web/src/main/js/api/issue-filters.js b/server/sonar-web/src/main/js/api/issue-filters.js deleted file mode 100644 index a5336c2dbe2..00000000000 --- a/server/sonar-web/src/main/js/api/issue-filters.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { post } from '../helpers/request'; - -export function toggleIssueFilter(id) { - const url = '/issues/toggle_fav'; - const data = { id }; - return post(url, data); -} diff --git a/server/sonar-web/src/main/js/api/issue-filters.ts b/server/sonar-web/src/main/js/api/issue-filters.ts new file mode 100644 index 00000000000..711a29de47a --- /dev/null +++ b/server/sonar-web/src/main/js/api/issue-filters.ts @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { post } from '../helpers/request'; + +export function toggleIssueFilter(id: string): Promise { + return post('/issues/toggle_fav', { id }); +} diff --git a/server/sonar-web/src/main/js/api/issues.js b/server/sonar-web/src/main/js/api/issues.js deleted file mode 100644 index 468df8c5da9..00000000000 --- a/server/sonar-web/src/main/js/api/issues.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, post, postJSON } from '../helpers/request'; - -/*:: -export type IssueResponse = { - components?: Array<*>, - issue: {}, - rules?: Array<*>, - users?: Array<*> -}; -*/ - -/*:: -type IssuesResponse = { - components?: Array<*>, - debtTotal?: number, - facets: Array<*>, - issues: Array<*>, - paging: { - pageIndex: number, - pageSize: number, - total: number - }, - rules?: Array<*>, - users?: Array<*> -}; -*/ - -export function searchIssues(query /*: {} */) /*: Promise */ { - return getJSON('/api/issues/search', query); -} - -export function getFacets(query /*: {} */, facets /*: Array */) /*: Promise<*> */ { - const data = { - ...query, - facets: facets.join(), - ps: 1, - additionalFields: '_all' - }; - return searchIssues(data).then(r => { - return { facets: r.facets, response: r }; - }); -} - -export function getFacet(query /*: {} */, facet /*: string */) /*: Promise<*> */ { - return getFacets(query, [facet]).then(r => { - return { facet: r.facets[0].values, response: r.response }; - }); -} - -export function getSeverities(query /*: {} */) /*: Promise<*> */ { - return getFacet(query, 'severities').then(r => r.facet); -} - -export function getTags(query /*: {} */) /*: Promise<*> */ { - return getFacet(query, 'tags').then(r => r.facet); -} - -export function extractAssignees( - facet /*: Array<{ val: string }> */, - response /*: IssuesResponse */ -) { - return facet.map(item => { - const user = response.users ? response.users.find(user => user.login === item.val) : null; - return { ...item, user }; - }); -} - -export function getAssignees(query /*: {} */) /*: Promise<*> */ { - return getFacet(query, 'assignees').then(r => extractAssignees(r.facet, r.response)); -} - -export function getIssuesCount(query /*: {} */) /*: Promise<*> */ { - const data = { ...query, ps: 1, facetMode: 'effort' }; - return searchIssues(data).then(r => { - return { issues: r.paging.total, debt: r.debtTotal }; - }); -} - -export function searchIssueTags( - data /*: { organization?: string, ps?: number, q?: string } */ = { ps: 500 } -) /*: Promise> */ { - return getJSON('/api/issues/tags', data).then(r => r.tags); -} - -export function getIssueChangelog(issue /*: string */) /*: Promise<*> */ { - const url = '/api/issues/changelog'; - return getJSON(url, { issue }).then(r => r.changelog); -} - -export function getIssueFilters() { - const url = '/api/issue_filters/search'; - return getJSON(url).then(r => r.issueFilters); -} - -export function addIssueComment( - data /*: { issue: string, text: string } */ -) /*: Promise */ { - const url = '/api/issues/add_comment'; - return postJSON(url, data); -} - -export function deleteIssueComment(data /*: { comment: string } */) /*: Promise */ { - const url = '/api/issues/delete_comment'; - return postJSON(url, data); -} - -export function editIssueComment( - data /*: { comment: string, text: string } */ -) /*: Promise */ { - const url = '/api/issues/edit_comment'; - return postJSON(url, data); -} - -export function setIssueAssignee( - data /*: { - issue: string, - assignee?: string -} */ -) /*: Promise */ { - const url = '/api/issues/assign'; - return postJSON(url, data); -} - -export function setIssueSeverity( - data /*: { issue: string, severity: string } */ -) /*: Promise<*> */ { - const url = '/api/issues/set_severity'; - return postJSON(url, data); -} - -export function setIssueTags( - data /*: { issue: string, tags: string } */ -) /*: Promise */ { - const url = '/api/issues/set_tags'; - return postJSON(url, data); -} - -export function setIssueTransition( - data /*: { - issue: string, - transition: string -} */ -) /*: Promise */ { - const url = '/api/issues/do_transition'; - return postJSON(url, data); -} - -export function setIssueType( - data /*: { issue: string, type: string } */ -) /*: Promise */ { - const url = '/api/issues/set_type'; - return postJSON(url, data); -} - -export function bulkChangeIssues(issueKeys /*: Array */, query /*: {} */) { - return post('/api/issues/bulk_change', { - issues: issueKeys.join(), - ...query - }); -} diff --git a/server/sonar-web/src/main/js/api/issues.ts b/server/sonar-web/src/main/js/api/issues.ts new file mode 100644 index 00000000000..57c14fc109c --- /dev/null +++ b/server/sonar-web/src/main/js/api/issues.ts @@ -0,0 +1,145 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, postJSON, RequestData } from '../helpers/request'; + +export interface IssueResponse { + components?: Array<{}>; + issue: {}; + rules?: Array<{}>; + users?: Array<{}>; +} + +interface IssuesResponse { + components?: Array<{}>; + debtTotal?: number; + facets: Array<{}>; + issues: Array<{}>; + paging: { + pageIndex: number; + pageSize: number; + total: number; + }; + rules?: Array<{}>; + users?: Array<{ login: string }>; +} + +export function searchIssues(query: RequestData): Promise { + return getJSON('/api/issues/search', query); +} + +export function getFacets(query: RequestData, facets: string[]): Promise { + const data = { + ...query, + facets: facets.join(), + ps: 1, + additionalFields: '_all' + }; + return searchIssues(data).then(r => { + return { facets: r.facets, response: r }; + }); +} + +export function getFacet(query: RequestData, facet: string): Promise { + return getFacets(query, [facet]).then(r => { + return { facet: r.facets[0].values, response: r.response }; + }); +} + +export function getSeverities(query: RequestData): Promise { + return getFacet(query, 'severities').then(r => r.facet); +} + +export function getTags(query: RequestData): Promise { + return getFacet(query, 'tags').then(r => r.facet); +} + +export function extractAssignees(facet: Array<{ val: string }>, response: IssuesResponse): any { + return facet.map(item => { + const user = response.users ? response.users.find(user => user.login === item.val) : null; + return { ...item, user }; + }); +} + +export function getAssignees(query: RequestData): Promise { + return getFacet(query, 'assignees').then(r => extractAssignees(r.facet, r.response)); +} + +export function getIssuesCount(query: RequestData): Promise { + const data = { ...query, ps: 1, facetMode: 'effort' }; + return searchIssues(data).then(r => { + return { issues: r.paging.total, debt: r.debtTotal }; + }); +} + +export function searchIssueTags( + data: { organization?: string; ps?: number; q?: string } = { ps: 500 } +): Promise { + return getJSON('/api/issues/tags', data).then(r => r.tags); +} + +export function getIssueChangelog(issue: string): Promise { + return getJSON('/api/issues/changelog', { issue }).then(r => r.changelog); +} + +export function getIssueFilters() { + return getJSON('/api/issue_filters/search').then(r => r.issueFilters); +} + +export function addIssueComment(data: { issue: string; text: string }): Promise { + return postJSON('/api/issues/add_comment', data); +} + +export function deleteIssueComment(data: { comment: string }): Promise { + return postJSON('/api/issues/delete_comment', data); +} + +export function editIssueComment(data: { comment: string; text: string }): Promise { + return postJSON('/api/issues/edit_comment', data); +} + +export function setIssueAssignee(data: { + issue: string; + assignee?: string; +}): Promise { + return postJSON('/api/issues/assign', data); +} + +export function setIssueSeverity(data: { issue: string; severity: string }): Promise { + return postJSON('/api/issues/set_severity', data); +} + +export function setIssueTags(data: { issue: string; tags: string }): Promise { + return postJSON('/api/issues/set_tags', data); +} + +export function setIssueTransition(data: { + issue: string; + transition: string; +}): Promise { + return postJSON('/api/issues/do_transition', data); +} + +export function setIssueType(data: { issue: string; type: string }): Promise { + return postJSON('/api/issues/set_type', data); +} + +export function bulkChangeIssues(issueKeys: string[], query: RequestData): Promise { + return post('/api/issues/bulk_change', { issues: issueKeys.join(), ...query }); +} diff --git a/server/sonar-web/src/main/js/api/languages.js b/server/sonar-web/src/main/js/api/languages.js deleted file mode 100644 index 5f58849b1ed..00000000000 --- a/server/sonar-web/src/main/js/api/languages.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON } from '../helpers/request'; - -export function getLanguages() { - const url = '/api/languages/list'; - return getJSON(url).then(r => r.languages); -} diff --git a/server/sonar-web/src/main/js/api/languages.ts b/server/sonar-web/src/main/js/api/languages.ts new file mode 100644 index 00000000000..ee5bd130a5e --- /dev/null +++ b/server/sonar-web/src/main/js/api/languages.ts @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; + +export function getLanguages(): Promise { + return getJSON('/api/languages/list').then(r => r.languages); +} diff --git a/server/sonar-web/src/main/js/api/licenses.js b/server/sonar-web/src/main/js/api/licenses.js deleted file mode 100644 index 49c8df01978..00000000000 --- a/server/sonar-web/src/main/js/api/licenses.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON, post } from '../helpers/request'; - -export const getLicenses = () => getJSON('/api/licenses/list').then(r => r.licenses); - -export const setLicense = (key, value) => { - const url = '/api/settings/set'; - const data = { key, value }; - return post(url, data); -}; - -export const resetLicense = key => { - const url = '/api/settings/reset'; - const data = { keys: key }; - return post(url, data); -}; diff --git a/server/sonar-web/src/main/js/api/licenses.ts b/server/sonar-web/src/main/js/api/licenses.ts new file mode 100644 index 00000000000..8df37f10ed1 --- /dev/null +++ b/server/sonar-web/src/main/js/api/licenses.ts @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post } from '../helpers/request'; + +export function getLicenses(): Promise { + return getJSON('/api/licenses/list').then(r => r.licenses); +} + +export function setLicense(key: string, value: string): Promise { + const url = '/api/settings/set'; + const data = { key, value }; + return post(url, data); +} + +export function resetLicense(key: string): Promise { + const url = '/api/settings/reset'; + const data = { keys: key }; + return post(url, data); +} diff --git a/server/sonar-web/src/main/js/api/measures.js b/server/sonar-web/src/main/js/api/measures.js deleted file mode 100644 index 2ad2f9643c2..00000000000 --- a/server/sonar-web/src/main/js/api/measures.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON } from '../helpers/request'; - -export function getMeasures(componentKey, metrics) { - const url = '/api/measures/component'; - const data = { componentKey, metricKeys: metrics.join(',') }; - return getJSON(url, data).then(r => r.component.measures); -} - -export function getMeasuresAndMeta(componentKey, metrics, additional = {}) { - const url = '/api/measures/component'; - const data = Object.assign({}, additional, { - componentKey, - metricKeys: metrics.join(',') - }); - return getJSON(url, data); -} - -export const getMeasuresForProjects = (projectKeys, metricKeys) => - getJSON('/api/measures/search', { - projectKeys: projectKeys.join(), - metricKeys: metricKeys.join() - }); diff --git a/server/sonar-web/src/main/js/api/measures.ts b/server/sonar-web/src/main/js/api/measures.ts new file mode 100644 index 00000000000..5f6ff93f40f --- /dev/null +++ b/server/sonar-web/src/main/js/api/measures.ts @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, RequestData } from '../helpers/request'; + +export function getMeasures(componentKey: string, metrics: string[]): Promise { + const url = '/api/measures/component'; + const data = { componentKey, metricKeys: metrics.join(',') }; + return getJSON(url, data).then(r => r.component.measures); +} + +export function getMeasuresAndMeta( + componentKey: string, + metrics: string[], + additional: RequestData = {} +): Promise { + const data = { ...additional, componentKey, metricKeys: metrics.join(',') }; + return getJSON('/api/measures/component', data); +} + +export function getMeasuresForProjects(projectKeys: string[], metricKeys: string[]): Promise { + return getJSON('/api/measures/search', { + projectKeys: projectKeys.join(), + metricKeys: metricKeys.join() + }); +} diff --git a/server/sonar-web/src/main/js/api/metrics.js b/server/sonar-web/src/main/js/api/metrics.js deleted file mode 100644 index b48abd7ed2e..00000000000 --- a/server/sonar-web/src/main/js/api/metrics.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON } from '../helpers/request'; - -export function getMetrics() { - const url = '/api/metrics/search'; - const data = { ps: 9999 }; - return getJSON(url, data).then(r => r.metrics); -} diff --git a/server/sonar-web/src/main/js/api/metrics.ts b/server/sonar-web/src/main/js/api/metrics.ts new file mode 100644 index 00000000000..ea2f78d569c --- /dev/null +++ b/server/sonar-web/src/main/js/api/metrics.ts @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; + +export function getMetrics(): Promise { + return getJSON('/api/metrics/search', { ps: 9999 }).then(r => r.metrics); +} diff --git a/server/sonar-web/src/main/js/api/nav.js b/server/sonar-web/src/main/js/api/nav.js deleted file mode 100644 index eacb2faa4f2..00000000000 --- a/server/sonar-web/src/main/js/api/nav.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON } from '../helpers/request'; - -export function getGlobalNavigation() { - const url = '/api/navigation/global'; - return getJSON(url); -} - -export function getComponentNavigation(componentKey) { - const url = '/api/navigation/component'; - const data = { componentKey }; - return getJSON(url, data); -} - -export function getSettingsNavigation() { - const url = '/api/navigation/settings'; - return getJSON(url); -} diff --git a/server/sonar-web/src/main/js/api/nav.ts b/server/sonar-web/src/main/js/api/nav.ts new file mode 100644 index 00000000000..3b2046df1c0 --- /dev/null +++ b/server/sonar-web/src/main/js/api/nav.ts @@ -0,0 +1,32 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; + +export function getGlobalNavigation(): Promise { + return getJSON('/api/navigation/global'); +} + +export function getComponentNavigation(componentKey: string): Promise { + return getJSON('/api/navigation/component', { componentKey }); +} + +export function getSettingsNavigation(): Promise { + return getJSON('/api/navigation/settings'); +} diff --git a/server/sonar-web/src/main/js/api/notifications.js b/server/sonar-web/src/main/js/api/notifications.js deleted file mode 100644 index 8361401b60b..00000000000 --- a/server/sonar-web/src/main/js/api/notifications.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, post } from '../helpers/request'; - -/*:: -export type GetNotificationsResponse = { - notifications: Array<{ - channel: string, - type: string, - organization?: string, - project?: string, - projectName?: string - }>, - channels: Array, - globalTypes: Array, - perProjectTypes: Array -}; -*/ - -export function getNotifications() /*: Promise */ { - return getJSON('/api/notifications/list'); -} - -export function addNotification( - channel /*: string */, - type /*: string */, - project /*: ?string */ -) /*: Promise<*> */ { - const data /*: Object */ = { channel, type }; - if (project) { - Object.assign(data, { project }); - } - return post('/api/notifications/add', data); -} - -export function removeNotification( - channel /*: string */, - type /*: string */, - project /*: ?string */ -) /*: Promise<*> */ { - const data /*: Object */ = { channel, type }; - if (project) { - Object.assign(data, { project }); - } - return post('/api/notifications/remove', data); -} diff --git a/server/sonar-web/src/main/js/api/notifications.ts b/server/sonar-web/src/main/js/api/notifications.ts new file mode 100644 index 00000000000..a95def188f3 --- /dev/null +++ b/server/sonar-web/src/main/js/api/notifications.ts @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, RequestData } from '../helpers/request'; + +export interface IGetNotificationsResponse { + notifications: Array<{ + channel: string; + type: string; + organization?: string; + project?: string; + projectName?: string; + }>; + channels: Array; + globalTypes: Array; + perProjectTypes: Array; +} + +export function getNotifications(): Promise { + return getJSON('/api/notifications/list'); +} + +export function addNotification(channel: string, type: string, project?: string): Promise { + const data: RequestData = { channel, type }; + if (project) { + Object.assign(data, { project }); + } + return post('/api/notifications/add', data); +} + +export function removeNotification(channel: string, type: string, project?: string): Promise { + const data: RequestData = { channel, type }; + if (project) { + Object.assign(data, { project }); + } + return post('/api/notifications/remove', data); +} diff --git a/server/sonar-web/src/main/js/api/organizations.js b/server/sonar-web/src/main/js/api/organizations.js deleted file mode 100644 index 940d698fac7..00000000000 --- a/server/sonar-web/src/main/js/api/organizations.js +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, post, postJSON } from '../helpers/request'; -/*:: import type { Organization } from '../store/organizations/duck'; */ -import throwGlobalError from '../app/utils/throwGlobalError'; - -export function getOrganizations(organizations /*: ?Array */) { - const data = {}; - if (organizations) { - Object.assign(data, { organizations: organizations.join() }); - } - return getJSON('/api/organizations/search', data); -} - -export function getMyOrganizations() { - return getJSON('/api/organizations/search_my_organizations').then(r => r.organizations); -} - -/*:: -type GetOrganizationType = null | Organization; -*/ - -/*:: -type GetOrganizationNavigation = { - canAdmin: boolean, - canDelete: boolean, - canProvisionProjects: boolean, - isDefault: boolean, - pages: Array<{ key: string, name: string }>, - adminPages: Array<{ key: string, name: string }> -}; -*/ - -export function getOrganization(key /*: string */) /*: Promise */ { - return getOrganizations([key]) - .then(r => r.organizations.find(o => o.key === key)) - .catch(throwGlobalError); -} - -export function getOrganizationNavigation( - key /*: string */ -) /*: Promise */ { - return getJSON('/api/navigation/organization', { organization: key }).then(r => r.organization); -} - -export function createOrganization(fields /*: {} */) /*: Promise */ { - return postJSON('/api/organizations/create', fields).then(r => r.organization, throwGlobalError); -} - -export function updateOrganization(key /*: string */, changes /*: {} */) { - return post('/api/organizations/update', { key, ...changes }); -} - -export function deleteOrganization(key /*: string */) { - return post('/api/organizations/delete', { key }).catch(throwGlobalError); -} - -export function searchMembers( - data /*: { - organization?: string, - p?: number, - ps?: number, - q?: string, - selected?: string -} */ -) { - return getJSON('/api/organizations/search_members', data); -} - -export function addMember(data /*: { login: string, organization: string } */) { - return postJSON('/api/organizations/add_member', data).then(r => r.user); -} - -export function removeMember(data /*: { login: string, organization: string } */) { - return post('/api/organizations/remove_member', data); -} - -export function changeProjectVisibility( - organization /*: string */, - projectVisibility /*: string */ -) { - return post('/api/organizations/update_project_visibility', { organization, projectVisibility }); -} diff --git a/server/sonar-web/src/main/js/api/organizations.ts b/server/sonar-web/src/main/js/api/organizations.ts new file mode 100644 index 00000000000..d16eb61e07e --- /dev/null +++ b/server/sonar-web/src/main/js/api/organizations.ts @@ -0,0 +1,89 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, postJSON, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +export function getOrganizations(organizations?: string[]): Promise { + const data: RequestData = {}; + if (organizations) { + Object.assign(data, { organizations: organizations.join() }); + } + return getJSON('/api/organizations/search', data); +} + +export function getMyOrganizations(): Promise { + return getJSON('/api/organizations/search_my_organizations').then(r => r.organizations); +} + +export function getOrganization(key: string): Promise { + return getOrganizations([key]) + .then(r => r.organizations.find((o: any) => o.key === key)) + .catch(throwGlobalError); +} + +interface GetOrganizationNavigation { + canAdmin: boolean; + canDelete: boolean; + canProvisionProjects: boolean; + isDefault: boolean; + pages: Array<{ key: string; name: string }>; + adminPages: Array<{ key: string; name: string }>; +} + +export function getOrganizationNavigation(key: string): Promise { + return getJSON('/api/navigation/organization', { organization: key }).then(r => r.organization); +} + +export function createOrganization(data: RequestData): Promise { + return postJSON('/api/organizations/create', data).then(r => r.organization, throwGlobalError); +} + +export function updateOrganization(key: string, changes: RequestData): Promise { + return post('/api/organizations/update', { key, ...changes }); +} + +export function deleteOrganization(key: string): Promise { + return post('/api/organizations/delete', { key }).catch(throwGlobalError); +} + +export function searchMembers(data: { + organization?: string; + p?: number; + ps?: number; + q?: string; + selected?: string; +}): Promise { + return getJSON('/api/organizations/search_members', data); +} + +export function addMember(data: { login: string; organization: string }): Promise { + return postJSON('/api/organizations/add_member', data).then(r => r.user); +} + +export function removeMember(data: { login: string; organization: string }): Promise { + return post('/api/organizations/remove_member', data); +} + +export function changeProjectVisibility( + organization: string, + projectVisibility: string +): Promise { + return post('/api/organizations/update_project_visibility', { organization, projectVisibility }); +} diff --git a/server/sonar-web/src/main/js/api/permissions.js b/server/sonar-web/src/main/js/api/permissions.js deleted file mode 100644 index e6f043dc970..00000000000 --- a/server/sonar-web/src/main/js/api/permissions.js +++ /dev/null @@ -1,310 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, post, postJSON } from '../helpers/request'; - -const PAGE_SIZE = 100; - -export function grantPermissionToUser( - projectKey /*: string | null */, - login /*: string */, - permission /*: string */, - organization /*: ?string */ -) { - const url = '/api/permissions/add_user'; - const data /*: Object */ = { login, permission }; - if (projectKey) { - data.projectKey = projectKey; - } - if (organization && !projectKey) { - data.organization = organization; - } - return post(url, data); -} - -export function revokePermissionFromUser( - projectKey /*: string | null */, - login /*: string */, - permission /*: string */, - organization /*: ?string */ -) { - const url = '/api/permissions/remove_user'; - const data /*: Object */ = { login, permission }; - if (projectKey) { - data.projectKey = projectKey; - } - if (organization && !projectKey) { - data.organization = organization; - } - return post(url, data); -} - -export function grantPermissionToGroup( - projectKey /*: string | null */, - groupName /*: string */, - permission /*: string */, - organization /*: ?string */ -) { - const url = '/api/permissions/add_group'; - const data /*: Object */ = { groupName, permission }; - if (projectKey) { - data.projectKey = projectKey; - } - if (organization) { - data.organization = organization; - } - return post(url, data); -} - -export function revokePermissionFromGroup( - projectKey /*: string | null */, - groupName /*: string */, - permission /*: string */, - organization /*: ?string */ -) { - const url = '/api/permissions/remove_group'; - const data /*: Object */ = { groupName, permission }; - if (projectKey) { - data.projectKey = projectKey; - } - if (organization) { - data.organization = organization; - } - return post(url, data); -} - -/** - * Get list of permission templates - * @returns {Promise} - */ -export function getPermissionTemplates(organization /*: ?string */) { - const url = '/api/permissions/search_templates'; - return organization ? getJSON(url, { organization }) : getJSON(url); -} - -export function createPermissionTemplate(data /*: Object */) { - return postJSON('/api/permissions/create_template', data); -} - -export function updatePermissionTemplate(data /*: Object */) { - return post('/api/permissions/update_template', data); -} - -export function deletePermissionTemplate(data /*: Object */) { - return post('/api/permissions/delete_template', data); -} - -/** - * Set default permission template for a given qualifier - * @param {string} templateId - * @param {string} qualifier - * @returns {Promise} - */ -export function setDefaultPermissionTemplate(templateId /*: string */, qualifier /*: string */) { - const url = '/api/permissions/set_default_template'; - const data = { templateId, qualifier }; - return post(url, data); -} - -export function applyTemplateToProject(data /*: Object */) { - const url = '/api/permissions/apply_template'; - return post(url, data); -} - -export function bulkApplyTemplate(data /*: Object */) { - const url = '/api/permissions/bulk_apply_template'; - return post(url, data); -} - -export function grantTemplatePermissionToUser( - data /*: { - templateId: string, - login: string, - permission: string, - organization?: string -} */ -) { - const url = '/api/permissions/add_user_to_template'; - return post(url, data); -} - -export function revokeTemplatePermissionFromUser( - data /*: { - templateId: string, - login: string, - permission: string, - organization?: string -} */ -) { - const url = '/api/permissions/remove_user_from_template'; - return post(url, data); -} - -export function grantTemplatePermissionToGroup(data /*: Object */) { - const url = '/api/permissions/add_group_to_template'; - return post(url, data); -} - -export function revokeTemplatePermissionFromGroup(data /*: Object */) { - const url = '/api/permissions/remove_group_from_template'; - return post(url, data); -} - -export function addProjectCreatorToTemplate(templateId /*: string */, permission /*: string */) { - const url = '/api/permissions/add_project_creator_to_template'; - const data = { templateId, permission }; - return post(url, data); -} - -export function removeProjectCreatorFromTemplate( - templateId /*: string */, - permission /*: string */ -) { - const url = '/api/permissions/remove_project_creator_from_template'; - const data = { templateId, permission }; - return post(url, data); -} - -export function getPermissionsUsersForComponent( - projectKey /*: string */, - query /*: ?string */, - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/users'; - const data /*: Object */ = { projectKey, ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - data.organization = organization; - } - return getJSON(url, data).then(r => r.users); -} - -export function getPermissionsGroupsForComponent( - projectKey /*: string */, - query /*: string */ = '', - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/groups'; - const data /*: Object */ = { projectKey, ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - data.organization = organization; - } - return getJSON(url, data).then(r => r.groups); -} - -export function getGlobalPermissionsUsers( - query /*: ?string */, - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/users'; - const data /*: Object */ = { ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - data.organization = organization; - } - return getJSON(url, data).then(r => r.users); -} - -export function getGlobalPermissionsGroups( - query /*: ?string */, - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/groups'; - const data /*: Object */ = { ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - data.organization = organization; - } - return getJSON(url, data).then(r => r.groups); -} - -export function getPermissionTemplateUsers( - templateId /*: string */, - query /*: ?string */, - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/template_users'; - const data /*: Object */ = { templateId, ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - Object.assign(data, { organization }); - } - return getJSON(url, data).then(r => r.users); -} - -export function getPermissionTemplateGroups( - templateId /*: string */, - query /*: ?string */, - permission /*: ?string */, - organization /*: ?string */ -) { - const url = '/api/permissions/template_groups'; - const data /*: Object */ = { templateId, ps: PAGE_SIZE }; - if (query) { - data.q = query; - } - if (permission) { - data.permission = permission; - } - if (organization) { - Object.assign(data, { organization }); - } - return getJSON(url, data).then(r => r.groups); -} - -export function changeProjectVisibility( - project /*: string */, - visibility /*: string */ -) /*: Promise */ { - const url = '/api/projects/update_visibility'; - const data = { project, visibility }; - return post(url, data); -} diff --git a/server/sonar-web/src/main/js/api/permissions.ts b/server/sonar-web/src/main/js/api/permissions.ts new file mode 100644 index 00000000000..de6b169104f --- /dev/null +++ b/server/sonar-web/src/main/js/api/permissions.ts @@ -0,0 +1,274 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, postJSON, RequestData } from '../helpers/request'; + +const PAGE_SIZE = 100; + +export function grantPermissionToUser( + projectKey: string | null, + login: string, + permission: string, + organization?: string +): Promise { + const data: RequestData = { login, permission }; + if (projectKey) { + data.projectKey = projectKey; + } + if (organization && !projectKey) { + data.organization = organization; + } + return post('/api/permissions/add_user', data); +} + +export function revokePermissionFromUser( + projectKey: string | null, + login: string, + permission: string, + organization?: string +): Promise { + const data: RequestData = { login, permission }; + if (projectKey) { + data.projectKey = projectKey; + } + if (organization && !projectKey) { + data.organization = organization; + } + return post('/api/permissions/remove_user', data); +} + +export function grantPermissionToGroup( + projectKey: string | null, + groupName: string, + permission: string, + organization?: string +): Promise { + const data: RequestData = { groupName, permission }; + if (projectKey) { + data.projectKey = projectKey; + } + if (organization) { + data.organization = organization; + } + return post('/api/permissions/add_group', data); +} + +export function revokePermissionFromGroup( + projectKey: string | null, + groupName: string, + permission: string, + organization?: string +): Promise { + const data: RequestData = { groupName, permission }; + if (projectKey) { + data.projectKey = projectKey; + } + if (organization) { + data.organization = organization; + } + return post('/api/permissions/remove_group', data); +} + +/** + * Get list of permission templates + */ +export function getPermissionTemplates(organization?: string) { + const url = '/api/permissions/search_templates'; + return organization ? getJSON(url, { organization }) : getJSON(url); +} + +export function createPermissionTemplate(data: RequestData) { + return postJSON('/api/permissions/create_template', data); +} + +export function updatePermissionTemplate(data: RequestData): Promise { + return post('/api/permissions/update_template', data); +} + +export function deletePermissionTemplate(data: RequestData): Promise { + return post('/api/permissions/delete_template', data); +} + +/** + * Set default permission template for a given qualifier + */ +export function setDefaultPermissionTemplate(templateId: string, qualifier: string): Promise { + return post('/api/permissions/set_default_template', { templateId, qualifier }); +} + +export function applyTemplateToProject(data: RequestData): Promise { + return post('/api/permissions/apply_template', data); +} + +export function bulkApplyTemplate(data: RequestData): Promise { + return post('/api/permissions/bulk_apply_template', data); +} + +export function grantTemplatePermissionToUser(data: { + templateId: string; + login: string; + permission: string; + organization?: string; +}): Promise { + return post('/api/permissions/add_user_to_template', data); +} + +export function revokeTemplatePermissionFromUser(data: { + templateId: string; + login: string; + permission: string; + organization?: string; +}): Promise { + return post('/api/permissions/remove_user_from_template', data); +} + +export function grantTemplatePermissionToGroup(data: RequestData): Promise { + return post('/api/permissions/add_group_to_template', data); +} + +export function revokeTemplatePermissionFromGroup(data: RequestData): Promise { + return post('/api/permissions/remove_group_from_template', data); +} + +export function addProjectCreatorToTemplate(templateId: string, permission: string): Promise { + return post('/api/permissions/add_project_creator_to_template', { templateId, permission }); +} + +export function removeProjectCreatorFromTemplate( + templateId: string, + permission: string +): Promise { + return post('/api/permissions/remove_project_creator_from_template', { templateId, permission }); +} + +export function getPermissionsUsersForComponent( + projectKey: string, + query?: string, + permission?: string, + organization?: string +): Promise { + const data: RequestData = { projectKey, ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + data.organization = organization; + } + return getJSON('/api/permissions/users', data).then(r => r.users); +} + +export function getPermissionsGroupsForComponent( + projectKey: string, + query: string = '', + permission?: string, + organization?: string +): Promise { + const data: RequestData = { projectKey, ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + data.organization = organization; + } + return getJSON('/api/permissions/groups', data).then(r => r.groups); +} + +export function getGlobalPermissionsUsers( + query?: string, + permission?: string, + organization?: string +): Promise { + const data: RequestData = { ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + data.organization = organization; + } + return getJSON('/api/permissions/users', data).then(r => r.users); +} + +export function getGlobalPermissionsGroups( + query?: string, + permission?: string, + organization?: string +): Promise { + const data: RequestData = { ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + data.organization = organization; + } + return getJSON('/api/permissions/groups', data).then(r => r.groups); +} + +export function getPermissionTemplateUsers( + templateId: string, + query?: string, + permission?: string, + organization?: string +): Promise { + const data: RequestData = { templateId, ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + Object.assign(data, { organization }); + } + return getJSON('/api/permissions/template_users', data).then(r => r.users); +} + +export function getPermissionTemplateGroups( + templateId: string, + query?: string, + permission?: string, + organization?: string +): Promise { + const data: RequestData = { templateId, ps: PAGE_SIZE }; + if (query) { + data.q = query; + } + if (permission) { + data.permission = permission; + } + if (organization) { + Object.assign(data, { organization }); + } + return getJSON('/api/permissions/template_groups', data).then(r => r.groups); +} + +export function changeProjectVisibility(project: string, visibility: string): Promise { + return post('/api/projects/update_visibility', { project, visibility }); +} diff --git a/server/sonar-web/src/main/js/api/projectActivity.js b/server/sonar-web/src/main/js/api/projectActivity.js deleted file mode 100644 index ffb3200c08e..00000000000 --- a/server/sonar-web/src/main/js/api/projectActivity.js +++ /dev/null @@ -1,97 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, postJSON, post } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -/*:: -type GetProjectActivityResponse = { - analyses: Array, - paging: { - total: number, - pageIndex: number, - pageSize: number - } -}; -*/ - -/*:: -type GetProjectActivityOptions = { - project: string, - category?: ?string, - p?: ?number, - ps?: ?number -}; -*/ - -export function getProjectActivity( - data /*: GetProjectActivityOptions */ -) /*: Promise */ { - return getJSON('/api/project_analyses/search', data).catch(throwGlobalError); -} - -/*:: -type CreateEventResponse = { - analysis: string, - key: string, - name: string, - category: string, - description?: string -}; -*/ - -export function createEvent( - analysis /*: string */, - name /*: string */, - category /*: ?string */, - description /*: ?string */ -) /*: Promise */ { - const data /*: Object */ = { analysis, name }; - if (category) { - data.category = category; - } - if (description) { - data.description = description; - } - return postJSON('/api/project_analyses/create_event', data).then(r => r.event, throwGlobalError); -} - -export function deleteEvent(event /*: string */) /*: Promise<*> */ { - return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError); -} - -export function changeEvent( - event /*: string */, - name /*: ?string */, - description /*: ?string */ -) /*: Promise */ { - const data /*: Object */ = { event }; - if (name) { - data.name = name; - } - if (description) { - data.description = description; - } - return postJSON('/api/project_analyses/update_event', data).then(r => r.event, throwGlobalError); -} - -export function deleteAnalysis(analysis /*: string */) /*: Promise<*> */ { - return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError); -} diff --git a/server/sonar-web/src/main/js/api/projectActivity.ts b/server/sonar-web/src/main/js/api/projectActivity.ts new file mode 100644 index 00000000000..6edd9732081 --- /dev/null +++ b/server/sonar-web/src/main/js/api/projectActivity.ts @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, postJSON, post, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +interface IGetProjectActivityResponse { + analyses: any[]; + paging: { + total: number; + pageIndex: number; + pageSize: number; + }; +} + +export function getProjectActivity(data: { + project: string; + category?: string; + p?: number; + ps?: number; +}): Promise { + return getJSON('/api/project_analyses/search', data).catch(throwGlobalError); +} + +interface ICreateEventResponse { + analysis: string; + key: string; + name: string; + category: string; + description?: string; +} + +export function createEvent( + analysis: string, + name: string, + category?: string, + description?: string +): Promise { + const data: RequestData = { analysis, name }; + if (category) { + data.category = category; + } + if (description) { + data.description = description; + } + return postJSON('/api/project_analyses/create_event', data).then(r => r.event, throwGlobalError); +} + +export function deleteEvent(event: string): Promise { + return post('/api/project_analyses/delete_event', { event }).catch(throwGlobalError); +} + +export function changeEvent( + event: string, + name?: string, + description?: string +): Promise { + const data: RequestData = { event }; + if (name) { + data.name = name; + } + if (description) { + data.description = description; + } + return postJSON('/api/project_analyses/update_event', data).then(r => r.event, throwGlobalError); +} + +export function deleteAnalysis(analysis: string): Promise { + return post('/api/project_analyses/delete', { analysis }).catch(throwGlobalError); +} diff --git a/server/sonar-web/src/main/js/api/projectLinks.js b/server/sonar-web/src/main/js/api/projectLinks.js deleted file mode 100644 index 5982fbf365e..00000000000 --- a/server/sonar-web/src/main/js/api/projectLinks.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON, post, postJSON } from '../helpers/request'; - -export function getProjectLinks(projectKey) { - const url = '/api/project_links/search'; - const data = { projectKey }; - return getJSON(url, data).then(r => r.links); -} - -export function deleteLink(linkId) { - const url = '/api/project_links/delete'; - const data = { id: linkId }; - return post(url, data); -} - -export function createLink(projectKey, name, url) { - const apiURL = '/api/project_links/create'; - const data = { projectKey, name, url }; - return postJSON(apiURL, data).then(r => r.link); -} diff --git a/server/sonar-web/src/main/js/api/projectLinks.ts b/server/sonar-web/src/main/js/api/projectLinks.ts new file mode 100644 index 00000000000..d2efd438bb3 --- /dev/null +++ b/server/sonar-web/src/main/js/api/projectLinks.ts @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, postJSON } from '../helpers/request'; + +export function getProjectLinks(projectKey: string): Promise { + const url = '/api/project_links/search'; + const data = { projectKey }; + return getJSON(url, data).then(r => r.links); +} + +export function deleteLink(linkId: string): Promise { + const url = '/api/project_links/delete'; + const data = { id: linkId }; + return post(url, data); +} + +export function createLink(projectKey: string, name: string, url: string): Promise { + const apiURL = '/api/project_links/create'; + const data = { projectKey, name, url }; + return postJSON(apiURL, data).then(r => r.link); +} diff --git a/server/sonar-web/src/main/js/api/quality-gates.js b/server/sonar-web/src/main/js/api/quality-gates.js deleted file mode 100644 index 7bf0a0c73ef..00000000000 --- a/server/sonar-web/src/main/js/api/quality-gates.js +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON, post, postJSON } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -export function fetchQualityGatesAppDetails() { - const url = '/api/qualitygates/app'; - return getJSON(url).catch(throwGlobalError); -} - -export function fetchQualityGates() { - const url = '/api/qualitygates/list'; - return getJSON(url).then( - r => - r.qualitygates.map(qualityGate => { - return { - ...qualityGate, - isDefault: qualityGate.id === r.default - }; - }), - throwGlobalError - ); -} - -export function fetchQualityGate(id) { - const url = '/api/qualitygates/show'; - return getJSON(url, { id }).catch(throwGlobalError); -} - -export function createQualityGate(name) { - const url = '/api/qualitygates/create'; - return postJSON(url, { name }); -} - -export function deleteQualityGate(id) { - const url = '/api/qualitygates/destroy'; - return post(url, { id }); -} - -export function renameQualityGate(id, name) { - const url = '/api/qualitygates/rename'; - return post(url, { id, name }); -} - -export function copyQualityGate(id, name) { - const url = '/api/qualitygates/copy'; - return postJSON(url, { id, name }); -} - -export function setQualityGateAsDefault(id) { - const url = '/api/qualitygates/set_as_default'; - return post(url, { id }).catch(throwGlobalError); -} - -export function unsetQualityGateAsDefault(id) { - const url = '/api/qualitygates/unset_default'; - return post(url, { id }).catch(throwGlobalError); -} - -export function createCondition(gateId, condition) { - const url = '/api/qualitygates/create_condition'; - return postJSON(url, { ...condition, gateId }); -} - -export function updateCondition(condition) { - const url = '/api/qualitygates/update_condition'; - return postJSON(url, { ...condition }); -} - -export function deleteCondition(id) { - const url = '/api/qualitygates/delete_condition'; - return post(url, { id }); -} - -export function getGateForProject(projectKey) { - const url = '/api/qualitygates/get_by_project'; - const data = { projectKey }; - return getJSON(url, data).then(r => r.qualityGate); -} - -export function associateGateWithProject(gateId, projectKey) { - const url = '/api/qualitygates/select'; - const data = { gateId, projectKey }; - return post(url, data).catch(throwGlobalError); -} - -export function dissociateGateWithProject(gateId, projectKey) { - const url = '/api/qualitygates/deselect'; - const data = { gateId, projectKey }; - return post(url, data).catch(throwGlobalError); -} - -export function getApplicationQualityGate(application) { - return getJSON('/api/qualitygates/application_status', { application }); -} diff --git a/server/sonar-web/src/main/js/api/quality-gates.ts b/server/sonar-web/src/main/js/api/quality-gates.ts new file mode 100644 index 00000000000..b07f1a89104 --- /dev/null +++ b/server/sonar-web/src/main/js/api/quality-gates.ts @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, postJSON, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +export function fetchQualityGatesAppDetails(): Promise { + return getJSON('/api/qualitygates/app').catch(throwGlobalError); +} + +export function fetchQualityGates(): Promise { + return getJSON('/api/qualitygates/list').then( + r => + r.qualitygates.map((qualityGate: any) => { + return { ...qualityGate, isDefault: qualityGate.id === r.default }; + }), + throwGlobalError + ); +} + +export function fetchQualityGate(id: string): Promise { + return getJSON('/api/qualitygates/show', { id }).catch(throwGlobalError); +} + +export function createQualityGate(name: string): Promise { + return postJSON('/api/qualitygates/create', { name }); +} + +export function deleteQualityGate(id: string): Promise { + return post('/api/qualitygates/destroy', { id }); +} + +export function renameQualityGate(id: string, name: string): Promise { + return post('/api/qualitygates/rename', { id, name }); +} + +export function copyQualityGate(id: string, name: string): Promise { + return postJSON('/api/qualitygates/copy', { id, name }); +} + +export function setQualityGateAsDefault(id: string): Promise { + return post('/api/qualitygates/set_as_default', { id }).catch(throwGlobalError); +} + +export function unsetQualityGateAsDefault(id: string): Promise { + return post('/api/qualitygates/unset_default', { id }).catch(throwGlobalError); +} + +export function createCondition(gateId: string, condition: RequestData): Promise { + return postJSON('/api/qualitygates/create_condition', { ...condition, gateId }); +} + +export function updateCondition(condition: RequestData): Promise { + return postJSON('/api/qualitygates/update_condition', condition); +} + +export function deleteCondition(id: string): Promise { + return post('/api/qualitygates/delete_condition', { id }); +} + +export function getGateForProject(projectKey: string): Promise { + return getJSON('/api/qualitygates/get_by_project', { projectKey }).then(r => r.qualityGate); +} + +export function associateGateWithProject( + gateId: string, + projectKey: string +): Promise { + return post('/api/qualitygates/select', { gateId, projectKey }).catch(throwGlobalError); +} + +export function dissociateGateWithProject( + gateId: string, + projectKey: string +): Promise { + return post('/api/qualitygates/deselect', { gateId, projectKey }).catch(throwGlobalError); +} + +export function getApplicationQualityGate(application: string): Promise { + return getJSON('/api/qualitygates/application_status', { application }); +} diff --git a/server/sonar-web/src/main/js/api/quality-profiles.js b/server/sonar-web/src/main/js/api/quality-profiles.js deleted file mode 100644 index f3fbf7cbd46..00000000000 --- a/server/sonar-web/src/main/js/api/quality-profiles.js +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { request, checkStatus, parseJSON, getJSON, post, postJSON } from '../helpers/request'; - -export function searchQualityProfiles(data /*: { organization?: string, projectKey?: string } */) { - const url = '/api/qualityprofiles/search'; - return getJSON(url, data).then(r => r.profiles); -} - -export function getQualityProfiles(data /*: { compareToSonarWay?: boolean, profile: string } */) { - const url = '/api/qualityprofiles/show'; - return getJSON(url, data); -} - -export function createQualityProfile(data /*: Object */) { - return request('/api/qualityprofiles/create') - .setMethod('post') - .setData(data) - .submit() - .then(checkStatus) - .then(parseJSON); -} - -export function restoreQualityProfile(data /*: Object */) { - return request('/api/qualityprofiles/restore') - .setMethod('post') - .setData(data) - .submit() - .then(checkStatus) - .then(parseJSON); -} - -export function getProfileProjects(data /*: Object */) { - const url = '/api/qualityprofiles/projects'; - return getJSON(url, data); -} - -export function getProfileInheritance(profileKey /*: string */) { - const url = '/api/qualityprofiles/inheritance'; - const data = { profileKey }; - return getJSON(url, data); -} - -export function setDefaultProfile(profileKey /*: string */) { - const url = '/api/qualityprofiles/set_default'; - const data = { profileKey }; - return post(url, data); -} - -export function renameProfile(key /*: string */, name /*: string */) { - const url = '/api/qualityprofiles/rename'; - const data = { key, name }; - return post(url, data); -} - -export function copyProfile(fromKey /*: string */, toName /*: string */) { - const url = '/api/qualityprofiles/copy'; - const data = { fromKey, toName }; - return postJSON(url, data); -} - -export function deleteProfile(profileKey /*: string */) { - const url = '/api/qualityprofiles/delete'; - const data = { profileKey }; - return post(url, data); -} - -export function changeProfileParent(profileKey /*: string */, parentKey /*: string */) { - const url = '/api/qualityprofiles/change_parent'; - const data = { profileKey, parentKey }; - return post(url, data); -} - -export function getImporters() { - const url = '/api/qualityprofiles/importers'; - return getJSON(url).then(r => r.importers); -} - -export function getExporters() { - const url = '/api/qualityprofiles/exporters'; - return getJSON(url).then(r => r.exporters); -} - -export function getProfileChangelog(data /*: Object */) { - const url = '/api/qualityprofiles/changelog'; - return getJSON(url, data); -} - -export function compareProfiles(leftKey /*: string */, rightKey /*: string */) { - const url = '/api/qualityprofiles/compare'; - const data = { leftKey, rightKey }; - return getJSON(url, data); -} - -export function associateProject(profileKey /*: string */, projectKey /*: string */) { - const url = '/api/qualityprofiles/add_project'; - const data = { profileKey, projectKey }; - return post(url, data); -} - -export function dissociateProject(profileKey /*: string */, projectKey /*: string */) { - const url = '/api/qualityprofiles/remove_project'; - const data = { profileKey, projectKey }; - return post(url, data); -} diff --git a/server/sonar-web/src/main/js/api/quality-profiles.ts b/server/sonar-web/src/main/js/api/quality-profiles.ts new file mode 100644 index 00000000000..630effa1831 --- /dev/null +++ b/server/sonar-web/src/main/js/api/quality-profiles.ts @@ -0,0 +1,112 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { + request, + checkStatus, + parseJSON, + getJSON, + post, + postJSON, + RequestData +} from '../helpers/request'; + +export function searchQualityProfiles(data: { + organization?: string; + projectKey?: string; +}): Promise { + return getJSON('/api/qualityprofiles/search', data).then(r => r.profiles); +} + +export function getQualityProfiles(data: { + compareToSonarWay?: boolean; + profile: string; +}): Promise { + return getJSON('/api/qualityprofiles/show', data); +} + +export function createQualityProfile(data: RequestData): Promise { + return request('/api/qualityprofiles/create') + .setMethod('post') + .setData(data) + .submit() + .then(checkStatus) + .then(parseJSON); +} + +export function restoreQualityProfile(data: RequestData): Promise { + return request('/api/qualityprofiles/restore') + .setMethod('post') + .setData(data) + .submit() + .then(checkStatus) + .then(parseJSON); +} + +export function getProfileProjects(data: RequestData): Promise { + return getJSON('/api/qualityprofiles/projects', data); +} + +export function getProfileInheritance(profileKey: string): Promise { + return getJSON('/api/qualityprofiles/inheritance', { profileKey }); +} + +export function setDefaultProfile(profileKey: string): Promise { + return post('/api/qualityprofiles/set_default', { profileKey }); +} + +export function renameProfile(key: string, name: string): Promise { + return post('/api/qualityprofiles/rename', { key, name }); +} + +export function copyProfile(fromKey: string, toName: string): Promise { + return postJSON('/api/qualityprofiles/copy', { fromKey, toName }); +} + +export function deleteProfile(profileKey: string): Promise { + return post('/api/qualityprofiles/delete', { profileKey }); +} + +export function changeProfileParent(profileKey: string, parentKey: string): Promise { + return post('/api/qualityprofiles/change_parent', { profileKey, parentKey }); +} + +export function getImporters(): Promise { + return getJSON('/api/qualityprofiles/importers').then(r => r.importers); +} + +export function getExporters(): Promise { + return getJSON('/api/qualityprofiles/exporters').then(r => r.exporters); +} + +export function getProfileChangelog(data: RequestData): Promise { + return getJSON('/api/qualityprofiles/changelog', data); +} + +export function compareProfiles(leftKey: string, rightKey: string): Promise { + return getJSON('/api/qualityprofiles/compare', { leftKey, rightKey }); +} + +export function associateProject(profileKey: string, projectKey: string): Promise { + return post('/api/qualityprofiles/add_project', { profileKey, projectKey }); +} + +export function dissociateProject(profileKey: string, projectKey: string): Promise { + return post('/api/qualityprofiles/remove_project', { profileKey, projectKey }); +} diff --git a/server/sonar-web/src/main/js/api/rules.js b/server/sonar-web/src/main/js/api/rules.js deleted file mode 100644 index 194b7514574..00000000000 --- a/server/sonar-web/src/main/js/api/rules.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON } from '../helpers/request'; - -export function searchRules(data) { - const url = '/api/rules/search'; - return getJSON(url, data); -} - -export function takeFacet(response, property) { - const facet = response.facets.find(facet => facet.property === property); - return facet ? facet.values : []; -} diff --git a/server/sonar-web/src/main/js/api/rules.ts b/server/sonar-web/src/main/js/api/rules.ts new file mode 100644 index 00000000000..20a0b26f5a2 --- /dev/null +++ b/server/sonar-web/src/main/js/api/rules.ts @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, RequestData } from '../helpers/request'; + +export function searchRules(data: RequestData) { + return getJSON('/api/rules/search', data); +} + +export function takeFacet(response: any, property: string) { + const facet = response.facets.find((facet: any) => facet.property === property); + return facet ? facet.values : []; +} diff --git a/server/sonar-web/src/main/js/api/settings.js b/server/sonar-web/src/main/js/api/settings.js deleted file mode 100644 index 40e4efc6c74..00000000000 --- a/server/sonar-web/src/main/js/api/settings.js +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { omitBy } from 'lodash'; -import { getJSON, post, postJSON } from '../helpers/request'; -import { TYPE_PROPERTY_SET } from '../apps/settings/constants'; - -export function getDefinitions(componentKey) { - const url = '/api/settings/list_definitions'; - const data = {}; - if (componentKey) { - data.component = componentKey; - } - return getJSON(url, data).then(r => r.definitions); -} - -export function getValues(keys, componentKey) { - const url = '/api/settings/values'; - const data = { keys }; - if (componentKey) { - data.component = componentKey; - } - return getJSON(url, data).then(r => r.settings); -} - -export function setSettingValue(definition, value, componentKey) { - const url = '/api/settings/set'; - - const { key } = definition; - const data = { key }; - - if (definition.multiValues) { - data.values = value; - } else if (definition.type === TYPE_PROPERTY_SET) { - data.fieldValues = value - .map(fields => omitBy(fields, value => value == null)) - .map(JSON.stringify); - } else { - data.value = value; - } - - if (componentKey) { - data.component = componentKey; - } - - return post(url, data); -} - -export function resetSettingValue(key, componentKey) { - const url = '/api/settings/reset'; - const data = { keys: key }; - if (componentKey) { - data.component = componentKey; - } - return post(url, data); -} - -export function sendTestEmail(to, subject, message) { - const url = '/api/emails/send'; - const data = { to, subject, message }; - return post(url, data); -} - -export function checkSecretKey() { - return getJSON('/api/settings/check_secret_key'); -} - -export function generateSecretKey() { - return postJSON('/api/settings/generate_secret_key'); -} - -export function encryptValue(value) { - return postJSON('/api/settings/encrypt', { value }); -} - -export function getServerId() { - return getJSON('/api/server_id/show'); -} - -export function generateServerId(organization, ip) { - return postJSON('/api/server_id/generate', { organization, ip }); -} diff --git a/server/sonar-web/src/main/js/api/settings.ts b/server/sonar-web/src/main/js/api/settings.ts new file mode 100644 index 00000000000..fb579b166f8 --- /dev/null +++ b/server/sonar-web/src/main/js/api/settings.ts @@ -0,0 +1,91 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { omitBy } from 'lodash'; +import { getJSON, RequestData, post, postJSON } from '../helpers/request'; +import { TYPE_PROPERTY_SET } from '../apps/settings/constants'; + +export function getDefinitions(componentKey: string): Promise { + const data: RequestData = {}; + if (componentKey) { + data.component = componentKey; + } + return getJSON('/api/settings/list_definitions', data).then(r => r.definitions); +} + +export function getValues(keys: string, componentKey: string): Promise { + const data: RequestData = { keys }; + if (componentKey) { + data.component = componentKey; + } + return getJSON('/api/settings/values', data).then(r => r.settings); +} + +export function setSettingValue(definition: any, value: any, componentKey: string): Promise { + const { key } = definition; + const data: RequestData = { key }; + + if (definition.multiValues) { + data.values = value; + } else if (definition.type === TYPE_PROPERTY_SET) { + data.fieldValues = value + .map((fields: any) => omitBy(fields, value => value == null)) + .map(JSON.stringify); + } else { + data.value = value; + } + + if (componentKey) { + data.component = componentKey; + } + + return post('/api/settings/set', data); +} + +export function resetSettingValue(key: string, componentKey: string): Promise { + const data: RequestData = { keys: key }; + if (componentKey) { + data.component = componentKey; + } + return post('/api/settings/reset', data); +} + +export function sendTestEmail(to: string, subject: string, message: string): Promise { + return post('/api/emails/send', { to, subject, message }); +} + +export function checkSecretKey(): Promise { + return getJSON('/api/settings/check_secret_key'); +} + +export function generateSecretKey(): Promise { + return postJSON('/api/settings/generate_secret_key'); +} + +export function encryptValue(value: string): Promise { + return postJSON('/api/settings/encrypt', { value }); +} + +export function getServerId(): Promise { + return getJSON('/api/server_id/show'); +} + +export function generateServerId(organization: string, ip: string): Promise { + return postJSON('/api/server_id/generate', { organization, ip }); +} diff --git a/server/sonar-web/src/main/js/api/system.js b/server/sonar-web/src/main/js/api/system.js deleted file mode 100644 index 2d0420b05c0..00000000000 --- a/server/sonar-web/src/main/js/api/system.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { getJSON, post } from '../helpers/request'; - -export function setLogLevel(level) { - const url = '/api/system/change_log_level'; - const data = { level }; - return post(url, data); -} - -export function getSystemInfo() { - const url = '/api/system/info'; - return getJSON(url); -} - -export function getSystemStatus() { - const url = '/api/system/status'; - return getJSON(url); -} - -export function restart() { - const url = '/api/system/restart'; - return post(url); -} - -const POLLING_INTERVAL = 2000; - -function pollStatus(cb) { - setTimeout(() => { - getSystemStatus() - .then(r => { - if (r.status === 'UP') { - cb(); - } else { - pollStatus(cb); - } - }) - .catch(() => pollStatus(cb)); - }, POLLING_INTERVAL); -} - -function promiseStatus() { - return new Promise(resolve => pollStatus(resolve)); -} - -export function restartAndWait() { - return restart().then(promiseStatus); -} diff --git a/server/sonar-web/src/main/js/api/system.ts b/server/sonar-web/src/main/js/api/system.ts new file mode 100644 index 00000000000..93eeaaf5b77 --- /dev/null +++ b/server/sonar-web/src/main/js/api/system.ts @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post } from '../helpers/request'; + +export function setLogLevel(level: string): Promise { + return post('/api/system/change_log_level', { level }); +} + +export function getSystemInfo(): Promise { + return getJSON('/api/system/info'); +} + +export function getSystemStatus(): Promise { + return getJSON('/api/system/status'); +} + +export function restart(): Promise { + return post('/api/system/restart'); +} + +const POLLING_INTERVAL = 2000; + +function pollStatus(cb: Function): void { + setTimeout(() => { + getSystemStatus() + .then(r => { + if (r.status === 'UP') { + cb(); + } else { + pollStatus(cb); + } + }) + .catch(() => pollStatus(cb)); + }, POLLING_INTERVAL); +} + +function promiseStatus(): Promise { + return new Promise(resolve => pollStatus(resolve)); +} + +export function restartAndWait(): Promise { + return restart().then(promiseStatus); +} diff --git a/server/sonar-web/src/main/js/api/time-machine.js b/server/sonar-web/src/main/js/api/time-machine.js deleted file mode 100644 index c2f03a80d35..00000000000 --- a/server/sonar-web/src/main/js/api/time-machine.js +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON } from '../helpers/request'; - -/*:: -type Response = { - measures: Array<{ - metric: string, - history: Array<{ - date: string, - value: string - }> - }>, - paging: { - pageIndex: number, - pageSize: number, - total: number - } -}; -*/ - -export function getTimeMachineData( - component /*: string */, - metrics /*: Array */, - other /*: ?{ p?: number, ps?: number, from?: string, to?: string } */ -) /*: Promise */ { - return getJSON('/api/measures/search_history', { - component, - metrics: metrics.join(), - ps: 1000, - ...other - }); -} - -export function getAllTimeMachineData( - component /*: string */, - metrics /*: Array */, - other /*: ?{ p?: number, from?: string, to?: string } */, - prev /*: ?Response */ -) /*: Promise */ { - return getTimeMachineData(component, metrics, { ...other, ps: 1000 }).then(r => { - const result = prev - ? { - measures: prev.measures.map((measure, idx) => ({ - ...measure, - history: measure.history.concat(r.measures[idx].history) - })), - paging: r.paging - } - : r; - - if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) { - return result; - } - return getAllTimeMachineData( - component, - metrics, - { ...other, p: result.paging.pageIndex + 1 }, - result - ); - }); -} diff --git a/server/sonar-web/src/main/js/api/time-machine.ts b/server/sonar-web/src/main/js/api/time-machine.ts new file mode 100644 index 00000000000..643b3fb9848 --- /dev/null +++ b/server/sonar-web/src/main/js/api/time-machine.ts @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; + +interface ITimeMachineResponse { + measures: Array<{ + metric: string; + history: Array<{ date: string; value: string }>; + }>; + paging: { pageIndex: number; pageSize: number; total: number }; +} + +export function getTimeMachineData( + component: string, + metrics: string[], + other?: { p?: number; ps?: number; from?: string; to?: string } +): Promise { + return getJSON('/api/measures/search_history', { + component, + metrics: metrics.join(), + ps: 1000, + ...other + }); +} + +export function getAllTimeMachineData( + component: string, + metrics: Array, + other?: { p?: number; from?: string; to?: string }, + prev?: ITimeMachineResponse +): Promise { + return getTimeMachineData(component, metrics, { ...other, ps: 1000 }).then(r => { + const result = prev + ? { + measures: prev.measures.map((measure, idx) => ({ + ...measure, + history: measure.history.concat(r.measures[idx].history) + })), + paging: r.paging + } + : r; + + if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) { + return result; + } + return getAllTimeMachineData( + component, + metrics, + { ...other, p: result.paging.pageIndex + 1 }, + result + ); + }); +} diff --git a/server/sonar-web/src/main/js/api/user-tokens.js b/server/sonar-web/src/main/js/api/user-tokens.js deleted file mode 100644 index 8c46657979e..00000000000 --- a/server/sonar-web/src/main/js/api/user-tokens.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON, postJSON, post } from '../helpers/request'; -import throwGlobalError from '../app/utils/throwGlobalError'; - -/** - * List tokens for given user login - * @param {string} login - * @returns {Promise} - */ -export function getTokens(login /*: string */) { - const url = '/api/user_tokens/search'; - const data = { login }; - return getJSON(url, data).then(r => r.userTokens); -} - -/** - * Generate a user token - * @param {string} userLogin - * @param {string} tokenName - * @returns {Promise} - */ -export function generateToken( - tokenName /*: string */, - userLogin /*: ?string */ -) /*: Promise<{ name: string, token: string }> */ { - const url = '/api/user_tokens/generate'; - const data /*: { [string]: string } */ = { name: tokenName }; - if (userLogin) { - data.login = userLogin; - } - return postJSON(url, data).catch(throwGlobalError); -} - -/** - * Revoke a user token - * @param {string} userLogin - * @param {string} tokenName - * @returns {Promise} - */ -export function revokeToken(tokenName /*: string */, userLogin /*: ?string */) { - const url = '/api/user_tokens/revoke'; - const data /*: { [string]: string } */ = { name: tokenName }; - if (userLogin) { - data.login = userLogin; - } - return post(url, data).catch(throwGlobalError); -} diff --git a/server/sonar-web/src/main/js/api/user-tokens.ts b/server/sonar-web/src/main/js/api/user-tokens.ts new file mode 100644 index 00000000000..2b98e0407cd --- /dev/null +++ b/server/sonar-web/src/main/js/api/user-tokens.ts @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, postJSON, post, RequestData } from '../helpers/request'; +import throwGlobalError from '../app/utils/throwGlobalError'; + +/** + * List tokens for given user login + */ +export function getTokens(login: string): Promise { + return getJSON('/api/user_tokens/search', { login }).then(r => r.userTokens); +} + +/** + * Generate a user token + */ +export function generateToken( + tokenName: string, + userLogin?: string +): Promise<{ name: string; token: string }> { + const data: RequestData = { name: tokenName }; + if (userLogin) { + data.login = userLogin; + } + return postJSON('/api/user_tokens/generate', data).catch(throwGlobalError); +} + +/** + * Revoke a user token + */ +export function revokeToken(tokenName: string, userLogin?: string): Promise { + const data: RequestData = { name: tokenName }; + if (userLogin) { + data.login = userLogin; + } + return post('/api/user_tokens/revoke', data).catch(throwGlobalError); +} diff --git a/server/sonar-web/src/main/js/api/user_groups.js b/server/sonar-web/src/main/js/api/user_groups.js deleted file mode 100644 index 71c07fd802b..00000000000 --- a/server/sonar-web/src/main/js/api/user_groups.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -//@flow -import { getJSON, post } from '../helpers/request'; - -export function searchUsersGroups( - data /*: { - f?: string, - organization?: string, - p?: number, - ps?: number, - q?: string -} */ -) { - const url = '/api/user_groups/search'; - return getJSON(url, data); -} - -export function addUserToGroup( - data /*: { - id?: string, - name?: string, - login?: string, - organization?: string -} */ -) { - const url = '/api/user_groups/add_user'; - return post(url, data); -} - -export function removeUserFromGroup( - data /*: { - id?: string, - name?: string, - login?: string, - organization?: string -} */ -) { - const url = '/api/user_groups/remove_user'; - return post(url, data); -} diff --git a/server/sonar-web/src/main/js/api/user_groups.ts b/server/sonar-web/src/main/js/api/user_groups.ts new file mode 100644 index 00000000000..9b2a9bdc5f8 --- /dev/null +++ b/server/sonar-web/src/main/js/api/user_groups.ts @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post } from '../helpers/request'; + +export function searchUsersGroups(data: { + f?: string; + organization?: string; + p?: number; + ps?: number; + q?: string; +}) { + return getJSON('/api/user_groups/search', data); +} + +export function addUserToGroup(data: { + id?: string; + name?: string; + login?: string; + organization?: string; +}) { + return post('/api/user_groups/add_user', data); +} + +export function removeUserFromGroup(data: { + id?: string; + name?: string; + login?: string; + organization?: string; +}) { + return post('/api/user_groups/remove_user', data); +} diff --git a/server/sonar-web/src/main/js/api/users.js b/server/sonar-web/src/main/js/api/users.js deleted file mode 100644 index d7d6c8a45e2..00000000000 --- a/server/sonar-web/src/main/js/api/users.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -//@flow -import { getJSON, post } from '../helpers/request'; - -export function getCurrentUser() { - const url = '/api/users/current'; - return getJSON(url); -} - -export function changePassword( - login /*: string */, - password /*: string */, - previousPassword /*: ?string */ -) { - const url = '/api/users/change_password'; - const data /*: { login: string, password: string, previousPassword?: string } */ = { - login, - password - }; - if (previousPassword != null) { - data.previousPassword = previousPassword; - } - return post(url, data); -} - -export function getUserGroups(login /*: string */, organization /*: ?string */) { - const url = '/api/users/groups'; - const data /*: { login: string, organization?: string, q?: string } */ = { login }; - if (organization) { - data.organization = organization; - } - return getJSON(url, data); -} - -export function getIdentityProviders() { - const url = '/api/users/identity_providers'; - return getJSON(url); -} - -export function searchUsers(query /*: string */, pageSize /*: ?number */) { - const url = '/api/users/search'; - const data /*: { q: string, ps?: number } */ = { q: query }; - if (pageSize != null) { - data.ps = pageSize; - } - return getJSON(url, data); -} - -export function skipOnboarding() /*: Promise */ { - return post('/api/users/skip_onboarding_tutorial'); -} diff --git a/server/sonar-web/src/main/js/api/users.ts b/server/sonar-web/src/main/js/api/users.ts new file mode 100644 index 00000000000..07a5d7996d3 --- /dev/null +++ b/server/sonar-web/src/main/js/api/users.ts @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post, RequestData } from '../helpers/request'; + +export function getCurrentUser(): Promise { + return getJSON('/api/users/current'); +} + +export function changePassword( + login: string, + password: string, + previousPassword?: string +): Promise { + const data: RequestData = { login, password }; + if (previousPassword != null) { + data.previousPassword = previousPassword; + } + return post('/api/users/change_password', data); +} + +export function getUserGroups(login: string, organization?: string): Promise { + const data: RequestData = { login }; + if (organization) { + data.organization = organization; + } + return getJSON('/api/users/groups', data); +} + +export function getIdentityProviders(): Promise { + return getJSON('/api/users/identity_providers'); +} + +export function searchUsers(query: string, pageSize?: number): Promise { + const data: RequestData = { q: query }; + if (pageSize != null) { + data.ps = pageSize; + } + return getJSON('/api/users/search', data); +} + +export function skipOnboarding(): Promise { + return post('/api/users/skip_onboarding_tutorial'); +} diff --git a/server/sonar-web/src/main/js/api/web-api.js b/server/sonar-web/src/main/js/api/web-api.js deleted file mode 100644 index f9323bd67d1..00000000000 --- a/server/sonar-web/src/main/js/api/web-api.js +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getJSON } from '../helpers/request'; - -/*:: -export type Param = { - key: string, - defaultValue?: string, - description: string, - deprecatedKey?: string, - deprecatedKeySince?: string, - deprecatedSince?: string, - exampleValue?: string, - internal: boolean, - possibleValues?: Array, - required: boolean -}; -*/ - -/*:: -export type Action = { - key: string, - description: string, - deprecatedSince?: string, - since?: string, - internal: boolean, - post: boolean, - hasResponseExample: boolean, - changelog: Array<{ - version: string, - description: string - }>, - params?: Array -}; -*/ - -/*:: -export type Domain = { - actions: Array, - description: string, - deprecated: boolean, - internal: boolean, - path: string -}; -*/ - -export function fetchWebApi(showInternal /*: boolean */ = true) /*: Promise> */ { - const url = '/api/webservices/list'; - const data = { include_internals: showInternal }; - - return getJSON(url, data).then(r => - r.webServices.map(domain => { - const deprecated = !domain.actions.find(action => !action.deprecatedSince); - const internal = !domain.actions.find(action => !action.internal); - - return { ...domain, deprecated, internal }; - }) - ); -} - -export function fetchResponseExample( - domain /*: string */, - action /*: string */ -) /*: Promise<{ example: string }> */ { - const url = '/api/webservices/response_example'; - const data = { controller: domain, action }; - - return getJSON(url, data); -} diff --git a/server/sonar-web/src/main/js/api/web-api.ts b/server/sonar-web/src/main/js/api/web-api.ts new file mode 100644 index 00000000000..3bd512e43f9 --- /dev/null +++ b/server/sonar-web/src/main/js/api/web-api.ts @@ -0,0 +1,67 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON } from '../helpers/request'; + +export interface Param { + key: string; + defaultValue?: string; + description: string; + deprecatedKey?: string; + deprecatedKeySince?: string; + deprecatedSince?: string; + exampleValue?: string; + internal: boolean; + possibleValues?: string[]; + required: boolean; +} + +export interface Action { + key: string; + description: string; + deprecatedSince?: string; + since?: string; + internal: boolean; + post: boolean; + hasResponseExample: boolean; + changelog: Array<{ version: string; description: string }>; + params?: Param[]; +} + +export interface Domain { + actions: Action[]; + description: string; + deprecated: boolean; + internal: boolean; + path: string; +} + +export function fetchWebApi(showInternal: boolean = true): Promise> { + return getJSON('/api/webservices/list', { include_internals: showInternal }).then(r => + r.webServices.map((domain: any) => { + const deprecated = !domain.actions.find((action: any) => !action.deprecatedSince); + const internal = !domain.actions.find((action: any) => !action.internal); + return { ...domain, deprecated, internal }; + }) + ); +} + +export function fetchResponseExample(domain: string, action: string): Promise<{ example: string }> { + return getJSON('/api/webservices/response_example', { controller: domain, action }); +} diff --git a/server/sonar-web/src/main/js/app/utils/throwGlobalError.js b/server/sonar-web/src/main/js/app/utils/throwGlobalError.js deleted file mode 100644 index d0441a65c94..00000000000 --- a/server/sonar-web/src/main/js/app/utils/throwGlobalError.js +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import getStore from './getStore'; -import { onFail } from '../../store/rootActions'; - -export default function throwGlobalError(error /*: Object */) { - const store = getStore(); - onFail(store.dispatch)(error); - return Promise.reject(); -} diff --git a/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts b/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts new file mode 100644 index 00000000000..f7c3d929268 --- /dev/null +++ b/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import getStore from './getStore'; +import { onFail } from '../../store/rootActions'; + +export default function throwGlobalError({ response }: { response: Response }): Promise { + const store = getStore(); + onFail(store.dispatch)({ response }); + return Promise.reject(response); +} diff --git a/server/sonar-web/src/main/js/helpers/request.js b/server/sonar-web/src/main/js/helpers/request.js deleted file mode 100644 index f49a5881bdc..00000000000 --- a/server/sonar-web/src/main/js/helpers/request.js +++ /dev/null @@ -1,222 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { stringify } from 'querystring'; -import { omitBy, isNil } from 'lodash'; -import { getCookie } from './cookies'; - -/*:: -type Response = { - json: () => Promise, - status: number -}; -*/ - -export function getCSRFTokenName() /*: string */ { - return 'X-XSRF-TOKEN'; -} - -export function getCSRFTokenValue() /*: string */ { - const cookieName = 'XSRF-TOKEN'; - const cookieValue = getCookie(cookieName); - if (!cookieValue) { - return ''; - } - return cookieValue; -} - -/** - * Return an object containing a special http request header used to prevent CSRF attacks. - * @returns {Object} - */ -export function getCSRFToken() /*: Object */ { - // Fetch API in Edge doesn't work with empty header, - // so we ensure non-empty value - const value = getCSRFTokenValue(); - return value ? { [getCSRFTokenName()]: value } : {}; -} - -export function omitNil(obj /*: Object */) /*: Object */ { - return omitBy(obj, isNil); -} - -/** - * Default options for any request - */ -const DEFAULT_OPTIONS /*: { - credentials: string, - method: string -} */ = { - method: 'GET', - credentials: 'same-origin' -}; - -/** - * Default request headers - */ -const DEFAULT_HEADERS /*: { - 'Accept': string -} */ = { - Accept: 'application/json' -}; - -/** - * Request - */ -class Request { - /*:: url: string; */ - /*:: options: { method?: string }; */ - /*:: headers: Object; */ - /*:: data: ?Object; */ - - constructor(url /*: string */) /*: void */ { - this.url = url; - this.options = {}; - this.headers = {}; - } - - submit() { - let url /*: string */ = this.url; - - const options = { ...DEFAULT_OPTIONS, ...this.options }; - const customHeaders = {}; - - if (this.data) { - if (this.data instanceof FormData) { - options.body = this.data; - } else { - const strData = stringify(omitNil(this.data)); - if (options.method === 'GET') { - url += '?' + strData; - } else { - customHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; - options.body = strData; - } - } - } - - options.headers = { - ...DEFAULT_HEADERS, - ...customHeaders, - ...this.headers, - ...getCSRFToken() - }; - - return window.fetch(window.baseUrl + url, options); - } - - setMethod(method /*: string */) /*: Request */ { - this.options.method = method; - return this; - } - - setData(data /*: ?Object */) /*: Request */ { - this.data = data; - return this; - } - - setHeader(name /*: string */, value /*: string */) /*: Request */ { - this.headers[name] = value; - return this; - } -} - -/** - * Make a request - * @param {string} url - * @returns {Request} - */ -export function request(url /*: string */) /*: Request */ { - return new Request(url); -} - -/** - * Check that response status is ok - * @param response - * @returns {*} - */ -export function checkStatus(response /*: Response */) /*: Promise */ { - return new Promise((resolve, reject) => { - if (response.status === 401) { - // workaround cyclic dependencies - const requireAuthentication = require('../app/utils/handleRequiredAuthentication').default; - requireAuthentication(); - reject(); - } else if (response.status >= 200 && response.status < 300) { - resolve(response); - } else { - reject({ response }); - } - }); -} - -/** - * Parse response as JSON - * @param response - * @returns {object} - */ -export function parseJSON(response /*: Response */) /*: Promise */ { - return response.json(); -} - -/** - * Shortcut to do a GET request and return response json - * @param url - * @param data - */ -export function getJSON(url /*: string */, data /*: ?Object */) /*: Promise */ { - return request(url).setData(data).submit().then(checkStatus).then(parseJSON); -} - -/** - * Shortcut to do a POST request and return response json - * @param url - * @param data - */ -export function postJSON(url /*: string */, data /*: ?Object */) /*: Promise */ { - return request(url).setMethod('POST').setData(data).submit().then(checkStatus).then(parseJSON); -} - -/** - * Shortcut to do a POST request - * @param url - * @param data - */ -export function post(url /*: string */, data /*: ?Object */) /*: Promise */ { - return request(url).setMethod('POST').setData(data).submit().then(checkStatus); -} - -/** - * Shortcut to do a POST request and return response json - * @param url - * @param data - */ -export function requestDelete(url /*: string */, data /*: ?Object */) /*: Promise */ { - return request(url).setMethod('DELETE').setData(data).submit().then(checkStatus); -} - -/** - * Delay promise for testing purposes - * @param response - * @returns {Promise} - */ -export function delay(response /*: * */) /*: Promise<*> */ { - return new Promise(resolve => setTimeout(() => resolve(response), 1200)); -} diff --git a/server/sonar-web/src/main/js/helpers/request.ts b/server/sonar-web/src/main/js/helpers/request.ts new file mode 100644 index 00000000000..b225df5d4fc --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/request.ts @@ -0,0 +1,192 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { stringify } from 'querystring'; +import { omitBy, isNil } from 'lodash'; +import { getCookie } from './cookies'; + +export function getCSRFTokenName(): string { + return 'X-XSRF-TOKEN'; +} + +export function getCSRFTokenValue(): string { + const cookieName = 'XSRF-TOKEN'; + const cookieValue = getCookie(cookieName); + if (!cookieValue) { + return ''; + } + return cookieValue; +} + +/** + * Return an object containing a special http request header used to prevent CSRF attacks. + */ +export function getCSRFToken(): { [x: string]: string } { + // Fetch API in Edge doesn't work with empty header, + // so we ensure non-empty value + const value = getCSRFTokenValue(); + return value ? { [getCSRFTokenName()]: value } : {}; +} + +export function omitNil(obj: { [x: string]: any }): { [x: string]: any } { + return omitBy(obj, isNil); +} + +/** + * Default options for any request + */ +const DEFAULT_OPTIONS: { + credentials: RequestCredentials; + method: string; +} = { + credentials: 'same-origin', + method: 'GET' +}; + +/** + * Default request headers + */ +const DEFAULT_HEADERS = { + Accept: 'application/json' +}; + +export interface RequestData { + [x: string]: any; +} + +/** + * Request + */ +class Request { + private data: RequestData; + + constructor(private url: string, private options: { method?: string } = {}) {} + + submit(): Promise { + let url = this.url; + + const options: RequestInit = { ...DEFAULT_OPTIONS, ...this.options }; + const customHeaders: any = {}; + + if (this.data) { + if (this.data instanceof FormData) { + options.body = this.data; + } else { + const strData = stringify(omitNil(this.data)); + if (options.method === 'GET') { + url += '?' + strData; + } else { + customHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; + options.body = strData; + } + } + } + + options.headers = { + ...DEFAULT_HEADERS, + ...customHeaders, + ...getCSRFToken() + }; + + return window.fetch((window as any).baseUrl + url, options); + } + + setMethod(method: string): Request { + this.options.method = method; + return this; + } + + setData(data?: RequestData): Request { + if (data) { + this.data = data; + } + return this; + } +} + +/** + * Make a request + */ +export function request(url: string): Request { + return new Request(url); +} + +/** + * Check that response status is ok + */ +export function checkStatus(response: Response): Promise { + return new Promise((resolve, reject) => { + if (response.status === 401) { + // workaround cyclic dependencies + const requireAuthentication = require('../app/utils/handleRequiredAuthentication').default; + requireAuthentication(); + reject(); + } else if (response.status >= 200 && response.status < 300) { + resolve(response); + } else { + reject({ response }); + } + }); +} + +/** + * Parse response as JSON + */ +export function parseJSON(response: Response): Promise { + return response.json(); +} + +/** + * Shortcut to do a GET request and return response json + */ +export function getJSON(url: string, data?: RequestData): Promise { + return request(url).setData(data).submit().then(checkStatus).then(parseJSON); +} + +/** + * Shortcut to do a POST request and return response json + */ +export function postJSON(url: string, data?: RequestData): Promise { + return request(url).setMethod('POST').setData(data).submit().then(checkStatus).then(parseJSON); +} + +/** + * Shortcut to do a POST request + */ +export function post(url: string, data?: RequestData): Promise { + return new Promise(resolve => { + request(url).setMethod('POST').setData(data).submit().then(checkStatus).then(() => { + resolve(); + }); + }); +} + +/** + * Shortcut to do a POST request and return response json + */ +export function requestDelete(url: string, data?: RequestData): Promise { + return request(url).setMethod('DELETE').setData(data).submit().then(checkStatus); +} + +/** + * Delay promise for testing purposes + */ +export function delay(response: any): Promise { + return new Promise(resolve => setTimeout(() => resolve(response), 1200)); +}