import CheckIcon from '../../components/icons/CheckIcon';
import { Alert } from '../../components/ui/Alert';
import { translate, translateWithParameters } from '../../helpers/l10n';
-import { useSyncStatusQuery } from '../../queries/github-sync';
+import { useGitHubSyncStatusQuery } from '../../queries/identity-provider';
import { GithubStatusEnabled } from '../../types/provisioning';
import { TaskStatuses } from '../../types/tasks';
import './SystemAnnouncement.css';
}
function GitHubSynchronisationWarning({ short }: GitHubSynchronisationWarningProps) {
- const { data } = useSyncStatusQuery();
+ const { data } = useGitHubSyncStatusQuery();
if (!data) {
return null;
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
import { throwGlobalError } from '../../../helpers/error';
import { translate } from '../../../helpers/l10n';
-import { useGithubStatusQuery } from '../../settings/components/authentication/queries/identity-provider';
+import { useGithubProvisioningEnabledQuery } from '../../../queries/identity-provider';
import { PERMISSION_TEMPLATES_PATH } from '../utils';
import Form from './Form';
function Header(props: Props) {
const { ready, router } = props;
const [createModal, setCreateModal] = useState(false);
- const { data: gitHubProvisioningStatus } = useGithubStatusQuery();
+ const { data: gitHubProvisioningStatus } = useGithubProvisioningEnabledQuery();
const handleCreateModalSubmit = async (data: {
description: string;
PERMISSIONS_ORDER_FOR_PROJECT_TEMPLATE,
} from '../../../helpers/permissions';
import UseQuery from '../../../helpers/UseQuery';
+import { useGithubProvisioningEnabledQuery } from '../../../queries/identity-provider';
import { Paging, PermissionGroup, PermissionTemplate, PermissionUser } from '../../../types/types';
-import { useGithubStatusQuery } from '../../settings/components/authentication/queries/identity-provider';
import TemplateDetails from './TemplateDetails';
import TemplateHeader from './TemplateHeader';
/>
<main>
<TemplateDetails template={template} />
- <UseQuery query={useGithubStatusQuery}>
+ <UseQuery query={useGithubProvisioningEnabledQuery}>
{({ data: githubProvisioningStatus }) =>
githubProvisioningStatus ? (
<Alert variant="warning" className="sw-w-fit">
import DeferredSpinner from '../../../../components/ui/DeferredSpinner';
import { translate } from '../../../../helpers/l10n';
import { getBaseUrl } from '../../../../helpers/system';
+import { useGithubProvisioningEnabledQuery } from '../../../../queries/identity-provider';
import { isApplication, isPortfolioLike, isProject } from '../../../../types/component';
import { Component } from '../../../../types/types';
-import { useGithubStatusQuery } from '../../../settings/components/authentication/queries/identity-provider';
import ApplyTemplate from './ApplyTemplate';
interface Props {
export default function PageHeader(props: Props) {
const [applyTemplateModal, setApplyTemplateModal] = React.useState(false);
- const { data: githubProvisioningStatus } = useGithubStatusQuery();
+ const { data: githubProvisioningStatus } = useGithubProvisioningEnabledQuery();
const { component, isGitHubProject, loading } = props;
const { configuration } = component;
PERMISSIONS_ORDER_BY_QUALIFIER,
convertToPermissionDefinitions,
} from '../../../../helpers/permissions';
+import { useGithubProvisioningEnabledQuery } from '../../../../queries/identity-provider';
import { AlmKeys } from '../../../../types/alm-settings';
import { ComponentContextShape, Visibility } from '../../../../types/component';
import { Permissions } from '../../../../types/permissions';
import { Component, Paging, PermissionGroup, PermissionUser } from '../../../../types/types';
-import { useGithubStatusQuery } from '../../../settings/components/authentication/queries/identity-provider';
import '../../styles.css';
import PageHeader from './PageHeader';
import PublicProjectDisclaimer from './PublicProjectDisclaimer';
loading={loading}
/>
<div>
- <UseQuery query={useGithubStatusQuery}>
+ <UseQuery query={useGithubProvisioningEnabledQuery}>
{({ data: githubProvisioningStatus, isFetching }) => (
<VisibilitySelector
canTurnToPrivate={canTurnToPrivate}
import { useState } from 'react';
import { getBranchLikeQuery } from '../../../helpers/branch-like';
import { translate } from '../../../helpers/l10n';
-import { BranchLike } from '../../../types/branch-like';
-import { MetricKey } from '../../../types/metrics';
-import { Component } from '../../../types/types';
import {
useBadgeMetricsQuery,
useBadgeTokenQuery,
useRenewBagdeTokenMutation,
-} from '../query/badges';
+} from '../../../queries/badges';
+import { BranchLike } from '../../../types/branch-like';
+import { MetricKey } from '../../../types/metrics';
+import { Component } from '../../../types/types';
import { BadgeFormats, BadgeOptions, BadgeType, getBadgeSnippet, getBadgeUrl } from './utils';
export interface ProjectBadgesProps {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
-import { useContext } from 'react';
-import { getProjectBadgesToken, renewProjectBadgesToken } from '../../../api/project-badges';
-import { fetchWebApi } from '../../../api/web-api';
-import { MetricsContext } from '../../../app/components/metrics/MetricsContext';
-import { getLocalizedMetricName } from '../../../helpers/l10n';
-import { MetricKey } from '../../../types/metrics';
-
-export function useFetchWebApiQuery() {
- return useQuery(['web-api'], () => fetchWebApi(false));
-}
-
-export function useRenewBagdeTokenMutation() {
- const queryClient = useQueryClient();
- return useMutation({
- mutationFn: async (key: string) => {
- await renewProjectBadgesToken(key);
- },
- onSuccess: (_, key) => {
- queryClient.invalidateQueries({ queryKey: ['badges-token', key], refetchType: 'all' });
- },
- });
-}
-
-export function useBadgeMetricsQuery() {
- const metrics = useContext(MetricsContext);
- const { data: webservices = [], ...rest } = useFetchWebApiQuery();
- const domain = webservices.find((d) => d.path === 'api/project_badges');
- const ws = domain?.actions.find((w) => w.key === 'measure');
- const param = ws?.params?.find((p) => p.key === 'metric');
- if (param?.possibleValues) {
- return {
- ...rest,
- data: param.possibleValues.map((key) => {
- const metric = metrics[key];
- return {
- value: key as MetricKey,
- label: metric ? getLocalizedMetricName(metric) : key,
- };
- }),
- };
- }
- return { ...rest, data: [] };
-}
-
-export function useBadgeTokenQuery(componentKey: string) {
- return useQuery(['badges-token', componentKey] as const, ({ queryKey: [_, key] }) =>
- getProjectBadgesToken(key)
- );
-}
import { Button, ResetButtonLink } from '../../components/controls/buttons';
import { Alert } from '../../components/ui/Alert';
import { translate } from '../../helpers/l10n';
+import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider';
import { Visibility } from '../../types/component';
-import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider';
export interface Props {
defaultVisibility: Visibility;
export default function ChangeDefaultVisibilityForm(props: Props) {
const [visibility, setVisibility] = useState(props.defaultVisibility);
- const { data: githubProbivisioningEnabled } = useGithubStatusQuery();
+ const { data: githubProbivisioningEnabled } = useGithubProvisioningEnabledQuery();
const handleConfirmClick = () => {
props.onConfirm(visibility);
import DateFormatter from '../../components/intl/DateFormatter';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { getComponentOverviewUrl } from '../../helpers/urls';
+import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider';
import { ComponentQualifier } from '../../types/component';
import { LoggedInUser } from '../../types/users';
-import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider';
import './ProjectRow.css';
import ProjectRowActions from './ProjectRowActions';
export default function ProjectRow(props: Props) {
const { currentUser, project, selected } = props;
- const { data: githubProvisioningEnabled } = useGithubStatusQuery();
+ const { data: githubProvisioningEnabled } = useGithubProvisioningEnabledQuery();
const handleProjectCheck = (checked: boolean) => {
props.onProjectCheck(project, checked);
import DeferredSpinner from '../../components/ui/DeferredSpinner';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { getComponentPermissionsUrl } from '../../helpers/urls';
+import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider';
import { LoggedInUser } from '../../types/users';
import ApplyTemplate from '../permissions/project/components/ApplyTemplate';
-import { useGithubStatusQuery } from '../settings/components/authentication/queries/identity-provider';
import RestoreAccessModal from './RestoreAccessModal';
export interface Props {
const [hasAccess, setHasAccess] = useState<boolean | undefined>(undefined);
const [loading, setLoading] = useState(false);
const [restoreAccessModal, setRestoreAccessModal] = useState(false);
- const { data: githubProvisioningEnabled } = useGithubStatusQuery();
+ const { data: githubProvisioningEnabled } = useGithubProvisioningEnabledQuery();
const fetchPermissions = () => {
setLoading(true);
import { Alert } from '../../../../components/ui/Alert';
import { translate } from '../../../../helpers/l10n';
import { getBaseUrl } from '../../../../helpers/system';
+import { useGetValuesQuery } from '../../../../queries/settings';
import {
AlmKeys,
AlmSettingsBindingDefinitions,
} from '../../../../types/alm-settings';
import { SettingsKey } from '../../../../types/settings';
import { Dict } from '../../../../types/types';
-import { useGetValuesQuery } from '../../queries/settings';
import { AlmTabs } from './AlmIntegration';
import AlmTab from './AlmTab';
import DeleteModal from './DeleteModal';
import { Alert } from '../../../../components/ui/Alert';
import DeferredSpinner from '../../../../components/ui/DeferredSpinner';
import { translate } from '../../../../helpers/l10n';
+import { useSaveValuesMutation } from '../../../../queries/settings';
import { Dict } from '../../../../types/types';
-import { useSaveValuesMutation } from '../../queries/settings';
import { AuthenticationTabs, DOCUMENTATION_LINK_SUFFIXES } from './Authentication';
import AuthenticationFormField from './AuthenticationFormField';
import { SettingValue } from './hook/useConfiguration';
import HelpIcon from '../../../../components/icons/HelpIcon';
import { Alert, AlertVariant } from '../../../../components/ui/Alert';
import { translate, translateWithParameters } from '../../../../helpers/l10n';
+import { useCheckGitHubConfigQuery } from '../../../../queries/identity-provider';
import { GitHubProvisioningStatus } from '../../../../types/provisioning';
-import { useCheckGitHubConfigQuery } from './queries/identity-provider';
const intlPrefix = 'settings.authentication.github.configuration.validation';
import EditIcon from '../../../../components/icons/EditIcon';
import { Alert } from '../../../../components/ui/Alert';
import { translate, translateWithParameters } from '../../../../helpers/l10n';
-import { useSyncNow } from '../../../../queries/github-sync';
+import {
+ useCheckGitHubConfigQuery,
+ useIdentityProviderQuery,
+ useSyncWithGitHubNow,
+} from '../../../../queries/identity-provider';
import { AlmKeys } from '../../../../types/alm-settings';
import { ExtendedSettingDefinition } from '../../../../types/settings';
import { DOCUMENTATION_LINK_SUFFIXES } from './Authentication';
import ConfigurationForm from './ConfigurationForm';
import GitHubConfigurationValidity from './GitHubConfigurationValidity';
import useGithubConfiguration, { GITHUB_JIT_FIELDS } from './hook/useGithubConfiguration';
-import { useCheckGitHubConfigQuery, useIdentityProviderQuery } from './queries/identity-provider';
interface GithubAuthenticationProps {
definitions: ExtendedSettingDefinition[];
} = useGithubConfiguration(definitions);
const hasDifferentProvider = data?.provider !== undefined && data.provider !== Provider.Github;
- const { canSyncNow, synchronizeNow } = useSyncNow();
+ const { canSyncNow, synchronizeNow } = useSyncWithGitHubNow();
const { refetch } = useCheckGitHubConfigQuery(enabled);
const handleCreateConfiguration = () => {
import EditIcon from '../../../../components/icons/EditIcon';
import { Alert } from '../../../../components/ui/Alert';
import { translate } from '../../../../helpers/l10n';
+import {
+ useIdentityProviderQuery,
+ useToggleScimMutation,
+} from '../../../../queries/identity-provider';
+import { useSaveValueMutation } from '../../../../queries/settings';
import { ExtendedSettingDefinition } from '../../../../types/settings';
-import { useSaveValueMutation } from '../../queries/settings';
import { getPropertyName } from '../../utils';
import DefinitionDescription from '../DefinitionDescription';
import ConfigurationForm from './ConfigurationForm';
SAML_GROUP_NAME,
SAML_SCIM_DEPRECATED,
} from './hook/useSamlConfiguration';
-import { useIdentityProviderQuery, useToggleScimMutation } from './queries/identity-provider';
interface SamlAuthenticationProps {
definitions: ExtendedSettingDefinition[];
import { UseMutationResult } from '@tanstack/react-query';
import { every, isEmpty, keyBy, update } from 'lodash';
import { useCallback, useEffect, useState } from 'react';
+import { useGetValuesQuery, useResetSettingsMutation } from '../../../../../queries/settings';
import { ExtendedSettingDefinition } from '../../../../../types/settings';
import { Dict } from '../../../../../types/types';
-import { useGetValuesQuery, useResetSettingsMutation } from '../../../queries/settings';
export type SettingValue =
| {
import { some } from 'lodash';
import { useContext, useState } from 'react';
import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext';
-import { Feature } from '../../../../../types/features';
-import { ExtendedSettingDefinition } from '../../../../../types/settings';
-import { useSaveValueMutation, useSaveValuesMutation } from '../../../queries/settings';
import {
- useGithubStatusQuery,
+ useGithubProvisioningEnabledQuery,
useToggleGithubProvisioningMutation,
-} from '../queries/identity-provider';
+} from '../../../../../queries/identity-provider';
+import { useSaveValueMutation, useSaveValuesMutation } from '../../../../../queries/settings';
+import { Feature } from '../../../../../types/features';
+import { ExtendedSettingDefinition } from '../../../../../types/settings';
import useConfiguration from './useConfiguration';
export const GITHUB_ENABLED_FIELD = 'sonar.auth.github.enabled';
const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes(
Feature.GithubProvisioning
);
- const { data: githubProvisioningStatus } = useGithubStatusQuery();
+ const { data: githubProvisioningStatus } = useGithubProvisioningEnabledQuery();
const toggleGithubProvisioning = useToggleGithubProvisioningMutation();
const [newGithubProvisioningStatus, setNewGithubProvisioningStatus] = useState<boolean>();
const hasGithubProvisioningTypeChange =
*/
import React from 'react';
import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext';
+import { useScimStatusQuery } from '../../../../../queries/identity-provider';
import { Feature } from '../../../../../types/features';
import { ExtendedSettingDefinition } from '../../../../../types/settings';
-import { useScimStatusQuery } from '../queries/identity-provider';
import useConfiguration from './useConfiguration';
export const SAML_ENABLED_FIELD = 'sonar.auth.saml.enabled';
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
-import { useContext } from 'react';
-import {
- activateGithubProvisioning,
- activateScim,
- checkConfigurationValidity,
- deactivateGithubProvisioning,
- deactivateScim,
- fetchIsScimEnabled,
-} from '../../../../../api/provisioning';
-import { getSystemInfo } from '../../../../../api/system';
-import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext';
-import { mapReactQueryResult } from '../../../../../helpers/react-query';
-import { useSyncStatusQuery } from '../../../../../queries/github-sync';
-import { Feature } from '../../../../../types/features';
-import { SysInfoCluster } from '../../../../../types/types';
-
-export function useIdentityProviderQuery() {
- return useQuery(['identity_provider'], async () => {
- const info = (await getSystemInfo()) as SysInfoCluster;
- return { provider: info.System['External Users and Groups Provisioning'] };
- });
-}
-
-export function useScimStatusQuery() {
- const hasScim = useContext(AvailableFeaturesContext).includes(Feature.Scim);
-
- return useQuery(['identity_provider', 'scim_status'], () => {
- if (!hasScim) {
- return false;
- }
- return fetchIsScimEnabled();
- });
-}
-
-export function useGithubStatusQuery() {
- const res = useSyncStatusQuery({ noRefetch: true });
-
- return mapReactQueryResult(res, (data) => data.enabled);
-}
-
-export function useToggleScimMutation() {
- const client = useQueryClient();
- return useMutation({
- mutationFn: (activate: boolean) => (activate ? activateScim() : deactivateScim()),
- onSuccess: () => {
- client.invalidateQueries({ queryKey: ['identity_provider'] });
- },
- });
-}
-
-export function useToggleGithubProvisioningMutation() {
- const client = useQueryClient();
- return useMutation({
- mutationFn: (activate: boolean) =>
- activate ? activateGithubProvisioning() : deactivateGithubProvisioning(),
- onSuccess: () => {
- client.invalidateQueries({ queryKey: ['identity_provider'] });
- client.invalidateQueries({ queryKey: ['github_sync'] });
- },
- });
-}
-
-export const useCheckGitHubConfigQuery = (githubEnabled: boolean) => {
- return useQuery(['identity_provider', 'github_check'], checkConfigurationValidity, {
- enabled: githubEnabled,
- });
-};
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
-import { getValues, resetSettingValue, setSettingValue } from '../../../api/settings';
-import { ExtendedSettingDefinition } from '../../../types/settings';
-
-type SettingValue = string | boolean | string[];
-
-export function useGetValuesQuery(keys: string[]) {
- return useQuery(['settings', 'values', keys] as const, ({ queryKey: [_a, _b, keys] }) => {
- return getValues({ keys });
- });
-}
-
-export function useResetSettingsMutation() {
- const queryClient = useQueryClient();
- return useMutation({
- mutationFn: (keys: string[]) => resetSettingValue({ keys: keys.join(',') }),
- onSuccess: () => {
- queryClient.invalidateQueries(['settings']);
- },
- });
-}
-
-export function useSaveValuesMutation() {
- const queryClient = useQueryClient();
- return useMutation({
- mutationFn: (
- values: {
- newValue?: SettingValue;
- definition: ExtendedSettingDefinition;
- }[]
- ) => {
- return Promise.all(
- values
- .filter((v) => v.newValue !== undefined)
- .map(async ({ newValue, definition }) => {
- try {
- if (isDefaultValue(newValue as string | boolean | string[], definition)) {
- await resetSettingValue({ keys: definition.key });
- } else {
- await setSettingValue(definition, newValue);
- }
- return { key: definition.key, success: true };
- } catch (error) {
- return { key: definition.key, success: false };
- }
- })
- );
- },
- onSuccess: () => {
- queryClient.invalidateQueries(['settings']);
- },
- });
-}
-
-export function useSaveValueMutation() {
- const queryClient = useQueryClient();
- return useMutation({
- mutationFn: async ({
- newValue,
- definition,
- }: {
- newValue: SettingValue;
- definition: ExtendedSettingDefinition;
- }) => {
- if (isDefaultValue(newValue, definition)) {
- await resetSettingValue({ keys: definition.key });
- } else {
- await setSettingValue(definition, newValue);
- }
- },
- onSuccess: () => {
- queryClient.invalidateQueries(['settings']);
- },
- });
-}
-
-function isDefaultValue(value: SettingValue, definition: ExtendedSettingDefinition) {
- const defaultValue = definition.defaultValue ?? '';
- if (definition.multiValues) {
- return defaultValue === (value as string[]).join(',');
- }
-
- return defaultValue === String(value);
-}
import { Helmet } from 'react-helmet-async';
import { useLocation } from 'react-router-dom';
import { translate } from '../../helpers/l10n';
+import { useOpenAPI } from '../../queries/web-api';
import ApiInformation from './components/ApiInformation';
import ApiSidebar from './components/ApiSidebar';
-import { useOpenAPI } from './queries';
import { URL_DIVIDER, dereferenceSchema } from './utils';
export default function WebApiApp() {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { useQuery } from '@tanstack/react-query';
-import { fetchOpenAPI } from '../../api/web-api';
-
-export const useOpenAPI = () => {
- return useQuery(['open_api'], fetchOpenAPI, { staleTime: Infinity, cacheTime: Infinity });
-};
*/
import { partition } from 'lodash';
import * as React from 'react';
-import { useGithubStatusQuery } from '../../apps/settings/components/authentication/queries/identity-provider';
import UseQuery from '../../helpers/UseQuery';
import { translate } from '../../helpers/l10n';
import { isPermissionDefinitionGroup } from '../../helpers/permissions';
+import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider';
import { Dict, PermissionDefinitions, PermissionGroup, PermissionUser } from '../../types/types';
import GroupHolder from './GroupHolder';
import PermissionHeader from './PermissionHeader';
renderItem(item: PermissionUser | PermissionGroup, permissions: PermissionDefinitions) {
const { isGitHubProject, selectedPermission, isComponentPrivate } = this.props;
return (
- <UseQuery key={this.getKey(item)} query={useGithubStatusQuery}>
+ <UseQuery key={this.getKey(item)} query={useGithubProvisioningEnabledQuery}>
{({ data: githubProvisioningStatus }) => (
<>
{this.isPermissionUser(item) ? (
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { useContext } from 'react';
+import { getProjectBadgesToken, renewProjectBadgesToken } from '../api/project-badges';
+import { MetricsContext } from '../app/components/metrics/MetricsContext';
+import { getLocalizedMetricName } from '../helpers/l10n';
+import { MetricKey } from '../types/metrics';
+import { useWebApiQuery } from './web-api';
+
+export function useRenewBagdeTokenMutation() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async (key: string) => {
+ await renewProjectBadgesToken(key);
+ },
+ onSuccess: (_, key) => {
+ queryClient.invalidateQueries({ queryKey: ['badges-token', key], refetchType: 'all' });
+ },
+ });
+}
+
+export function useBadgeMetricsQuery() {
+ const metrics = useContext(MetricsContext);
+ const { data: webservices = [], ...rest } = useWebApiQuery();
+ const domain = webservices.find((d) => d.path === 'api/project_badges');
+ const ws = domain?.actions.find((w) => w.key === 'measure');
+ const param = ws?.params?.find((p) => p.key === 'metric');
+ if (param?.possibleValues) {
+ return {
+ ...rest,
+ data: param.possibleValues.map((key) => {
+ const metric = metrics[key];
+ return {
+ value: key as MetricKey,
+ label: metric ? getLocalizedMetricName(metric) : key,
+ };
+ }),
+ };
+ }
+ return { ...rest, data: [] };
+}
+
+export function useBadgeTokenQuery(componentKey: string) {
+ return useQuery(['badges-token', componentKey] as const, ({ queryKey: [_, key] }) =>
+ getProjectBadgesToken(key)
+ );
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
-import { useContext } from 'react';
-import { fetchGithubProvisioningStatus, syncNowGithubProvisioning } from '../api/provisioning';
-import { AvailableFeaturesContext } from '../app/components/available-features/AvailableFeaturesContext';
-import { Feature } from '../types/features';
-
-interface GithubSyncStatusOptions {
- noRefetch?: boolean;
-}
-
-export function useSyncStatusQuery(options: GithubSyncStatusOptions = {}) {
- const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes(
- Feature.GithubProvisioning
- );
- return useQuery(['github_sync', 'status'], fetchGithubProvisioningStatus, {
- enabled: hasGithubProvisioning,
- refetchInterval: options.noRefetch ? undefined : 10_000,
- });
-}
-
-export function useSyncNow() {
- const queryClient = useQueryClient();
- const { data } = useSyncStatusQuery();
- const mutation = useMutation(syncNowGithubProvisioning, {
- onSuccess: () => {
- queryClient.invalidateQueries(['github_sync']);
- },
- });
-
- return {
- synchronizeNow: mutation.mutate,
- canSyncNow: data && data.enabled && !data.nextSync && !mutation.isLoading,
- };
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { useContext } from 'react';
+import {
+ activateGithubProvisioning,
+ activateScim,
+ checkConfigurationValidity,
+ deactivateGithubProvisioning,
+ deactivateScim,
+ fetchGithubProvisioningStatus,
+ fetchIsScimEnabled,
+ syncNowGithubProvisioning,
+} from '../api/provisioning';
+import { getSystemInfo } from '../api/system';
+import { AvailableFeaturesContext } from '../app/components/available-features/AvailableFeaturesContext';
+import { mapReactQueryResult } from '../helpers/react-query';
+import { Feature } from '../types/features';
+import { SysInfoCluster } from '../types/types';
+
+export function useIdentityProviderQuery() {
+ return useQuery(['identity_provider'], async () => {
+ const info = (await getSystemInfo()) as SysInfoCluster;
+ return { provider: info.System['External Users and Groups Provisioning'] };
+ });
+}
+
+export function useScimStatusQuery() {
+ const hasScim = useContext(AvailableFeaturesContext).includes(Feature.Scim);
+
+ return useQuery(['identity_provider', 'scim_status'], () => {
+ if (!hasScim) {
+ return false;
+ }
+ return fetchIsScimEnabled();
+ });
+}
+
+export function useToggleScimMutation() {
+ const client = useQueryClient();
+ return useMutation({
+ mutationFn: (activate: boolean) => (activate ? activateScim() : deactivateScim()),
+ onSuccess: () => {
+ client.invalidateQueries({ queryKey: ['identity_provider'] });
+ },
+ });
+}
+
+export function useToggleGithubProvisioningMutation() {
+ const client = useQueryClient();
+ return useMutation({
+ mutationFn: (activate: boolean) =>
+ activate ? activateGithubProvisioning() : deactivateGithubProvisioning(),
+ onSuccess: () => {
+ client.invalidateQueries({ queryKey: ['identity_provider'] });
+ },
+ });
+}
+
+export const useCheckGitHubConfigQuery = (githubEnabled: boolean) => {
+ return useQuery(['identity_provider', 'github_check'], checkConfigurationValidity, {
+ enabled: githubEnabled,
+ });
+};
+
+interface GithubSyncStatusOptions {
+ noRefetch?: boolean;
+}
+
+export function useGitHubSyncStatusQuery(options: GithubSyncStatusOptions = {}) {
+ const hasGithubProvisioning = useContext(AvailableFeaturesContext).includes(
+ Feature.GithubProvisioning
+ );
+ return useQuery(['identity_provider', 'github_sync', 'status'], fetchGithubProvisioningStatus, {
+ enabled: hasGithubProvisioning,
+ refetchInterval: options.noRefetch ? undefined : 10_000,
+ });
+}
+
+export function useGithubProvisioningEnabledQuery() {
+ const res = useGitHubSyncStatusQuery({ noRefetch: true });
+
+ return mapReactQueryResult(res, (data) => data.enabled);
+}
+
+export function useSyncWithGitHubNow() {
+ const queryClient = useQueryClient();
+ const { data } = useGitHubSyncStatusQuery();
+ const mutation = useMutation(syncNowGithubProvisioning, {
+ onSuccess: () => {
+ queryClient.invalidateQueries(['identity_provider', 'github_sync']);
+ },
+ });
+
+ return {
+ synchronizeNow: mutation.mutate,
+ canSyncNow: data?.enabled && !data.nextSync && !mutation.isLoading,
+ };
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
+import { getValues, resetSettingValue, setSettingValue } from '../api/settings';
+import { ExtendedSettingDefinition } from '../types/settings';
+
+type SettingValue = string | boolean | string[];
+
+export function useGetValuesQuery(keys: string[]) {
+ return useQuery(['settings', 'values', keys] as const, ({ queryKey: [_a, _b, keys] }) => {
+ return getValues({ keys });
+ });
+}
+
+export function useResetSettingsMutation() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: (keys: string[]) => resetSettingValue({ keys: keys.join(',') }),
+ onSuccess: () => {
+ queryClient.invalidateQueries(['settings']);
+ },
+ });
+}
+
+export function useSaveValuesMutation() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: (
+ values: {
+ newValue?: SettingValue;
+ definition: ExtendedSettingDefinition;
+ }[]
+ ) => {
+ return Promise.all(
+ values
+ .filter((v) => v.newValue !== undefined)
+ .map(async ({ newValue, definition }) => {
+ try {
+ if (isDefaultValue(newValue as string | boolean | string[], definition)) {
+ await resetSettingValue({ keys: definition.key });
+ } else {
+ await setSettingValue(definition, newValue);
+ }
+ return { key: definition.key, success: true };
+ } catch (error) {
+ return { key: definition.key, success: false };
+ }
+ })
+ );
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries(['settings']);
+ },
+ });
+}
+
+export function useSaveValueMutation() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async ({
+ newValue,
+ definition,
+ }: {
+ newValue: SettingValue;
+ definition: ExtendedSettingDefinition;
+ }) => {
+ if (isDefaultValue(newValue, definition)) {
+ await resetSettingValue({ keys: definition.key });
+ } else {
+ await setSettingValue(definition, newValue);
+ }
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries(['settings']);
+ },
+ });
+}
+
+function isDefaultValue(value: SettingValue, definition: ExtendedSettingDefinition) {
+ const defaultValue = definition.defaultValue ?? '';
+ if (definition.multiValues) {
+ return defaultValue === (value as string[]).join(',');
+ }
+
+ return defaultValue === String(value);
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { useQuery } from '@tanstack/react-query';
+import { fetchOpenAPI, fetchWebApi } from '../api/web-api';
+
+export function useWebApiQuery() {
+ return useQuery(['web-api'], () => fetchWebApi(false));
+}
+
+export const useOpenAPI = () => {
+ return useQuery(['open_api'], fetchOpenAPI, { staleTime: Infinity, cacheTime: Infinity });
+};