mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-20 15:29:48 +01:00
Remove plugin center authentication
Squash commits of branch feature/remove_plugin_center_auth: - Remove plugin center authentication - Fix i18n file - Fix tests - Changelog entry
This commit is contained in:
@@ -43,7 +43,6 @@ describe("Test config hooks", () => {
|
||||
namespaceStrategy: "",
|
||||
emergencyContacts: [],
|
||||
pluginUrl: "",
|
||||
pluginAuthUrl: "",
|
||||
proxyExcludes: [],
|
||||
proxyPassword: null,
|
||||
proxyPort: 0,
|
||||
|
||||
@@ -55,7 +55,6 @@ export * from "./annotations";
|
||||
export * from "./search";
|
||||
export * from "./loginInfo";
|
||||
export * from "./useInvalidation";
|
||||
export * from "./usePluginCenterAuthInfo";
|
||||
export * from "./compare";
|
||||
export * from "./utils";
|
||||
export * from "./links";
|
||||
|
||||
@@ -40,7 +40,6 @@ describe("Test plugin hooks", () => {
|
||||
pending: false,
|
||||
dependencies: [],
|
||||
optionalDependencies: [],
|
||||
type: "SCM",
|
||||
_links: {
|
||||
install: { href: "/plugins/available/heart-of-gold-plugin/install" },
|
||||
installWithRestart: {
|
||||
@@ -59,7 +58,6 @@ describe("Test plugin hooks", () => {
|
||||
markedForUninstall: false,
|
||||
dependencies: [],
|
||||
optionalDependencies: [],
|
||||
type: "SCM",
|
||||
_links: {
|
||||
self: {
|
||||
href: "/plugins/installed/heart-of-gold-plugin",
|
||||
@@ -87,7 +85,6 @@ describe("Test plugin hooks", () => {
|
||||
name: "heart-of-gold-core-plugin",
|
||||
pending: false,
|
||||
markedForUninstall: false,
|
||||
type: "SCM",
|
||||
dependencies: [],
|
||||
optionalDependencies: [],
|
||||
_links: {
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 - present Cloudogu GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* 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 Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
import { ApiResult, useIndexLink } from "./base";
|
||||
import { Link, PluginCenterAuthenticationInfo } from "@scm-manager/ui-types";
|
||||
import { useMutation, useQuery, useQueryClient } from "react-query";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
const appendQueryParam = (link: Link, name: string, value: string) => {
|
||||
let href = link.href;
|
||||
if (href.includes("?")) {
|
||||
href += "&";
|
||||
} else {
|
||||
href += "?";
|
||||
}
|
||||
link.href = href + name + "=" + value;
|
||||
};
|
||||
|
||||
export const usePluginCenterAuthInfo = (): ApiResult<PluginCenterAuthenticationInfo> => {
|
||||
const link = useIndexLink("pluginCenterAuth");
|
||||
const location = useLocation();
|
||||
return useQuery<PluginCenterAuthenticationInfo, Error>(
|
||||
["pluginCenterAuth"],
|
||||
() => {
|
||||
if (!link) {
|
||||
throw new Error("no such plugin center auth link");
|
||||
}
|
||||
return apiClient
|
||||
.get(link)
|
||||
.then(response => response.json())
|
||||
.then((result: PluginCenterAuthenticationInfo) => {
|
||||
if (result._links?.login) {
|
||||
appendQueryParam(result._links.login as Link, "source", location.pathname);
|
||||
}
|
||||
if (result._links?.reconnect) {
|
||||
appendQueryParam(result._links.reconnect as Link, "source", location.pathname);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
},
|
||||
{
|
||||
enabled: !!link
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const usePluginCenterLogout = (authenticationInfo: PluginCenterAuthenticationInfo) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { mutate, isLoading, error } = useMutation<unknown, Error>(
|
||||
() => {
|
||||
if (!authenticationInfo._links.logout) {
|
||||
throw new Error("authenticationInfo has no logout link");
|
||||
}
|
||||
const logout = authenticationInfo._links.logout as Link;
|
||||
return apiClient.delete(logout.href);
|
||||
},
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("pluginCenterAuth")
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
logout: () => {
|
||||
mutate();
|
||||
},
|
||||
isLoading,
|
||||
error
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user