Search in sources :

Example 1 with BasicComment

use of com.cloudogu.scm.review.comment.service.BasicComment in project scm-review-plugin by scm-manager.

the class MentionMapper method parseMentionsUserIdsToDisplayNames.

public BasicComment parseMentionsUserIdsToDisplayNames(BasicComment rootComment) {
    BasicComment comment = rootComment.clone();
    for (String mentionUserId : rootComment.getMentionUserIds()) {
        Optional<DisplayUser> user = userDisplayManager.get(mentionUserId);
        user.ifPresent(displayUser -> comment.setComment(comment.getComment().replaceAll("\\[" + mentionUserId + "]", displayUser.getDisplayName())));
    }
    return comment;
}
Also used : DisplayUser(sonia.scm.user.DisplayUser) BasicComment(com.cloudogu.scm.review.comment.service.BasicComment)

Example 2 with BasicComment

use of com.cloudogu.scm.review.comment.service.BasicComment in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldAllowModificationsForAuthor.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldAllowModificationsForAuthor() {
    BasicComment comment = createComment("trillian");
    boolean modificationsAllowed = PermissionCheck.mayModifyComment(createRepository(), comment);
    assertTrue(modificationsAllowed);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 3 with BasicComment

use of com.cloudogu.scm.review.comment.service.BasicComment in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldDisallowModificationsForNonAuthorWithoutPermission.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldDisallowModificationsForNonAuthorWithoutPermission() {
    BasicComment comment = createComment("other");
    boolean modificationsAllowed = PermissionCheck.mayModifyComment(createRepository(), comment);
    assertFalse(modificationsAllowed);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 4 with BasicComment

use of com.cloudogu.scm.review.comment.service.BasicComment in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldFailOnModificationsForNonAuthorWithoutPermission.

@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "trillian", password = "secret")
public void shouldFailOnModificationsForNonAuthorWithoutPermission() {
    BasicComment comment = createComment("other");
    PermissionCheck.checkModifyComment(createRepository(), comment);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 5 with BasicComment

use of com.cloudogu.scm.review.comment.service.BasicComment in project scm-review-plugin by scm-manager.

the class RemoveReviewMarksOnChangedCommentsHook method checkForLocation.

private <C extends BasicComment, T extends BasicCommentEvent<C>> void checkForLocation(T event, Function<C, Location> locationExtractor) {
    if (event.getEventType() == HandlerEventType.DELETE) {
        return;
    }
    Location location = locationExtractor.apply(event.getItem());
    if (location == null) {
        return;
    }
    Collection<ReviewMark> reviewMarksToBeRemoved = event.getPullRequest().getReviewMarks().stream().filter(mark -> mark.getFile().equals(location.getFile())).collect(Collectors.toList());
    pullRequestService.removeReviewMarks(event.getRepository(), event.getPullRequest().getId(), reviewMarksToBeRemoved);
}
Also used : EagerSingleton(sonia.scm.EagerSingleton) Collection(java.util.Collection) BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Subscribe(com.github.legman.Subscribe) Extension(sonia.scm.plugin.Extension) ReplyEvent(com.cloudogu.scm.review.comment.service.ReplyEvent) Repository(sonia.scm.repository.Repository) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BasicCommentEvent(com.cloudogu.scm.review.comment.service.BasicCommentEvent) CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Inject(javax.inject.Inject) Objects(java.util.Objects) HandlerEventType(sonia.scm.HandlerEventType) Reply(com.cloudogu.scm.review.comment.service.Reply) Comment(com.cloudogu.scm.review.comment.service.Comment) CommentService(com.cloudogu.scm.review.comment.service.CommentService) Location(com.cloudogu.scm.review.comment.service.Location) Location(com.cloudogu.scm.review.comment.service.Location)

Aggregations

BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)9 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Test (org.junit.Test)6 Location (com.cloudogu.scm.review.comment.service.Location)2 BasicCommentEvent (com.cloudogu.scm.review.comment.service.BasicCommentEvent)1 Comment (com.cloudogu.scm.review.comment.service.Comment)1 CommentEvent (com.cloudogu.scm.review.comment.service.CommentEvent)1 CommentService (com.cloudogu.scm.review.comment.service.CommentService)1 Reply (com.cloudogu.scm.review.comment.service.Reply)1 ReplyEvent (com.cloudogu.scm.review.comment.service.ReplyEvent)1 Subscribe (com.github.legman.Subscribe)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Test (org.junit.jupiter.api.Test)1 EagerSingleton (sonia.scm.EagerSingleton)1 HandlerEventType (sonia.scm.HandlerEventType)1 Extension (sonia.scm.plugin.Extension)1