aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/organizations.ts
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-08-18 19:28:04 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-08-21 10:29:05 +0200
commitb6f7557b705bee15f1b86d325b58dbc539a22245 (patch)
tree927f54e57d3a984240015da744ae760c7f49c08c /server/sonar-web/src/main/js/api/organizations.ts
parent7983068e4d2a45531ba0942688e659adf9ee61a2 (diff)
downloadsonarqube-b6f7557b705bee15f1b86d325b58dbc539a22245.tar.gz
sonarqube-b6f7557b705bee15f1b86d325b58dbc539a22245.zip
translate api/ to ts
Diffstat (limited to 'server/sonar-web/src/main/js/api/organizations.ts')
-rw-r--r--server/sonar-web/src/main/js/api/organizations.ts89
1 files changed, 89 insertions, 0 deletions
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<any> {
+ const data: RequestData = {};
+ if (organizations) {
+ Object.assign(data, { organizations: organizations.join() });
+ }
+ return getJSON('/api/organizations/search', data);
+}
+
+export function getMyOrganizations(): Promise<any> {
+ return getJSON('/api/organizations/search_my_organizations').then(r => r.organizations);
+}
+
+export function getOrganization(key: string): Promise<any> {
+ 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<GetOrganizationNavigation> {
+ return getJSON('/api/navigation/organization', { organization: key }).then(r => r.organization);
+}
+
+export function createOrganization(data: RequestData): Promise<any> {
+ return postJSON('/api/organizations/create', data).then(r => r.organization, throwGlobalError);
+}
+
+export function updateOrganization(key: string, changes: RequestData): Promise<void> {
+ return post('/api/organizations/update', { key, ...changes });
+}
+
+export function deleteOrganization(key: string): Promise<void | Response> {
+ return post('/api/organizations/delete', { key }).catch(throwGlobalError);
+}
+
+export function searchMembers(data: {
+ organization?: string;
+ p?: number;
+ ps?: number;
+ q?: string;
+ selected?: string;
+}): Promise<any> {
+ return getJSON('/api/organizations/search_members', data);
+}
+
+export function addMember(data: { login: string; organization: string }): Promise<any> {
+ return postJSON('/api/organizations/add_member', data).then(r => r.user);
+}
+
+export function removeMember(data: { login: string; organization: string }): Promise<void> {
+ return post('/api/organizations/remove_member', data);
+}
+
+export function changeProjectVisibility(
+ organization: string,
+ projectVisibility: string
+): Promise<void> {
+ return post('/api/organizations/update_project_visibility', { organization, projectVisibility });
+}