Disable edition and removal of default user admin
FEA: ItEr76S30PermissionsEnhancements
This commit is contained in:
parent
909a007042
commit
26d5638b41
3 changed files with 56 additions and 10 deletions
|
|
@ -718,17 +718,29 @@ public class Util {
|
|||
*
|
||||
* If <code>removeButtonListener</code> is null, it only adds the edit
|
||||
* button and the <code>ON_CLICK</code> event.
|
||||
*
|
||||
* @return An array of 1 or 2 positions (depending if
|
||||
* <code>removeButtonListener</code> param is or not
|
||||
* <code>null</code>) 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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<User> 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<User> 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<User> 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<User> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('First name')}" />
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
<label value="${i18n:_('Disabled')}" />
|
||||
<checkbox id="disabled"
|
||||
checked="@{controller.user.disabled}" width="300px"
|
||||
disabled="@{controller.ldapUser}" />
|
||||
disabled="@{controller.ldapUserOrDefaultAdmin}" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('E-mail')}" />
|
||||
|
|
@ -130,7 +130,8 @@
|
|||
<hbox align="center">
|
||||
<combobox id="userRolesCombo" autodrop="true" />
|
||||
<button label="${i18n:_('Add role')}"
|
||||
onClick="controller.addSelectedRole()" disabled="@{controller.ldapUserRolesLdapConfiguration}"/>
|
||||
onClick="controller.addSelectedRole()"
|
||||
disabled="@{controller.areRolesAndProfilesDisabled}" />
|
||||
</hbox>
|
||||
<grid id="listing" model="@{controller.roles}"
|
||||
rowRenderer="@{controller.rolesRenderer}">
|
||||
|
|
@ -152,7 +153,8 @@
|
|||
autodrop="true" constraint=""
|
||||
finder="ProfileFinder" />
|
||||
<button label="${i18n:_('Add profile')}"
|
||||
onClick="controller.addSelectedProfile()" disabled="@{controller.ldapUserRolesLdapConfiguration}"/>
|
||||
onClick="controller.addSelectedProfile()"
|
||||
disabled="@{controller.areRolesAndProfilesDisabled}" />
|
||||
</hbox>
|
||||
<grid id="profilesListing" model="@{controller.profiles}">
|
||||
<columns sizable="true">
|
||||
|
|
@ -166,7 +168,8 @@
|
|||
<button sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="controller.removeProfile(self.parent.parent.value);" disabled="@{controller.ldapUserRolesLdapConfiguration}">
|
||||
onClick="controller.removeProfile(self.parent.parent.value);"
|
||||
disabled="@{controller.areRolesAndProfilesDisabled}" >
|
||||
</button>
|
||||
</hbox>
|
||||
</row>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue