new AbstractActionCall() {
public String doInAction(ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
ActionsHelper.rememberPage(request, "/user/invoice/showInvoices");
ActionsHelper.rememberContext(request, "admin");
User userLogged = (User)request.getSession().getAttribute(Params.LOGIN.SESSION.USER);
if (userLogged==null) {
LOGGER.debug("user try to access license page without being logged in.");
return ActionsHelper.loginForwardName();
}
String userLogin = (String)request.getParameter(Params.USER_INVOICE.SHOW.PARAMS.LOGIN);
User u = null;
if (userLogin!=null) {
if (!userLogged.getLogin().equals(userLogin) && !ActionsHelper.isAdmin(request)) {
// a non admin user try to edit another user page
LOGGER.debug("user " + userLogged.getLogin() + " try to edit " + userLogin + " license page without admin rights");
return ActionsHelper.homepageForwardName();
}
LOGGER.debug("showing license form for user with login : " + userLogin);
u = DaoFactory.getUserDao().findUser(userLogin);
} else {
LOGGER.debug("showing license form for connected user");
u = (User)request.getSession().getAttribute(Params.LOGIN.SESSION.USER);
if (u!=null) {
// We refresh the user
u = Portal.getInstance().getUserService().getUser(u.getLogin());
if (u!=null) {
request.getSession().setAttribute(Params.LOGIN.SESSION.USER, u);
}
}
}
if (u == null) {
LOGGER.debug("failed to retrieve user to modify in license form");
request.setAttribute(Params.REDIRECT.REQUEST.REDIRECTION_URL, ActionsHelper.homepageForward().getPath());
request.setAttribute(Params.REDIRECT.REQUEST.MESSAGE_KEY, "illegal.state");
return "redirect";
}
request.setAttribute(Params.USER_INVOICE.SHOW.REQUEST.USER_LOGIN, u.getLogin());
request.setAttribute(Params.USER_INVOICE.SHOW.REQUEST.USER, u);
List orders = ServiceFactory.getCommercialService().getOrders(u);
request.setAttribute(Params.USER_INVOICE.SHOW.REQUEST.ORDERS, orders);
return null;