Search in sources :

Example 71 with User

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;
}
Also used : User(com.axelor.auth.db.User) JpaSecurity(com.axelor.db.JpaSecurity) QuickMenuItem(com.axelor.ui.QuickMenuItem) Collection(java.util.Collection) QuickMenu(com.axelor.ui.QuickMenu) AccessContactQuickMenu(com.axelor.contact.service.AccessContactQuickMenu)

Example 72 with User

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);
        }
    }
}
Also used : GlobalTrackingConfigurationLine(com.axelor.apps.base.db.GlobalTrackingConfigurationLine) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) Arrays(java.util.Arrays) LocalDateTime(java.time.LocalDateTime) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) HashMap(java.util.HashMap) ScriptBindings(com.axelor.script.ScriptBindings) PersistentSet(org.hibernate.collection.internal.PersistentSet) ArrayList(java.util.ArrayList) Transaction(org.hibernate.Transaction) Strings(com.google.common.base.Strings) Introspector(java.beans.Introspector) GlobalTrackingLog(com.axelor.apps.base.db.GlobalTrackingLog) CollectionUtils(org.apache.commons.collections.CollectionUtils) AuditInterceptor(com.axelor.auth.AuditInterceptor) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) GlobalTrackingLogRepository(com.axelor.apps.base.db.repo.GlobalTrackingLogRepository) Method(java.lang.reflect.Method) JPA(com.axelor.db.JPA) PersistentBag(org.hibernate.collection.internal.PersistentBag) Model(com.axelor.db.Model) Collection(java.util.Collection) GlobalTrackingLogLine(com.axelor.apps.base.db.GlobalTrackingLogLine) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GlobalTrackingConfigurationLineRepository(com.axelor.apps.base.db.repo.GlobalTrackingConfigurationLineRepository) List(java.util.List) Beans(com.axelor.inject.Beans) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository) PropertyDescriptor(java.beans.PropertyDescriptor) AbstractPersistentCollection(org.hibernate.collection.internal.AbstractPersistentCollection) AuditableModel(com.axelor.auth.db.AuditableModel) AuthUtils(com.axelor.auth.AuthUtils) User(com.axelor.auth.db.User) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) GlobalTrackingLog(com.axelor.apps.base.db.GlobalTrackingLog) GlobalTrackingConfigurationLineRepository(com.axelor.apps.base.db.repo.GlobalTrackingConfigurationLineRepository) ArrayList(java.util.ArrayList) GlobalTrackingLogLine(com.axelor.apps.base.db.GlobalTrackingLogLine) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GlobalTrackingLogRepository(com.axelor.apps.base.db.repo.GlobalTrackingLogRepository) GlobalTrackingConfigurationLine(com.axelor.apps.base.db.GlobalTrackingConfigurationLine) ScriptBindings(com.axelor.script.ScriptBindings)

Example 73 with User

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());
}
Also used : User(com.axelor.auth.db.User) UserService(com.axelor.apps.base.service.user.UserService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 74 with User

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);
    }
}
Also used : Context(com.axelor.rpc.Context) User(com.axelor.auth.db.User) ValidationException(javax.validation.ValidationException) UserService(com.axelor.apps.base.service.user.UserService) ValidationException(javax.validation.ValidationException)

Example 75 with User

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);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) UserService(com.axelor.apps.base.service.user.UserService) Partner(com.axelor.apps.base.db.Partner) ValidationException(javax.validation.ValidationException)

Aggregations

User (com.axelor.auth.db.User)157 AxelorException (com.axelor.exception.AxelorException)35 Employee (com.axelor.apps.hr.db.Employee)28 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)25 Transactional (com.google.inject.persist.Transactional)24 LocalDate (java.time.LocalDate)23 Filter (com.axelor.rpc.filter.Filter)22 BigDecimal (java.math.BigDecimal)22 ClientViewService (com.axelor.apps.portal.service.ClientViewService)20 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)17 List (java.util.List)17 Map (java.util.Map)16 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)12 LocalDateTime (java.time.LocalDateTime)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 Beans (com.axelor.inject.Beans)11 Inject (com.google.inject.Inject)11 Product (com.axelor.apps.base.db.Product)9