Total Complexity | 2 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | |||
3 | from attachments.views import delete_attachment |
||
4 | from modernrpc.core import rpc_method, REQUEST_KEY |
||
5 | |||
6 | from tcms.xmlrpc.decorators import permissions_required |
||
7 | |||
8 | __all__ = ( |
||
9 | 'remove_attachment', |
||
10 | ) |
||
11 | |||
12 | |||
13 | @permissions_required('attachments.delete_attachment') |
||
14 | @rpc_method(name='Attachment.remove_attachment') |
||
15 | def remove_attachment(attachment_id, **kwargs): |
||
16 | """ |
||
17 | .. function:: XML-RPC Attachment.remove_attachment(attachment_id) |
||
18 | |||
19 | Remove the given attachment file. |
||
20 | |||
21 | :param attachment_id: PK of attachment to remove |
||
22 | :type attachment_id: int |
||
23 | :return: None |
||
24 | :raises: Exception if attachment doesn't exist, |
||
25 | InternalError or removal fails |
||
26 | """ |
||
27 | request = kwargs.get(REQUEST_KEY) |
||
28 | response = delete_attachment(request, attachment_id) |
||
29 | if response.status_code == 404: |
||
30 | raise Exception("Removing attachment %d failed" % attachment_id) |
||
31 |