SEBSERV-142 fixed

This commit is contained in:
anhefti 2021-01-12 16:04:35 +01:00
parent c5008ad5c2
commit a7e0dded7f
3 changed files with 75 additions and 38 deletions

View file

@ -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.EntityKey;
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; 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.UserInfo;
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
@ -69,6 +70,8 @@ public class UserAccountDeletePopup {
new LocTextKey("sebserver.useraccount.delete.form.title"); new LocTextKey("sebserver.useraccount.delete.form.title");
private final static LocTextKey FORM_INFO = private final static LocTextKey FORM_INFO =
new LocTextKey("sebserver.useraccount.delete.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 = private final static LocTextKey FORM_REPORT_INFO =
new LocTextKey("sebserver.useraccount.delete.form.report.info"); new LocTextKey("sebserver.useraccount.delete.form.report.info");
private final static LocTextKey FORM_REPORT_LIST_TYPE = private final static LocTextKey FORM_REPORT_LIST_TYPE =
@ -109,30 +112,55 @@ public class UserAccountDeletePopup {
this.pageService.getWidgetFactory()) this.pageService.getWidgetFactory())
.setVeryLargeDialogWidth(); .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<String> 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 page1Id = "DELETE_PAGE";
final String page2Id = "REPORT_PAGE"; final String page2Id = "REPORT_PAGE";
final Predicate<PageContext> callback = pc -> doDelete(this.pageService, pc); final Predicate<PageContext> callback = pc -> doDelete(this.pageService, pc);
final BiFunction<PageContext, Composite, Supplier<PageContext>> composePage1 = final BiFunction<PageContext, Composite, Supplier<PageContext>> composePage1 =
(prefPageContext, content) -> composeDeleteDialog(content, (prefPageContext, content) -> composeDeleteDialog(
(prefPageContext != null) ? prefPageContext : pageContext); content,
(prefPageContext != null) ? prefPageContext : pageContext,
userInfo,
showDeps);
final BiFunction<PageContext, Composite, Supplier<PageContext>> composePage2 = final BiFunction<PageContext, Composite, Supplier<PageContext>> composePage2 =
(prefPageContext, content) -> composeReportDialog(content, (prefPageContext, content) -> composeReportDialog(content,
(prefPageContext != null) ? prefPageContext : pageContext); (prefPageContext != null) ? prefPageContext : pageContext);
final WizardPage<PageContext> page1 = new WizardPage<>( if (showDeps) {
page1Id, final WizardPage<PageContext> page1 = new WizardPage<>(
true, page1Id,
composePage1, true,
new WizardAction<>(ACTION_DELETE, callback), composePage1,
new WizardAction<>(ACTION_REPORT, page2Id)); new WizardAction<>(ACTION_DELETE, callback),
new WizardAction<>(ACTION_REPORT, page2Id));
final WizardPage<PageContext> page2 = new WizardPage<>( final WizardPage<PageContext> page2 = new WizardPage<>(
page2Id, page2Id,
false, false,
composePage2, composePage2,
new WizardAction<>(ACTION_DELETE, callback)); 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<PageContext> page1 = new WizardPage<>(
page1Id,
true,
composePage1,
new WizardAction<>(ACTION_DELETE, callback));
wizard.open(FORM_TITLE, Utils.EMPTY_EXECUTION, page1);
}
return action; return action;
}; };
@ -188,13 +216,22 @@ public class UserAccountDeletePopup {
final List<EntityKey> dependencies = report.results.stream() final List<EntityKey> dependencies = report.results.stream()
.filter(key -> !key.equals(entityKey)) .filter(key -> !key.equals(entityKey))
.collect(Collectors.toList()); .collect(Collectors.toList());
pageContext.publishPageMessage(
DELETE_CONFIRM_TITLE, if (dependencies.size() > 0) {
new LocTextKey( pageContext.publishPageMessage(
"sebserver.useraccount.delete.confirm.message", DELETE_CONFIRM_TITLE,
userName, new LocTextKey(
dependencies.size(), "sebserver.useraccount.delete.confirm.message",
(report.errors.isEmpty()) ? "no" : String.valueOf((report.errors.size())))); 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; return true;
} catch (final Exception e) { } catch (final Exception e) {
log.error("Unexpected error while trying to delete User Account:", e); log.error("Unexpected error while trying to delete User Account:", e);
@ -205,25 +242,20 @@ public class UserAccountDeletePopup {
private Supplier<PageContext> composeDeleteDialog( private Supplier<PageContext> composeDeleteDialog(
final Composite parent, final Composite parent,
final PageContext pageContext) { final PageContext pageContext,
final UserInfo userInfo,
final boolean showDeps) {
final Composite grid = this.pageService.getWidgetFactory() final Composite grid = this.pageService.getWidgetFactory()
.createPopupScrollComposite(parent); .createPopupScrollComposite(parent);
final Label title = this.pageService.getWidgetFactory() 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(); final GridData gridData = new GridData();
gridData.horizontalIndent = 10; gridData.horizontalIndent = 10;
gridData.verticalIndent = 10; gridData.verticalIndent = 10;
title.setLayoutData(gridData); 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( final FormHandle<?> formHandle = this.pageService.formBuilder(
pageContext.copyOf(grid)) pageContext.copyOf(grid))
.readonly(false) .readonly(false)
@ -235,13 +267,17 @@ public class UserAccountDeletePopup {
userInfo.toName().name) userInfo.toName().name)
.readonly(true)) .readonly(true))
.addField(FormBuilder.checkbox( .addFieldIf(
ARG_WITH_CONFIGS, () -> showDeps,
FORM_CONFIGS)) () -> FormBuilder.checkbox(
ARG_WITH_CONFIGS,
FORM_CONFIGS))
.addField(FormBuilder.checkbox( .addFieldIf(
ARG_WITH_EXAMS, () -> showDeps,
FORM_EXAMS)) () -> FormBuilder.checkbox(
ARG_WITH_EXAMS,
FORM_EXAMS))
.build(); .build();
final Form form = formHandle.getForm(); final Form form = formHandle.getForm();

View file

@ -77,7 +77,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
.withInstitutionalPrivilege(PrivilegeType.READ) .withInstitutionalPrivilege(PrivilegeType.READ)
.withOwnerPrivilege(PrivilegeType.MODIFY) .withOwnerPrivilege(PrivilegeType.MODIFY)
.andForRole(UserRole.EXAM_SUPPORTER) .andForRole(UserRole.EXAM_SUPPORTER)
.withOwnerPrivilege(PrivilegeType.MODIFY) .withOwnerPrivilege(PrivilegeType.WRITE)
.create(); .create();
// grants for seb client config // grants for seb client config

View file

@ -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.title=Delete User Account
sebserver.useraccount.delete.form.info=Please Note:<br/>&nbsp;&nbsp;&nbsp;&nbsp;This deletes the particular User Account with all selected dependencies.<br/>&nbsp;&nbsp;&nbsp;&nbsp;The User Account and selected dependent exams and exam configurations, will be lost after deletion.<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please use the "Show Report" action below to see a report of all objects that will be<br/>&nbsp;&nbsp;&nbsp;&nbsp;deleted and check them carefully. sebserver.useraccount.delete.form.info=Please Note:<br/>&nbsp;&nbsp;&nbsp;&nbsp;This deletes the particular User Account with all selected dependencies.<br/>&nbsp;&nbsp;&nbsp;&nbsp;The User Account and selected dependent exams and exam configurations, will be lost after deletion.<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please use the "Show Report" action below to see a report of all objects that will be<br/>&nbsp;&nbsp;&nbsp;&nbsp;deleted and check them carefully.
sebserver.useraccount.delete.form.info.noDeps=Please Note:<br/>&nbsp;&nbsp;&nbsp;&nbsp;This deletes the particular User Account<br/>&nbsp;&nbsp;&nbsp;&nbsp;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.<br/>Please check them carefully before delete. sebserver.useraccount.delete.form.report.info=The following objects will be deleted within this User Account deletion.<br/>Please check them carefully before delete.
sebserver.useraccount.delete.form.report.empty=No dependencies will be deleted. sebserver.useraccount.delete.form.report.empty=No dependencies will be deleted.
sebserver.useraccount.delete.form.report.list.type=Type 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.form.action.report=Show Report
sebserver.useraccount.delete.confirm.title=Deletion Successful sebserver.useraccount.delete.confirm.title=Deletion Successful
sebserver.useraccount.delete.confirm.message=The User Account ({0}) was successfully deleted.<br/>Also the following number dependencies where successfully deleted: {1}.<br/><br/>And there where {2} errors. sebserver.useraccount.delete.confirm.message=The User Account ({0}) was successfully deleted.<br/>Also the following number dependencies where successfully deleted: {1}.<br/><br/>And there where {2} errors.
sebserver.useraccount.delete.confirm.message.noDeps=The User Account ({0}) was successfully deleted.
################################ ################################
# LMS Setup # LMS Setup
################################ ################################