SEBSERV-408

This commit is contained in:
anhefti 2024-02-27 16:12:32 +01:00
parent d100a50e1e
commit 4ceaf50385
5 changed files with 57 additions and 25 deletions

View file

@ -60,6 +60,7 @@ public class LoginPage implements TemplateComposer {
final PageService pageService, final PageService pageService,
final DefaultRegisterPage defaultRegisterPage, final DefaultRegisterPage defaultRegisterPage,
@Value("${sebserver.gui.registering:false}") final boolean guiRegEnabled, @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) { @Value("${sebserver.feature.admin.user.account.self.registering:true}") final boolean webRegEnabled) {
this.pageService = pageService; this.pageService = pageService;
@ -67,7 +68,7 @@ public class LoginPage implements TemplateComposer {
this.widgetFactory = pageService.getWidgetFactory(); this.widgetFactory = pageService.getWidgetFactory();
this.i18nSupport = pageService.getI18nSupport(); this.i18nSupport = pageService.getI18nSupport();
this.defaultRegisterPage = defaultRegisterPage; this.defaultRegisterPage = defaultRegisterPage;
this.registeringEnabled = webRegEnabled && guiRegEnabled; this.registeringEnabled = webRegEnabled && (guiRegEnabled || guiRegEnabledOld);
} }
@Override @Override

View file

