Align lock file button permission logic to the directory one

What does this MR do and why?

Currently, the permission logic for lock file and lock directory buttons are inconsistent. This issue aims to align them by using the GraphQL fields added in Project graphql query is returning incorrect pa... (#512677 - closed)

AI code change summary

This change refines the file locking functionality in the repository interface by splitting a single "canLock" permission into two more specific permissions: "canCreateLock" and "canDestroyLock". This allows for more granular control over who can create new locks on files versus who can remove existing locks. The code now properly distinguishes between these two actions, making the permission system more precise. Additionally, the implementation now relies on permissions from the API rather than calculating them client-side, and removes the dependency on the global username variable. The changes also improve how locked files are detected and how the UI responds to different permission combinations, ensuring buttons are properly enabled or disabled based on the user's actual permissions.

References

Screenshots or screen recordings

after
user can create lock CleanShot 2025-05-01 at 16.03.41.png
user cannot create lock CleanShot 2025-05-01 at 16.06.46.png
On default branch On non-default branch

user can destroy lock

(user is the author of the lock)

CleanShot 2025-05-01 at 16.02.47.png

user cannot destroy lock

(user is not the author of the lock)

CleanShot 2025-05-01 at 16.12.19.png

CleanShot 2025-05-01 at 16.12.45.png

How to set up and validate locally

  1. Go to Project overview or Code / Repository
  2. Enable blob_repository_vue_header_app flag
  3. Log in as a user who has developer permission to a project
  4. User should be able to lock and unlock a file (e.g. button should not be disabled)

MR acceptance checklist

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

Related to #526589 (closed)

Edited by Chaoyue Zhao

Merge request reports

Loading
Loading