Disable Replace/Delete on default branch when user cannot unlock file

What does this MR do and why?

When a file is locked by another user, the unlock action is not available to other users on both default and non-default branches. The replace and delete actions are still available to users on the default branch, even though file modification is restricted to the user who has permission to unlock the file or Maintainers. Currently, it's possible to go through replacing and deleting flow, which eventually returns an error from the backend when submitting the change.

This MR updates to indicate the user they cannot perform the action earlier by disabling those buttons. This only applies to default branch since user can still perform those actions on non-default branches.

Technically speaking, this MR:

  • Passes down root-ref from tree_helper.rb and blob_helper.rb

  • Adds a check to disable the button based on !this.canLock && this.rootRef === this.currentRef

  • Moves up the logic for canLock, isLocked and pathLockedByUser to blob_overflow_menu.vue (new file under /ee) since it's now being used by blob_button_group.vue (new file under /ee)

    and blob_delete_file_group.vue

  • Adjusts tests accordingly

  • Adjust the CE/EE split of the logic - essentially no longer fetching for pathLocks in CE

  • Adds tests for new logic

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

On default branch On non-default branch

when user has permission to unlock the file

(user is the author of the lock)

CleanShot 2025-03-07 at 00.35.08.mp4

CleanShot 2025-03-07 at 00.35.33.mp4

when user does not permission to unlock the file

(user is not the author of the lock)

CleanShot 2025-03-07 at 00.34.23.mp4

CleanShot 2025-03-07 at 00.36.26.mp4

running app in CE

expected: lock button does not show, replace and delete are enabled

(basically no change)

CleanShot 2025-03-12 at 12.43.51.png

CleanShot 2025-03-12 at 12.46.49.png

How to set up and validate locally

  1. Enable blob_overflow_menu and enable blob_repository_vue_header_app feature flag
   Feature.enable(:blob_overflow_menu)
   Feature.enable(:blob_repository_vue_header_app)
  1. See table above for different scenarios. To set things up:
    1. Have two users who both have developer+ permission in the same repo
    2. Place a lock on file A with user A
    3. Place a lock on file B with user B

Related to #516868 (closed)

Edited by Chaoyue Zhao

Merge request reports

Loading