@PublicApi public interface

AttachmentService

com.atlassian.jira.bc.issue.attachment.AttachmentService
Known Indirect Subclasses

@PublicApi

This interface is designed for plugins to consume (call its methods).

Clients of @PublicApi can expect that programs compiled against a given version will remain binary compatible with later versions of the @PublicApi as per each product's API policy as long as the client does not implement/extend @PublicApi interfaces or classes (refer to each product's API policy for the exact guarantee---usually binary compatibility is guaranteed at least across minor versions).

Note: since @PublicApi interfaces and classes are not designed to be implemented or extended by clients, we may perform certain types of binary-incompatible changes to these classes and interfaces, but these will not affect well-behaved clients that do not extend/implement these types (in general, only classes and interfaces annotated with @PublicSpi are safe to extend/implement).

Class Overview

AttachmentService contains methods for managing issue attachments in JIRA.

Summary

Public Methods
boolean canAttachScreenshots(JiraServiceContext jiraServiceContext, Issue issue)
Determines whether the user:
  • has the required permission (CREATE_ATTACHMENT) to create an attachment
  • has the screenshot enabled
  • is using a screenshot applet compatible OS (Windows or OSX)
  • the issue is in an editable workflow state
boolean canCreateAttachments(JiraServiceContext jiraServiceContext, Issue issue)
Determines whether attachments are enabled in JIRA and that the user has the required permission (CREATE_ATTACHMENT) to create an attachment for this issue.
boolean canCreateAttachments(JiraServiceContext jiraServiceContext, Project project)
Determines whether attachments are enabled in JIRA and that the user has the required permission (CREATE_ATTACHMENT) to create an attachment for this project.
boolean canCreateTemporaryAttachments(JiraServiceContext jiraServiceContext, Issue issue)
Determines whether:
  • the user has the required permission (CREATE_ATTACHMENT) to create an attachment
  • attachments are enabled
This method does *not* check if the issue is in an editable workflow step, since temporary attachments may be created when reopening an issue *before* the issue is actually reopened!
boolean canDeleteAttachment(JiraServiceContext jiraServiceContext, Long attachmentId)
Retrieves the attachment specified by the attachment id and determines if the user can delete it.
boolean canManageAttachments(JiraServiceContext jiraServiceContext, Issue issue)
Checks whether the user has permission to manage the attachments of the specified issue.
void delete(JiraServiceContext jiraServiceContext, Long attachmentId)
Deletes the specified attachment and updates the issue change history and 'updated' date.
Attachment getAttachment(JiraServiceContext jiraServiceContext, Long attachmentId)
Retrieves the specified issue.

Public Methods

public boolean canAttachScreenshots (JiraServiceContext jiraServiceContext, Issue issue)

Determines whether the user:

  • has the required permission (CREATE_ATTACHMENT) to create an attachment
  • has the screenshot enabled
  • is using a screenshot applet compatible OS (Windows or OSX)
  • the issue is in an editable workflow state

Parameters
jiraServiceContext containing the user who wishes to attach a screenshot and the errorCollection that will contain any errors in calling the method
issue that will have the screenshot attached to it
Returns
  • true if the user may attach a screenshot, false otherwise

public boolean canCreateAttachments (JiraServiceContext jiraServiceContext, Issue issue)

Determines whether attachments are enabled in JIRA and that the user has the required permission (CREATE_ATTACHMENT) to create an attachment for this issue. This method also checks that the provided issue is in an editable workflow state.

Parameters
jiraServiceContext containing the user who wishes to create an attachment and the errorCollection that will contain any errors in calling the method
issue that will have an attachment attached to it
Returns
  • true if the user has permission to attach an attachment to the issue and the issue is in an editable workflow state, false otherwise

public boolean canCreateAttachments (JiraServiceContext jiraServiceContext, Project project)

Determines whether attachments are enabled in JIRA and that the user has the required permission (CREATE_ATTACHMENT) to create an attachment for this project.

Parameters
jiraServiceContext containing the user who wishes to create an attachment and the errorCollection that will contain any errors in calling the method
project where the attachment will be created in
Returns
  • true if the user has permission to attach an attachment in the project provided, false otherwise

public boolean canCreateTemporaryAttachments (JiraServiceContext jiraServiceContext, Issue issue)

Determines whether:

  • the user has the required permission (CREATE_ATTACHMENT) to create an attachment
  • attachments are enabled
This method does *not* check if the issue is in an editable workflow step, since temporary attachments may be created when reopening an issue *before* the issue is actually reopened!

Parameters
jiraServiceContext containing the user who wishes to attach a file and the errorCollection that will contain any errors in calling the method
issue that will have the file attached to it
Returns
  • true if the user may attach a file, false otherwise

public boolean canDeleteAttachment (JiraServiceContext jiraServiceContext, Long attachmentId)

Retrieves the attachment specified by the attachment id and determines if the user can delete it. The user can delete it if:

  • They have the DELETE_ALL permission OR they have the DELETE_OWN permission and they are the author of the specified attachment; and
  • The specified attachment exists

Parameters
jiraServiceContext containing the user who the permission checks will be run against (can be null, indicating an anonymous user) and the errorCollection that will contain any errors in calling the method
attachmentId specifies the attachment to be deleted
Returns
  • true if the user has permission to delete the attachment; false otherwise

public boolean canManageAttachments (JiraServiceContext jiraServiceContext, Issue issue)

Checks whether the user has permission to manage the attachments of the specified issue. This is true if

  • Attachments are enabled in JIRA
  • The Attachment path is set
  • The user is allowed to create OR delete attachments associated with the specified issue

Parameters
jiraServiceContext containing the user who the permission checks will be run against (can be null, indicating an anonymous user) and the errorCollection that will contain any errors in calling the method
issue who's attachments will be checked against the specified user's delete permissions (if the issue is null an error will be placed into the supplied ErrorCollection and false will be returned)
Returns
  • true if the user has permission to manage attachments

public void delete (JiraServiceContext jiraServiceContext, Long attachmentId)

Deletes the specified attachment and updates the issue change history and 'updated' date.

This method expects that canDeleteAttachment(com.atlassian.jira.bc.JiraServiceContext, Long) has been successfully called.

Parameters
jiraServiceContext containing the user who is attempting to delete the attachment and the errorCollection that will contain any errors in calling the method
attachmentId of the target attachment, must not be null and must identify a valid attachment

public Attachment getAttachment (JiraServiceContext jiraServiceContext, Long attachmentId)

Retrieves the specified issue. Does not perform permission checks.

Parameters
jiraServiceContext containing the user who is attempting to retrieve the attachment and the errorCollection that will contain any errors in calling the method
attachmentId of the target attachment, must not be null and must identify a valid attachment
Returns
  • target attachment if no errors occur, null otherwise
Throws
AttachmentNotFoundException if the attachment does not exist