From 520815956d1c43239447b11d6812b18b44c2be70 Mon Sep 17 00:00:00 2001 From: ulferts Date: Mon, 19 Jun 2017 12:55:28 +0200 Subject: [PATCH] preserve params when redirecting for login on repository (#5671) [ci skip] --- app/controllers/repositories_controller.rb | 4 +++ config/routes.rb | 3 ++- .../repositories_controller_spec.rb | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7f741447f8..8690a67ff6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -489,6 +489,10 @@ class RepositoriesController < ApplicationController ) graph.burn end + + def login_back_url_params + params.permit(:path) + end end class Date diff --git a/config/routes.rb b/config/routes.rb index b569e14f54..a7678b9366 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -348,7 +348,8 @@ OpenProject::Application.routes.draw do get '(/revisions/:rev)(/*path)', action: :show, format: false, - rev: /[a-z0-9\.\-_]+/ + rev: /[a-z0-9\.\-_]+/, + as: 'show_revisions_path' end end diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 3dbaf1c391..5f3a2ea698 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -35,10 +35,11 @@ describe RepositoriesController, type: :controller do allow(Project).to receive(:find).and_return(project) project end - let(:user) { + let(:user) do FactoryGirl.create(:user, member_in_project: project, member_through_role: role) - } + end + let(:role) { FactoryGirl.create(:role, permissions: []) } let (:url) { 'file:///tmp/something/does/not/exist.svn' } let(:repository) do @@ -167,7 +168,7 @@ describe RepositoriesController, type: :controller do end end - describe 'with filesystem repository' do + describe 'with subversion repository' do with_subversion_repository do |repo_dir| let(:root_url) { repo_dir } let(:url) { "file://#{root_url}" } @@ -332,4 +333,22 @@ describe RepositoriesController, type: :controller do end end end + + describe 'when not being logged in' do + let(:anonymous) { FactoryGirl.build_stubbed(:anonymous) } + + before do + login_as(anonymous) + end + + describe '#show' do + it 'redirects to login while preserving the path' do + params = { path: 'aDir/within/aDir', rev: '42', project_id: project.id } + get :show, params: params + + expect(response) + .to redirect_to signin_path(back_url: show_revisions_path_project_repository_url(params)) + end + end + end end