Skip to content

Commit

Permalink
Merge pull request #268 from WISE-Community/prevent-creating-duplicat…
Browse files Browse the repository at this point in the history
…e-tags

feat(Tag): Prevent creating a duplicate tag
  • Loading branch information
geoffreykwan authored Apr 9, 2024
2 parents 485eadc + 25d1953 commit 9b5fa4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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

0 comments on commit 9b5fa4b

Please sign in to comment.