Search in sources :

Example 1 with UserRepository

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

the class MailServiceBaseImpl method resolve.

@Override
public Model resolve(String email) {
    final UserRepository users = Beans.get(UserRepository.class);
    final User user = users.all().filter("self.partner.emailAddress.address = ?1", email).fetchOne();
    if (user != null) {
        return user;
    }
    final PartnerRepository partners = Beans.get(PartnerRepository.class);
    final Partner partner = partners.all().filter("self.emailAddress.address = ?1", email).fetchOne();
    if (partner != null) {
        return partner;
    }
    return super.resolve(email);
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) Partner(com.axelor.apps.base.db.Partner)

Example 2 with UserRepository

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

the class UserController method comparePfpValidatorCompanySet.

@SuppressWarnings("unchecked")
public void comparePfpValidatorCompanySet(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());
    Set<Company> pfpValidatorUserCompanySet = pfpValidatorUser.getCompanySet();
    Set<Company> newPfpValidatorUserCompanySet = newPfpValidatorUser.getCompanySet();
    if (!pfpValidatorUserCompanySet.equals(newPfpValidatorUserCompanySet)) {
        response.setAttr("$pfpValidatorCompanySetLabel", "title", String.format(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_COMPANY_SET_NOT_EQUAL), newPfpValidatorUser.getName(), pfpValidatorUser.getName()));
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", false);
    } else {
        response.setAttr("$pfpValidatorCompanySetLabel", "hidden", true);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with UserRepository

use of com.axelor.auth.db.repo.UserRepository 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)

Example 4 with UserRepository

use of com.axelor.auth.db.repo.UserRepository 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()));
    }
}
Also used : UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) UserServiceAccountImpl(com.axelor.apps.account.service.UserServiceAccountImpl) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

User (com.axelor.auth.db.User)4 UserRepository (com.axelor.auth.db.repo.UserRepository)4 Partner (com.axelor.apps.base.db.Partner)2 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)2 LinkedHashMap (java.util.LinkedHashMap)2 UserServiceAccountImpl (com.axelor.apps.account.service.UserServiceAccountImpl)1 Company (com.axelor.apps.base.db.Company)1 UserService (com.axelor.apps.base.service.user.UserService)1 Context (com.axelor.rpc.Context)1 ValidationException (javax.validation.ValidationException)1