Skip to content

Commit

Permalink
SEBSERV-487 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Jan 30, 2024
1 parent 12f6714 commit a43042c
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void compose(final PageContext pageContext) {

// User Account
// if current user has role seb-server admin or institutional-admin, show list
if (isServerOrInstAdmin) {
if (isServerOrInstAdmin && !pageService.isSEBServerLightSetup()) {

final TreeItem userAccounts = this.widgetFactory.treeItemLocalized(
sebAdmin,
Expand All @@ -147,7 +147,11 @@ public void compose(final PageContext pageContext) {
.create());
} else {
// otherwise show the user account form for current user
final TreeItem userAccounts = this.widgetFactory.treeItemLocalized(
final TreeItem userAccounts = pageService.isSEBServerLightSetup()
? this.widgetFactory.treeItemLocalized(
sebAdmin,
ActivityDefinition.USER_ACCOUNT.displayName)
: this.widgetFactory.treeItemLocalized(
navigation,
ActivityDefinition.USER_ACCOUNT.displayName);
injectActivitySelection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ protected InstitutionList(

@Override
public void compose(final PageContext pageContext) {
final Composite content = this.pageService
.getWidgetFactory()
.defaultPageLayout(
pageContext.getParent(),
TITLE_TEXT_KEY);

if (pageService.isSEBServerLightSetup()) {
pageService.applyFullVersionNote(content, pageContext);
pageService.applyFullVersionNote(pageContext.getParent(), pageContext);
return;
}

final Composite content = this.pageService
.getWidgetFactory()
.defaultPageLayout(
pageContext.getParent(),
TITLE_TEXT_KEY);

final PageActionBuilder pageActionBuilder =
this.pageService.pageActionBuilder(pageContext.clearEntityKeys());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ protected UserAccountForm(

@Override
public void compose(final PageContext pageContext) {


final CurrentUser currentUser = this.resourceService.getCurrentUser();
final RestService restService = this.resourceService.getRestService();
final WidgetFactory widgetFactory = this.pageService.getWidgetFactory();
Expand All @@ -106,11 +108,22 @@ public void compose(final PageContext pageContext) {
final EntityKey entityKey = pageContext.getEntityKey();
final EntityKey parentEntityKey = pageContext.getParentEntityKey();
final boolean readonly = pageContext.isReadonly();
final boolean isLight = pageService.isSEBServerLightSetup();

final BooleanSupplier isNew = () -> entityKey == null;
final BooleanSupplier isNotNew = () -> !isNew.getAsBoolean();
final BooleanSupplier isSEBAdmin = () -> user.hasRole(UserRole.SEB_SERVER_ADMIN);

if (isLight && !readonly && isNew.getAsBoolean()) {
pageService.applyFullVersionNote(pageContext.getParent(), pageContext);
this.pageService.pageActionBuilder(pageContext.clearEntityKeys())
.newAction(ActionDefinition.USER_ACCOUNT_CANCEL_MODIFY)
.withExec(this.pageService.backToCurrentFunction())
.ignoreMoveAwayFromEdit()
.publish();
return;
}

// get data or create new. handle error if happen
final UserAccount userAccount = isNew.getAsBoolean()
? UserMod.createNew((parentEntityKey != null)
Expand Down Expand Up @@ -165,7 +178,7 @@ public void compose(final PageContext pageContext) {
Domain.USER.ATTR_LANGUAGE,
Locale.ENGLISH.getLanguage())
.addFieldIf(
() -> isSEBAdmin.getAsBoolean() && currentUser.isFeatureEnabled(UserFeatures.Feature.ADMIN_INSTITUTION),
() -> !isLight && isSEBAdmin.getAsBoolean() && currentUser.isFeatureEnabled(UserFeatures.Feature.ADMIN_INSTITUTION),
() -> FormBuilder.singleSelection(
Domain.USER.ATTR_INSTITUTION_ID,
FORM_INSTITUTION_TEXT_KEY,
Expand Down Expand Up @@ -213,7 +226,7 @@ public void compose(final PageContext pageContext) {
this.resourceService::timeZoneResources)
.mandatory(!readonly))
.addFieldIf(
() -> modifyGrant,
() -> modifyGrant && !isLight,
() -> FormBuilder.multiCheckboxSelection(
USER_ROLE.REFERENCE_NAME,
FORM_ROLES_TEXT_KEY,
Expand Down Expand Up @@ -257,17 +270,17 @@ public void compose(final PageContext pageContext) {
.withEntityKey(entityKey)
.withSimpleRestCall(restService, DeactivateUserAccount.class)
.withConfirm(this.pageService.confirmDeactivation(userAccount))
.publishIf(() -> writeGrant && readonly && institutionActive && userAccount.isActive())
.publishIf(() -> !isLight && writeGrant && readonly && institutionActive && userAccount.isActive())

.newAction(ActionDefinition.USER_ACCOUNT_ACTIVATE)
.withEntityKey(entityKey)
.withSimpleRestCall(restService, ActivateUserAccount.class)
.publishIf(() -> writeGrant && readonly && institutionActive && !userAccount.isActive())
.publishIf(() -> !isLight && writeGrant && readonly && institutionActive && !userAccount.isActive())

.newAction(ActionDefinition.USER_ACCOUNT_DELETE)
.withEntityKey(entityKey)
.withExec(this.userAccountDeletePopup.deleteWizardFunction(pageContext))
.publishIf(() -> writeGrant && readonly && institutionActive)
.publishIf(() -> !isLight && writeGrant && readonly && institutionActive)

.newAction(ActionDefinition.USER_ACCOUNT_SAVE)
.withEntityKey(entityKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ protected CertificateList(
@Override
public void compose(final PageContext pageContext) {

if (pageService.isSEBServerLightSetup()) {
pageService.applyFullVersionNote(pageContext.getParent(), pageContext);
return;
}

final GrantCheck grantCheck = this.currentUser.grantCheck(EntityType.CERTIFICATE);

final Composite content = this.pageService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ protected ConfigTemplateList(

@Override
public void compose(final PageContext pageContext) {

if (pageService.isSEBServerLightSetup()) {
pageService.applyFullVersionNote(pageContext.getParent(), pageContext);
return;
}

final WidgetFactory widgetFactory = this.pageService.getWidgetFactory();
final Composite content = widgetFactory.defaultPageLayout(
pageContext.getParent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void compose(final PageContext pageContext) {
final EntityKey entityKey = pageContext.getEntityKey();
final EntityKey parentEntityKey = pageContext.getParentEntityKey();
final boolean isNew = entityKey == null;
final boolean isLight = pageService.isSEBServerLightSetup();

// get data or create new. Handle error if happen
final ConfigurationNode examConfig = (isNew)
Expand Down Expand Up @@ -187,16 +188,12 @@ public void compose(final PageContext pageContext) {
final boolean hasRunningExam = isAttachedToExam && examsPage
.map(res -> res.content
.stream()
.filter(map -> map.examStatus == ExamStatus.RUNNING)
.findAny()
.isPresent())
.anyMatch(map -> map.examStatus == ExamStatus.RUNNING))
.getOr(false);
final boolean hasActiveExams = hasRunningExam || examsPage
.map(res -> res.content
.stream()
.filter(map -> map.examStatus == ExamStatus.UP_COMING)
.findAny()
.isPresent())
.anyMatch(map -> map.examStatus == ExamStatus.UP_COMING))
.getOr(false);

// new PageContext with actual EntityKey
Expand Down Expand Up @@ -224,7 +221,7 @@ public void compose(final PageContext pageContext) {
Domain.CONFIGURATION_NODE.ATTR_TYPE,
ConfigurationType.EXAM_CONFIG.name())
.addFieldIf(
() -> !examConfigTemplateResources.isEmpty(),
() -> !isLight && !examConfigTemplateResources.isEmpty(),
() -> FormBuilder.singleSelection(
Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID,
FORM_TEMPLATE_TEXT_KEY,
Expand Down Expand Up @@ -306,10 +303,11 @@ public void compose(final PageContext pageContext) {
.withExec(this::restoreToTemplateSettings)
.noEventPropagation()
.publishIf(() -> modifyGrant
&& !isLight
&& isReadonly
&& examConfig.status != ConfigurationStatus.IN_USE
&& examConfig.templateId != null
&& examConfig.templateId.longValue() > 0)
&& examConfig.templateId > 0)

.newAction(ActionDefinition.SEB_EXAM_CONFIG_COPY_CONFIG)
.withEntityKey(entityKey)
Expand All @@ -332,7 +330,7 @@ public void compose(final PageContext pageContext) {
PageContext.AttributeKeys.COPY_AS_TEMPLATE,
Constants.TRUE_STRING)))
.noEventPropagation()
.publishIf(() -> modifyGrant && isReadonly)
.publishIf(() -> modifyGrant && !isLight && isReadonly)

.newAction(ActionDefinition.SEB_EXAM_CONFIG_GET_CONFIG_KEY)
.withEntityKey(entityKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void compose(final PageContext pageContext) {
TITLE_CONFIGURATION_TEXT_KEY);

final boolean isSEBAdmin = this.currentUser.get().hasRole(UserRole.SEB_SERVER_ADMIN);
final boolean isLight = pageService.isSEBServerLightSetup();
final PageActionBuilder pageActionBuilder =
this.pageService.pageActionBuilder(pageContext.clearEntityKeys());

Expand Down Expand Up @@ -245,7 +246,7 @@ public void compose(final PageContext pageContext) {
this.sebExamConfigBatchResetToTemplatePopup.popupCreationFunction(pageContext),
EMPTY_SELECTION_TEXT_KEY)
.noEventPropagation()
.publishIf(() -> examConfigGrant.im(), false)
.publishIf(() -> !isLight && examConfigGrant.im(), false)

.newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG)
.withSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ protected ClientGroupForm(final PageService pageService) {

@Override
public void compose(final PageContext pageContext) {

if (pageService.isSEBServerLightSetup()) {
pageService.applyFullVersionNote(pageContext.getParent(), pageContext);
this.pageService.pageActionBuilder(pageContext.clearEntityKeys())
.newAction(ActionDefinition.EXAM_CLIENT_GROUP_CANCEL_MODIFY)
.withEntityKey(pageContext.getParentEntityKey())
.withExec(this.pageService.backToCurrentFunction())
.ignoreMoveAwayFromEdit()
.publish();
return;
}

final RestService restService = this.resourceService.getRestService();
final WidgetFactory widgetFactory = this.pageService.getWidgetFactory();
final EntityKey entityKey = pageContext.getEntityKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public ExamClientGroupList(final PageService pageService) {
public void compose(final PageContext pageContext) {
final Composite content = pageContext.getParent();
final EntityKey entityKey = pageContext.getEntityKey();
final boolean editable = BooleanUtils.toBoolean(
pageContext.getAttribute(ExamForm.ATTR_EDITABLE));
final boolean editable = BooleanUtils.toBoolean(pageContext.getAttribute(ExamForm.ATTR_EDITABLE));
final boolean isLight = pageService.isSEBServerLightSetup();

// List of ClientGroups
this.widgetFactory.addFormSubContextHeader(
Expand Down Expand Up @@ -106,20 +106,20 @@ public void compose(final PageContext pageContext) {
.withColumn(new ColumnDefinition<ClientGroup>(
Domain.CLIENT_GROUP.ATTR_TYPE,
CLIENT_GROUP_TYPE_COLUMN_KEY,
cgt -> this.resourceService.clientGroupTypeName(cgt))
this.resourceService::clientGroupTypeName)
.widthProportion(1))

.withColumn(new ColumnDefinition<ClientGroup>(
Domain.CLIENT_GROUP.ATTR_COLOR,
CLIENT_GROUP_COLOR_COLUMN_KEY,
cgt -> WidgetFactory.getColorValueHTML(cgt))
WidgetFactory::getColorValueHTML)
.asMarkup()
.widthProportion(1))

.withColumn(new ColumnDefinition<ClientGroup>(
Domain.CLIENT_GROUP.ATTR_DATA,
CLIENT_GROUP_DATA_COLUMN_KEY,
cgt -> this.widgetFactory.clientGroupDataToHTML(cgt))
this.widgetFactory::clientGroupDataToHTML)
.asMarkup()
.widthProportion(3))

Expand Down Expand Up @@ -153,7 +153,7 @@ public void compose(final PageContext pageContext) {
clientGroupTable::getMultiSelection,
this::deleteSelectedClientGroup,
CLIENT_GROUP_EMPTY_SELECTION_TEXT_KEY)
.publishIf(() -> editable && clientGroupTable.hasAnyContent(), false)
.publishIf(() -> !isLight && editable && clientGroupTable.hasAnyContent(), false)

.newAction(ActionDefinition.EXAM_CLIENT_GROUP_NEW)
.withParentEntityKey(entityKey)
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.*;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -194,6 +197,7 @@ public void compose(final PageContext pageContext) {
final EntityKey entityKey = (readonly || !newExamNoLMS) ? pageContext.getEntityKey() : null;
final PageContext formContext = pageContext.withEntityKey(exam.getEntityKey());
final EntityGrantCheck entityGrantCheck = currentUser.entityGrantCheck(exam);
final boolean isLight = pageService.isSEBServerLightSetup();
final boolean modifyGrant = entityGrantCheck.m();
final boolean writeGrant = entityGrantCheck.w();
final boolean editable = modifyGrant && (exam.getStatus() == ExamStatus.UP_COMING || exam.getStatus() == ExamStatus.RUNNING);
Expand Down Expand Up @@ -337,13 +341,13 @@ public void compose(final PageContext pageContext) {
.withEntityKey(entityKey)
.withExec(this.proctoringSettingsPopup.settingsFunction(this.pageService, modifyGrant && editable))
.noEventPropagation()
.publishIf(() -> proctoringEnabled && readonly)
.publishIf(() -> !isLight && proctoringEnabled && readonly)

.newAction(ActionDefinition.EXAM_PROCTORING_OFF)
.withEntityKey(entityKey)
.withExec(this.proctoringSettingsPopup.settingsFunction(this.pageService, modifyGrant && editable))
.noEventPropagation()
.publishIf(() -> !proctoringEnabled && readonly)
.publishIf(() -> !isLight && !proctoringEnabled && readonly)

.newAction(ActionDefinition.SCREEN_PROCTORING_ON)
.withEntityKey(entityKey)
Expand Down Expand Up @@ -498,6 +502,7 @@ private FormHandle<Exam> createEditForm(
final Exam exam) {

final I18nSupport i18nSupport = formContext.getI18nSupport();
final boolean isLight = pageService.isSEBServerLightSetup();
final boolean newExam = exam.id == null;
final boolean hasLMS = exam.lmsSetupId != null;
final boolean importFromLMS = newExam && hasLMS;
Expand All @@ -522,6 +527,9 @@ private FormHandle<Exam> createEditForm(
.putStaticValueIf(() -> exam.lmsSetupId != null,
QuizData.QUIZ_ATTR_ID,
exam.externalId)
.putStaticValueIf(() -> isLight && newExam,
Domain.EXAM.ATTR_SUPPORTER,
this.pageService.getCurrentUser().get().uuid)

.addField(FormBuilder.text(
Domain.EXAM.ATTR_STATUS + "_display",
Expand All @@ -537,7 +545,7 @@ private FormHandle<Exam> createEditForm(
this.resourceService::lmsSetupResource)
.readonly(true))

.addFieldIf(() -> exam.id == null,
.addFieldIf(() -> !isLight && exam.id == null,
() -> FormBuilder.singleSelection(
Domain.EXAM.ATTR_EXAM_TEMPLATE_ID,
FORM_EXAM_TEMPLATE_TEXT_KEY,
Expand Down Expand Up @@ -599,9 +607,8 @@ private FormHandle<Exam> createEditForm(
Domain.EXAM.ATTR_SUPPORTER,
FORM_SUPPORTER_TEXT_KEY,
StringUtils.join(exam.supporter, Constants.LIST_SEPARATOR_CHAR),
this.resourceService::examSupporterResources))


this.resourceService::examSupporterResources)
.readonlyIf(() -> isLight && newExam))

.buildFor(importFromLMS
? this.restService.getRestCall(ImportAsExam.class)
Expand All @@ -623,7 +630,9 @@ private Exam newExamNoLMS() {
DateTime.now(timeZone).plusHours(1),
Exam.ExamType.UNDEFINED,
null,
null,
pageService.isSEBServerLightSetup()
? Stream.of(this.pageService.getCurrentUser().get().uuid).collect(Collectors.toList())
: null,
ExamStatus.UP_COMING,
null,
false,
Expand Down Expand Up @@ -801,11 +810,15 @@ private Result<Exam> getExistingExam(final PageContext pageContext) {
private Result<Exam> createExamFromQuizData(final PageContext pageContext) {
final EntityKey entityKey = pageContext.getEntityKey();
final EntityKey parentEntityKey = pageContext.getParentEntityKey();
final POSTMapper mapper = new POSTMapper(null, null);
if (pageService.isSEBServerLightSetup()) {
mapper.putIfAbsent(Domain.EXAM.ATTR_SUPPORTER, this.pageService.getCurrentUser().get().uuid);
}
return this.restService.getBuilder(GetQuizData.class)
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
.withQueryParam(QuizData.QUIZ_ATTR_LMS_SETUP_ID, parentEntityKey.modelId)
.call()
.map(Exam::new)
.map(qd -> new Exam(null, qd, mapper))
.onError(error -> pageContext.notifyLoadError(EntityType.EXAM, error));
}

Expand Down
Loading

0 comments on commit a43042c

Please sign in to comment.