use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class ExtraHoursController method historicExtraHours.
public void historicExtraHours(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
Employee employee = user.getEmployee();
ActionViewBuilder actionView = ActionView.define(I18n.get("Historic colleague extra hours")).model(ExtraHours.class.getName()).add("grid", "extra-hours-grid").add("form", "extra-hours-form").param("search-filters", "extra-hours-filters");
actionView.domain("self.company = :_activeCompany AND (self.statusSelect = 3 OR self.statusSelect = 4)").context("_activeCompany", user.getActiveCompany());
if (employee == null || !employee.getHrManager()) {
actionView.domain(actionView.get().getDomain() + " AND self.user.employee.managerUser = :_user").context("_user", user);
}
response.setView(actionView.map());
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class LeaveController method editLeave.
public void editLeave(ActionRequest request, ActionResponse response) {
try {
User user = AuthUtils.getUser();
List<LeaveRequest> leaveList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1", user, user.getActiveCompany()).fetch();
if (leaveList.isEmpty()) {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").map());
} else if (leaveList.size() == 1) {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").param("forceEdit", "true").context("_showRecord", String.valueOf(leaveList.get(0).getId())).map());
} else {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(Wizard.class.getName()).add("form", "popup-leave-request-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class LeaveController method validateLeave.
public void validateLeave(ActionRequest request, ActionResponse response) {
try {
User user = AuthUtils.getUser();
Employee employee = user.getEmployee();
ActionViewBuilder actionView = ActionView.define(I18n.get("Leave Requests to Validate")).model(LeaveRequest.class.getName()).add("grid", "leave-request-validate-grid").add("form", "leave-request-form").param("search-filters", "leave-request-filters");
Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
response.setView(actionView.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class UserController method changePfpValidator.
@SuppressWarnings("unchecked")
public void changePfpValidator(ActionRequest request, ActionResponse response) {
Integer pfpValidatorUserId = (Integer) request.getContext().get("_userId");
LinkedHashMap<String, Object> newPfpValidatorUserMap = (LinkedHashMap<String, Object>) request.getContext().get("newPfpValidatorUser");
if (newPfpValidatorUserMap == null) {
return;
}
UserRepository userRepository = Beans.get(UserRepository.class);
User newPfpValidatorUser = userRepository.find(((Integer) newPfpValidatorUserMap.get("id")).longValue());
User pfpValidatorUser = userRepository.find(pfpValidatorUserId.longValue());
int updateCount = Beans.get(UserServiceAccountImpl.class).changePfpValidator(pfpValidatorUser, newPfpValidatorUser);
if (updateCount >= 1) {
response.setFlash(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_UPDATED));
response.setCanClose(true);
} else if (updateCount == 0) {
response.setAlert(String.format(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_NO_RELATED_ACCOUNTING_SITUATION), pfpValidatorUser.getName()));
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class WkfEmailServiceImpl method sendEmail.
@Override
public void sendEmail(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException, MessagingException, AxelorException, InstantiationException, IllegalAccessException, IOException {
String title = wkfTaskConfig.getTaskEmailTitle();
if (title == null) {
return;
}
FullContext wkfContext = wkfUserActionService.getModelCtx(wkfTaskConfig, execution);
if (wkfContext == null) {
return;
}
String model = null;
String tag = null;
Long id = null;
title = wkfUserActionService.processTitle(title, wkfContext);
model = wkfContext.getTarget().getClass().getName();
if (wkfContext.getTarget().getClass().equals(MetaJsonRecord.class)) {
tag = (String) wkfContext.get("jsonModel");
model = tag;
} else {
tag = wkfContext.getTarget().getClass().getSimpleName();
}
id = (Long) wkfContext.get("id");
String url = createUrl(wkfContext, wkfTaskConfig.getDefaultForm());
String activeNode = execution.getCurrentActivityName();
Template template = Beans.get(TemplateRepository.class).findByName(wkfTaskConfig.getTemplateName());
Message message = null;
if (template != null) {
url = "<a href=\"" + url + "\" >" + url + "</a>";
message = Beans.get(TemplateMessageService.class).generateMessage(id, model, tag, template);
message.setSubject(message.getSubject().replace("{{activeNode}}", activeNode));
message.setContent(message.getContent().replace("{{activeNode}}", activeNode));
message.setSubject(message.getSubject().replace("{{recordUrl}}", url));
message.setContent(message.getContent().replace("{{recordUrl}}", url));
} else {
User user = null;
if (wkfTaskConfig.getUserPath() != null) {
user = wkfUserActionService.getUser(wkfTaskConfig.getUserPath(), wkfContext);
}
if (user == null || user.getEmail() == null) {
return;
}
String content = String.format(EMAIL_CONTENT, user.getName(), activeNode, url, url);
List<EmailAddress> toEmailAddressList = new ArrayList<EmailAddress>();
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(user.getEmail());
if (emailAddress == null) {
emailAddress = new EmailAddress(user.getEmail());
}
toEmailAddressList.add(emailAddress);
message = messageService.createMessage(model, id, title, content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, null, null);
}
messageService.sendByEmail(message);
}
Aggregations