diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectMainPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectMainPanel.java index 843b265ba48..f203607cd02 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectMainPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectMainPanel.java @@ -1,322 +1,320 @@ -/* - * Copyright (c) 2015-2016 Evolveum and contributors - * - * This work is dual-licensed under the Apache License 2.0 - * and European Union Public License. See LICENSE file for details. - */ -package com.evolveum.midpoint.web.component.objectdetails; - -import java.util.List; - -import org.apache.commons.lang.Validate; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.extensions.markup.html.tabs.ITab; -import org.apache.wicket.markup.html.panel.Panel; -import org.apache.wicket.model.StringResourceModel; -import org.apache.wicket.request.mapper.parameter.PageParameters; - -import com.evolveum.midpoint.gui.api.model.LoadableModel; -import com.evolveum.midpoint.gui.api.prism.ItemStatus; -import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper; -import com.evolveum.midpoint.gui.api.util.WebComponentUtil; -import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.security.api.AuthorizationConstants; -import com.evolveum.midpoint.web.component.AjaxButton; -import com.evolveum.midpoint.web.component.AjaxSubmitButton; -import com.evolveum.midpoint.web.component.TabbedPanel; -import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; -import com.evolveum.midpoint.web.component.form.Form; -import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour; -import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails; -import com.evolveum.midpoint.web.page.admin.configuration.PageDebugView; -import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto; -import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsPanel; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; - -/** - * @author semancik - * - */ -public abstract class AbstractObjectMainPanel extends Panel { - private static final long serialVersionUID = 1L; - - public static final String PARAMETER_SELECTED_TAB = "tab"; - - private static final String ID_MAIN_FORM = "mainForm"; - public static final String ID_TAB_PANEL = "tabPanel"; - private static final String ID_EXECUTE_OPTIONS = "executeOptions"; - private static final String ID_BACK = "back"; - private static final String ID_SAVE = "save"; - private static final String ID_EDIT_XML = "editXml"; - private static final String ID_PREVIEW_CHANGES = "previewChanges"; - - //private static final Trace LOGGER = TraceManager.getTrace(AbstractObjectMainPanel.class); - - private Form> mainForm; - - private LoadableModel> objectModel; - //get rid of it. - private PageAdminObjectDetails parentPage; - - private LoadableModel executeOptionsModel = new LoadableModel(false) { - private static final long serialVersionUID = 1L; - - @Override - protected ExecuteChangeOptionsDto load() { - return ExecuteChangeOptionsDto.createFromSystemConfiguration(); - } - }; - - public AbstractObjectMainPanel(String id, LoadableModel> objectModel, PageAdminObjectDetails parentPage) { - super(id, objectModel); - Validate.notNull(objectModel, "Null object model"); - this.objectModel = objectModel; - this.parentPage = parentPage; - - } - - @Override - protected void onInitialize() { - super.onInitialize(); - initLayout(parentPage); - } - - @Override - protected void onConfigure() { - super.onConfigure(); - - TabbedPanel tabbedPanel = (TabbedPanel) get(ID_MAIN_FORM + ":" + ID_TAB_PANEL); - WebComponentUtil.setSelectedTabFromPageParameters(tabbedPanel, getPage().getPageParameters(), - PARAMETER_SELECTED_TAB); - } - - public LoadableModel> getObjectModel() { - return objectModel; - } - - public PrismObjectWrapper getObjectWrapper() { - return objectModel.getObject(); - } - - public PrismObject getObject() { - return objectModel.getObject().getObject(); - } - - public Form> getMainForm() { - return mainForm; - } - - private void initLayout(PageAdminObjectDetails parentPage) { - mainForm = new Form<>(ID_MAIN_FORM, true); - add(mainForm); - initLayoutTabs(parentPage); - initLayoutOptions(); - initLayoutButtons(parentPage); - } - - protected void initLayoutTabs(final PageAdminObjectDetails parentPage) { - List tabs = createTabs(parentPage); - TabbedPanel tabPanel = WebComponentUtil.createTabPanel(ID_TAB_PANEL, parentPage, tabs, null, PARAMETER_SELECTED_TAB); - mainForm.add(tabPanel); - } - - protected abstract List createTabs(PageAdminObjectDetails parentPage); - - protected void initLayoutOptions() { - ExecuteChangeOptionsPanel optionsPanel = new ExecuteChangeOptionsPanel(ID_EXECUTE_OPTIONS, - executeOptionsModel, true, false); - optionsPanel.setOutputMarkupId(true); - optionsPanel.add(new VisibleEnableBehaviour() { - private static final long serialVersionUID = 1L; - - @Override - public boolean isVisible() { - return getOptionsPanelVisibility(); - } - - }); - mainForm.add(optionsPanel); - } - - protected void initLayoutButtons(PageAdminObjectDetails parentPage) { - initLayoutPreviewButton(parentPage); - initLayoutSaveButton(parentPage); - initLayoutBackButton(parentPage); - initLayoutEditXmlButton(parentPage); - } - - protected void initLayoutSaveButton(final PageAdminObjectDetails parentPage) { - AjaxSubmitButton saveButton = new AjaxSubmitButton(ID_SAVE, parentPage.createStringResource("pageAdminFocus.button.save")) { - private static final long serialVersionUID = 1L; - - @Override - protected void onSubmit(AjaxRequestTarget target) { - getDetailsPage().savePerformed(target); - } - - @Override - protected void onError(AjaxRequestTarget target) { - target.add(parentPage.getFeedbackPanel()); - } - }; - saveButton.add(new VisibleEnableBehaviour(){ - private static final long serialVersionUID = 1L; - - @Override - public boolean isVisible() { - return !getObjectWrapper().isReadOnly() && - !getDetailsPage().isForcedPreview(); - } - - @Override - public boolean isEnabled() { - //in case user isn't allowed to modify focus data but has - // e.g. #assign authorization, Save button is disabled on page load. - // Save button becomes enabled just if some changes are made - // on the Assignments tab (in the use case with #assign authorization) -// PrismContainerDefinition def = getObjectWrapper().getDefinition(); - if (ItemStatus.NOT_CHANGED.equals(getObjectWrapper().getStatus()) - && !getObjectWrapper().canModify()){ - return areSavePreviewButtonsEnabled(); - } - return true; - } - }); - saveButton.setOutputMarkupId(true); - saveButton.setOutputMarkupPlaceholderTag(true); - mainForm.setDefaultButton(saveButton); - mainForm.add(saveButton); - } - - // TEMPORARY - protected void initLayoutPreviewButton(final PageAdminObjectDetails parentPage) { - AjaxSubmitButton previewButton = new AjaxSubmitButton(ID_PREVIEW_CHANGES, parentPage.createStringResource("pageAdminFocus.button.previewChanges")) { - private static final long serialVersionUID = 1L; - - @Override - protected void onSubmit(AjaxRequestTarget target) { - getDetailsPage().previewPerformed(target); - } - - @Override - protected void onError(AjaxRequestTarget target) { - target.add(parentPage.getFeedbackPanel()); - } - }; - previewButton.add(new VisibleEnableBehaviour(){ - private static final long serialVersionUID = 1L; - - @Override - public boolean isVisible(){ - return AbstractObjectMainPanel.this.isPreviewButtonVisible(); - } - - @Override - public boolean isEnabled() { -// PrismContainerDefinition def = getObjectWrapper().getDefinition(); - if (ItemStatus.NOT_CHANGED.equals(getObjectWrapper().getStatus()) - && !getObjectWrapper().canModify()){ - return areSavePreviewButtonsEnabled(); - } - return true; - } - }); - previewButton.setOutputMarkupId(true); - previewButton.setOutputMarkupPlaceholderTag(true); - mainForm.add(previewButton); - } - - protected boolean isPreviewButtonVisible(){ - return !getObjectWrapper().isReadOnly(); - } - - protected void initLayoutBackButton(PageAdminObjectDetails parentPage) { - AjaxButton back = new AjaxButton(ID_BACK, parentPage.createStringResource("pageAdminFocus.button.back")) { - private static final long serialVersionUID = 1L; - - @Override - public void onClick(AjaxRequestTarget target) { - backPerformed(); - } - - }; - back.setOutputMarkupId(true); - back.setOutputMarkupPlaceholderTag(true); - mainForm.add(back); - } - - private void initLayoutEditXmlButton(final PageAdminObjectDetails parentPage){ - AjaxButton editXmlButton = new AjaxButton(ID_EDIT_XML, parentPage.createStringResource("AbstractObjectMainPanel.editXmlButton")) { - private static final long serialVersionUID = 1L; - - @Override - public void onClick(AjaxRequestTarget target) { - ConfirmationPanel confirmationPanel = new ConfirmationPanel(parentPage.getMainPopupBodyId(), - parentPage.createStringResource("AbstractObjectMainPanel.confirmEditXmlRedirect")){ - private static final long serialVersionUID = 1L; - - @Override - public void yesPerformed(AjaxRequestTarget target) { - PageParameters parameters = new PageParameters(); - parameters.add(PageDebugView.PARAM_OBJECT_ID, parentPage.getObjectWrapper().getOid()); - parameters.add(PageDebugView.PARAM_OBJECT_TYPE, parentPage.getCompileTimeClass().getSimpleName()); - parentPage.navigateToNext(PageDebugView.class, parameters); - } - - @Override - public StringResourceModel getTitle() { - return new StringResourceModel("pageUsers.message.confirmActionPopupTitle"); - } - }; - - parentPage.showMainPopup(confirmationPanel, target); - } - }; - editXmlButton.add(new VisibleEnableBehaviour(){ - private static final long serialVersionUID = 1L; - - @Override - public boolean isVisible(){ - return WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_CONFIGURATION_URL, - AuthorizationConstants.AUTZ_UI_CONFIGURATION_DEBUG_URL) && - !getObjectWrapper().isReadOnly(); - } - }); - mainForm.add(editXmlButton); - - } - public ExecuteChangeOptionsDto getExecuteChangeOptionsDto() { - return executeOptionsModel.getObject(); - } - - private void backPerformed() { - getDetailsPage().redirectBack(); - } - - @SuppressWarnings("unchecked") - protected PageAdminObjectDetails getDetailsPage() { - return (PageAdminObjectDetails) getPage(); - } - - protected boolean getOptionsPanelVisibility(){ - if (getObjectWrapper().isReadOnly()){ - return false; - } - return ItemStatus.NOT_CHANGED != getObjectWrapper().getStatus() - || getObjectWrapper().canModify(); - } - - public void reloadSavePreviewButtons(AjaxRequestTarget target){ - target.add(AbstractObjectMainPanel.this.get(ID_MAIN_FORM).get(ID_PREVIEW_CHANGES)); - target.add(AbstractObjectMainPanel.this.get(ID_MAIN_FORM).get(ID_SAVE)); - - } - - protected boolean areSavePreviewButtonsEnabled() { - return false; - } - - public TabbedPanel getTabbedPanel() { - return (TabbedPanel) get(WebComponentUtil.getPageBase(this).createComponentPath(ID_MAIN_FORM, ID_TAB_PANEL)); - } -} +/* + * Copyright (c) 2015-2016 Evolveum and contributors + * + * This work is dual-licensed under the Apache License 2.0 + * and European Union Public License. See LICENSE file for details. + */ +package com.evolveum.midpoint.web.component.objectdetails; + +import java.util.List; + +import org.apache.commons.lang.Validate; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.extensions.markup.html.tabs.ITab; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.StringResourceModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +import com.evolveum.midpoint.gui.api.model.LoadableModel; +import com.evolveum.midpoint.gui.api.prism.ItemStatus; +import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper; +import com.evolveum.midpoint.gui.api.util.WebComponentUtil; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.security.api.AuthorizationConstants; +import com.evolveum.midpoint.web.component.AjaxButton; +import com.evolveum.midpoint.web.component.AjaxSubmitButton; +import com.evolveum.midpoint.web.component.TabbedPanel; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; +import com.evolveum.midpoint.web.component.form.Form; +import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour; +import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails; +import com.evolveum.midpoint.web.page.admin.configuration.PageDebugView; +import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto; +import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsPanel; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; + +/** + * @author semancik + * + */ +public abstract class AbstractObjectMainPanel extends Panel { + private static final long serialVersionUID = 1L; + + public static final String PARAMETER_SELECTED_TAB = "tab"; + + private static final String ID_MAIN_FORM = "mainForm"; + public static final String ID_TAB_PANEL = "tabPanel"; + private static final String ID_EXECUTE_OPTIONS = "executeOptions"; + private static final String ID_BACK = "back"; + private static final String ID_SAVE = "save"; + private static final String ID_EDIT_XML = "editXml"; + private static final String ID_PREVIEW_CHANGES = "previewChanges"; + + //private static final Trace LOGGER = TraceManager.getTrace(AbstractObjectMainPanel.class); + + private Form> mainForm; + + private LoadableModel> objectModel; + //get rid of it. + private PageAdminObjectDetails parentPage; + + private LoadableModel executeOptionsModel = new LoadableModel(false) { + private static final long serialVersionUID = 1L; + + @Override + protected ExecuteChangeOptionsDto load() { + return ExecuteChangeOptionsDto.createFromSystemConfiguration(); + } + }; + + public AbstractObjectMainPanel(String id, LoadableModel> objectModel, PageAdminObjectDetails parentPage) { + super(id, objectModel); + Validate.notNull(objectModel, "Null object model"); + this.objectModel = objectModel; + this.parentPage = parentPage; + + } + + @Override + protected void onInitialize() { + super.onInitialize(); + initLayout(parentPage); + } + + @Override + protected void onConfigure() { + super.onConfigure(); + + TabbedPanel tabbedPanel = (TabbedPanel) get(ID_MAIN_FORM + ":" + ID_TAB_PANEL); + WebComponentUtil.setSelectedTabFromPageParameters(tabbedPanel, getPage().getPageParameters(), + PARAMETER_SELECTED_TAB); + } + + public LoadableModel> getObjectModel() { + return objectModel; + } + + public PrismObjectWrapper getObjectWrapper() { + return objectModel.getObject(); + } + + public PrismObject getObject() { + return objectModel.getObject().getObject(); + } + + public Form> getMainForm() { + return mainForm; + } + + private void initLayout(PageAdminObjectDetails parentPage) { + mainForm = new Form<>(ID_MAIN_FORM, true); + add(mainForm); + initLayoutTabs(parentPage); + initLayoutOptions(); + initLayoutButtons(parentPage); + } + + protected void initLayoutTabs(final PageAdminObjectDetails parentPage) { + List tabs = createTabs(parentPage); + TabbedPanel tabPanel = WebComponentUtil.createTabPanel(ID_TAB_PANEL, parentPage, tabs, null, PARAMETER_SELECTED_TAB); + mainForm.add(tabPanel); + } + + protected abstract List createTabs(PageAdminObjectDetails parentPage); + + protected void initLayoutOptions() { + ExecuteChangeOptionsPanel optionsPanel = new ExecuteChangeOptionsPanel(ID_EXECUTE_OPTIONS, + executeOptionsModel, true, false); + optionsPanel.setOutputMarkupId(true); + optionsPanel.add(new VisibleEnableBehaviour() { + private static final long serialVersionUID = 1L; + + @Override + public boolean isVisible() { + return getOptionsPanelVisibility(); + } + + }); + mainForm.add(optionsPanel); + } + + protected void initLayoutButtons(PageAdminObjectDetails parentPage) { + initLayoutPreviewButton(parentPage); + initLayoutSaveButton(parentPage); + initLayoutBackButton(parentPage); + initLayoutEditXmlButton(parentPage); + } + + protected void initLayoutSaveButton(final PageAdminObjectDetails parentPage) { + AjaxSubmitButton saveButton = new AjaxSubmitButton(ID_SAVE, parentPage.createStringResource("pageAdminFocus.button.save")) { + private static final long serialVersionUID = 1L; + + @Override + protected void onSubmit(AjaxRequestTarget target) { + getDetailsPage().savePerformed(target); + } + + @Override + protected void onError(AjaxRequestTarget target) { + target.add(parentPage.getFeedbackPanel()); + } + }; + saveButton.add(new VisibleEnableBehaviour(){ + private static final long serialVersionUID = 1L; + + @Override + public boolean isVisible() { + return !getObjectWrapper().isReadOnly() && + !getDetailsPage().isForcedPreview(); + } + + @Override + public boolean isEnabled() { + //in case user isn't allowed to modify focus data but has + // e.g. #assign authorization, Save button is disabled on page load. + // Save button becomes enabled just if some changes are made + // on the Assignments tab (in the use case with #assign authorization) +// PrismContainerDefinition def = getObjectWrapper().getDefinition(); + if (ItemStatus.NOT_CHANGED.equals(getObjectWrapper().getStatus()) + && !getObjectWrapper().canModify()){ + return areSavePreviewButtonsEnabled(); + } + return true; + } + }); + saveButton.setOutputMarkupId(true); + saveButton.setOutputMarkupPlaceholderTag(true); + mainForm.setDefaultButton(saveButton); + mainForm.add(saveButton); + } + + // TEMPORARY + protected void initLayoutPreviewButton(final PageAdminObjectDetails parentPage) { + AjaxSubmitButton previewButton = new AjaxSubmitButton(ID_PREVIEW_CHANGES, parentPage.createStringResource("pageAdminFocus.button.previewChanges")) { + private static final long serialVersionUID = 1L; + + @Override + protected void onSubmit(AjaxRequestTarget target) { + getDetailsPage().previewPerformed(target); + } + + @Override + protected void onError(AjaxRequestTarget target) { + target.add(parentPage.getFeedbackPanel()); + } + }; + previewButton.add(new VisibleEnableBehaviour(){ + private static final long serialVersionUID = 1L; + + @Override + public boolean isVisible(){ + return WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_PREVIEW_CHANGES_URL) && AbstractObjectMainPanel.this.isPreviewButtonVisible(); + } + + @Override + public boolean isEnabled() { + if (ItemStatus.NOT_CHANGED == getObjectWrapper().getStatus() && !getObjectWrapper().canModify()){ + return areSavePreviewButtonsEnabled(); + } + return true; + } + }); + previewButton.setOutputMarkupId(true); + previewButton.setOutputMarkupPlaceholderTag(true); + mainForm.add(previewButton); + } + + protected boolean isPreviewButtonVisible(){ + return !getObjectWrapper().isReadOnly(); + } + + protected void initLayoutBackButton(PageAdminObjectDetails parentPage) { + AjaxButton back = new AjaxButton(ID_BACK, parentPage.createStringResource("pageAdminFocus.button.back")) { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + backPerformed(); + } + + }; + back.setOutputMarkupId(true); + back.setOutputMarkupPlaceholderTag(true); + mainForm.add(back); + } + + private void initLayoutEditXmlButton(final PageAdminObjectDetails parentPage){ + AjaxButton editXmlButton = new AjaxButton(ID_EDIT_XML, parentPage.createStringResource("AbstractObjectMainPanel.editXmlButton")) { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + ConfirmationPanel confirmationPanel = new ConfirmationPanel(parentPage.getMainPopupBodyId(), + parentPage.createStringResource("AbstractObjectMainPanel.confirmEditXmlRedirect")){ + private static final long serialVersionUID = 1L; + + @Override + public void yesPerformed(AjaxRequestTarget target) { + PageParameters parameters = new PageParameters(); + parameters.add(PageDebugView.PARAM_OBJECT_ID, parentPage.getObjectWrapper().getOid()); + parameters.add(PageDebugView.PARAM_OBJECT_TYPE, parentPage.getCompileTimeClass().getSimpleName()); + parentPage.navigateToNext(PageDebugView.class, parameters); + } + + @Override + public StringResourceModel getTitle() { + return new StringResourceModel("pageUsers.message.confirmActionPopupTitle"); + } + }; + + parentPage.showMainPopup(confirmationPanel, target); + } + }; + editXmlButton.add(new VisibleEnableBehaviour(){ + private static final long serialVersionUID = 1L; + + @Override + public boolean isVisible(){ + return WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_CONFIGURATION_URL, + AuthorizationConstants.AUTZ_UI_CONFIGURATION_DEBUG_URL) && + !getObjectWrapper().isReadOnly(); + } + }); + mainForm.add(editXmlButton); + + } + public ExecuteChangeOptionsDto getExecuteChangeOptionsDto() { + return executeOptionsModel.getObject(); + } + + private void backPerformed() { + getDetailsPage().redirectBack(); + } + + @SuppressWarnings("unchecked") + protected PageAdminObjectDetails getDetailsPage() { + return (PageAdminObjectDetails) getPage(); + } + + protected boolean getOptionsPanelVisibility(){ + if (getObjectWrapper().isReadOnly()){ + return false; + } + return ItemStatus.NOT_CHANGED != getObjectWrapper().getStatus() + || getObjectWrapper().canModify(); + } + + public void reloadSavePreviewButtons(AjaxRequestTarget target){ + target.add(AbstractObjectMainPanel.this.get(ID_MAIN_FORM).get(ID_PREVIEW_CHANGES)); + target.add(AbstractObjectMainPanel.this.get(ID_MAIN_FORM).get(ID_SAVE)); + + } + + protected boolean areSavePreviewButtonsEnabled() { + return false; + } + + public TabbedPanel getTabbedPanel() { + return (TabbedPanel) get(WebComponentUtil.getPageBase(this).createComponentPath(ID_MAIN_FORM, ID_TAB_PANEL)); + } +} diff --git a/testing/schrodingertest/src/test/java/com/evolveum/midpoint/testing/schrodinger/page/PreviewPageTest.java b/testing/schrodingertest/src/test/java/com/evolveum/midpoint/testing/schrodinger/page/PreviewPageTest.java index 62e476067df..2b7e39df7ab 100644 --- a/testing/schrodingertest/src/test/java/com/evolveum/midpoint/testing/schrodinger/page/PreviewPageTest.java +++ b/testing/schrodingertest/src/test/java/com/evolveum/midpoint/testing/schrodinger/page/PreviewPageTest.java @@ -7,12 +7,10 @@ package com.evolveum.midpoint.testing.schrodinger.page; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - import java.io.File; import java.util.List; +import com.codeborne.selenide.Screenshots; import com.codeborne.selenide.Selenide; import com.evolveum.midpoint.schema.result.OperationResult; @@ -35,6 +33,8 @@ import com.evolveum.midpoint.testing.schrodinger.AbstractSchrodingerTest; import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; +import static org.testng.Assert.*; + public class PreviewPageTest extends AbstractSchrodingerTest { private static final String TEST_DIR = "./src/test/resources/page/preview"; @@ -42,11 +42,15 @@ public class PreviewPageTest extends AbstractSchrodingerTest { private static final File ROLE_USER_PREVIEW_FILE = new File(TEST_DIR, "role-user-preview.xml"); private static final String ROLE_USER_PREVIEW_NAME = "rolePreviewChanges"; + private static final File ROLE_USER_NO_PREVIEW_FILE = new File(TEST_DIR, "role-user-no-preview.xml"); + private static final String ROLE_USER_NO_PREVIEW_NAME = "roleNoPreviewChanges"; + @Override protected void initSystem(Task task, OperationResult initResult) throws Exception { super.initSystem(task, initResult); repoAddObjectFromFile(ROLE_USER_PREVIEW_FILE, initResult); + repoAddObjectFromFile(ROLE_USER_NO_PREVIEW_FILE, initResult); } @Test @@ -55,9 +59,7 @@ public void test001createUser() { //@formatter:off UserPage user = basicPage.newUser(); - PreviewPage previewPage = null; - - PreviewPage f = user.selectTabBasic() + PreviewPage previewPage = user.selectTabBasic() .form() .addAttributeValue("name", "jack") .addAttributeValue(UserType.F_GIVEN_NAME, "Jack") @@ -97,7 +99,7 @@ public void test002modifyUser() { .addAttributeValue(UserType.F_FAMILY_NAME, "Sparrow") .and() .and() - .clickPreviewChanges(); + .clickPreview(); //@formatter:on ScenePanel primaryDeltaScene = previewPage.selectPanelByName("jack").primaryDeltas(); @@ -157,7 +159,7 @@ public void test004loginWithUserJack() { .addAttributeValue(UserType.F_FULL_NAME, "Jack Sparrow") .and() .and() - .clickPreviewChanges(); + .clickPreview(); ScenePanel primaryDeltaScene = previewPage.selectPanelByName("jack").primaryDeltas(); assertTrue(primaryDeltaScene.isExpanded(), "Primary deltas should be expanded"); @@ -177,5 +179,67 @@ public void test004loginWithUserJack() { } + @Test + public void test005unassignRolePreview() { + //@formatter:off + ProgressPage previewPage = basicPage.listUsers() + .table() + .clickByName("jack") + .selectTabAssignments() + .table() + .removeByName(ROLE_USER_PREVIEW_NAME) + .and() + .and() + .clickSave(); + //@formatter:on + + assertTrue(previewPage.feedback().isSuccess()); + + } + + @Test + public void test006assignRoleNoPreview() { + //@formatter:off + ProgressPage previewPage = basicPage.listUsers() + .table() + .clickByName("jack") + .selectTabAssignments() + .clickAddAssignemnt() + .selectType(ConstantsUtil.ASSIGNMENT_TYPE_SELECTOR_ROLE) + .table() + .search() + .byName() + .inputValue(ROLE_USER_NO_PREVIEW_NAME) + .updateSearch() + .and() + .selectCheckboxByName(ROLE_USER_NO_PREVIEW_NAME) + .and() + .clickAdd() + .and() + .clickSave(); + //@formatter:on + + assertTrue(previewPage.feedback().isSuccess()); + + } + + @Test + public void test007loginWithUserJack() { + + midPoint.logout(); + + basicPage = midPoint.formLogin().login("jack", "asd123"); + + UserPage userPage = basicPage.profile() + .selectTabBasic() + .form() + .addAttributeValue(UserType.F_FULL_NAME, "Jack Sparrow") + .and() + .and(); + + Selenide.screenshot("previewVisible"); + assertFalse(userPage.isPreviewButtonVisible(), "Preview button should not be visible"); + midPoint.logout(); + } } diff --git a/testing/schrodingertest/src/test/resources/page/preview/role-user-no-preview.xml b/testing/schrodingertest/src/test/resources/page/preview/role-user-no-preview.xml new file mode 100644 index 00000000000..0316ba9ff1c --- /dev/null +++ b/testing/schrodingertest/src/test/resources/page/preview/role-user-no-preview.xml @@ -0,0 +1,131 @@ + + + + roleNoPreviewChanges + Role authorizing end users to log in, change their passwords and review assigned accounts. Note: This role definition is just an example. It should be tailored for each specific deployment. + system + + gui-self-service-access + + Allow access to all self-service operations in GUI. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-ui-3#selfAll + + + self-read + + Allow to read all the properties of "self" object. I.e. every logged-in user can read + object that represent his own identity. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#read + + self + + + + read-requestable-roles + + Allow to read requestable roles. This allows to search for requestable roles in user interface. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#read + + RoleType + + + requestable + true + + + + + + requestable-role-details + + Allow to show details of requestable roles in the user interface. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-ui-3#roleDetails + + + assign-requestable-roles + + Allow to assign requestable roles. This allows to request roles in a request-and-approve process. + The requestable roles will be displayed in the role request dialog by default. + Please note that the roles also need an approval definition to go through the approval process. + Otherwise they will be assigned automatically without any approval. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#assign + request + + self + + + RoleType + + + requestable + true + + + + org:default + + + self-execution-modify + + Authorization that allows to self-modification of some properties, but only in execution phase. + The limitation real limitation of these operations is done in the request phase. + E.g. the modification of assignments is controlled in the request phase by using the #assign + authorization. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#modify + + UserType + + credentials + assignment + name + fullName + + + assignment-target-get + + Authorization that allows to read all the object that are possible assignment targets. We want that + to display the targets in the selection windows. + Note that this authorization may be too broad for production use. Normally it should be limited to just + selected properties such as name and description. + + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#get + + OrgType + + + ResourceType + + + RoleType + + + ServiceType + + + + createUser-previewChanges + http://midpoint.evolveum.com/xml/ns/public/security/authorization-model-3#add + + UserType + + name + familyName + givenName + fullName + + diff --git a/testing/schrodingertest/src/test/resources/page/preview/role-user-preview.xml b/testing/schrodingertest/src/test/resources/page/preview/role-user-preview.xml index 4cb200e4195..6d24fd035b0 100644 --- a/testing/schrodingertest/src/test/resources/page/preview/role-user-preview.xml +++ b/testing/schrodingertest/src/test/resources/page/preview/role-user-preview.xml @@ -1,11 +1,15 @@ + - - + rolePreviewChanges Role authorizing end users to log in, change their passwords and review assigned accounts. Note: This role definition is just an example. It should be tailored for each specific deployment. system diff --git a/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/AssignmentHolderDetailsPage.java b/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/AssignmentHolderDetailsPage.java index 8f591bfb995..9e9f5e9644a 100644 --- a/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/AssignmentHolderDetailsPage.java +++ b/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/AssignmentHolderDetailsPage.java @@ -36,10 +36,18 @@ public ProgressPage clickSave() { } public PreviewPage clickPreview() { - $(Schrodinger.byDataId("previewChanges")).waitUntil(Condition.visible, MidPoint.TIMEOUT_MEDIUM_6_S).click(); + getPreviewButton().waitUntil(Condition.visible, MidPoint.TIMEOUT_DEFAULT_2_S).click(); return new PreviewPage(); } + public boolean isPreviewButtonVisible() { + return getPreviewButton().exists(); + } + + private SelenideElement getPreviewButton() { + return $(Schrodinger.byDataId("previewChanges")); + } + protected TabPanel findTabPanel() { SelenideElement tabPanelElement = $(Schrodinger.byDataId("div", "tabPanel")) .waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S); diff --git a/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/user/UserPage.java b/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/user/UserPage.java index 38d05db3697..d2cb59ec01a 100644 --- a/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/user/UserPage.java +++ b/tools/schrodinger/src/main/java/com/evolveum/midpoint/schrodinger/page/user/UserPage.java @@ -68,12 +68,6 @@ public UserPage uncheckKeepDisplayingResults() { return this; } - public PreviewPage clickPreviewChanges() { - $(Schrodinger.byDataId("previewChanges")).click(); - return new PreviewPage(); - } - - public ProjectionsTab selectTabProjections() { SelenideElement element = findTabPanel().clickTab("pageAdminFocus.projections"); Selenide.sleep(2000);