Skip to content

Commit

Permalink
Feature/ciac 9901/jira v3 add delete attachment command (#33315)
Browse files Browse the repository at this point in the history
* added delete attachment logic

* added delete attachment in yml file

* done

* docker image updated

* added test for delete_attachment_file_command

* Apply suggestions from code review

Co-authored-by: samuelFain <65926551+samuelFain@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: samuelFain <65926551+samuelFain@users.noreply.github.com>

* Update Packs/Jira/ReleaseNotes/3_1_11.md

Co-authored-by: JudithB <132264628+jbabazadeh@users.noreply.github.com>

* Update Packs/Jira/Integrations/JiraV3/JiraV3.yml

Co-authored-by: JudithB <132264628+jbabazadeh@users.noreply.github.com>

* Update Packs/Jira/Integrations/JiraV3/README.md

Co-authored-by: JudithB <132264628+jbabazadeh@users.noreply.github.com>

* added a delete file

* updated command description

* RN

---------

Co-authored-by: samuelFain <65926551+samuelFain@users.noreply.github.com>
Co-authored-by: JudithB <132264628+jbabazadeh@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 24, 2024
1 parent f17aaa6 commit 166eccb
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Packs/Jira/Integrations/JiraV3/JiraV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,21 @@ def get_attachment_metadata(self, attachment_id: str) -> Dict[str, Any]:
method='GET', url_suffix=f'rest/api/{self.api_version}/attachment/{attachment_id}'
)

def delete_attachment_file(self, attachment_id: str):
"""This method is in charge of deleting an attached file.
Args:
attachment_id (str): The id of the attachment file.
Returns:
requests.Response: The raw response of the endpoint.
"""
return self.http_request(
method='DELETE',
url_suffix=f'rest/api/{self.api_version}/attachment/{attachment_id}',
resp_type='response',
)

@abstractmethod
def get_attachment_content(self, attachment_id: str = '', attachment_content_url: str = '') -> str:
"""This method is in charge of returning the content for an attachment.
Expand Down Expand Up @@ -2076,6 +2091,21 @@ def delete_issue_command(client: JiraBaseClient, args: Dict[str, str]) -> Comman
return CommandResults(readable_output='Issue deleted successfully.')


def delete_attachment_file_command(client: JiraBaseClient, args: Dict[str, str]) -> CommandResults:
"""This command is in charge of deleting an attachment file.
Args:
client (JiraBaseClient): The jira client.
args (Dict[str, str]): The argument supplied by the user.
Returns:
CommandResults: CommandResults to return to XSOAR.
"""
attachment_id = args['attachment_id']
client.delete_attachment_file(attachment_id=attachment_id)
return CommandResults(readable_output=f'Attachment id {attachment_id} was deleted successfully.')


def update_issue_assignee_command(client: JiraBaseClient, args: Dict) -> CommandResults:
"""This command is in charge of assigning an assignee to an issue.
Expand Down Expand Up @@ -4055,6 +4085,7 @@ def main(): # pragma: no cover
'jira-epic-issue-list': epic_issues_list_command,
'jira-issue-link-type-get': get_issue_link_types_command,
'jira-issue-to-issue-link': link_issue_to_issue_command,
'jira-issue-delete-file': delete_attachment_file_command,
}
try:
client: JiraBaseClient
Expand Down
8 changes: 7 additions & 1 deletion Packs/Jira/Integrations/JiraV3/JiraV3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@ script:
name: issue_key
description: Delete a comment from an issue.
name: jira-issue-delete-comment
- arguments:
- description: The attachment ID. In order to see the attachment ID please use the jira-get-issue command.
name: attachment_id
required: true
description: Delete an attachment from an issue.
name: jira-issue-delete-file
- arguments:
- description: The issue ID (Issue ID or key is required).
name: issue_id
Expand Down Expand Up @@ -1462,7 +1468,7 @@ script:
- description: Updates the remote incident with local incident changes. This method is only used for debugging purposes and will not update the current incident.
name: update-remote-system
arguments: []
dockerimage: demisto/btfl-soup:1.0.1.87353
dockerimage: demisto/btfl-soup:1.0.1.89280
isfetch: true
ismappable: true
isremotesyncin: true
Expand Down
18 changes: 18 additions & 0 deletions Packs/Jira/Integrations/JiraV3/JiraV3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,24 @@ def test_delete_issue_command(self, mocker):
assert 'Issue deleted successfully' in command_result.to_context().get('HumanReadable')


