Skip to content

Commit

Permalink
Bugfix for implicit type conversion of ordinal position of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 20, 2024
1 parent 41a8dd6 commit 7c116a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions server/src/main/java/access/api/InvitationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public ResponseEntity<Invitation> getInvitation(@RequestParam("hash") String has
public ResponseEntity<List<Invitation>> all(@Parameter(hidden = true) User user) {
LOG.debug("/all invitations");
UserPermissions.assertAuthority(user, Authority.SUPER_USER);
return ResponseEntity.ok(invitationRepository.findByStatus(Status.OPEN));
return ResponseEntity.ok(invitationRepository.findByStatus(Status.OPEN.name()));
}


Expand Down Expand Up @@ -313,7 +313,7 @@ public ResponseEntity<List<Invitation>> byRole(@PathVariable("roleId") Long role

Role role = roleRepository.findById(roleId).orElseThrow(() -> new NotFoundException("Role not found"));
UserPermissions.assertRoleAccess(user, role, Authority.INVITER);
List<Invitation> invitations = invitationRepository.findByStatusAndRoles_role(Status.OPEN, role);
List<Invitation> invitations = invitationRepository.findByStatusAndRoles_role(Status.OPEN.name(), role);
return ResponseEntity.ok(invitations);
}

Expand All @@ -333,14 +333,14 @@ public ResponseEntity<Page<Map<String, Object>>> search(@Parameter(hidden = true
if (roleId == null) {
UserPermissions.assertSuperUser(user);
invitationsPage = StringUtils.hasText(query) ?
invitationRepository.searchByStatusPageWithKeyword(Status.OPEN, FullSearchQueryParser.parse(query), pageable) :
invitationRepository.searchByStatusPage(Status.OPEN, pageable);
invitationRepository.searchByStatusPageWithKeyword(Status.OPEN.name(), FullSearchQueryParser.parse(query), pageable) :
invitationRepository.searchByStatusPage(Status.OPEN.name(), pageable);
} else {
Role role = roleRepository.findById(roleId).orElseThrow(() -> new NotFoundException("Role not found"));
UserPermissions.assertRoleAccess(user, role, Authority.INVITER);
invitationsPage = StringUtils.hasText(query) ?
invitationRepository.searchByStatusAndRoleWithKeywordPage(Status.OPEN, role.getId(), FullSearchQueryParser.parse(query), pageable) :
invitationRepository.searchByStatusAndRolePage(Status.OPEN, role.getId(), pageable);
invitationRepository.searchByStatusAndRoleWithKeywordPage(Status.OPEN.name(), role.getId(), FullSearchQueryParser.parse(query), pageable) :
invitationRepository.searchByStatusAndRolePage(Status.OPEN.name(), role.getId(), pageable);
}
if (invitationsPage.getTotalElements() == 0L) {
return ResponseEntity.ok(invitationsPage);
Expand Down
13 changes: 6 additions & 7 deletions server/src/main/java/access/repository/InvitationRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import access.model.Invitation;
import access.model.Role;
import access.model.Status;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
Expand All @@ -25,9 +24,9 @@ public interface InvitationRepository extends JpaRepository<Invitation, Long>, Q

Optional<Invitation> findTopBySubInviteeOrderByCreatedAtDesc(String email);

List<Invitation> findByStatus(Status status);
List<Invitation> findByStatus(String status);

List<Invitation> findByStatusAndRoles_role(Status status, Role role);
List<Invitation> findByStatusAndRoles_role(String status, Role role);

@Query(value = """
SELECT i.id, i.email, i.intended_authority,i.created_at, i.expiry_date,
Expand All @@ -38,7 +37,7 @@ public interface InvitationRepository extends JpaRepository<Invitation, Long>, Q
countQuery = "SELECT count(*) FROM invitations WHERE status = ?1",
queryRewriter = InvitationRepository.class,
nativeQuery = true)
Page<Map<String, Object>> searchByStatusPage(Status status, Pageable pageable);
Page<Map<String, Object>> searchByStatusPage(String status, Pageable pageable);

@Query(value = """
SELECT i.id, i.email, i.intended_authority,i.created_at, i.expiry_date,
Expand All @@ -56,7 +55,7 @@ OR MATCH (u.given_name, u.family_name, u.email) against (?2 IN BOOLEAN MODE))
""",
queryRewriter = InvitationRepository.class,
nativeQuery = true)
Page<Map<String, Object>> searchByStatusPageWithKeyword(Status status, String keyWord, Pageable pageable);
Page<Map<String, Object>> searchByStatusPageWithKeyword(String status, String keyWord, Pageable pageable);

@Query(value = """
SELECT i.id, i.email, i.intended_authority,i.created_at, i.expiry_date,
Expand All @@ -73,7 +72,7 @@ SELECT count(*) FROM invitations i
""",
queryRewriter = InvitationRepository.class,
nativeQuery = true)
Page<Map<String, Object>> searchByStatusAndRolePage(Status status, Long roleId, Pageable pageable);
Page<Map<String, Object>> searchByStatusAndRolePage(String status, Long roleId, Pageable pageable);

@Query(value = """
SELECT i.id, i.email, i.intended_authority,i.created_at, i.expiry_date,
Expand All @@ -95,7 +94,7 @@ OR MATCH (u.given_name, u.family_name, u.email) against (?3 IN BOOLEAN MODE))
""",
queryRewriter = InvitationRepository.class,
nativeQuery = true)
Page<Map<String, Object>> searchByStatusAndRoleWithKeywordPage(Status status, Long roleId, String keyWord, Pageable pageable);
Page<Map<String, Object>> searchByStatusAndRoleWithKeywordPage(String status, Long roleId, String keyWord, Pageable pageable);

@Query(value = """
SELECT ir.invitation_id as id, r.name, r.id as role_id, a.manage_id
Expand Down

0 comments on commit 7c116a3

Please sign in to comment.