use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class ContractManagementController method addContractAdminPage.
/**
* @param userId
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.ADD_CONTRACT_FROM_CONTRACT_MNGT_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String addContractAdminPage(@RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) {
Long lUserId;
try {
lUserId = Long.valueOf(userId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
User userToManage = userDataService.read(lUserId);
if (userToManage == null) {
throw new ForbiddenUserException();
}
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, lUserId);
return prepateDataAndReturnCreateContractView(model, userToManage, null, ContractOptionFormFieldHelper.getFreshContractOptionFormFieldMap(contractOptionFormFieldBuilderMap), TgolKeyStore.ADD_CONTRACT_VIEW_NAME);
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class ContractManagementController method submitManageContractsAdminPage.
/**
* @param contractDisplayCommand
* @param userId
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.MANAGE_CONTRACTS_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String submitManageContractsAdminPage(@ModelAttribute(TgolKeyStore.CONTRACT_SORT_COMMAND_KEY) ContractSortCommand contractDisplayCommand, @RequestParam(TgolKeyStore.USER_ID_KEY) String userId, Model model) {
Long lUserId;
try {
lUserId = Long.valueOf(userId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
User userToManage = userDataService.read(lUserId);
model.addAttribute(TgolKeyStore.CONTRACT_LIST_KEY, contractSortCommandHelper.prepareContract(userToManage, contractDisplayCommand, displayOptionFieldsBuilderList, model));
model.addAttribute(TgolKeyStore.USER_NAME_KEY, userToManage.getEmail1());
return TgolKeyStore.MANAGE_CONTRACTS_VIEW_NAME;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class AbstractAuditDataHandlerController method isUserAllowedToDisplayResult.
/**
* This methods checks whether the current user is allowed to display the
* audit result of a given audit. To do so, we verify that the act
* associated with the audit belongs to the current user and
* that the current contract is not expired
*
* @param audit
* @return
* true if the user is allowed to display the result, false otherwise.
*/
protected boolean isUserAllowedToDisplayResult(Audit audit) {
if (audit == null) {
throw new ForbiddenPageException();
}
User user = getCurrentUser();
Contract contract = actDataService.getActFromAudit(audit).getContract();
if (isAdminUser() || (!isContractExpired(contract) && user.getId().compareTo(contract.getUser().getId()) == 0)) {
return true;
}
throw new ForbiddenUserException();
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class AccountSettingsController method submitAccountSettingForm.
/**
* This methods controls the validity of the edit user form.
* If the user tries to modidy its email, or try to desactivate its account
* or try to set him as admin where he's not admin, return attack message.
*
* @param createUserCommand
* @param result
* @param model
* @return
* @throws Exception
*/
@RequestMapping(value = TgolKeyStore.ACCOUNT_SETTINGS_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitAccountSettingForm(@ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception {
User user = getCurrentUser();
if (this.forbiddenUserList.contains(user.getEmail1())) {
throw new ForbiddenPageException();
}
if (!createUserCommand.getEmail().equals(user.getEmail1()) || (createUserCommand.getAdmin() && !isUserAdmin(user))) {
model.addAttribute(TgolKeyStore.CREATE_USER_ATTACK_COMMAND_KEY, true);
return prepateDataAndReturnCreateUserView(model, user, TgolKeyStore.ACCOUNT_SETTINGS_VIEW_NAME);
}
secondaryLevelMenuDisplayer.setModifiableReferentialsForUserToModel(user, model);
return submitUpdateUserForm(createUserCommand, result, null, model, user, TgolKeyStore.ACCOUNT_SETTINGS_VIEW_NAME, TgolKeyStore.ACCOUNT_SETTINGS_VIEW_NAME, false, false, TgolKeyStore.UPDATED_USER_NAME_KEY);
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class HomeController method submitForm.
@RequestMapping(value = TgolKeyStore.HOME_URL, method = RequestMethod.POST)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
protected String submitForm(@ModelAttribute(TgolKeyStore.CONTRACT_SORT_COMMAND_KEY) ContractSortCommand contractDisplayCommand, Model model) {
User user = getCurrentUser();
if (!user.getId().equals(contractDisplayCommand.getUserId())) {
throw new ForbiddenUserException();
}
// The page is displayed with sort option. Form needs to be set up
model.addAttribute(TgolKeyStore.CONTRACT_LIST_KEY, contractSortCommandHelper.prepareContractInfo(user, contractDisplayCommand, displayOptionFieldsBuilderList, model));
return TgolKeyStore.HOME_VIEW_NAME;
}
Aggregations