Skip to content

Commit 4787c2e

Browse files
committed
Update Signature API to use client for change_status
1 parent 647e940 commit 4787c2e

File tree

1 file changed

+6
-47
lines changed

1 file changed

+6
-47
lines changed

assemblyline_ui/api/v4/signature.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from assemblyline.common import forge
77
from assemblyline.common.isotime import now_as_iso
88
from assemblyline.odm.messages.changes import Operation
9-
from assemblyline.odm.models.signature import DEPLOYED_STATUSES, STALE_STATUSES, DRAFT_STATUSES
109
from assemblyline.odm.models.user import ROLES
1110
from assemblyline.remote.datatypes.hash import Hash
1211
from assemblyline.remote.datatypes.lock import Lock
@@ -219,59 +218,19 @@ def change_status(signature_id, status, **kwargs):
219218
{ "success" : true } #If saving the rule was a success or not
220219
"""
221220
user = kwargs['user']
222-
possible_statuses = DEPLOYED_STATUSES + DRAFT_STATUSES
223-
if status not in possible_statuses:
224-
return make_api_response("",
225-
f"You cannot apply the status {status} on yara rules.",
226-
403)
227-
228-
data = STORAGE.signature.get(signature_id, as_obj=False)
229-
if data:
230-
if not Classification.is_accessible(user['classification'],
231-
data.get('classification', Classification.UNRESTRICTED)):
232-
return make_api_response("", "You are not allowed change status on this signature", 403)
233-
234-
if data['status'] in STALE_STATUSES and status not in DRAFT_STATUSES:
235-
return make_api_response("",
236-
f"Only action available while signature in {data['status']} "
237-
f"status is to change signature to a DRAFT status. ({', '.join(DRAFT_STATUSES)})",
238-
403)
239-
240-
if data['status'] in DEPLOYED_STATUSES and status in DRAFT_STATUSES:
241-
return make_api_response("",
242-
f"You cannot change the status of signature {signature_id} from "
243-
f"{data['status']} to {status}.", 403)
244-
245-
today = now_as_iso()
246-
uname = user['uname']
247-
248-
if status not in ['DISABLED', 'INVALID', 'TESTING']:
249-
query = f"status:{status} AND signature_id:{data['signature_id']} AND NOT id:{signature_id}"
250-
others_operations = [
251-
('SET', 'last_modified', today),
252-
('SET', 'state_change_date', today),
253-
('SET', 'state_change_user', uname),
254-
('SET', 'status', 'DISABLED')
255-
]
256-
STORAGE.signature.update_by_query(query, others_operations)
257-
258-
operations = [
259-
('SET', 'last_modified', today),
260-
('SET', 'state_change_date', today),
261-
('SET', 'state_change_user', uname),
262-
('SET', 'status', status)
263-
]
264-
265-
success = STORAGE.signature.update(signature_id, operations)
221+
try:
222+
success, data = CLIENT.change_status(signature_id, status, user)
266223
signature_event_sender.send(data['type'], {
267224
'signature_id': signature_id,
268225
'signature_type': data['type'],
269226
'source': data['source'],
270227
'operation': Operation.Modified
271228
})
272229
return make_api_response({"success": success})
273-
else:
274-
return make_api_response("", f"Signature not found. ({signature_id})", 404)
230+
except (ValueError, PermissionError) as e:
231+
make_api_response("", str(e), 403)
232+
except FileNotFoundError as e:
233+
make_api_response("", str(e), 404)
275234

276235

277236
@signature_api.route("/<signature_id>/", methods=["DELETE"])

0 commit comments

Comments
 (0)