Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2590 - Deleted users makes it impossible to download CSV cont… #2593

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
@NamedQueries({
@NamedQuery(name = "AuthenticatedUser.findAll",
query = "select au from AuthenticatedUser au"),
query = "select au from AuthenticatedUser au where au.userIdentifier not like 'ERASED%'"),
@NamedQuery(name = "AuthenticatedUser.findSuperUsers",
query = "SELECT au FROM AuthenticatedUser au WHERE au.superuser = TRUE"),
@NamedQuery(name = "AuthenticatedUser.findByIdentifier",
Expand Down Expand Up @@ -221,6 +221,7 @@ public Timestamp getLastApiUseTime() {
public String getIdentifier() {
return IDENTIFIER_PREFIX + userIdentifier;
}


@Override
public AuthenticatedUserDisplayInfo getDisplayInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;

@Stateless
Expand Down Expand Up @@ -63,16 +62,22 @@ public Long countSearchedAuthenticatedUsers(String searchTerm) {

// -------------------- PRIVATE --------------------

private Predicate[] getSearchPredicates(String searchTerm, Root<AuthenticatedUser> root, CriteriaBuilder criteriaBuilder) {
private Predicate getSearchPredicates(String searchTerm, Root<AuthenticatedUser> root, CriteriaBuilder criteriaBuilder) {

final Predicate notErased = criteriaBuilder.notLike(criteriaBuilder.upper(root.get("userIdentifier")), "ERASED%");
if (searchTerm.isEmpty()) {
return new Predicate[]{};
return notErased;
} else {
searchTerm = searchTerm.toLowerCase().concat("%");
return criteriaBuilder.and(
criteriaBuilder.or(
criteriaBuilder.like(criteriaBuilder.lower(root.get("userIdentifier")), searchTerm),
criteriaBuilder.like(criteriaBuilder.lower(root.get("affiliation")), searchTerm),
criteriaBuilder.like(criteriaBuilder.lower(root.get("lastName")), searchTerm),
criteriaBuilder.like(criteriaBuilder.lower(root.get("email")), searchTerm)
),
notErased);
}
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(root.get("userIdentifier")), searchTerm.toLowerCase() + "%"));
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(root.get("affiliation")), searchTerm.toLowerCase() + "%"));
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(root.get("lastName")), searchTerm.toLowerCase() + "%"));
predicates.add(criteriaBuilder.like(criteriaBuilder.lower(root.get("email")), searchTerm.toLowerCase() + "%"));
return new Predicate[]{criteriaBuilder.or(predicates.toArray(new Predicate[]{}))};
}

// -------------------- INNER CLASSES --------------------
Expand Down