Skip to content
代码片段 群组 项目
提交 afd7d801 编辑于 作者: psjakubowska's avatar psjakubowska
浏览文件

Expose can_modify_blob_with_web_ide

Single file editor and other UI editing actions need
to make sure the ref is on top of the branch. WebIDE
doesn't have that limitation and allows editing in such
situation, by applying a new commit onto a newly created
branch. Exposing can_modify_blob_with_web_ide filed
will allow to independently manage both edit options.

Changelog: added
上级 5e1c025d
No related branches found
No related tags found
无相关合并请求
......@@ -127,6 +127,9 @@ class BlobType < BaseObject
calls_gitaly: true,
description: 'Whether the current user can modify the blob.'
field :can_modify_blob_with_web_ide, GraphQL::Types::Boolean, null: false, method: :can_modify_blob_with_web_ide?,
description: 'Whether the current user can modify the blob with Web IDE.'
field :can_current_user_push_to_branch, GraphQL::Types::Boolean, null: true, method: :can_current_user_push_to_branch?,
description: 'Whether the current user can push to the branch.'
......
......@@ -76,10 +76,17 @@ def edit_blob_button(project = @project, ref = @ref, path = @path, options = {})
)
end
# Used for single file Web Editor, Delete and Replace UI actions.
# can_edit_tree checks if ref is on top of the branch.
def can_modify_blob?(blob, project = @project, ref = @ref)
!blob.stored_externally? && can_edit_tree?(project, ref)
end
# Used for WebIDE editor where editing is possible even if ref is not on top of the branch.
def can_modify_blob_with_web_ide?(blob, project = @project)
!blob.stored_externally? && can_collaborate_with_project?(project)
end
def leave_edit_message
_("Leave edit mode? All unsaved changes will be lost.")
end
......
......@@ -140,6 +140,10 @@ def can_modify_blob?
super(blob, project, commit_id)
end
def can_modify_blob_with_web_ide?
super(blob, project)
end
def can_current_user_push_to_branch?
return false unless current_user && project.repository.branch_exists?(commit_id)
......
......@@ -30863,6 +30863,7 @@ Returns [`RepositoryCodeownerValidation`](#repositorycodeownervalidation).
| <a id="repositoryblobblamepath"></a>`blamePath` | [`String`](#string) | Web path to blob blame page. |
| <a id="repositoryblobcancurrentuserpushtobranch"></a>`canCurrentUserPushToBranch` | [`Boolean`](#boolean) | Whether the current user can push to the branch. |
| <a id="repositoryblobcanmodifyblob"></a>`canModifyBlob` | [`Boolean`](#boolean) | Whether the current user can modify the blob. |
| <a id="repositoryblobcanmodifyblobwithwebide"></a>`canModifyBlobWithWebIde` | [`Boolean!`](#boolean) | Whether the current user can modify the blob with Web IDE. |
| <a id="repositoryblobcodenavigationpath"></a>`codeNavigationPath` | [`String`](#string) | Web path for code navigation. |
| <a id="repositoryblobcodeowners"></a>`codeOwners` | [`[UserCore!]`](#usercore) | List of code owners for the blob. |
| <a id="repositoryblobeditblobpath"></a>`editBlobPath` | [`String`](#string) | Web path to edit the blob in the old-style editor. |
......@@ -42,6 +42,7 @@
:rich_viewer,
:plain_data,
:can_modify_blob,
:can_modify_blob_with_web_ide,
:can_current_user_push_to_branch,
:archived,
:ide_edit_path,
......
......@@ -119,6 +119,31 @@
end
end
describe '#can_modify_blob_with_web_ide?' do
before do
allow(blob).to receive(:stored_externally?).and_return(false)
allow(presenter).to receive(:can_collaborate_with_project?).with(project).and_return(false)
end
it { expect(presenter.can_modify_blob_with_web_ide?).to be_falsey }
context 'when blob is stored externally' do
before do
allow(blob).to receive(:stored_externally?).and_return(true)
end
it { expect(presenter.can_modify_blob_with_web_ide?).to be_falsey }
end
context 'when user can collaborate with the project' do
before do
allow(presenter).to receive(:can_collaborate_with_project?).with(project).and_return(true)
end
it { expect(presenter.can_modify_blob_with_web_ide?).to be_truthy }
end
end
describe '#can_current_user_push_to_branch?' do
context 'when ref is a branch' do
let(:ref) { 'feature' }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册