ItEr46S22CUPasarPedidosAHistorico: code rebase that will help in the implementation of this use case.

This commit is contained in:
Jacobo Aragunde Pérez 2010-02-07 00:50:47 +01:00 committed by Javier Moran Rua
parent 5760b9509d
commit 09b510f2b0
4 changed files with 34 additions and 59 deletions

View file

@ -548,6 +548,7 @@ public class OrderCRUDController extends GenericForwardComposer {
public void initEdit(Order order) {
orderModel.initEdit(order);
addEditWindowIfNeeded();
checkWritePermissions(order);
orderAuthorizationController.initEdit(order);
showEditWindow(_("Edit order"));
}
@ -583,6 +584,7 @@ public class OrderCRUDController extends GenericForwardComposer {
showOrderElementFilter();
orderModel.prepareForCreate();
showEditWindow(_("Create order"));
checkCreationPermissions();
orderAuthorizationController.initCreate((Order) orderModel.getOrder());
} catch (ConcurrentModificationException e) {
messagesForUser.showMessage(Level.ERROR, e.getMessage());
@ -895,4 +897,36 @@ public class OrderCRUDController extends GenericForwardComposer {
}
}
/**
* Checks the creation permissions of the current user and enables/disables
* the save buttons accordingly.
*/
private void checkCreationPermissions() {
if(SecurityUtils.isUserInRole(UserRole.ROLE_CREATE_ORDER)) {
((Button)editWindow.getFellowIfAny("save")).setDisabled(false);
((Button)editWindow.getFellowIfAny("save_and_continue")).setDisabled(false);
}
else {
((Button)editWindow.getFellowIfAny("save")).setDisabled(true);
((Button)editWindow.getFellowIfAny("save_and_continue")).setDisabled(true);
}
}
/**
* Checks the write permissions of the current user on this Order and enables/disables
* the save buttons accordingly.
*/
private void checkWritePermissions(Order order) {
if(orderModel.userCanWrite(order, SecurityUtils.getSessionUserLoginName())) {
setEditionDisabled(false);
}
else {
setEditionDisabled(true);
}
}
private void setEditionDisabled(boolean disabled) {
((Button)editWindow.getFellowIfAny("save")).setDisabled(disabled);
((Button)editWindow.getFellowIfAny("save_and_continue")).setDisabled(disabled);
}
}

View file

@ -71,6 +71,4 @@ public interface IOrderAuthorizationModel {
void removeOrderAuthorization(OrderAuthorization orderAuthorization);
boolean userCanWrite(String loginName);
}

View file

@ -65,13 +65,11 @@ public class OrderAuthorizationController extends GenericForwardComposer{
public void initCreate(Order order) {
orderAuthorizationModel.initCreate(order);
checkCreationPermissions();
Util.reloadBindings(window);
}
public void initEdit(Order order) {
orderAuthorizationModel.initEdit(order);
checkWritePermissions();
Util.reloadBindings(window);
}
@ -138,33 +136,4 @@ public class OrderAuthorizationController extends GenericForwardComposer{
messagesForUser = component;
}
/**
* Checks the creation permissions of the current user and enables/disables
* the save buttons accordingly.
*/
private void checkCreationPermissions() {
if(SecurityUtils.isUserInRole(UserRole.ROLE_CREATE_ORDER)) {
((Button)window.getFellowIfAny("save")).setDisabled(false);
((Button)window.getFellowIfAny("save_and_continue")).setDisabled(false);
}
else {
((Button)window.getFellowIfAny("save")).setDisabled(true);
((Button)window.getFellowIfAny("save_and_continue")).setDisabled(true);
}
}
/**
* Checks the write permissions of the current user on this Order and enables/disables
* the save buttons accordingly.
*/
private void checkWritePermissions() {
if(orderAuthorizationModel.userCanWrite(SecurityUtils.getSessionUserLoginName())) {
((Button)window.getFellowIfAny("save")).setDisabled(false);
((Button)window.getFellowIfAny("save_and_continue")).setDisabled(false);
}
else {
((Button)window.getFellowIfAny("save")).setDisabled(true);
((Button)window.getFellowIfAny("save_and_continue")).setDisabled(true);
}
}
}

View file

@ -223,32 +223,6 @@ public class OrderAuthorizationModel implements IOrderAuthorizationModel {
}
}
@Override
@Transactional(readOnly = true)
public boolean userCanWrite(String loginName) {
if (SecurityUtils.isUserInRole(UserRole.ROLE_EDIT_ALL_ORDERS)) {
return true;
}
else {
User user;
try {
user = userDAO.findByLoginName(loginName);
}
catch(InstanceNotFoundException e) {
return false;
}
List<OrderAuthorization> authorizations =
dao.listByOrderUserAndItsProfiles(order, user);
for(OrderAuthorization authorization : authorizations) {
if (authorization.getAuthorizationType() ==
OrderAuthorizationType.WRITE_AUTHORIZATION) {
return true;
}
}
return false;
}
}
private ProfileOrderAuthorization createProfileOrderAuthorization(
Order order, Profile profile) {
ProfileOrderAuthorization orderAuthorization =