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

feat(Tag): Prevent creating a duplicate tag #268

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,11 @@ public class UserTagController {
protected ResponseEntity<Map<String, Object>> createTag(Authentication auth,
@RequestBody Map<String, Object> tag) {
User user = userService.retrieveUserByUsername(auth.getName());
UserTag userTag = userTagsService.createTag(user, (String) tag.get("text"));
String tagText = ((String) tag.get("text")).trim();
if (userTagsService.hasTag(user, tagText)) {
return ResponseEntityGenerator.createError("tagAlreadyExists");
}
UserTag userTag = userTagsService.createTag(user, tagText);
return ResponseEntityGenerator.createSuccess(userTag.toMap());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface UserTagsService {

Set<UserTag> getTags(User user, Project project);

Boolean hasTag(User user, String tag);

Boolean hasTag(User user, Project project, String tag);

void applyTag(Project project, UserTag tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public Set<UserTag> getTags(User user, Project project) {
.collect(Collectors.toSet());
}

@Override
public Boolean hasTag(User user, String tag) {
return getTags(user).stream()
.anyMatch(t -> t.getText().toLowerCase().equals(tag.toLowerCase()));
}

@Override
public Boolean hasTag(User user, Project project, String tag) {
MutableAclTargetObjectIdentity mutableObjectIdentity = getMutableObjectIdentity(project);
Expand Down
Loading