diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/Util.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/Util.java index 698bf6e50..8ecce7d15 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/Util.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/Util.java @@ -718,17 +718,29 @@ public class Util { * * If removeButtonListener is null, it only adds the edit * button and the ON_CLICK event. + * + * @return An array of 1 or 2 positions (depending if + * removeButtonListener param is or not + * null) with the edit and remove buttons. As maybe you + * need to disable any of them depending on different situations. */ - public static void appendOperationsAndOnClickEvent(Row row, + public static Button[] appendOperationsAndOnClickEvent(Row row, EventListener editButtonListener, EventListener removeButtonListener) { + Button[] buttons = new Button[removeButtonListener != null ? 2 : 1]; + Hbox hbox = new Hbox(); - hbox.appendChild(Util.createEditButton(editButtonListener)); + buttons[0] = Util.createEditButton(editButtonListener); + hbox.appendChild(buttons[0]); + if (removeButtonListener != null) { - hbox.appendChild(Util.createRemoveButton(removeButtonListener)); + buttons[1] = Util.createRemoveButton(removeButtonListener); + hbox.appendChild(buttons[1]); } row.appendChild(hbox); row.addEventListener(Events.ON_CLICK, editButtonListener); + + return buttons; } /** diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java index 28ef82f3b..d2ad5ec7f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java @@ -43,6 +43,7 @@ import org.libreplan.web.common.entrypoints.EntryPointsHandler; import org.libreplan.web.common.entrypoints.IURLHandlerRegistry; import org.libreplan.web.resources.worker.IWorkerCRUDControllerEntryPoints; import org.libreplan.web.security.SecurityUtils; +import org.libreplan.web.users.bootstrap.MandatoryUser; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.Event; @@ -101,7 +102,8 @@ public class UserCRUDController extends BaseCRUDController implements Util.appendLabel(row, user.isBound() ? user.getWorker() .getShortDescription() : ""); - Util.appendOperationsAndOnClickEvent(row, new EventListener() { + Button[] buttons = Util.appendOperationsAndOnClickEvent(row, + new EventListener() { @Override public void onEvent(Event event) throws Exception { goToEditForm(user); @@ -112,7 +114,15 @@ public class UserCRUDController extends BaseCRUDController implements confirmDelete(user); } }); + + // Disable remove button for default admin as it's mandatory + if (isDefaultAdmin(user)) { + buttons[1].setDisabled(true); + buttons[1] + .setTooltiptext(_("Default user \"admin\" cannot be removed as it is mandatory")); + } } + }; @Override @@ -320,7 +330,8 @@ public class UserCRUDController extends BaseCRUDController implements } }); removeButton.setDisabled(getLdapUserRolesLdapConfiguration() - || role.equals(UserRole.ROLE_BOUND_USER)); + || role.equals(UserRole.ROLE_BOUND_USER) + || isUserDefaultAdmin()); row.appendChild(removeButton); } }; @@ -405,4 +416,24 @@ public class UserCRUDController extends BaseCRUDController implements return ""; } + private boolean isDefaultAdmin(final User user) { + return user.getLoginName().equals(MandatoryUser.ADMIN.getLoginName()); + } + + private boolean isUserDefaultAdmin() { + User user = userModel.getUser(); + if (user != null) { + return isDefaultAdmin(user); + } + return false; + } + + public boolean areRolesAndProfilesDisabled() { + return isLdapUserLdapConfiguration() || isUserDefaultAdmin(); + } + + public boolean isLdapUserOrDefaultAdmin() { + return isLdapUser() || isUserDefaultAdmin(); + } + } diff --git a/libreplan-webapp/src/main/webapp/users/_editUser.zul b/libreplan-webapp/src/main/webapp/users/_editUser.zul index 8f16a6ea8..e54f9c856 100644 --- a/libreplan-webapp/src/main/webapp/users/_editUser.zul +++ b/libreplan-webapp/src/main/webapp/users/_editUser.zul @@ -49,7 +49,7 @@ value="@{controller.user.loginName}" width="300px" constraint="no empty:${i18n:_('cannot be null or empty')}" onBlur="controller.updateWindowTitle()" - disabled="@{controller.ldapUser}" /> + disabled="@{controller.ldapUserOrDefaultAdmin}" />