Fix errors on pushing/editing files on empty repositories
What does this MR do?
- In this branch we allow admins to push to empty projects, where the default branch is protected.
- This fixes a crash when someone is not authorized.
The crash was initially caused by calling
Gitlab::UserAccess#can_push_to_branch? without a project, we would end up there because a the user
can_collaborate_with_project? since they can
push_code. Then we'd check if they can push to the branch, but there is none yet, and we don't allow developers to create a new default branch, this needs to be done by owners or admins. So the
CreatesCommit would be empty.
But in the case of a developer, they wouldn't actually be allowed to push to create the new default branch. So we're hiding the buttons
This MR hides the buttons if the user cannot push to the master branch, and hides the commands the user cannot perform.
Screenshots (if relevant)
User can push
User can not push
Does this MR meet the acceptance criteria?
- Changelog entry added, if necessary
- Documentation created/updated
- API support added
- Tests added for this feature/bug
- Has been reviewed by UX
- Has been reviewed by Frontend
- Has been reviewed by Backend
- Has been reviewed by Database
- Conform by the merge request performance guides
- Conform by the style guides
- Squashed related commits together
- Internationalization required/considered
End-to-end tests pass (
package-and-qamanual pipeline job)