diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index 52ac48ee..a226ccb9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -522,6 +522,11 @@ public enum ActionDefinition { ImageIcon.EXPORT, PageStateDefinitionImpl.SEB_CLIENT_CONFIG_VIEW, ActionCategory.FORM), + SEB_CLIENT_CONFIG_DELETE( + new LocTextKey("sebserver.clientconfig.action.delete"), + ImageIcon.DELETE, + PageStateDefinitionImpl.SEB_CLIENT_CONFIG_VIEW, + ActionCategory.FORM), SEB_EXAM_CONFIG_LIST( new LocTextKey("sebserver.examconfig.action.list"), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBClientConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBClientConfigForm.java index ec70de13..7ec7b2f4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBClientConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBClientConfigForm.java @@ -44,11 +44,13 @@ import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; +import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.download.DownloadService; import ch.ethz.seb.sebserver.gui.service.remote.download.SEBClientConfigDownload; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.ActivateClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.DeactivateClientConfig; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.DeleteClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.NewClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.SaveClientConfig; @@ -114,6 +116,11 @@ public class SEBClientConfigForm implements TemplateComposer { private static final LocTextKey FORM_CONFIRM_ENCRYPT_SECRET_TEXT_KEY = new LocTextKey("sebserver.clientconfig.form.encryptSecret.confirm"); + private static final LocTextKey DELETE_CONFIRM = + new LocTextKey("sebserver.clientconfig.action.delete.confirm"); + private static final LocTextKey DELETE_SUCCESS = + new LocTextKey("sebserver.clientconfig.action.delete.success"); + private static final String DEFAULT_PING_INTERVAL = String.valueOf(1000); private static final String FALLBACK_DEFAULT_TIME = String.valueOf(30 * Constants.SECOND_IN_MILLIS); private static final String FALLBACK_DEFAULT_ATTEMPTS = String.valueOf(5); @@ -193,6 +200,12 @@ public class SEBClientConfigForm implements TemplateComposer { .withEntityKey(entityKey) .publishIf(() -> modifyGrant && isReadonly) + .newAction(ActionDefinition.SEB_CLIENT_CONFIG_DELETE) + .withEntityKey(entityKey) + .withConfirm(() -> DELETE_CONFIRM) + .withExec(this::deleteConnectionConfig) + .publishIf(() -> modifyGrant && isReadonly) + .newAction(ActionDefinition.SEB_CLIENT_CONFIG_EXPORT) .withEntityKey(entityKey) .withExec(action -> { @@ -234,6 +247,24 @@ public class SEBClientConfigForm implements TemplateComposer { .publishIf(() -> !isReadonly); } + private PageAction deleteConnectionConfig(final PageAction pageAction) { + + this.restService.getBuilder(DeleteClientConfig.class) + .withURIVariable(API.PARAM_MODEL_ID, pageAction.getEntityKey().modelId) + .call() + .onError(error -> pageAction.pageContext().notifyUnexpectedError(error)) + .ifPresent(rep -> { + if (rep.getErrors().isEmpty()) { + pageAction.pageContext().publishInfo(DELETE_SUCCESS); + } else { + pageAction.pageContext().notifyUnexpectedError( + new RuntimeException(rep.errors.iterator().next().errorMessage.details)); + } + }); + + return pageAction; + } + private void buildForm( final SEBClientConfig clientConfig, final PageContext formContext, diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/clientconfig/DeleteClientConfig.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/clientconfig/DeleteClientConfig.java new file mode 100644 index 00000000..ec384b6c --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/clientconfig/DeleteClientConfig.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig; + +import org.springframework.context.annotation.Lazy; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.type.TypeReference; + +import ch.ethz.seb.sebserver.gbl.api.API; +import ch.ethz.seb.sebserver.gbl.api.EntityType; +import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; +import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; + +@Lazy +@Component +@GuiProfile +public class DeleteClientConfig extends RestCall { + + public DeleteClientConfig() { + super(new TypeKey<>( + CallType.DELETE, + EntityType.EXAM, + new TypeReference() { + }), + HttpMethod.DELETE, + MediaType.APPLICATION_FORM_URLENCODED, + API.SEB_CLIENT_CONFIG_ENDPOINT + API.MODEL_ID_VAR_PATH_SEGMENT); + } + +} diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 9c0a9821..ad7da5b6 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -816,6 +816,8 @@ sebserver.clientconfig.action.save=Save Connection Configuration sebserver.clientconfig.action.activate=Activate Connection Configuration sebserver.clientconfig.action.deactivate=Deactivate Connection Configuration sebserver.clientconfig.action.export=Export Connection Configuration +sebserver.clientconfig.action.delete=Delete Connection Configuration +sebserver.clientconfig.action.delete.confirm=Please note that after deletion of this Connection Configuration,
a SEB that loads a former download of this Connection Configuration will never be able to connect to SEB Server again. ################################ # SEB Exam Configuration