Twist redirect to back url method to work with JSON params.

pull/1801/head
Richard 10 years ago
parent 5aa1bab149
commit 72b6e26461
  1. 30
      app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js
  2. 14
      app/controllers/application_controller.rb
  3. 3
      app/controllers/work_packages_controller.rb
  4. 22
      karma/tests/controllers/work-packages-list-controller-test.js

@ -137,6 +137,8 @@ angular.module('openproject.workPackages.controllers')
// Set up fresh query from retrieved query meta data
$scope.query = QueryService.initQuery($state.params.query_id, queryData, columnData, metaData.export_formats, afterQuerySetupCallback);
}
$scope.maintainBackUrl();
}
function afterQuerySetupCallback(query) {
@ -185,18 +187,31 @@ angular.module('openproject.workPackages.controllers')
});
}
// Updates
$scope.maintainUrlQueryState = function(){
var relativeUrl = decodeURIComponent($state.href($state.$current)); // ui-router escapes some of this string for whatever reason
function getCurrentStateUrl(){
var relativeUri = decodeURIComponent($state.href($state.$current)); // ui-router escapes some of this string for whatever reason
if($scope.query) {
var queryString = UrlParamsHelper.encodeQueryJsonParams($scope.query);
$location.search('query_props', queryString);
relativeUrl = relativeUrl + "?query_props=" + queryString;
if($scope.query.isNew()) {
relativeUri = relativeUri + "?query_props=" + queryString;
} else {
relativeUri = relativeUri + "&query_props=" + queryString;
}
}
$scope.backUrl = relativeUrl;
return relativeUri;
}
$scope.maintainBackUrl = function() {
$scope.backUrl = getCurrentStateUrl();
}
// Updates
$scope.maintainUrlQueryState = function(){
if($scope.query) {
$location.search('query_props', UrlParamsHelper.encodeQueryJsonParams($scope.query));
}
};
$scope.loadQuery = function(queryId) {
@ -237,6 +252,7 @@ angular.module('openproject.workPackages.controllers')
$rootScope.$on('queryStateChange', function(event, message) {
$scope.maintainUrlQueryState();
$scope.maintainBackUrl();
});
$rootScope.$on('workPackagesRefreshRequired', function(event, message) {

@ -451,17 +451,17 @@ class ApplicationController < ActionController::Base
params[:back_url] || request.env['HTTP_REFERER']
end
def redirect_back_or_default(default, escape = true)
back_url = if escape
def redirect_back_or_default(default, escape = true, use_escaped = true)
escaped_back_url = if escape
URI.escape(CGI.unescape(params[:back_url].to_s))
else
params[:back_url]
end
# if we have a back_url it must not contain two consecutive dots
if back_url.present? && !back_url.match(/\.\./)
if escaped_back_url.present? && !escaped_back_url.match(/\.\./)
begin
uri = URI.parse(back_url)
uri = URI.parse(escaped_back_url)
# do not redirect user to another host (even protocol relative urls have the host set)
# whenever a host is set it must match the request's host
@ -474,7 +474,11 @@ class ApplicationController < ActionController::Base
uri_subdir_allowed = relative_url_root.blank? || uri.path.match(/\A#{relative_url_root}/)
if uri_local_to_host && uri_path_allowed && uri_subdir_allowed
redirect_to(back_url)
if use_escaped
redirect_to(escaped_back_url)
else
redirect_to(back_url)
end
return
end
rescue URI::InvalidURIError

@ -185,7 +185,8 @@ class WorkPackagesController < ApplicationController
flash[:notice] = l(:notice_successful_update)
redirect_to_back_url_or_work_package(work_package)
redirect_back_or_default(work_package_path(work_package), true, false)
# redirect_to_back_url_or_work_package(work_package)
else
edit
end

@ -77,11 +77,15 @@ describe('WorkPackagesListController', function() {
testQueries = {
'1': {
id: 1,
columns: ['type']
columns: ['type'],
getSortation: function() { return null; },
isNew: function() { return false; }
},
'2': {
id: 2,
columns: ['type']
columns: ['type'],
getSortation: function() { return null; },
isNew: function() { return false; }
},
};
@ -191,7 +195,10 @@ describe('WorkPackagesListController', function() {
describe('initialisation of default query', function() {
beforeEach(function(){
testParams = {};
testState = { params: {} };
testState = {
params: {},
href: function() { return '' }
};
testLocation = {
search: function() {
return {};
@ -213,9 +220,12 @@ describe('WorkPackagesListController', function() {
describe('initialisation of query by id', function() {
beforeEach(function(){
testParams = { };
testState = { params: {
query_id: testQueries['2'].id
} };
testState = {
params: {
query_id: testQueries['2'].id
},
href: function() { return '' }
};
testLocation = {
search: function() {
return {};

Loading…
Cancel
Save