NCIOCPL / cgov-digital-platform

The Cancer.gov Digital Communications Platform
GNU General Public License v2.0
11 stars 33 forks source link

Investigate Module for "Locking" or "Checking out" content #93

Closed VictoriaSunNIH closed 1 year ago

VictoriaSunNIH commented 5 years ago

When a user is editing a piece of content, we would like to be able to "lock" the item so another user isn't able to modify it at the same time. Need to look into a module for this

adriancofie commented 5 years ago

https://www.drupal.org/project/content_lock

kalidindir commented 5 years ago

Content locking, Content lock timeout and conflict module should be used together to implement the locking functionality. Conflict module is only required if we need support for translations.

Does it support entity translations? Yes Does it support media? Yes it supports all entity types. I have tested for media and node types. Moderation Sidebar: We will have to implement hook_moderation_sidebar_alter to hide show the links based on the lock state and timeout.

Module Approach.

  1. When user A tries to edit a piece of content, the module checks if a lock already exists. If no lock exists currently, a new database record is inserted into the module’s custom table. A message is displayed on the edit page that the current user has the lock available.
  2. When user B tries to edit the same content, the module displays a message on the edit page that the content is locked by another user and cannot be edited. All input fields and buttons in the edit page are disabled.
  3. It supports different for operations for each entity type. Node has edit and delete. Media has add edit and delete etc.
  4. The lock is for a combination of user id, entity id, entity type, operation, language.
  5. The module does not prevent the user from saving. It only disables the buttons and fields.

Breaking the lock before it is stale:

  1. The lock has to be broken by the user A by clicking on the “Unlock” button or Saving the content.
  2. A user with the permission “Break content lock” can break the lock of other user.
  3. The lock does not break when user A closes the browser window.

Lock Timeout and autounlocking.

  1. A stale timeout value can be set in the config screen(default is 30 minutes).
  2. The lock can be broken by a cron run after the timeout.
  3. Break the lock automatically, when another user edits the content after the timeout.(Module claims as a feature but does not work correctly.)
  4. The stale lock timeout is reset everytime the lock owner reloads the edit page

Possible Customizations.

  1. Write custom hooks to alter the moderation sidebar links based on lock status and timeouts.
  2. Modifying the drupal lock messages has to be done using language translation. The messages are hardcoded.
  3. Add custom access check or validator to prevent user from saving a node when someone else has the lock. This is for a workaround of the bug below.

Bugs Found: 1) Auto Unlocking on edit form does not work correctly. The module claims it is a feature and it does not work. 2) Auto unlocking, does not prevent the original idle user from saving the content after the timeout. The module does not prevent the user from saving. It only disables the buttons and fields.

VictoriaSunNIH commented 5 years ago

Things to investigate further/To Do:

Consider implementing what Percussion had - when you click "Revise Content", the content is locked and when it moves to the next workflow state, the content is unlocked. Also have an optional button to lock/unlock content separately.

Do we want a future option to hide the workflow transitions when a user "views in edit form"? It may make more sense for us to tighten the workflow to not allow users to edit a node "published" or "reviewed" state until its been moved through the workflow to editing state (hide the buttons at the bottom)

andyvanavery31 commented 1 year ago

If this is required by the Content Modernization project, then they will be responsible for creating a new issue to track and prioritize this work.