adding locking mechanism for entities #1609
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the discussion
As mentioned in Issue #1504 , I added a locking mechanism so any entity currently being edited gets locked from being edited by other people. Specifically, this locking mechanism kicks in when one klicks the "save" button after entering data into an input-field related to the entity.
An error message is currently not being displayed, as I edited only the backend, not the frontend. Furthermore, when editing for example an institution, the insititution label is always displayed as though it had been changed in the current tab - even when the edit is not saved (due to the entity being locked at the time of attempting to edit it). See here:
That the change has not been saved only become apparent if one leaves the current bundle, returns to scenario-bundles/main and then selects the bundle again:
Technical Explanation of the changes made:
In factsheet/models.py I added a new table for tracking which entities are currently locked.
In factsheet/views.py I added two new functions: acquire_lock and release_lock.
acquire_lock checks if the entity someone is attempting to edit currently has an entry in the new "LockTable" table. If there is no such entry, the function generates a new entry and returns True.
If there is such an entry, the function checks whether the existing lock has already timed out. If the lock has not yet timed out, the function returns False, since the entity is considered locked. If the lock is timed out, the function overwrites the old lock with a new one and returns True.
release_lock deletes a lock once the entity it applies to is no longer being edited.
The "update_an_entity" function was changed to first call the "acquire_lock" function and only update the given entity if acquire_lock returns true (so if the entity is not already locked). Otherwise, it prints "Entity currently being edited!"
Once the entity was successfully updated, update_an_entity calls "release_lock".
Type of change (CHANGELOG.md)
Added
Updated
Workflow checklist
Part of #1504
PR-Assignee
Reviewer