Uploaded image for project: 'Jira Service Management Data Center'
  1. Jira Service Management Data Center
  2. JSDSERVER-3907

Unable to create comments using JSD API as the Portal User reporter

      As a Portal user X, I'm unable to create a comment using the JSD API as per JSD-1505, only Agents seem able to do this. It seems only users with application access can use the API. Is it expected that Portal users (without groups, having only Customer role membership) don't have that application access and are therefore unable to use the API, bug?

      final ServiceDeskCommentCreateParameters publicComment =
          serviceDeskCommentService.newCreateBuilder()
                                   .author(user)
                                   .issue(customerRequest.getIssue())
                                   .publicComment(true)
                                   .body("This is a public comment")
                                   .build();
      serviceDeskCommentService.createServiceDeskComment(user, publicComment);
      

      The comment returned is null, there is an embedded error:

      You don't have permission to access this Service Desk.

      It feels like a bug because, as that same user via Portal I can add such comments.

      This is stopping me using the API to create 'guaranteed' Public vs Private comments for Customers / Agents.

          Form Name

            [JSDSERVER-3907] Unable to create comments using JSD API as the Portal User reporter

            Andy Brook added a comment -

            Unfortunately the comment service doesn't currently expose a way to create comments without firing an event (triggering a JSD email) so even though we've figure out how to use the API, we can't actually use it yet

            Andy Brook added a comment - Unfortunately the comment service doesn't currently expose a way to create comments without firing an event (triggering a JSD email) so even though we've figure out how to use the API, we can't actually use it yet

            awesome!

            Andy Brook added a comment -

            OK, mojo found, I needed the following in Javaland:

            	private Either<AnError, ServiceDeskComment> createComment(final Issue issue, final ApplicationUser user, String body, boolean isCommentPublic)
            	{
            		final ServiceDeskCommentCreateParameters publicComment =
            				fCommentService.newCreateBuilder()
                		                             .author(user)
                		                             .issue(issue)
                		                             .publicComment(isCommentPublic)
                		                             .body(body)
                		                             .build();
            			return fCommentService.createServiceDeskComment(user, publicComment);
            	}
            ...
            	final Either<AnError, ServiceDeskComment> result =
                        fCustomerContextService.inCustomerContext(new Callable<Either<AnError, ServiceDeskComment>>(){
            				@Override
            				public Either<AnError, ServiceDeskComment> call() throws Exception {
            					return createComment(issue, user, body, isCommentPublic);
            				}});
            

            Andy Brook added a comment - OK, mojo found, I needed the following in Javaland: private Either<AnError, ServiceDeskComment> createComment( final Issue issue, final ApplicationUser user, String body, boolean isCommentPublic) { final ServiceDeskCommentCreateParameters publicComment = fCommentService.newCreateBuilder() .author(user) .issue(issue) .publicComment(isCommentPublic) .body(body) .build(); return fCommentService.createServiceDeskComment(user, publicComment); } ... final Either<AnError, ServiceDeskComment> result = fCustomerContextService.inCustomerContext( new Callable<Either<AnError, ServiceDeskComment>>(){ @Override public Either<AnError, ServiceDeskComment> call() throws Exception { return createComment(issue, user, body, isCommentPublic); }});

            I'll close this now, as I reckon this will be fixed by documentation with JSD-3962. Don't hesitate to reopen if this doesn't work for you !

            Grégory Joseph (Inactive) added a comment - I'll close this now, as I reckon this will be fixed by documentation with JSD-3962 . Don't hesitate to reopen if this doesn't work for you !

            andy11, dough, code that needs to be executed with elevated permissions for customers (i.e customer accounts don't have those permissions in JIRA, but are branded as "customers"), you need to run it within "customer context". eg:

            import com.atlassian.servicedesk.api.customer.CustomerContextService
            [...]
                private final CustomerContextService customerContextService;
            [...]
                    final Either<AnError, ServiceDeskComment> result =
                            customerContextService.runInCustomerContext(() -> {
                                        return addSampleComment(loggedInUser, issueId, isCommentPublic);
                                    }
                            );
            

            ... where addSampleComment is pretty much the code you had above. You will notice that customers are able to add “public” comments but not “private” ones, whereas agents can do both through API as well.

            edit: we will make sure this gets documented.

            Grégory Joseph (Inactive) added a comment - - edited andy11 , dough , code that needs to be executed with elevated permissions for customers (i.e customer accounts don't have those permissions in JIRA, but are branded as "customers"), you need to run it within "customer context". eg: import com.atlassian.servicedesk.api.customer.CustomerContextService [...] private final CustomerContextService customerContextService; [...] final Either<AnError, ServiceDeskComment> result = customerContextService.runInCustomerContext(() -> { return addSampleComment(loggedInUser, issueId, isCommentPublic); } ); ... where addSampleComment is pretty much the code you had above. You will notice that customers are able to add “public” comments but not “private” ones, whereas agents can do both through API as well. edit: we will make sure this gets documented.

            Doug Haws added a comment -

            Spent alot of time integrating JEMH (For Custom Email Content) with JSD. Got my vote!

            Doug Haws added a comment - Spent alot of time integrating JEMH (For Custom Email Content) with JSD. Got my vote!

              Unassigned Unassigned
              cd3cc7134331 Andy Brook
              Affected customers:
              2 This affects my team
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: