Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-5106] Cannot remove assignments #1450

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/actions/assignments/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ const removeAssignment = (assignment) => (
notify.error(
getErrorMessage(error, 'Failed to remove the Assignment')
);

dispatch(self.unlockAssignment(assignment));
return Promise.reject(error);
})
)
Expand Down
17 changes: 15 additions & 2 deletions server/features/assignments_delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ Feature: Assignments Delete

@auth
@notification
Scenario: Cannot delete an Assignment without Assignment and Planning locks by same user
Scenario: Cannot delete an Assignment if assignment is not locked
When we delete "/assignments/#assignmentId#"
Then we get error 403
When we post to "/assignments/#assignmentId#/lock"
"""
{"lock_action": "remove_assignment"}
"""
Then we get OK response
When we delete "/assignments/#assignmentId#"
Then we get OK response
When we get "/assignments/#assignmentId#"
Then we get error 404

@auth
@notification
Scenario: Can delete an Assignment if planning item is locked by the same user and session
When we delete "/assignments/#assignmentId#"
Then we get error 403
When we post to "/assignments/#assignmentId#/lock"
"""
{"lock_action": "remove_assignment"}
"""
Then we get OK response
When we post to "/planning/#planning._id#/lock"
"""
{"lock_action": "remove_assignment"}
Expand Down Expand Up @@ -105,7 +118,7 @@ Feature: Assignments Delete
}]
"""

@auth @today
@auth
Scenario: Deleting an Assignment removes the assignment id from the Archive item
When we post to "/archive"
"""
Expand Down
18 changes: 4 additions & 14 deletions server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,21 +938,11 @@ def on_delete(self, doc):
# Also make sure the Planning item is locked by this user and session
planning_service = get_resource_service('planning')
planning_item = planning_service.find_one(req=None, _id=doc.get('planning_item'))
planning_item_state = (planning_item or {}).get('state')

if planning_item_state != WORKFLOW_STATE.SPIKED:
if not self.is_associated_planning_or_event_locked(planning_item):
raise SuperdeskApiError.forbiddenError(
message='Lock is not obtained on the associated Planning item or Event'
)

# Make sure the Assignment is locked by this user and session
assignment_locked = is_locked_in_this_session(doc)
if planning_item_state in [WORKFLOW_STATE.KILLED, WORKFLOW_STATE.SPIKED] and\
(not doc.get('lock_user') or assignment_locked):
assignment_locked = True

if not assignment_locked:
# Make sure the Assignment is locked by this user and session unless when removing
# assignments during spiking/unposting planning items
if not is_locked_in_this_session(doc) and planning_item.get('state') not in [WORKFLOW_STATE.KILLED,
WORKFLOW_STATE.SPIKED]:
raise SuperdeskApiError.forbiddenError(
message='Lock is not obtained on the Assignment item'
)
Expand Down