Search in sources :

Example 6 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class EventController method changeCreator.

public void changeCreator(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    response.setValue("organizer", Beans.get(CalendarService.class).findOrCreateUser(user));
}
Also used : User(com.axelor.auth.db.User)

Example 7 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class EventController method setCalendarDomain.

public void setCalendarDomain(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    List<Long> calendarIdlist = Beans.get(CalendarService.class).showSharedCalendars(user);
    if (calendarIdlist.isEmpty()) {
        response.setAttr("calendar", "domain", "self.id is null");
    } else {
        response.setAttr("calendar", "domain", "self.id in (" + Joiner.on(",").join(calendarIdlist) + ")");
    }
}
Also used : User(com.axelor.auth.db.User) CalendarService(com.axelor.apps.crm.service.CalendarService)

Example 8 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class TimerTicketServiceImpl method find.

@Override
public Timer find(Model model) throws AxelorException {
    User user = userService.getUser();
    Ticket ticket = (Ticket) model;
    List<Timer> timerList = ticket.getTimerList();
    if (timerList != null && !timerList.isEmpty()) {
        return timerList.stream().filter(t -> t.getAssignedToUser() == user).findFirst().orElse(null);
    }
    return null;
}
Also used : Ticket(com.axelor.apps.helpdesk.db.Ticket) User(com.axelor.auth.db.User) Timer(com.axelor.apps.base.db.Timer)

Example 9 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class EventManagementRepository method save.

@Override
public Event save(Event entity) {
    if (entity.getTypeSelect() == EventRepository.TYPE_MEETING) {
        super.save(entity);
        Beans.get(EventService.class).manageFollowers(entity);
    }
    User creator = entity.getCreatedBy();
    if (creator == null) {
        creator = AuthUtils.getUser();
    }
    if (entity.getOrganizer() == null && creator != null) {
        if (creator.getPartner() != null && creator.getPartner().getEmailAddress() != null) {
            String email = creator.getPartner().getEmailAddress().getAddress();
            if (!Strings.isNullOrEmpty(email)) {
                ICalendarUser organizer = Beans.get(ICalendarUserRepository.class).all().filter("self.email = ?1 AND self.user.id = ?2", email, creator.getId()).fetchOne();
                if (organizer == null) {
                    organizer = new ICalendarUser();
                    organizer.setEmail(email);
                    organizer.setName(creator.getFullName());
                    organizer.setUser(creator);
                }
                entity.setOrganizer(organizer);
            }
        }
    }
    entity.setSubjectTeam(entity.getSubject());
    if (entity.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
        entity.setSubjectTeam(I18n.get("Available"));
        if (entity.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
            entity.setSubjectTeam(I18n.get("Busy"));
        }
    }
    return super.save(entity);
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) User(com.axelor.auth.db.User) EventService(com.axelor.apps.crm.service.EventService) ICalendarUserRepository(com.axelor.apps.base.db.repo.ICalendarUserRepository)

Example 10 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class MailServiceBaseImpl method findEmails.

@Override
public List<InternetAddress> findEmails(String matching, List<String> selected, int maxResult) {
    JpaSecurity jpaSecurity = Beans.get(JpaSecurity.class);
    // Users
    Filter userPermissionFilter = jpaSecurity.getFilter(JpaSecurity.CAN_READ, User.class);
    List<String> selectedWithoutNull = new ArrayList<String>(selected);
    for (int i = 0; i < selected.size(); i++) {
        if (Strings.isNullOrEmpty(selected.get(i)))
            selectedWithoutNull.remove(i);
    }
    final List<String> where = new ArrayList<>();
    final Map<String, Object> params = new HashMap<>();
    if (userPermissionFilter != null) {
        where.add(userPermissionFilter.getQuery());
    }
    where.add("((self.partner is not null AND self.partner.emailAddress is not null) OR (self.email is not null))");
    if (!isBlank(matching)) {
        where.add("(LOWER(self.partner.emailAddress.address) like LOWER(:email) OR LOWER(self.partner.fullName) like LOWER(:email) OR LOWER(self.email) like LOWER(:email) OR LOWER(self.name) like LOWER(:email))");
        params.put("email", "%" + matching + "%");
    }
    if (selectedWithoutNull != null && !selectedWithoutNull.isEmpty()) {
        where.add("self.partner.emailAddress.address not in (:selected)");
        params.put("selected", selectedWithoutNull);
    }
    final String filter = Joiner.on(" AND ").join(where);
    final Query<User> query = Query.of(User.class);
    if (!isBlank(filter)) {
        if (userPermissionFilter != null) {
            query.filter(filter, userPermissionFilter.getParams());
        } else {
            query.filter(filter);
        }
        query.bind(params);
    }
    final List<InternetAddress> addresses = new ArrayList<>();
    if (jpaSecurity.isPermitted(JpaSecurity.CAN_READ, User.class)) {
        for (User user : query.fetch(maxResult)) {
            try {
                if (user.getPartner() != null && user.getPartner().getEmailAddress() != null && !Strings.isNullOrEmpty(user.getPartner().getEmailAddress().getAddress())) {
                    final InternetAddress item = new InternetAddress(user.getPartner().getEmailAddress().getAddress(), user.getFullName());
                    addresses.add(item);
                    selectedWithoutNull.add(user.getPartner().getEmailAddress().getAddress());
                } else if (!Strings.isNullOrEmpty(user.getEmail())) {
                    final InternetAddress item = new InternetAddress(user.getEmail(), user.getFullName());
                    addresses.add(item);
                    selectedWithoutNull.add(user.getEmail());
                }
            } catch (UnsupportedEncodingException e) {
                TraceBackService.trace(e);
            }
        }
    }
    // Partners
    Filter partnerPermissionFilter = jpaSecurity.getFilter(JpaSecurity.CAN_READ, Partner.class);
    final List<String> where2 = new ArrayList<>();
    final Map<String, Object> params2 = new HashMap<>();
    if (partnerPermissionFilter != null) {
        where2.add(partnerPermissionFilter.getQuery());
    }
    where2.add("self.emailAddress is not null");
    if (!isBlank(matching)) {
        where2.add("(LOWER(self.emailAddress.address) like LOWER(:email) OR LOWER(self.fullName) like LOWER(:email))");
        params2.put("email", "%" + matching + "%");
    }
    if (selectedWithoutNull != null && !selectedWithoutNull.isEmpty()) {
        where2.add("self.emailAddress.address not in (:selected)");
        params2.put("selected", selectedWithoutNull);
    }
    final String filter2 = Joiner.on(" AND ").join(where2);
    final Query<Partner> query2 = Query.of(Partner.class);
    if (!isBlank(filter2)) {
        if (partnerPermissionFilter != null) {
            query2.filter(filter2, partnerPermissionFilter.getParams());
        } else {
            query2.filter(filter2);
        }
        query2.bind(params2);
    }
    if (jpaSecurity.isPermitted(JpaSecurity.CAN_READ, Partner.class)) {
        for (Partner partner : query2.fetch(maxResult)) {
            try {
                if (partner.getEmailAddress() != null && !Strings.isNullOrEmpty(partner.getEmailAddress().getAddress())) {
                    final InternetAddress item = new InternetAddress(partner.getEmailAddress().getAddress(), partner.getFullName());
                    addresses.add(item);
                }
            } catch (UnsupportedEncodingException e) {
                TraceBackService.trace(e);
            }
        }
    }
    return addresses;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) JpaSecurity(com.axelor.db.JpaSecurity) User(com.axelor.auth.db.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Filter(com.axelor.rpc.filter.Filter) Partner(com.axelor.apps.base.db.Partner)

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