class TestJiraDeleteAttachmentFileCommand:
def test_delete_attachment_file_command(self, mocker: MockerFixture):
"""
Given:
- A Jira client.
When
- Calling the delete attachment file command.
Then
- Validate that the correct readable output is outputted to the user.
"""
from JiraV3 import delete_attachment_file_command
attachment_id = "dummy_id"
client = jira_base_client_mock()
mocker.patch.object(client, 'delete_attachment_file', return_value=requests.Response())
command_result = delete_attachment_file_command(client=client, args={'attachment_id': attachment_id})
assert f'Attachment id {attachment_id} was deleted successfully' in command_result.to_context().get('HumanReadable')


class TestJiraGetTransitionsCommand:
def test_get_transitions_command(self, mocker):
"""
Expand Down
33 changes: 33 additions & 0 deletions Packs/Jira/Integrations/JiraV3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,39 @@ There is no context output for this command.
>|---|---|---|---|
>| https:<span>//</span>api.atlassian.com/ex/jira/1234/rest/api/3/attachment/16505 | dummy.pdf | 16505 | PROJECTKEY-31 |

### jira-issue-delete-file


***
Delete an attachment from an issue.

Scope: `write:jira-work`

#### Base Command

`jira-issue-delete-file
`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| attachment_id | The attachment ID. | Required |

#### Context Output

There is no context output for this command.

#### Command example

```!jira-issue-delete-file attachment_id=ATTACHMENT_ID```

#### Human Readable Output

>Attachment id ATTACHMENT_ID was deleted successfully.

### jira-list-transitions

***
Expand Down
7 changes: 7 additions & 0 deletions Packs/Jira/ReleaseNotes/3_1_12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### Atlassian Jira v3

- Updated the Docker image to: *demisto/btfl-soup:1.0.1.89280*.
- Added a new command ***jira-issue-delete-file*** to delete attachment file from an issue.
35 changes: 35 additions & 0 deletions Packs/Jira/TestPlaybooks/playbook_JiraV3_Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,41 @@ tasks:
quietmode: 0
isoversize: false
isautoswitchedtoquietmode: false
"68":
id: "68"
taskid: 80d1c831-18ef-487b-8de9-4b1d47576ff3
type: regular
task:
id: 80d1c831-18ef-487b-8de9-4b1d47576ff3
version: -1
name: Delete file from issue
description: Deletes an attachment from an issue.
script: '|||jira-issue-delete-file'
type: regular
iscommand: true
brand: ""
nexttasks:
'#none#':
- "32"
scriptarguments:
attachment_id:
simple: ${Ticket.Attachments.id}
separatecontext: false
continueonerrortype: ""
view: |-
{
"position": {
"x": 265,
"y": 4160
}
}
note: false
timertriggers: []
ignoreworker: false
skipunavailable: false
quietmode: 0
isoversize: false
isautoswitchedtoquietmode: false
view: |-
{
"linkLabelsPosition": {},
Expand Down
2 changes: 1 addition & 1 deletion Packs/Jira/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Atlassian Jira",
"description": "Use the Jira integration to manage issues and create Cortex XSOAR incidents from Jira projects.",
"support": "xsoar",
"currentVersion": "3.1.11",
"currentVersion": "3.1.12",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 166eccb

Please sign in to comment.