@ -137,6 +137,7 @@ public class ExamFormConfigs implements TemplateComposer {
.withSelectionListener(this.pageService.getSelectionPublisher( .withSelectionListener(this.pageService.getSelectionPublisher(
pageContext, pageContext,
ActionDefinition.EXAM_CONFIGURATION_MODIFY_FROM_LIST,
ActionDefinition.EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP, ActionDefinition.EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP,
ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST, ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST,
ActionDefinition.EXAM_CONFIGURATION_EXPORT, ActionDefinition.EXAM_CONFIGURATION_EXPORT,
@ -144,7 +145,7 @@ public class ExamFormConfigs implements TemplateComposer {
.compose(pageContext.copyOf(content)); .compose(pageContext.copyOf(content));
final EntityKey configMapKey = (configurationTable.hasAnyContent()) final EntityKey configKey = (configurationTable.hasAnyContent())
? new EntityKey( ? new EntityKey(
configurationTable.getFirstRowData().configurationNodeId, configurationTable.getFirstRowData().configurationNodeId,
EntityType.CONFIGURATION_NODE) EntityType.CONFIGURATION_NODE)
@ -162,9 +163,18 @@ public class ExamFormConfigs implements TemplateComposer {
.noEventPropagation() .noEventPropagation()
.publishIf(() -> examConfigEnabled && editable && !configurationTable.hasAnyContent()) .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) .newAction(ActionDefinition.EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP)
.withParentEntityKey(entityKey) .withParentEntityKey(entityKey)
.withEntityKey(configMapKey) .withEntityKey(configKey)
.publishIf(() -> examConfigEnabled && readGrant && configurationTable.hasAnyContent(), false) .publishIf(() -> examConfigEnabled && readGrant && configurationTable.hasAnyContent(), false)
.newAction(ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST) .newAction(ActionDefinition.EXAM_CONFIGURATION_DELETE_FROM_LIST)
@ -179,7 +189,7 @@ public class ExamFormConfigs implements TemplateComposer {
} }
return null; return null;
}) })
.publishIf(() -> examConfigEnabled && editable && configurationTable.hasAnyContent() && editable, false) .publishIf(() -> examConfigEnabled && editable && configurationTable.hasAnyContent(), false)
.newAction(ActionDefinition.EXAM_CONFIGURATION_GET_CONFIG_KEY) .newAction(ActionDefinition.EXAM_CONFIGURATION_GET_CONFIG_KEY)
.withSelect( .withSelect(

View file

@ -82,7 +82,7 @@ public class ExamToConfigBindingForm {
return action -> { return action -> {
final PageContext pageContext = action.pageContext(); final PageContext pageContext = action.pageContext();
final EntityKey entityKey = pageContext.getEntityKey(); final EntityKey entityKey = action.getSingleSelection();
final boolean isNew = entityKey == null; final boolean isNew = entityKey == null;
if (isNew) { if (isNew) {
@ -103,11 +103,12 @@ public class ExamToConfigBindingForm {
final BindFormContext bindFormContext = new BindFormContext( final BindFormContext bindFormContext = new BindFormContext(
this.pageService, this.pageService,
action.pageContext()); action.pageContext()
.withEntityKey(entityKey));
final Predicate<FormHandle<ExamConfigurationMap>> doBind = formHandle -> doCreate( final Predicate<FormHandle<ExamConfigurationMap>> doBind = formHandle -> doCreate(
this.pageService, this.pageService,
pageContext, bindFormContext.pageContext,
formHandle); formHandle);
// the default page layout // the default page layout
@ -181,14 +182,13 @@ public class ExamToConfigBindingForm {
final EntityKey parentEntityKey = this.pageContext.getParentEntityKey(); final EntityKey parentEntityKey = this.pageContext.getParentEntityKey();
final boolean isNew = entityKey == null; final boolean isNew = entityKey == null;
final Exam exam = (isNew) final Exam exam = restService
? restService .getBuilder(GetExam.class)
.getBuilder(GetExam.class) .withURIVariable(API.PARAM_MODEL_ID, parentEntityKey.modelId)
.withURIVariable(API.PARAM_MODEL_ID, parentEntityKey.modelId) .call()
.call() .onError(error -> this.pageContext.notifyLoadError(EntityType.EXAM, error))
.onError(error -> this.pageContext.notifyLoadError(EntityType.EXAM, error)) .getOrThrow();
.getOrThrow()
: null;
// get data or create new. Handle error if happen // get data or create new. Handle error if happen
final ExamConfigurationMap examConfigurationMap = (isNew) final ExamConfigurationMap examConfigurationMap = (isNew)
@ -217,8 +217,13 @@ public class ExamToConfigBindingForm {
.putStaticValue( .putStaticValue(
Domain.EXAM_CONFIGURATION_MAP.ATTR_EXAM_ID, Domain.EXAM_CONFIGURATION_MAP.ATTR_EXAM_ID,
String.valueOf(examConfigurationMap.examId)) 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, Domain.EXAM_CONFIGURATION_MAP.ATTR_CONFIGURATION_NODE_ID,
CONFIG_MAPPING_NAME_TEXT_KEY, CONFIG_MAPPING_NAME_TEXT_KEY,
String.valueOf(examConfigurationMap.configurationNodeId), String.valueOf(examConfigurationMap.configurationNodeId),
@ -226,6 +231,13 @@ public class ExamToConfigBindingForm {
.withSelectionListener(form -> updateFormValuesFromConfigSelection(form, resourceService)) .withSelectionListener(form -> updateFormValuesFromConfigSelection(form, resourceService))
.mandatory()) .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( .addField(FormBuilder.text(
Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION,
FORM_DESCRIPTION_TEXT_KEY, FORM_DESCRIPTION_TEXT_KEY,

View file

@ -8,6 +8,7 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; 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 static org.mybatis.dynamic.sql.SqlBuilder.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,6 +24,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.mybatis.dynamic.sql.SqlBuilder; import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -260,15 +262,17 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO {
public Result<ExamConfigurationMap> save(final ExamConfigurationMap data) { public Result<ExamConfigurationMap> save(final ExamConfigurationMap data) {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
final ExamConfigurationMapRecord newRecord = new ExamConfigurationMapRecord( final String p = (StringUtils.isNotBlank(data.encryptSecret))
data.id, ? getEncryptionPassword(data)
null, : null;
null,
null, UpdateDSL.updateWithMapper(examConfigurationMapRecordMapper::update, examConfigurationMapRecord)
getEncryptionPassword(data), .set(encryptSecret).equalTo(p )
data.clientGroupId); .set(clientGroupId).equalToWhenPresent(data.clientGroupId)
.where(id, isEqualTo(data.id))
.build()
.execute();
this.examConfigurationMapRecordMapper.updateByPrimaryKeySelective(newRecord);
return this.examConfigurationMapRecordMapper.selectByPrimaryKey(data.id); return this.examConfigurationMapRecordMapper.selectByPrimaryKey(data.id);
}) })
.flatMap(this::toDomainModel) .flatMap(this::toDomainModel)

View file

@ -133,6 +133,12 @@ public class ExamConfigurationMappingController extends EntityController<ExamCon
.map(this::checkNoActiveClientConnections); .map(this::checkNoActiveClientConnections);
} }
@Override
protected Result<ExamConfigurationMap> validForSave(final ExamConfigurationMap entity) {
return super.validForSave(entity)
.map(this::checkPasswordMatch);
}
@Override @Override
@RequestMapping( @RequestMapping(
method = RequestMethod.POST, method = RequestMethod.POST,
@ -154,7 +160,6 @@ public class ExamConfigurationMappingController extends EntityController<ExamCon
final ExamConfigurationMap requestModel = this.createNew(postMap); final ExamConfigurationMap requestModel = this.createNew(postMap);
return this.checkCreateAccess(requestModel) return this.checkCreateAccess(requestModel)
.flatMap(this::validForCreate) .flatMap(this::validForCreate)
.map(this::checkPasswordMatch)
.flatMap(entity -> this.examConfigUpdateService.processExamConfigurationMappingChange( .flatMap(entity -> this.examConfigUpdateService.processExamConfigurationMappingChange(
entity, entity,
this.entityDAO::createNew)) this.entityDAO::createNew))