diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountDeletePopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountDeletePopup.java index e9d4cdcf..5fd49e86 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountDeletePopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountDeletePopup.java @@ -33,6 +33,7 @@ import ch.ethz.seb.sebserver.gbl.model.EntityDependency; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; +import ch.ethz.seb.sebserver.gbl.model.user.UserRole; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; @@ -69,6 +70,8 @@ public class UserAccountDeletePopup { new LocTextKey("sebserver.useraccount.delete.form.title"); private final static LocTextKey FORM_INFO = new LocTextKey("sebserver.useraccount.delete.form.info"); + private final static LocTextKey FORM_INFO_NO_DEPS = + new LocTextKey("sebserver.useraccount.delete.form.info.noDeps"); private final static LocTextKey FORM_REPORT_INFO = new LocTextKey("sebserver.useraccount.delete.form.report.info"); private final static LocTextKey FORM_REPORT_LIST_TYPE = @@ -109,30 +112,55 @@ public class UserAccountDeletePopup { this.pageService.getWidgetFactory()) .setVeryLargeDialogWidth(); + final EntityKey entityKey = pageContext.getEntityKey(); + final UserInfo userInfo = this.pageService.getRestService() + .getBuilder(GetUserAccount.class) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) + .call() + .get(); + + final Set roles = userInfo.getRoles(); + final boolean showDeps = roles.contains(UserRole.EXAM_ADMIN.name()) + || roles.contains(UserRole.INSTITUTIONAL_ADMIN.name()) + || roles.contains(UserRole.SEB_SERVER_ADMIN.name()); + final String page1Id = "DELETE_PAGE"; final String page2Id = "REPORT_PAGE"; final Predicate callback = pc -> doDelete(this.pageService, pc); final BiFunction> composePage1 = - (prefPageContext, content) -> composeDeleteDialog(content, - (prefPageContext != null) ? prefPageContext : pageContext); + (prefPageContext, content) -> composeDeleteDialog( + content, + (prefPageContext != null) ? prefPageContext : pageContext, + userInfo, + showDeps); final BiFunction> composePage2 = (prefPageContext, content) -> composeReportDialog(content, (prefPageContext != null) ? prefPageContext : pageContext); - final WizardPage page1 = new WizardPage<>( - page1Id, - true, - composePage1, - new WizardAction<>(ACTION_DELETE, callback), - new WizardAction<>(ACTION_REPORT, page2Id)); + if (showDeps) { + final WizardPage page1 = new WizardPage<>( + page1Id, + true, + composePage1, + new WizardAction<>(ACTION_DELETE, callback), + new WizardAction<>(ACTION_REPORT, page2Id)); - final WizardPage page2 = new WizardPage<>( - page2Id, - false, - composePage2, - new WizardAction<>(ACTION_DELETE, callback)); + final WizardPage page2 = new WizardPage<>( + page2Id, + false, + composePage2, + new WizardAction<>(ACTION_DELETE, callback)); - wizard.open(FORM_TITLE, Utils.EMPTY_EXECUTION, page1, page2); + wizard.open(FORM_TITLE, Utils.EMPTY_EXECUTION, page1, page2); + } else { + final WizardPage page1 = new WizardPage<>( + page1Id, + true, + composePage1, + new WizardAction<>(ACTION_DELETE, callback)); + + wizard.open(FORM_TITLE, Utils.EMPTY_EXECUTION, page1); + } return action; }; @@ -188,13 +216,22 @@ public class UserAccountDeletePopup { final List dependencies = report.results.stream() .filter(key -> !key.equals(entityKey)) .collect(Collectors.toList()); - pageContext.publishPageMessage( - DELETE_CONFIRM_TITLE, - new LocTextKey( - "sebserver.useraccount.delete.confirm.message", - userName, - dependencies.size(), - (report.errors.isEmpty()) ? "no" : String.valueOf((report.errors.size())))); + + if (dependencies.size() > 0) { + pageContext.publishPageMessage( + DELETE_CONFIRM_TITLE, + new LocTextKey( + "sebserver.useraccount.delete.confirm.message", + userName, + dependencies.size(), + (report.errors.isEmpty()) ? "no" : String.valueOf((report.errors.size())))); + } else { + pageContext.publishPageMessage( + DELETE_CONFIRM_TITLE, + new LocTextKey( + "sebserver.useraccount.delete.confirm.message.noDeps", + userName)); + } return true; } catch (final Exception e) { log.error("Unexpected error while trying to delete User Account:", e); @@ -205,25 +242,20 @@ public class UserAccountDeletePopup { private Supplier composeDeleteDialog( final Composite parent, - final PageContext pageContext) { + final PageContext pageContext, + final UserInfo userInfo, + final boolean showDeps) { final Composite grid = this.pageService.getWidgetFactory() .createPopupScrollComposite(parent); final Label title = this.pageService.getWidgetFactory() - .labelLocalized(grid, CustomVariant.TEXT_H3, FORM_INFO); + .labelLocalized(grid, CustomVariant.TEXT_H3, (showDeps) ? FORM_INFO : FORM_INFO_NO_DEPS); final GridData gridData = new GridData(); gridData.horizontalIndent = 10; gridData.verticalIndent = 10; title.setLayoutData(gridData); - final EntityKey entityKey = pageContext.getEntityKey(); - final UserInfo userInfo = this.pageService.getRestService() - .getBuilder(GetUserAccount.class) - .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) - .call() - .get(); - final FormHandle formHandle = this.pageService.formBuilder( pageContext.copyOf(grid)) .readonly(false) @@ -235,13 +267,17 @@ public class UserAccountDeletePopup { userInfo.toName().name) .readonly(true)) - .addField(FormBuilder.checkbox( - ARG_WITH_CONFIGS, - FORM_CONFIGS)) + .addFieldIf( + () -> showDeps, + () -> FormBuilder.checkbox( + ARG_WITH_CONFIGS, + FORM_CONFIGS)) - .addField(FormBuilder.checkbox( - ARG_WITH_EXAMS, - FORM_EXAMS)) + .addFieldIf( + () -> showDeps, + () -> FormBuilder.checkbox( + ARG_WITH_EXAMS, + FORM_EXAMS)) .build(); final Form form = formHandle.getForm(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/AuthorizationServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/AuthorizationServiceImpl.java index 2d82592c..6dae3b3b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/AuthorizationServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/authorization/impl/AuthorizationServiceImpl.java @@ -77,7 +77,7 @@ public class AuthorizationServiceImpl implements AuthorizationService { .withInstitutionalPrivilege(PrivilegeType.READ) .withOwnerPrivilege(PrivilegeType.MODIFY) .andForRole(UserRole.EXAM_SUPPORTER) - .withOwnerPrivilege(PrivilegeType.MODIFY) + .withOwnerPrivilege(PrivilegeType.WRITE) .create(); // grants for seb client config diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 2c90b6d7..f93869d2 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -257,6 +257,7 @@ sebserver.useraccount.form.password.new.confirm.tooltip=Please confirm the passw sebserver.useraccount.delete.form.title=Delete User Account sebserver.useraccount.delete.form.info=Please Note:
    This deletes the particular User Account with all selected dependencies.
    The User Account and selected dependent exams and exam configurations, will be lost after deletion.
    Please use the "Show Report" action below to see a report of all objects that will be
    deleted and check them carefully. +sebserver.useraccount.delete.form.info.noDeps=Please Note:
    This deletes the particular User Account
    The User Account will be lost after deletion. sebserver.useraccount.delete.form.report.info=The following objects will be deleted within this User Account deletion.
Please check them carefully before delete. sebserver.useraccount.delete.form.report.empty=No dependencies will be deleted. sebserver.useraccount.delete.form.report.list.type=Type @@ -271,7 +272,7 @@ sebserver.useraccount.delete.form.action.delete=Delete sebserver.useraccount.delete.form.action.report=Show Report sebserver.useraccount.delete.confirm.title=Deletion Successful sebserver.useraccount.delete.confirm.message=The User Account ({0}) was successfully deleted.
Also the following number dependencies where successfully deleted: {1}.

And there where {2} errors. - +sebserver.useraccount.delete.confirm.message.noDeps=The User Account ({0}) was successfully deleted. ################################ # LMS Setup ################################