Add custom error message in files UpdateService
Problem
We have refactored edit blob to use rest API. This allowed us to again show the custom error, when the file has changed while editing:
if file_has_changed?(@file_path, @last_commit_sha)
raise FileChangedError, _('You are attempting to update a file that has changed since you started editing it.')
end
But previously we also had a custom message for when the fork and upstream project diverged. It was changed to a generic message (see !174287 (diffs)). But now that we're using /api/:version/projects/:id/repository/files/:file_path
, we are getting 403 Forbidden
(see the screenshot below).
Solution
Add another custom error to UpdateService
that returns:
Can't edit this file. The fork and upstream project have diverged. Edit the file on the fork
It should be shown in the case described in this feature test: https://gitlab.com/gitlab-org/gitlab/-/blob/2c910bfc98a544cacc64489139abfad3f7f2e890/spec/features/projects/files/editing_a_file_spec.rb#L56
Context
The following discussion from !202756 should be addressed:
-
@ms.mondrian started a discussion: (+2 comments) suggestion: can we update error message in
spec/features/projects/files/editing_a_file_spec.rb
to the more specific one like they were before? i updated them in Update edit blob to use commit change modal (!174287 - merged) and this refactor should give us the ability to put this back.
Good catch. I'm wondering why this hasn't failed in the pipeline.
FYI the copy is slightly different now:
You are attempting to update a file that has changed since you started editing it.
What I don't like is that for users without write access, it returns "403 Forbidden"
I think I'll map that on frontend to the current one "An error occurred editing the blob"