From 60a6074dc977a72e00043596623094e006c84704 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Thu, 11 Jul 2019 19:27:21 +0200 Subject: Open WebIDE in fork when user doesn't have access When opening the IDE on a project where the user doesn't have push access, we create a fork and then redirect back to the IDE. To make sure the user can actually commit, we need to open the IDE in the forked project rather than the upstream project. --- app/helpers/blob_helper.rb | 11 ++++++- .../51952-redirect-to-webide-in-fork.yml | 5 +++ .../projects/files/user_edits_files_spec.rb | 1 + spec/helpers/blob_helper_spec.rb | 38 ++++++++++++++++++---- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 changelogs/unreleased/51952-redirect-to-webide-in-fork.yml diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 0d6a6496993..4b0713001a1 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -18,7 +18,16 @@ module BlobHelper end def ide_edit_path(project = @project, ref = @ref, path = @path, options = {}) - segments = [ide_path, 'project', project.full_path, 'edit', ref] + project_path = + if !current_user || can?(current_user, :push_code, project) + project.full_path + else + # We currently always fork to the user's namespace + # in edit_fork_button_tag + "#{current_user.namespace.full_path}/#{project.path}" + end + + segments = [ide_path, 'project', project_path, 'edit', ref] segments.concat(['-', encode_ide_path(path)]) if path.present? File.join(segments) end diff --git a/changelogs/unreleased/51952-redirect-to-webide-in-fork.yml b/changelogs/unreleased/51952-redirect-to-webide-in-fork.yml new file mode 100644 index 00000000000..ada0efca968 --- /dev/null +++ b/changelogs/unreleased/51952-redirect-to-webide-in-fork.yml @@ -0,0 +1,5 @@ +--- +title: Open WebIDE in fork when user doesn't have access +merge_request: 30642 +author: +type: changed diff --git a/spec/features/projects/files/user_edits_files_spec.rb b/spec/features/projects/files/user_edits_files_spec.rb index e0fa9dbb5fa..e4b02408b49 100644 --- a/spec/features/projects/files/user_edits_files_spec.rb +++ b/spec/features/projects/files/user_edits_files_spec.rb @@ -162,6 +162,7 @@ describe 'Projects > Files > User edits files', :js do expect_fork_status + expect(page).to have_css('.ide-sidebar-project-title', text: "#{project2.name} #{user.namespace.full_path}/#{project2.path}") expect(page).to have_css('.ide .multi-file-tab', text: '.gitignore') end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 6808ed86c9a..1f236429347 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -29,14 +29,15 @@ describe BlobHelper do let(:project) { create(:project, :repository, namespace: namespace) } before do - allow(self).to receive(:current_user).and_return(nil) - allow(self).to receive(:can_collaborate_with_project?).and_return(true) + allow(helper).to receive(:current_user).and_return(nil) + allow(helper).to receive(:can?).and_return(true) + allow(helper).to receive(:can_collaborate_with_project?).and_return(true) end it 'verifies blob is text' do expect(helper).not_to receive(:blob_text_viewable?) - button = edit_blob_button(project, 'refs/heads/master', 'README.md') + button = helper.edit_blob_button(project, 'refs/heads/master', 'README.md') expect(button).to start_with('