show execute and restart button only if restarting is supported

This commit is contained in:
Sebastian Sdorra
2020-03-24 15:58:33 +01:00
parent 2873c44b52
commit fbc86e7d33
8 changed files with 252 additions and 101 deletions

View File

@@ -30,6 +30,7 @@
"installedNavLink": "Installiert", "installedNavLink": "Installiert",
"availableNavLink": "Verfügbar" "availableNavLink": "Verfügbar"
}, },
"showPending": "Änderungen anzeigen",
"executePending": "Änderungen ausführen", "executePending": "Änderungen ausführen",
"outdatedPlugins": "{{count}} veraltetes Plugin", "outdatedPlugins": "{{count}} veraltetes Plugin",
"outdatedPlugins_plural": "{{count}} veraltete Plugins", "outdatedPlugins_plural": "{{count}} veraltete Plugins",
@@ -55,6 +56,7 @@
"executeAndRestart": "Ausführen und Neustarten", "executeAndRestart": "Ausführen und Neustarten",
"updateAll": "Alle Plugins aktualisieren", "updateAll": "Alle Plugins aktualisieren",
"abort": "Abbrechen", "abort": "Abbrechen",
"close": "Schließen",
"author": "Autor", "author": "Autor",
"version": "Version", "version": "Version",
"currentVersion": "Installierte Version", "currentVersion": "Installierte Version",
@@ -66,11 +68,12 @@
"uninstalledNotification": "Das Plugin wurde erfolgreich installiert. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:", "uninstalledNotification": "Das Plugin wurde erfolgreich installiert. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:",
"executedChangesNotification": "Die Plugin Änderungen wurden erfolgreich durchgeführt. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:", "executedChangesNotification": "Die Plugin Änderungen wurden erfolgreich durchgeführt. Um Änderungen an der UI zu sehen, muss die Seite neu geladen werden:",
"reload": "jetzt neu laden", "reload": "jetzt neu laden",
"restartNotification": "Der SCM-Manager Kontext sollte nur neu gestartet werden, wenn aktuell niemand damit arbeitet.", "restartNotification": "Der SCM-Manager sollte nur neu gestartet werden, wenn aktuell niemand damit arbeitet.",
"executePending": "Die folgenden Plugin-Änderungen werden ausgeführt. Anschließend wird der SCM-Manager Kontext neu gestartet.", "executePending": "Die folgenden Plugin-Änderungen werden ausgeführt. Anschließend wird SCM-Manager neu gestartet.",
"cancelPending": "Die folgenden Plugin-Änderungen werden abgebrochen und zurückgesetzt.", "cancelPending": "Die folgenden Plugin-Änderungen werden abgebrochen und zurückgesetzt.",
"updateAllInfo": "Die folgenden Plugins werden aktualisiert. Die Änderungen werden nach dem nächsten Neustart wirksam.", "updateAllInfo": "Die folgenden Plugins werden aktualisiert. Die Änderungen werden nach dem nächsten Neustart wirksam.",
"manualRestartRequired": "Nach dem die Plugin-Änderung durchgeführt wurde, muss SCM-Manager neu gestartet werden." "manualRestartRequired": "Nach dem die Plugin-Änderung durchgeführt wurde, muss SCM-Manager neu gestartet werden.",
"showPending": "Um die folgenden Plugin-Änderungen auszuführen muss SCM-Manager neu gestartet werden."
} }
}, },
"repositoryRole": { "repositoryRole": {

View File

@@ -30,6 +30,7 @@
"installedNavLink": "Installed", "installedNavLink": "Installed",
"availableNavLink": "Available" "availableNavLink": "Available"
}, },
"showPending": "Show changes",
"executePending": "Execute changes", "executePending": "Execute changes",
"outdatedPlugins": "{{count}} outdated plugin", "outdatedPlugins": "{{count}} outdated plugin",
"outdatedPlugins_plural": "{{count}} outdated plugins", "outdatedPlugins_plural": "{{count}} outdated plugins",
@@ -55,6 +56,7 @@
"executeAndRestart": "Execute and Restart", "executeAndRestart": "Execute and Restart",
"updateAll": "Update all plugins", "updateAll": "Update all plugins",
"abort": "Abort", "abort": "Abort",
"close": "Close",
"author": "Author", "author": "Author",
"version": "Version", "version": "Version",
"currentVersion": "Installed version", "currentVersion": "Installed version",
@@ -66,11 +68,12 @@
"uninstalledNotification": "Successfully uninstalled plugin. You have to reload the page, to see ui changes:", "uninstalledNotification": "Successfully uninstalled plugin. You have to reload the page, to see ui changes:",
"executedChangesNotification": "Successfully executed plugin changes. You have to reload the page, to see ui changes:", "executedChangesNotification": "Successfully executed plugin changes. You have to reload the page, to see ui changes:",
"reload": "reload now", "reload": "reload now",
"restartNotification": "You should only restart the scm-manager context if no one else is currently working with it.", "restartNotification": "You should only restart scm-manager if no one else is currently working with it.",
"executePending": "The following plugin changes will be executed and after that the scm-manager context will be restarted.", "executePending": "The following plugin changes will be executed and after that the scm-manager will be restarted.",
"cancelPending": "The following plugin changes will be canceled.", "cancelPending": "The following plugin changes will be canceled.",
"updateAllInfo": "The following plugin changes will be executed. You need to restart the scm-manager to make these changes effective.", "updateAllInfo": "The following plugin changes will be executed. You need to restart the scm-manager to make these changes effective.",
"manualRestartRequired": "After the plugin change has been made, scm-manager must be restarted." "manualRestartRequired": "After the plugin change has been made, scm-manager must be restarted.",
"showPending": "To execute the following plugin changes, scm-manager must be restarted."
} }
}, },
"repositoryRole": { "repositoryRole": {

View File

@@ -27,6 +27,7 @@ import { PendingPlugins } from "@scm-manager/ui-types";
import { WithTranslation, withTranslation } from "react-i18next"; import { WithTranslation, withTranslation } from "react-i18next";
import waitForRestart from "./waitForRestart"; import waitForRestart from "./waitForRestart";
import SuccessNotification from "./SuccessNotification"; import SuccessNotification from "./SuccessNotification";
import PendingPluginsQueue from "./PendingPluginsQueue";
type Props = WithTranslation & { type Props = WithTranslation & {
onClose: () => void; onClose: () => void;
@@ -85,70 +86,14 @@ class ExecutePendingModal extends React.Component<Props, State> {
}); });
}; };
renderInstallQueue = () => {
const { pendingPlugins, t } = this.props;
return (
<>
{pendingPlugins._embedded && pendingPlugins._embedded.new.length > 0 && (
<>
<strong>{t("plugins.modal.installQueue")}</strong>
<ul>
{pendingPlugins._embedded.new.map(plugin => (
<li key={plugin.name}>{plugin.name}</li>
))}
</ul>
</>
)}
</>
);
};
renderUpdateQueue = () => {
const { pendingPlugins, t } = this.props;
return (
<>
{pendingPlugins._embedded && pendingPlugins._embedded.update.length > 0 && (
<>
<strong>{t("plugins.modal.updateQueue")}</strong>
<ul>
{pendingPlugins._embedded.update.map(plugin => (
<li key={plugin.name}>{plugin.name}</li>
))}
</ul>
</>
)}
</>
);
};
renderUninstallQueue = () => {
const { pendingPlugins, t } = this.props;
return (
<>
{pendingPlugins._embedded && pendingPlugins._embedded.uninstall.length > 0 && (
<>
<strong>{t("plugins.modal.uninstallQueue")}</strong>
<ul>
{pendingPlugins._embedded.uninstall.map(plugin => (
<li key={plugin.name}>{plugin.name}</li>
))}
</ul>
</>
)}
</>
);
};
renderBody = () => { renderBody = () => {
const { t } = this.props; const { pendingPlugins, t } = this.props;
return ( return (
<> <>
<div className="media"> <div className="media">
<div className="content"> <div className="content">
<p>{t("plugins.modal.executePending")}</p> <p>{t("plugins.modal.executePending")}</p>
{this.renderInstallQueue()} <PendingPluginsQueue pendingPlugins={pendingPlugins} />
{this.renderUpdateQueue()}
{this.renderUninstallQueue()}
</div> </div>
</div> </div>
<div className="media">{this.renderNotifications()}</div> <div className="media">{this.renderNotifications()}</div>

View File

@@ -0,0 +1,66 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { FC } from "react";
import { PendingPlugins } from "@scm-manager/ui-types";
import { useTranslation } from "react-i18next";
type Props = {
pendingPlugins: PendingPlugins;
};
type SectionProps = Props & {
type: string;
label: string;
};
const Section: FC<SectionProps> = ({ pendingPlugins, type, label }) => {
const plugins = pendingPlugins?._embedded[type];
if (!plugins || plugins.length === 0) {
return null;
}
return (
<>
<strong>{label}</strong>
<ul>
{plugins.map(plugin => (
<li key={plugin.name}>{plugin.name}</li>
))}
</ul>
</>
);
};
const PendingPluginsQueue: FC<Props> = ({ pendingPlugins }) => {
const [t] = useTranslation("admin");
return (
<>
<Section pendingPlugins={pendingPlugins} type="new" label={t("plugins.modal.installQueue")} />
<Section pendingPlugins={pendingPlugins} type="update" label={t("plugins.modal.updateQueue")} />
<Section pendingPlugins={pendingPlugins} type="uninstall" label={t("plugins.modal.uninstallQueue")} />
</>
);
};
export default PendingPluginsQueue;

View File

@@ -0,0 +1,70 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { FC } from "react";
import { Button, Modal, Notification } from "@scm-manager/ui-components";
import { PendingPlugins } from "@scm-manager/ui-types";
import { useTranslation } from "react-i18next";
import PendingPluginsQueue from "./PendingPluginsQueue";
type ModalBodyProps = {
pendingPlugins: PendingPlugins;
};
const ModalBody: FC<ModalBodyProps> = ({ pendingPlugins }) => {
const [t] = useTranslation("admin");
return (
<>
<div className="media">
<div className="content">
<p>{t("plugins.modal.showPending")}</p>
<PendingPluginsQueue pendingPlugins={pendingPlugins} />
</div>
</div>
<div className="media">
<Notification type="warning">{t("plugins.modal.restartNotification")}</Notification>
</div>
</>
);
};
type Props = {
onClose: () => void;
pendingPlugins: PendingPlugins;
};
const ShowPendingModal: FC<Props> = ({ pendingPlugins, onClose }) => {
const [t] = useTranslation("admin");
return (
<Modal
title={t("plugins.showPending")}
closeFunction={onClose}
body={<ModalBody pendingPlugins={pendingPlugins} />}
footer={<Button label={t("plugins.modal.close")} action={onClose} />}
active={true}
/>
);
};
export default ShowPendingModal;

View File

@@ -55,6 +55,7 @@ import ExecutePendingActionModal from "../components/ExecutePendingActionModal";
import CancelPendingActionModal from "../components/CancelPendingActionModal"; import CancelPendingActionModal from "../components/CancelPendingActionModal";
import UpdateAllActionModal from "../components/UpdateAllActionModal"; import UpdateAllActionModal from "../components/UpdateAllActionModal";
import { Plugin } from "@scm-manager/ui-types/src"; import { Plugin } from "@scm-manager/ui-types/src";
import ShowPendingModal from "../components/ShowPendingModal";
type Props = WithTranslation & { type Props = WithTranslation & {
loading: boolean; loading: boolean;
@@ -74,6 +75,7 @@ type Props = WithTranslation & {
type State = { type State = {
showPendingModal: boolean; showPendingModal: boolean;
showExecutePendingModal: boolean;
showUpdateAllModal: boolean; showUpdateAllModal: boolean;
showCancelModal: boolean; showCancelModal: boolean;
}; };
@@ -83,6 +85,7 @@ class PluginsOverview extends React.Component<Props, State> {
super(props); super(props);
this.state = { this.state = {
showPendingModal: false, showPendingModal: false,
showExecutePendingModal: false,
showUpdateAllModal: false, showUpdateAllModal: false,
showCancelModal: false showCancelModal: false
}; };
@@ -138,38 +141,57 @@ class PluginsOverview extends React.Component<Props, State> {
const { pendingPlugins, collection, t } = this.props; const { pendingPlugins, collection, t } = this.props;
const buttons = []; const buttons = [];
if (pendingPlugins && pendingPlugins._links && pendingPlugins._links.execute) { if (pendingPlugins && pendingPlugins._links) {
buttons.push( if (pendingPlugins._links.execute) {
<Button buttons.push(
color="primary" <Button
reducedMobile={true} color="primary"
key={"executePending"} reducedMobile={true}
icon={"arrow-circle-right"} key={"executePending"}
label={t("plugins.executePending")} icon={"arrow-circle-right"}
action={() => label={t("plugins.executePending")}
this.setState({ action={() =>
showPendingModal: true this.setState({
}) showExecutePendingModal: true
} })
/> }
); />
} );
}
if (pendingPlugins && pendingPlugins._links && pendingPlugins._links.cancel) { if (pendingPlugins._links.cancel) {
buttons.push( if (!pendingPlugins._links.execute) {
<Button buttons.push(
color="primary" <Button
reducedMobile={true} color="primary"
key={"cancelPending"} reducedMobile={true}
icon={"times"} key={"showPending"}
label={t("plugins.cancelPending")} icon={"info"}
action={() => label={t("plugins.showPending")}
this.setState({ action={() =>
showCancelModal: true this.setState({
}) showPendingModal: true
} })
/> }
); />
);
}
buttons.push(
<Button
color="primary"
reducedMobile={true}
key={"cancelPending"}
icon={"times"}
label={t("plugins.cancelPending")}
action={() =>
this.setState({
showCancelModal: true
})
}
/>
);
}
} }
if (collection && collection._links && collection._links.update) { if (collection && collection._links && collection._links.update) {
@@ -228,14 +250,27 @@ class PluginsOverview extends React.Component<Props, State> {
renderModals = () => { renderModals = () => {
const { collection, pendingPlugins } = this.props; const { collection, pendingPlugins } = this.props;
const { showPendingModal, showCancelModal, showUpdateAllModal } = this.state; const { showPendingModal, showExecutePendingModal, showCancelModal, showUpdateAllModal } = this.state;
if (showPendingModal) { if (showPendingModal) {
return (
<ShowPendingModal
onClose={() =>
this.setState({
showPendingModal: false
})
}
pendingPlugins={pendingPlugins}
/>
);
}
if (showExecutePendingModal) {
return ( return (
<ExecutePendingActionModal <ExecutePendingActionModal
onClose={() => onClose={() =>
this.setState({ this.setState({
showPendingModal: false showExecutePendingModal: false
}) })
} }
pendingPlugins={pendingPlugins} pendingPlugins={pendingPlugins}

View File

@@ -31,6 +31,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import sonia.scm.lifecycle.Restarter;
import sonia.scm.plugin.AvailablePlugin; import sonia.scm.plugin.AvailablePlugin;
import sonia.scm.plugin.InstalledPlugin; import sonia.scm.plugin.InstalledPlugin;
import sonia.scm.plugin.PluginManager; import sonia.scm.plugin.PluginManager;
@@ -56,12 +57,14 @@ public class PendingPluginResource {
private final PluginManager pluginManager; private final PluginManager pluginManager;
private final ResourceLinks resourceLinks; private final ResourceLinks resourceLinks;
private final PluginDtoMapper mapper; private final PluginDtoMapper mapper;
private final Restarter restarter;
@Inject @Inject
public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper) { public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper, Restarter restarter) {
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
this.resourceLinks = resourceLinks; this.resourceLinks = resourceLinks;
this.mapper = mapper; this.mapper = mapper;
this.restarter = restarter;
} }
@GET @GET
@@ -118,7 +121,9 @@ public class PendingPluginResource {
PluginPermissions.manage().isPermitted() && PluginPermissions.manage().isPermitted() &&
(!installDtos.isEmpty() || !updateDtos.isEmpty() || !uninstallDtos.isEmpty()) (!installDtos.isEmpty() || !updateDtos.isEmpty() || !uninstallDtos.isEmpty())
) { ) {
linksBuilder.single(link("execute", resourceLinks.pendingPluginCollection().executePending())); if (restarter.isSupported()) {
linksBuilder.single(link("execute", resourceLinks.pendingPluginCollection().executePending()));
}
linksBuilder.single(link("cancel", resourceLinks.pendingPluginCollection().cancelPending())); linksBuilder.single(link("cancel", resourceLinks.pendingPluginCollection().cancelPending()));
} }

View File

@@ -38,6 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.lifecycle.Restarter;
import sonia.scm.plugin.AvailablePlugin; import sonia.scm.plugin.AvailablePlugin;
import sonia.scm.plugin.AvailablePluginDescriptor; import sonia.scm.plugin.AvailablePluginDescriptor;
import sonia.scm.plugin.InstalledPlugin; import sonia.scm.plugin.InstalledPlugin;
@@ -66,10 +67,15 @@ class PendingPluginResourceTest {
private RestDispatcher dispatcher = new RestDispatcher(); private RestDispatcher dispatcher = new RestDispatcher();
@SuppressWarnings("unused")
ResourceLinks resourceLinks = ResourceLinksMock.createMock(create("/")); ResourceLinks resourceLinks = ResourceLinksMock.createMock(create("/"));
@Mock @Mock
PluginManager pluginManager; PluginManager pluginManager;
@Mock
Restarter restarter;
@Mock @Mock
PluginDtoMapper mapper; PluginDtoMapper mapper;
@@ -109,6 +115,7 @@ class PendingPluginResourceTest {
void bindSubject() { void bindSubject() {
ThreadContext.bind(subject); ThreadContext.bind(subject);
lenient().when(subject.isPermitted("plugin:manage")).thenReturn(true); lenient().when(subject.isPermitted("plugin:manage")).thenReturn(true);
lenient().when(restarter.isSupported()).thenReturn(true);
} }
@AfterEach @AfterEach
@@ -176,6 +183,23 @@ class PendingPluginResourceTest {
assertThat(response.getContentAsString()).contains("\"execute\":{\"href\":\"/v2/plugins/pending/execute\"}"); assertThat(response.getContentAsString()).contains("\"execute\":{\"href\":\"/v2/plugins/pending/execute\"}");
} }
@Test
void shouldNotReturnExecuteLinkIfRestartIsNotSupported() throws URISyntaxException, UnsupportedEncodingException {
when(restarter.isSupported()).thenReturn(false);
when(pluginManager.getAvailable()).thenReturn(emptyList());
InstalledPlugin installedPlugin = createInstalledPlugin("uninstalled-plugin");
when(installedPlugin.isMarkedForUninstall()).thenReturn(true);
when(pluginManager.getInstalled()).thenReturn(singletonList(installedPlugin));
MockHttpRequest request = MockHttpRequest.get("/v2/plugins/pending");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
assertThat(response.getContentAsString()).contains("\"uninstall\":[{\"name\":\"uninstalled-plugin\"");
assertThat(response.getContentAsString()).doesNotContain("\"execute\"");
}
@Test @Test
void shouldExecutePendingPlugins() throws URISyntaxException { void shouldExecutePendingPlugins() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest.post("/v2/plugins/pending/execute"); MockHttpRequest request = MockHttpRequest.post("/v2/plugins/pending/execute");