More sanity check changes

This commit is contained in:
Nassim Jahnke 2023-03-22 22:55:53 +01:00
parent 9d4a291376
commit 2cf3ff71a6
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 13 additions and 8 deletions

View File

@ -132,7 +132,9 @@ public class HangarUserController extends HangarComponent {
this.actionLogger.user(LogAction.USER_TAGLINE_CHANGED.create(UserContext.of(userTable.getId()), userTable.getTagline(), oldTagline));
}
// @el(userName: String)
@Unlocked
@CurrentUser("#userName")
@ResponseStatus(HttpStatus.OK)
@PermissionRequired(NamedPermission.EDIT_OWN_USER_SETTINGS)
@PostMapping("/users/{userName}/settings/resetTagline")
@ -150,7 +152,9 @@ public class HangarUserController extends HangarComponent {
this.actionLogger.user(LogAction.USER_TAGLINE_CHANGED.create(UserContext.of(userTable.getId()), "", oldTagline));
}
// @el(userName: String)
@Unlocked
@CurrentUser("#userName")
@ResponseStatus(HttpStatus.OK)
@RateLimit(overdraft = 5, refillTokens = 2)
@PermissionRequired(NamedPermission.EDIT_OWN_USER_SETTINGS)

View File

@ -120,11 +120,7 @@ public class ProjectController extends HangarComponent {
@PermissionRequired(type = PermissionType.PROJECT, perms = NamedPermission.EDIT_SUBJECT_SETTINGS, args = "{#author, #slug}")
@PostMapping(path = "/project/{author}/{slug}/sponsors", consumes = MediaType.APPLICATION_JSON_VALUE)
public void saveProjectSettings(@PathVariable final String author, @PathVariable final String slug, @RequestBody final StringContent content) {
final String trimmedContent = content.getContent() != null ? content.getContent().trim() : "";
if (trimmedContent.length() > this.config.projects.maxSponsorsLen()) {
throw new HangarApiException("page.new.error.maxLength");
}
this.projectService.saveSponsors(author, slug, trimmedContent);
this.projectService.saveSponsors(author, slug, content.getContent());
}
@Unlocked

View File

@ -102,10 +102,10 @@ public class ProjectFactory extends HangarComponent {
public String renameProject(final String author, final String slug, final String newName, final boolean skipNameCheck) {
final String compactNewName = StringUtils.compact(newName);
final ProjectTable projectTable = this.projectService.getProjectTable(author, slug);
final String oldName = projectTable.getName();
final String oldSlug = projectTable.getSlug();
this.checkProjectAvailability(projectTable.getOwnerId(), compactNewName, skipNameCheck);
final String oldName = projectTable.getName();
final String oldSlug = projectTable.getSlug();
final String newSlug = StringUtils.slugify(compactNewName);
projectTable.setName(compactNewName);
projectTable.setSlug(newSlug);

View File

@ -213,7 +213,12 @@ public class ProjectService extends HangarComponent {
}
@Transactional
public void saveSponsors(final String author, final String slug, final String content) {
public void saveSponsors(final String author, final String slug, final @Nullable String content) {
final String trimmedContent = content != null ? content.trim() : "";
if (trimmedContent.length() > this.config.projects.maxSponsorsLen()) {
throw new HangarApiException("page.new.error.maxLength");
}
final ProjectTable projectTable = this.getProjectTable(author, slug);
projectTable.setSponsors(content);
this.projectsDAO.update(projectTable);