SEBSERV-142 fixed
This commit is contained in:
		
							parent
							
								
									c5008ad5c2
								
							
						
					
					
						commit
						a7e0dded7f
					
				
					 3 changed files with 75 additions and 38 deletions
				
			
		|  | @ -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,16 +112,32 @@ 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); | ||||||
| 
 | 
 | ||||||
|  |             if (showDeps) { | ||||||
|                 final WizardPage<PageContext> page1 = new WizardPage<>( |                 final WizardPage<PageContext> page1 = new WizardPage<>( | ||||||
|                         page1Id, |                         page1Id, | ||||||
|                         true, |                         true, | ||||||
|  | @ -133,6 +152,15 @@ public class UserAccountDeletePopup { | ||||||
|                         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,6 +216,8 @@ 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()); | ||||||
|  | 
 | ||||||
|  |             if (dependencies.size() > 0) { | ||||||
|                 pageContext.publishPageMessage( |                 pageContext.publishPageMessage( | ||||||
|                         DELETE_CONFIRM_TITLE, |                         DELETE_CONFIRM_TITLE, | ||||||
|                         new LocTextKey( |                         new LocTextKey( | ||||||
|  | @ -195,6 +225,13 @@ public class UserAccountDeletePopup { | ||||||
|                                 userName, |                                 userName, | ||||||
|                                 dependencies.size(), |                                 dependencies.size(), | ||||||
|                                 (report.errors.isEmpty()) ? "no" : String.valueOf((report.errors.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,11 +267,15 @@ public class UserAccountDeletePopup { | ||||||
|                         userInfo.toName().name) |                         userInfo.toName().name) | ||||||
|                         .readonly(true)) |                         .readonly(true)) | ||||||
| 
 | 
 | ||||||
|                 .addField(FormBuilder.checkbox( |                 .addFieldIf( | ||||||
|  |                         () -> showDeps, | ||||||
|  |                         () -> FormBuilder.checkbox( | ||||||
|                                 ARG_WITH_CONFIGS, |                                 ARG_WITH_CONFIGS, | ||||||
|                                 FORM_CONFIGS)) |                                 FORM_CONFIGS)) | ||||||
| 
 | 
 | ||||||
|                 .addField(FormBuilder.checkbox( |                 .addFieldIf( | ||||||
|  |                         () -> showDeps, | ||||||
|  |                         () -> FormBuilder.checkbox( | ||||||
|                                 ARG_WITH_EXAMS, |                                 ARG_WITH_EXAMS, | ||||||
|                                 FORM_EXAMS)) |                                 FORM_EXAMS)) | ||||||
|                 .build(); |                 .build(); | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  |  | ||||||
|  | @ -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/>    This deletes the particular User Account with all selected dependencies.<br/>    The User Account and selected dependent exams and exam configurations, will be lost after deletion.<br/>    Please use the "Show Report" action below to see a report of all objects that will be<br/>    deleted and check them carefully. | sebserver.useraccount.delete.form.info=Please Note:<br/>    This deletes the particular User Account with all selected dependencies.<br/>    The User Account and selected dependent exams and exam configurations, will be lost after deletion.<br/>    Please use the "Show Report" action below to see a report of all objects that will be<br/>    deleted and check them carefully. | ||||||
|  | sebserver.useraccount.delete.form.info.noDeps=Please Note:<br/>    This deletes the particular User Account<br/>    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 | ||||||
| ################################ | ################################ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti