use of com.axelor.auth.db.User in project open-platform-demo by axelor.
the class AccessSaleQuickMenu method create.
@Override
public QuickMenu create() {
QuickMenu menu = super.create();
User user = AuthUtils.getUser();
if (user == null || !Beans.get(JpaSecurity.class).isPermitted(JpaSecurity.CAN_READ, Order.class)) {
return menu;
}
if (menu == null) {
// can be null in case use doesn't have permission on Contact domain.
menu = createAccessQuickMenu();
}
menu.setItems(Stream.of(menu.getItems(), List.of(new QuickMenuItem(I18n.get("Quotations"), "sale.orders.draft"), new QuickMenuItem(I18n.get("Sale Orders"), "sale.orders"))).flatMap(Collection::stream).collect(Collectors.toList()));
return menu;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class GlobalAuditTracker method onComplete.
/**
* This method should be called from {@link
* AuditInterceptor#beforeTransactionCompletion(Transaction)} method to finish change recording.
*
* @param tx the transaction in which the change tracking is being done
* @param user the session user
*/
public void onComplete(Transaction tx, User user) {
List<GlobalTrackingLog> logList = LOGS.get();
LOGS.remove();
if (CollectionUtils.isEmpty(logList)) {
return;
}
MetaModelRepository modelRepo = Beans.get(MetaModelRepository.class);
MetaFieldRepository fieldRepo = Beans.get(MetaFieldRepository.class);
GlobalTrackingLogRepository logRepo = Beans.get(GlobalTrackingLogRepository.class);
GlobalTrackingConfigurationLineRepository configLineRepo = Beans.get(GlobalTrackingConfigurationLineRepository.class);
GlobalTrackingConfigurationLine configLine;
List<GlobalTrackingConfigurationLine> configLineList;
ScriptBindings bindings;
for (GlobalTrackingLog log : logList) {
configLineList = configLineRepo.all().filter("self.metaModel.name = ?", log.getMetaModelName()).fetch();
if (configLineList.isEmpty()) {
continue;
}
log.setMetaModel(modelRepo.findByName(log.getMetaModelName()));
List<GlobalTrackingLogLine> logLinesToSave = new ArrayList<>();
if ((CollectionUtils.isNotEmpty(log.getGlobalTrackingLogLineList()))) {
try {
bindings = new ScriptBindings(this.getContext(JPA.find((Class<Model>) Class.forName(log.getMetaModel().getFullName()), log.getRelatedId())));
} catch (Exception e) {
continue;
}
for (GlobalTrackingLogLine line : log.getGlobalTrackingLogLineList()) {
configLine = configLineList.stream().filter(l -> l.getMetaField().getName().equals(line.getMetaFieldName())).findFirst().orElse(null);
if (configLine == null || !this.canTrack(configLine, log.getTypeSelect()) || (!Strings.isNullOrEmpty(configLine.getTrackingCondition()) && !Boolean.TRUE.equals(new GroovyScriptHelper(bindings).eval(configLine.getTrackingCondition())))) {
continue;
}
line.setMetaField(fieldRepo.all().filter("self.metaModel.id = ? AND self.name = ?", log.getMetaModel().getId(), line.getMetaFieldName()).fetchOne());
logLinesToSave.add(line);
}
}
if (!logLinesToSave.isEmpty() || (GlobalTrackingLogRepository.TYPE_DELETE == log.getTypeSelect() && configLineList.stream().anyMatch(l -> Boolean.TRUE.equals(l.getTrackDeletion())))) {
log.getGlobalTrackingLogLineList().stream().forEach(l -> l.setGlobalTrackingLog(null));
logLinesToSave.stream().forEach(l -> l.setGlobalTrackingLog(log));
log.setUser(user);
logRepo.save(log);
}
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class ProductController method printProductCatalog.
@SuppressWarnings("unchecked")
public void printProductCatalog(ActionRequest request, ActionResponse response) throws AxelorException {
User user = Beans.get(UserService.class).getUser();
int currentYear = Beans.get(AppBaseService.class).getTodayDateTime().getYear();
String productIds = "";
List<Integer> lstSelectedProduct = (List<Integer>) request.getContext().get("_ids");
if (lstSelectedProduct != null) {
productIds = Joiner.on(",").join(lstSelectedProduct);
} else {
List<Long> displayedProductIdList = getDisplayedProductIdList(request);
if (ObjectUtils.notEmpty(displayedProductIdList)) {
productIds = Joiner.on(",").join(displayedProductIdList);
}
}
String name = I18n.get("Product Catalog");
String fileLink = ReportFactory.createReport(IReport.PRODUCT_CATALOG, name + "-${date}").addParam("UserId", user.getId()).addParam("CurrYear", Integer.toString(currentYear)).addParam("ProductIds", productIds).addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("Timezone", user.getActiveCompany() != null ? user.getActiveCompany().getTimezone() : null).generate().getFileLink();
logger.debug("Printing " + name);
response.setView(ActionView.define(name).add("html", fileLink).map());
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class UserController method validate.
public void validate(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
User user = request.getContext().asType(User.class);
Map<String, String> errors = ModelTool.getUniqueErrors(user, UNIQUE_MESSAGES);
if (!errors.isEmpty()) {
response.setErrors(errors);
return;
}
UserService userService = Beans.get(UserService.class);
user = userService.changeUserPassword(user, context);
response.setValue("transientPassword", user.getTransientPassword());
} catch (ValidationException e) {
response.setError(e.getMessage());
} 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 setUserPartner.
public void setUserPartner(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Partner partner = Beans.get(PartnerRepository.class).find(context.asType(Partner.class).getId());
if (context.get("created_from_user_id") != null && partner != null) {
UserRepository userRepo = Beans.get(UserRepository.class);
User user = userRepo.find(((Integer) context.get("created_from_user_id")).longValue());
Beans.get(UserService.class).setUserPartner(partner, user);
}
} catch (Exception e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
}
Aggregations