fix username validation

This commit is contained in:
_Bastler 2021-10-22 11:44:46 +02:00
parent a24f0650d1
commit 3c98987678
2 changed files with 12 additions and 6 deletions

View File

@ -98,7 +98,7 @@ public class ParteyUserTagManager {
*/ */
public List<ParteyUserTag> getAllForUsername(String username) { public List<ParteyUserTag> getAllForUsername(String username) {
return Lists.newArrayList( return Lists.newArrayList(
parteyUserTagRepository.findAll(qParteyUserTag.username.eq(username))); parteyUserTagRepository.findAll(qParteyUserTag.username.equalsIgnoreCase(username)));
} }
/** /**
@ -122,7 +122,7 @@ public class ParteyUserTagManager {
BooleanBuilder query = new BooleanBuilder(); BooleanBuilder query = new BooleanBuilder();
query.and(qParteyUserTag.username.eq(username)); query.and(qParteyUserTag.username.equalsIgnoreCase(username));
query.and(qParteyUserTag.expires.isNull().or(qParteyUserTag.expires.after(Instant.now()))); query.and(qParteyUserTag.expires.isNull().or(qParteyUserTag.expires.after(Instant.now())));
if (!upcoming) { if (!upcoming) {
@ -160,7 +160,7 @@ public class ParteyUserTagManager {
*/ */
public void deleteAllForTarget(String username) { public void deleteAllForTarget(String username) {
parteyUserTagRepository parteyUserTagRepository
.deleteAll(parteyUserTagRepository.findAll(qParteyUserTag.username.eq(username))); .deleteAll(parteyUserTagRepository.findAll(qParteyUserTag.username.equalsIgnoreCase(username)));
} }
} }

View File

@ -56,7 +56,8 @@ public class UserTagManagementController extends BaseController {
@RequestParam("desc") Optional<Boolean> descParameter) { @RequestParam("desc") Optional<Boolean> descParameter) {
Page<ParteyUserTag> page = parteyUserTagManager.getAll(pageParameter.orElse(0), Page<ParteyUserTag> page = parteyUserTagManager.getAll(pageParameter.orElse(0),
sizeParameter.orElse(10), sortParameter.orElse("username"), descParameter.orElse(false)); sizeParameter.orElse(10), sortParameter.orElse("username"),
descParameter.orElse(false));
return page; return page;
} }
@ -93,7 +94,7 @@ public class UserTagManagementController extends BaseController {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.CONFLICT);
} }
return parteyUserTagManager.getNonExpiredForUsername(username); return parteyUserTagManager.getNonExpiredForUsername(username);
@ -112,7 +113,7 @@ public class UserTagManagementController extends BaseController {
User user = userManager.getByUsername(username); User user = userManager.getByUsername(username);
if (user == null) { if (user == null) {
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); throw new EntityResponseStatusException(HttpStatus.CONFLICT);
} }
return parteyUserTagManager.getNonExpiredForUsername(username, true); return parteyUserTagManager.getNonExpiredForUsername(username, true);
@ -127,6 +128,11 @@ public class UserTagManagementController extends BaseController {
@PreAuthorize("hasRole('ROLE_ADMIN')") @PreAuthorize("hasRole('ROLE_ADMIN')")
@PostMapping @PostMapping
public ParteyUserTag createOrUpdateParteyUserTag(@RequestBody ParteyUserTag parteyUserTag) { public ParteyUserTag createOrUpdateParteyUserTag(@RequestBody ParteyUserTag parteyUserTag) {
User user = userManager.getByUsername(parteyUserTag.getUsername());
if (user == null) {
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
}
return parteyUserTagManager.save(parteyUserTag); return parteyUserTagManager.save(parteyUserTag);
} }