forked from OSC/ondemand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configurable referer redirect for preset pinned apps
- Loading branch information
Showing
9 changed files
with
111 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Helper for pinned apps widget | ||
module PinnedAppsHelper | ||
|
||
# utility to add query string parameters to an existing URL | ||
def add_query_parameters(url, parameters) | ||
return url if parameters.to_h.empty? | ||
|
||
as_uri = Addressable::URI.parse(url.to_s) | ||
query_params = as_uri.query_values || {} | ||
as_uri.query_values = query_params.merge(parameters.to_h) | ||
as_uri.to_s | ||
end | ||
|
||
def redirect_to_referer?(link) | ||
@user_configuration.pinned_apps_redirect && link.data.fetch(:method, '').downcase == 'post' | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class PinnedAppsHelperTest < ActionView::TestCase | ||
include PinnedAppsHelper | ||
|
||
def setup | ||
@user_configuration = stub | ||
end | ||
|
||
test 'add_query_parameters should not break with nil values' do | ||
assert_nil add_query_parameters(nil, nil) | ||
end | ||
|
||
test 'add_query_parameters should same URL when query parameters is empty' do | ||
result = add_query_parameters('/test/url', { }) | ||
assert_equal '/test/url', result | ||
end | ||
|
||
test 'add_query_parameters should not break with empty URL when adding extra query parameters' do | ||
assert_equal '?param1=value1¶m2=value2', add_query_parameters(nil, { param1: 'value1', param2: 'value2' }) | ||
end | ||
|
||
test 'add_query_parameters should add query parameters to existing ones' do | ||
result = add_query_parameters('/test?static=one&test=two&', { param1: 'value1', param2: 'value2' }) | ||
assert_equal '/test?param1=value1¶m2=value2&static=one&test=two', result | ||
end | ||
|
||
test 'redirect_to_referer? should return false when pinned_apps_redirect is false' do | ||
@user_configuration.stubs(:pinned_apps_redirect).returns(false) | ||
link = OodAppLink.new({ data: {method: 'post'} }) | ||
|
||
assert_equal false, redirect_to_referer?(link) | ||
end | ||
|
||
test 'redirect_to_referer? should return false when pinned_apps_redirect is true and OodAppLink.data does not include post method' do | ||
@user_configuration.stubs(:pinned_apps_redirect).returns(true) | ||
link = OodAppLink.new | ||
|
||
assert_equal false, redirect_to_referer?(link) | ||
end | ||
|
||
test 'redirect_to_referer? should return true when pinned_apps_redirect is true and OodAppLink.data includes post method' do | ||
@user_configuration.stubs(:pinned_apps_redirect).returns(true) | ||
link = OodAppLink.new({ data: {method: 'PoSt'} }) | ||
|
||
assert_equal true, redirect_to_referer?(link) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters