diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/LoginPage.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/LoginPage.java index 240224d3..82cdd89b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/LoginPage.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/LoginPage.java @@ -60,6 +60,7 @@ public class LoginPage implements TemplateComposer { final PageService pageService, final DefaultRegisterPage defaultRegisterPage, @Value("${sebserver.gui.registering:false}") final boolean guiRegEnabled, + @Value("${sebserver.gui.self-registering:false}") final boolean guiRegEnabledOld, @Value("${sebserver.feature.admin.user.account.self.registering:true}") final boolean webRegEnabled) { this.pageService = pageService; @@ -67,7 +68,7 @@ public class LoginPage implements TemplateComposer { this.widgetFactory = pageService.getWidgetFactory(); this.i18nSupport = pageService.getI18nSupport(); this.defaultRegisterPage = defaultRegisterPage; - this.registeringEnabled = webRegEnabled && guiRegEnabled; + this.registeringEnabled = webRegEnabled && (guiRegEnabled || guiRegEnabledOld); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java index c13d387f..51a62228 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamFormConfigs.java @@ -137,6 +137,7 @@ public class ExamFormConfigs implements TemplateComposer { .withSelectionListener(this.pageService.getSelectionPublisher( pageContext, + ActionDefinition.EXAM_CONFIGURATION_MODIFY_FROM_LIST, ActionDefinition.EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP, ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST, ActionDefinition.EXAM_CONFIGURATION_EXPORT, @@ -144,7 +145,7 @@ public class ExamFormConfigs implements TemplateComposer { .compose(pageContext.copyOf(content)); - final EntityKey configMapKey = (configurationTable.hasAnyContent()) + final EntityKey configKey = (configurationTable.hasAnyContent()) ? new EntityKey( configurationTable.getFirstRowData().configurationNodeId, EntityType.CONFIGURATION_NODE) @@ -162,9 +163,18 @@ public class ExamFormConfigs implements TemplateComposer { .noEventPropagation() .publishIf(() -> examConfigEnabled && editable && !configurationTable.hasAnyContent()) + .newAction(ActionDefinition.EXAM_CONFIGURATION_MODIFY_FROM_LIST) + .withParentEntityKey(entityKey) + .withSelect( + getConfigMappingSelection(configurationTable), + this.examToConfigBindingForm.bindFunction(), + CONFIG_EMPTY_SELECTION_TEXT_KEY) + .noEventPropagation() + .publishIf(() -> examConfigEnabled && editable && configurationTable.hasAnyContent(), false) + .newAction(ActionDefinition.EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP) .withParentEntityKey(entityKey) - .withEntityKey(configMapKey) + .withEntityKey(configKey) .publishIf(() -> examConfigEnabled && readGrant && configurationTable.hasAnyContent(), false) .newAction(ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST) @@ -179,7 +189,7 @@ public class ExamFormConfigs implements TemplateComposer { } return null; }) - .publishIf(() -> examConfigEnabled && editable && configurationTable.hasAnyContent() && editable, false) + .publishIf(() -> examConfigEnabled && editable && configurationTable.hasAnyContent(), false) .newAction(ActionDefinition.EXAM_CONFIGURATION_GET_CONFIG_KEY) .withSelect( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamToConfigBindingForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamToConfigBindingForm.java index 6c017e24..8aefad2d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamToConfigBindingForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamToConfigBindingForm.java @@ -82,7 +82,7 @@ public class ExamToConfigBindingForm { return action -> { final PageContext pageContext = action.pageContext(); - final EntityKey entityKey = pageContext.getEntityKey(); + final EntityKey entityKey = action.getSingleSelection(); final boolean isNew = entityKey == null; if (isNew) { @@ -103,11 +103,12 @@ public class ExamToConfigBindingForm { final BindFormContext bindFormContext = new BindFormContext( this.pageService, - action.pageContext()); + action.pageContext() + .withEntityKey(entityKey)); final Predicate> doBind = formHandle -> doCreate( this.pageService, - pageContext, + bindFormContext.pageContext, formHandle); // the default page layout @@ -181,14 +182,13 @@ public class ExamToConfigBindingForm { final EntityKey parentEntityKey = this.pageContext.getParentEntityKey(); final boolean isNew = entityKey == null; - final Exam exam = (isNew) - ? restService - .getBuilder(GetExam.class) - .withURIVariable(API.PARAM_MODEL_ID, parentEntityKey.modelId) - .call() - .onError(error -> this.pageContext.notifyLoadError(EntityType.EXAM, error)) - .getOrThrow() - : null; + final Exam exam = restService + .getBuilder(GetExam.class) + .withURIVariable(API.PARAM_MODEL_ID, parentEntityKey.modelId) + .call() + .onError(error -> this.pageContext.notifyLoadError(EntityType.EXAM, error)) + .getOrThrow(); + // get data or create new. Handle error if happen final ExamConfigurationMap examConfigurationMap = (isNew) @@ -217,8 +217,13 @@ public class ExamToConfigBindingForm { .putStaticValue( Domain.EXAM_CONFIGURATION_MAP.ATTR_EXAM_ID, String.valueOf(examConfigurationMap.examId)) + .putStaticValueIf( + () -> !isNew, + Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID, + String.valueOf(examConfigurationMap.configurationNodeId)) - .addField(FormBuilder.singleSelection( + .addFieldIf( () -> isNew, + () -> FormBuilder.singleSelection( Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID, CONFIG_MAPPING_NAME_TEXT_KEY, String.valueOf(examConfigurationMap.configurationNodeId), @@ -226,6 +231,13 @@ public class ExamToConfigBindingForm { .withSelectionListener(form -> updateFormValuesFromConfigSelection(form, resourceService)) .mandatory()) + .addFieldIf( () -> !isNew, + () -> FormBuilder.text( + Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID, + CONFIG_MAPPING_NAME_TEXT_KEY, + examConfigurationMap.configName) + .readonly(true)) + .addField(FormBuilder.text( Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, FORM_DESCRIPTION_TEXT_KEY, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java index b9eb515c..95da4266 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamConfigurationMapDAOImpl.java @@ -8,6 +8,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; +import static ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamConfigurationMapRecordDynamicSqlSupport.*; import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.util.ArrayList; @@ -23,6 +24,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.mybatis.dynamic.sql.SqlBuilder; +import org.mybatis.dynamic.sql.update.UpdateDSL; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -260,15 +262,17 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO { public Result save(final ExamConfigurationMap data) { return Result.tryCatch(() -> { - final ExamConfigurationMapRecord newRecord = new ExamConfigurationMapRecord( - data.id, - null, - null, - null, - getEncryptionPassword(data), - data.clientGroupId); + final String p = (StringUtils.isNotBlank(data.encryptSecret)) + ? getEncryptionPassword(data) + : null; + + UpdateDSL.updateWithMapper(examConfigurationMapRecordMapper::update, examConfigurationMapRecord) + .set(encryptSecret).equalTo(p ) + .set(clientGroupId).equalToWhenPresent(data.clientGroupId) + .where(id, isEqualTo(data.id)) + .build() + .execute(); - this.examConfigurationMapRecordMapper.updateByPrimaryKeySelective(newRecord); return this.examConfigurationMapRecordMapper.selectByPrimaryKey(data.id); }) .flatMap(this::toDomainModel) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamConfigurationMappingController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamConfigurationMappingController.java index f9df75d5..ee530be4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamConfigurationMappingController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamConfigurationMappingController.java @@ -133,6 +133,12 @@ public class ExamConfigurationMappingController extends EntityController validForSave(final ExamConfigurationMap entity) { + return super.validForSave(entity) + .map(this::checkPasswordMatch); + } + @Override @RequestMapping( method = RequestMethod.POST, @@ -154,7 +160,6 @@ public class ExamConfigurationMappingController extends EntityController this.examConfigUpdateService.processExamConfigurationMappingChange( entity, this.entityDAO::createNew))