Search in sources :

Example 1 with UserWrapper

use of org.apache.syncope.client.console.wizards.any.UserWrapper in project syncope by apache.

the class UserDirectoryPanel method getActions.

@Override
public ActionsPanel<UserTO> getActions(final IModel<UserTO> model) {
    final ActionsPanel<UserTO> panel = super.getActions(model);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new UserWrapper(new UserRestClient().read(model.getObject().getKey())), target));
        }
    }, ActionType.EDIT, StringUtils.join(new String[] { StandardEntitlement.USER_READ, StandardEntitlement.USER_UPDATE }, ",")).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            UserTO clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            clone.setUsername(model.getObject().getUsername() + "_clone");
            send(UserDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new UserWrapper(clone), target));
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.CLONE, StandardEntitlement.USER_CREATE).setRealm(realm);
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                UserRestClient.class.cast(restClient).mustChangePassword(model.getObject().getETagValue(), !model.getObject().isMustChangePassword(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While actioning object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionType.MUSTCHANGEPASSWORD, StandardEntitlement.USER_UPDATE).setRealm(realm);
    if (wizardInModal) {
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -4875218360625971340L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                displayAttributeModal.setFormModel(formModel);
                target.add(displayAttributeModal.setContent(new ChangePasswordModal(displayAttributeModal, pageRef, new UserWrapper(model.getObject()))));
                displayAttributeModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                displayAttributeModal.show(true);
            }
        }, ActionType.PASSWORD_MANAGEMENT, StandardEntitlement.USER_UPDATE).setRealm(realm);
        if (SyncopeConsoleSession.get().getPlatformInfo().isPwdResetAllowed() && !SyncopeConsoleSession.get().getPlatformInfo().isPwdResetRequiringSecurityQuestions()) {
            panel.add(new ActionLink<UserTO>() {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                    try {
                        SyncopeConsoleSession.get().getAnonymousClient().getService(UserSelfService.class).requestPasswordReset(model.getObject().getUsername(), null);
                        SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                        target.add(container);
                    } catch (Exception e) {
                        LOG.error("While actioning object {}", model.getObject().getKey(), e);
                        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }, ActionType.REQUEST_PASSWORD_RESET, StandardEntitlement.USER_UPDATE).setRealm(realm);
        }
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", true)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.ENABLE, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                IModel<AnyWrapper<UserTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
                altDefaultModal.setFormModel(formModel);
                target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
                altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
                altDefaultModal.show(true);
            }
        }, ActionType.MANAGE_RESOURCES, StandardEntitlement.USER_UPDATE).setRealm(realm);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
                utilityModal.show(true);
            }
        }, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
        panel.add(new ActionLink<UserTO>() {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
                target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.USER, model.getObject().getKey(), pageRef)));
                utilityModal.header(new StringResourceModel("any.notification.tasks", model));
                utilityModal.show(true);
                target.add(utilityModal);
            }
        }, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
    }
    panel.add(new ActionLink<UserTO>() {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target, final UserTO ignore) {
            try {
                restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (Exception e) {
                LOG.error("While deleting object {}", model.getObject().getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }

        @Override
        protected boolean statusCondition(final UserTO modelObject) {
            return realm.startsWith(SyncopeConstants.ROOT_REALM);
        }
    }, ActionType.DELETE, StandardEntitlement.USER_DELETE, true).setRealm(realm);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) AnyWrapper(org.apache.syncope.client.console.wizards.any.AnyWrapper) NotificationTasks(org.apache.syncope.client.console.notifications.NotificationTasks) UserWrapper(org.apache.syncope.client.console.wizards.any.UserWrapper) UserRestClient(org.apache.syncope.client.console.rest.UserRestClient) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyStatusModal(org.apache.syncope.client.console.status.AnyStatusModal) AnyPropagationTasks(org.apache.syncope.client.console.tasks.AnyPropagationTasks) UserTO(org.apache.syncope.common.lib.to.UserTO) ChangePasswordModal(org.apache.syncope.client.console.status.ChangePasswordModal) StringResourceModel(org.apache.wicket.model.StringResourceModel) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Aggregations

NotificationTasks (org.apache.syncope.client.console.notifications.NotificationTasks)1 UserRestClient (org.apache.syncope.client.console.rest.UserRestClient)1 AnyStatusModal (org.apache.syncope.client.console.status.AnyStatusModal)1 ChangePasswordModal (org.apache.syncope.client.console.status.ChangePasswordModal)1 AnyPropagationTasks (org.apache.syncope.client.console.tasks.AnyPropagationTasks)1 ActionLink (org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)1 AjaxWizard (org.apache.syncope.client.console.wizards.AjaxWizard)1 AnyWrapper (org.apache.syncope.client.console.wizards.any.AnyWrapper)1 UserWrapper (org.apache.syncope.client.console.wizards.any.UserWrapper)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 UserSelfService (org.apache.syncope.common.rest.api.service.UserSelfService)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)1 StringResourceModel (org.apache.wicket.model.StringResourceModel)1