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",
"availableNavLink": "Verfügbar"
},
"showPending": "Änderungen anzeigen",
"executePending": "Änderungen ausführen",
"outdatedPlugins": "{{count}} veraltetes Plugin",
"outdatedPlugins_plural": "{{count}} veraltete Plugins",
@@ -55,6 +56,7 @@
"executeAndRestart": "Ausführen und Neustarten",
"updateAll": "Alle Plugins aktualisieren",
"abort": "Abbrechen",
"close": "Schließen",
"author": "Autor",
"version": "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:",
"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",
"restartNotification": "Der SCM-Manager Kontext 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.",
"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 SCM-Manager neu gestartet.",
"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.",
"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": {

View File

@@ -30,6 +30,7 @@
"installedNavLink": "Installed",
"availableNavLink": "Available"
},
"showPending": "Show changes",
"executePending": "Execute changes",
"outdatedPlugins": "{{count}} outdated plugin",
"outdatedPlugins_plural": "{{count}} outdated plugins",
@@ -55,6 +56,7 @@
"executeAndRestart": "Execute and Restart",
"updateAll": "Update all plugins",
"abort": "Abort",
"close": "Close",
"author": "Author",
"version": "Version",
"currentVersion": "Installed version",
@@ -66,11 +68,12 @@
"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:",
"reload": "reload now",
"restartNotification": "You should only restart the scm-manager context 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.",
"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 will be restarted.",
"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.",
"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": {

View File

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

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Embedded;
@@ -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.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import sonia.scm.lifecycle.Restarter;
import sonia.scm.plugin.AvailablePlugin;
import sonia.scm.plugin.InstalledPlugin;
import sonia.scm.plugin.PluginManager;
@@ -56,12 +57,14 @@ public class PendingPluginResource {
private final PluginManager pluginManager;
private final ResourceLinks resourceLinks;
private final PluginDtoMapper mapper;
private final Restarter restarter;
@Inject
public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper) {
public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper, Restarter restarter) {
this.pluginManager = pluginManager;
this.resourceLinks = resourceLinks;
this.mapper = mapper;
this.restarter = restarter;
}
@GET
@@ -118,7 +121,9 @@ public class PendingPluginResource {
PluginPermissions.manage().isPermitted() &&
(!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()));
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import com.google.inject.util.Providers;
@@ -38,6 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.lifecycle.Restarter;
import sonia.scm.plugin.AvailablePlugin;
import sonia.scm.plugin.AvailablePluginDescriptor;
import sonia.scm.plugin.InstalledPlugin;
@@ -66,10 +67,15 @@ class PendingPluginResourceTest {
private RestDispatcher dispatcher = new RestDispatcher();
@SuppressWarnings("unused")
ResourceLinks resourceLinks = ResourceLinksMock.createMock(create("/"));
@Mock
PluginManager pluginManager;
@Mock
Restarter restarter;
@Mock
PluginDtoMapper mapper;
@@ -109,6 +115,7 @@ class PendingPluginResourceTest {
void bindSubject() {
ThreadContext.bind(subject);
lenient().when(subject.isPermitted("plugin:manage")).thenReturn(true);
lenient().when(restarter.isSupported()).thenReturn(true);
}
@AfterEach
@@ -176,6 +183,23 @@ class PendingPluginResourceTest {
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
void shouldExecutePendingPlugins() throws URISyntaxException {
MockHttpRequest request = MockHttpRequest.post("/v2/plugins/pending/execute");