return false;
}
private boolean validateOrganizationUserLimit(Set<String> emails, Organization organization, Errors errors) {
DomainConfiguration domainConfiguration = organization.getDomainConfiguration();
if (domainConfiguration == null) {
log.error(String.format("Null domainConfiguration for Organization with ID: %s", organization.getId()));
errors.reject("invitationValidator.error.generic");
return false;
}
long numEmailsWithoutInvitations = invitationService.countEmailsWithoutInvitationsForOrganization(emails, organization.getId(), true);
long currentOrgUsers = organizationService.countOrganizationUsers(organization.getId(), true);
long currentOrgPendingInvites = invitationService.countAllForOrganizationIncludingGroups(organization.getId());
long totalUsers = currentOrgUsers + currentOrgPendingInvites;
if (domainConfiguration.getUserLimit() < totalUsers + numEmailsWithoutInvitations) {
String domainTypeMessage = messageSource.getMessage(DomainType.ORGANIZATION.getMessageKey(), null, LocaleContextHolder.getLocale());
if (emails.size() > 1) {
errors.reject("invitationValidator.domain.userLimit.multipleInvites", new Object[]{domainTypeMessage, domainConfiguration.getUserLimit(), totalUsers - domainConfiguration.getUserLimit()}, "");
} else {
errors.reject("invitationValidator.domain.userLimit", new Object[]{domainTypeMessage}, "");
}
return false;
}