Skip to content

Commit f553242

Browse files
committed
When bulk-unassigning tag, emit sentry warning instead of returning error
1 parent 8f1e254 commit f553242

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

back/boxtribute_server/business_logic/warehouse/box/mutations.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ariadne import MutationType
44
from flask import g
55
from peewee import JOIN
6+
from sentry_sdk import capture_message as emit_sentry_message
67

78
from ....authz import authorize, authorized_bases_filter, handle_unauthorized
89
from ....enums import TaggableObjectType, TagType
@@ -201,9 +202,24 @@ def resolve_unassign_tag_from_boxes(*_, update_input):
201202
return ResourceDoesNotExist(name="Tag", id=tag_id)
202203
authorize(permission="tag_relation:assign", base_id=tag.base_id)
203204
if tag.deleted_on is not None:
204-
return DeletedTag(name=tag.name)
205+
# When a tag is deleted, it is also unassigned from any resource, hence in
206+
# theory unassigning a deleted tag should not happen. However we have to deal
207+
# with legacy data (there are 1.3k boxes assigned to deleted tags) and want to
208+
# be notified about it.
209+
emit_sentry_message(
210+
"User unassigned deleted tag from boxes",
211+
level="warning",
212+
extras={"tag_id": tag_id},
213+
)
205214
if tag.type == TagType.Beneficiary:
206-
return TagTypeMismatch(expected_type=TagType.Box)
215+
# When a tag type changes, it is also unassigned from any resource, hence in
216+
# theory boxes assigned with a Beneficiary tag should not occur. However we have
217+
# to deal with legacy data and want to be notified about it.
218+
emit_sentry_message(
219+
"User unassigned Beneficiary-type tag from boxes",
220+
level="warning",
221+
extras={"tag_id": tag_id},
222+
)
207223

208224
label_identifiers = set(update_input["label_identifiers"])
209225
boxes = (

back/boxtribute_server/graph_ql/definitions/protected/types.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ type DeletedTagError {
611611

612612
union MoveBoxesResult = BoxResult | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError | DeletedLocationError
613613
union AssignTagToBoxesResult = BoxResult | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError | TagTypeMismatchError | DeletedTagError
614-
union UnassignTagFromBoxesResult = BoxResult | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError | TagTypeMismatchError | DeletedTagError
614+
union UnassignTagFromBoxesResult = BoxResult | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError
615615
union DeleteBoxesResult = BoxResult | InsufficientPermissionError
616616
union CreateCustomProductResult = Product | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError | InvalidPriceError | EmptyNameError
617617
union EditCustomProductResult = Product | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError | InvalidPriceError | EmptyNameError | ProductTypeMismatchError

back/test/endpoint_tests/test_box.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,15 @@ def test_box_mutations(
423423
# Test case 8.2.24h
424424
mutation = f"""mutation {{ unassignTagFromBoxes( updateInput: {{
425425
labelIdentifiers: [{label_identifiers}], tagId: {beneficiary_tag_id} }} ) {{
426-
...on TagTypeMismatchError {{ expectedType }} }} }}"""
426+
...on BoxResult {{
427+
updatedBoxes {{ id }}
428+
invalidBoxLabelIdentifiers
429+
}} }} }}"""
427430
response = assert_successful_request(client, mutation)
428-
assert response == {"expectedType": TagType.Box.name}
431+
assert response == {
432+
"updatedBoxes": [],
433+
"invalidBoxLabelIdentifiers": raw_label_identifiers,
434+
}
429435

430436
# Test case 8.2.23i
431437
deleted_tag_id = str(tags[4]["id"])
@@ -439,9 +445,15 @@ def test_box_mutations(
439445
# Test case 8.2.24i
440446
mutation = f"""mutation {{ unassignTagFromBoxes( updateInput: {{
441447
labelIdentifiers: [{label_identifiers}], tagId: {deleted_tag_id} }} ) {{
442-
...on DeletedTagError {{ name }} }} }}"""
448+
...on BoxResult {{
449+
updatedBoxes {{ id }}
450+
invalidBoxLabelIdentifiers
451+
}} }} }}"""
443452
response = assert_successful_request(client, mutation)
444-
assert response == {"name": tag_name}
453+
assert response == {
454+
"updatedBoxes": [],
455+
"invalidBoxLabelIdentifiers": raw_label_identifiers,
456+
}
445457

446458
# Test case 8.2.25
447459
mutation = f"""mutation {{ deleteBoxes( labelIdentifiers: [{label_identifiers}] ) {{

front/src/types/generated/graphql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ export enum TransferAgreementType {
20102010
SendingTo = 'SendingTo'
20112011
}
20122012

2013-
export type UnassignTagFromBoxesResult = BoxResult | DeletedTagError | InsufficientPermissionError | ResourceDoesNotExistError | TagTypeMismatchError | UnauthorizedForBaseError;
2013+
export type UnassignTagFromBoxesResult = BoxResult | InsufficientPermissionError | ResourceDoesNotExistError | UnauthorizedForBaseError;
20142014

20152015
export type UnauthorizedForBaseError = {
20162016
__typename?: 'UnauthorizedForBaseError';

0 commit comments

Comments
 (0)