hancock_cms_goto 1.0.1.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/hancock/goto/decorators/transfer.rb +8 -1
- data/app/views/hancock/goto/transfers/index.html.slim +8 -0
- data/hancock_cms_goto.gemspec +2 -2
- data/lib/generators/hancock/goto/config/templates/hancock_goto.erb +2 -0
- data/lib/generators/hancock/goto/models/templates/transfer.erb +13 -6
- data/lib/hancock/goto/admin/transfer.rb +20 -4
- data/lib/hancock/goto/configuration.rb +7 -1
- data/lib/hancock/goto/controllers/transfers.rb +32 -12
- data/lib/hancock/goto/middleware.rb +22 -21
- data/lib/hancock/goto/models/mongoid/transfer.rb +25 -9
- data/lib/hancock/goto/models/transfer.rb +21 -10
- data/lib/hancock/goto/routes.rb +9 -2
- data/lib/hancock/goto/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 932b515ab4747afce58b9df9d20db449b4ae7c06
|
4
|
+
data.tar.gz: ab16fc9166fb4dd6442d00747ccea30292fc4c88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6577e2407fae1ed2bb2275be10d41250264a84fa861229150b0a605920351fae0a45cfc7d038b24afd601bfb30f87fb6cc3a814de60b767963f3e4c66db7c2c
|
7
|
+
data.tar.gz: d5bd15db08c6203d61309cf090c83ce8383a08a8ed385f884a5064598402cbc2a746c475c38fb1b8ad21deed5fd376aa9c5b437a84cec1c84f37464cf6443f85
|
@@ -24,8 +24,15 @@ module Hancock::Goto::Decorators
|
|
24
24
|
# end
|
25
25
|
|
26
26
|
############# rails_admin ##############
|
27
|
+
# def self.rails_admin_name_synonyms
|
28
|
+
# "".freeze
|
29
|
+
# end
|
30
|
+
# def self.rails_admin_navigation_icon
|
31
|
+
# ''.freeze
|
32
|
+
# end
|
33
|
+
#
|
27
34
|
# def self.rails_admin_add_fields
|
28
|
-
# [] #super
|
35
|
+
# [].freeze #super
|
29
36
|
# end
|
30
37
|
#
|
31
38
|
# def self.rails_admin_add_config(config)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
= hidden_field_tag nil, @target_url, id: 'redir'
|
2
|
+
javascript:
|
3
|
+
window.opener=null;
|
4
|
+
window.location.replace(document.getElementById('redir').value);
|
5
|
+
noscript
|
6
|
+
meta content="0;URL='#{@target_url}'" http-equiv="refresh"
|
7
|
+
= form_tag @target_url, method: "GET", authenticity_token: false, enforce_utf8: false do
|
8
|
+
= submit_tag "Continue"
|
data/hancock_cms_goto.gemspec
CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.10"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
|
33
|
-
spec.add_dependency 'hancock_cms', [">=1.0.
|
34
|
-
# spec.add_dependency 'hancock_cms', ["~> 1.0", "~> 2.
|
33
|
+
spec.add_dependency 'hancock_cms', [">=1.0.2", "<2.1.x"]
|
34
|
+
# spec.add_dependency 'hancock_cms', ["~> 1.0.2", "~> 2.0"]
|
35
35
|
|
36
36
|
spec.add_dependency 'nokogiri'
|
37
37
|
spec.add_dependency 'addressable'
|
@@ -13,4 +13,6 @@ Hancock::Goto.configure do |config|
|
|
13
13
|
# config.model_settings_support = !!defined?(RailsAdminModelSettings)
|
14
14
|
# config.user_abilities_support = !!defined?(RailsAdminUserAbilities)
|
15
15
|
# config.ra_comments_support = !!defined?(RailsAdminComments)
|
16
|
+
|
17
|
+
# config.method = :render_view # or :redirect_from_controller
|
16
18
|
end
|
@@ -16,27 +16,34 @@ class <%= camelcased_class_name %> < Hancock::Goto::Transfer
|
|
16
16
|
# end
|
17
17
|
|
18
18
|
############ rails_admin ##############
|
19
|
+
def self.rails_admin_name_synonyms
|
20
|
+
"".freeze
|
21
|
+
end
|
22
|
+
def self.rails_admin_navigation_icon
|
23
|
+
''.freeze
|
24
|
+
end
|
25
|
+
|
19
26
|
def self.rails_admin_add_fields
|
20
|
-
[] #super
|
27
|
+
[].freeze #super
|
21
28
|
end
|
22
29
|
|
23
30
|
def self.rails_admin_add_config(config)
|
24
31
|
#super(config)
|
25
32
|
end
|
26
33
|
|
27
|
-
def admin_can_user_defined_actions
|
34
|
+
def self.admin_can_user_defined_actions
|
28
35
|
[].freeze
|
29
36
|
end
|
30
|
-
def admin_cannot_user_defined_actions
|
37
|
+
def self.admin_cannot_user_defined_actions
|
31
38
|
[].freeze
|
32
39
|
end
|
33
|
-
def manager_can_user_defined_actions
|
40
|
+
def self.manager_can_user_defined_actions
|
34
41
|
[].freeze
|
35
42
|
end
|
36
|
-
def manager_cannot_user_defined_actions
|
43
|
+
def self.manager_cannot_user_defined_actions
|
37
44
|
[].freeze
|
38
45
|
end
|
39
|
-
def rails_admin_user_defined_visible_actions
|
46
|
+
def self.rails_admin_user_defined_visible_actions
|
40
47
|
[].freeze
|
41
48
|
end
|
42
49
|
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module Hancock::Goto
|
2
2
|
module Admin
|
3
3
|
module Transfer
|
4
|
-
def self.config(fields = {})
|
4
|
+
def self.config(nav_label = nil, fields = {})
|
5
|
+
if nav_label.is_a?(Hash)
|
6
|
+
nav_label, fields = nav_label[:nav_label], nav_label
|
7
|
+
elsif nav_label.is_a?(Array)
|
8
|
+
nav_label, fields = nil, nav_label
|
9
|
+
end
|
10
|
+
|
5
11
|
Proc.new {
|
6
12
|
if defined?(Hancock::Feedback)
|
7
|
-
navigation_label I18n.t('hancock.feedback')
|
13
|
+
navigation_label nav_label || I18n.t('hancock.feedback')
|
8
14
|
else
|
9
|
-
navigation_label I18n.t('hancock.goto')
|
15
|
+
navigation_label nav_label || I18n.t('hancock.goto')
|
10
16
|
end
|
11
17
|
|
12
18
|
field :creator do
|
@@ -17,7 +23,7 @@ module Hancock::Goto
|
|
17
23
|
creator = bindings[:object].creator
|
18
24
|
model_name = creator.class.to_param.gsub("::", "~").underscore
|
19
25
|
_url = route.rails_admin.show_path(model_name: model_name, id: creator._id)
|
20
|
-
route.link_to(creator
|
26
|
+
route.link_to(creator, _url, class: "creator_link")
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -58,12 +64,22 @@ module Hancock::Goto
|
|
58
64
|
end
|
59
65
|
field :session_id do
|
60
66
|
searchable true
|
67
|
+
visible do
|
68
|
+
render_object = (bindings[:controller] || bindings[:view])
|
69
|
+
render_object and render_object.current_user.admin?
|
70
|
+
end
|
61
71
|
end
|
62
72
|
field :session_data_unpack do
|
63
73
|
searchable true
|
64
74
|
read_only true
|
75
|
+
visible do
|
76
|
+
render_object = (bindings[:controller] || bindings[:view])
|
77
|
+
render_object and render_object.current_user.admin?
|
78
|
+
end
|
65
79
|
end
|
66
80
|
|
81
|
+
Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
|
82
|
+
|
67
83
|
if block_given?
|
68
84
|
yield self
|
69
85
|
end
|
@@ -14,6 +14,7 @@ module Hancock
|
|
14
14
|
|
15
15
|
attr_accessor :css_selector
|
16
16
|
attr_accessor :href_regex
|
17
|
+
attr_accessor :href_attr_regex
|
17
18
|
attr_accessor :excluded_hosts
|
18
19
|
|
19
20
|
attr_accessor :add_nofollow
|
@@ -26,20 +27,25 @@ module Hancock
|
|
26
27
|
attr_accessor :user_abilities_support
|
27
28
|
attr_accessor :ra_comments_support
|
28
29
|
|
30
|
+
attr_accessor :method
|
31
|
+
|
29
32
|
def initialize
|
30
33
|
@css_selector = "a[href]"
|
31
34
|
@href_regex = /^(https?:)?\/\//i
|
35
|
+
@href_attr_regex = /\shref=[\'\"](https?:)?\/\//i
|
32
36
|
@excluded_hosts = []
|
33
37
|
|
34
38
|
@add_nofollow = true
|
35
39
|
@add_noindex = true
|
36
|
-
@add_noreferrer =
|
40
|
+
@add_noreferrer = false
|
37
41
|
@add_noopener = true
|
38
42
|
@del_attrs = true
|
39
43
|
|
40
44
|
@model_settings_support = !!defined?(RailsAdminModelSettings)
|
41
45
|
@user_abilities_support = !!defined?(RailsAdminUserAbilities)
|
42
46
|
@ra_comments_support = !!defined?(RailsAdminComments)
|
47
|
+
|
48
|
+
@method = :render_view
|
43
49
|
end
|
44
50
|
|
45
51
|
def default_html_options
|
@@ -4,21 +4,41 @@ module Hancock::Goto
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
begin
|
8
|
+
@url = Addressable::URI.heuristic_parse(params[:url])
|
9
|
+
@target_url = @url.to_s
|
10
|
+
rescue
|
11
|
+
redirect_to root_path
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
Thread.new(params.clone, session.clone, request.clone, transfer_class, @url) do |_params, _session, _request, transfer_class, url|
|
16
|
+
begin
|
17
|
+
referer = (_request.referer ? Addressable::URI.parse(_request.referer) : nil) rescue nil
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
@transfer = transfer_class.new
|
20
|
+
@transfer.recieved_url = _params[:url]
|
21
|
+
@transfer.url = url.to_s
|
22
|
+
@transfer.host = url.host.to_s if url
|
23
|
+
@transfer.referer = referer.to_s
|
24
|
+
@transfer.source_ip = _request.env['HTTP_X_FORWARDED_FOR'] || _request.remote_ip
|
25
|
+
if Hancock::Goto.mongoid?
|
26
|
+
@transfer.set_session(_session)
|
27
|
+
end
|
28
|
+
@transfer.save
|
29
|
+
rescue Exception => ex
|
30
|
+
puts ex.inspect
|
31
|
+
end
|
18
32
|
end
|
19
|
-
@transfer.save
|
20
33
|
|
21
|
-
|
34
|
+
case Hancock::Goto.config.method.to_sym
|
35
|
+
when :render_view
|
36
|
+
render layout: false
|
37
|
+
when :redirect_from_controller
|
38
|
+
redirect_to @url, code: 303
|
39
|
+
else
|
40
|
+
redirect_to @url, code: 303
|
41
|
+
end
|
22
42
|
end
|
23
43
|
|
24
44
|
def transfer_class
|
@@ -32,32 +32,33 @@ module Hancock::Goto
|
|
32
32
|
if should_process?(status, headers, env)
|
33
33
|
begin
|
34
34
|
content = extract_content(response)
|
35
|
-
|
36
|
-
|
35
|
+
if Hancock::Goto.config.href_attr_regex and content =~ Hancock::Goto.config.href_attr_regex
|
36
|
+
doc = ::Nokogiri::HTML(content)
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
doc.css(Hancock::Goto.config.css_selector).each do |a|
|
39
|
+
if (!a[ATTRS[:disabled]].blank? and !["0", "false", "no"].include?(a[ATTRS[:disabled]]))
|
40
|
+
del_attrs(a)
|
41
|
+
next
|
42
|
+
end
|
43
|
+
_href = a['href']
|
44
|
+
if _href =~ Hancock::Goto.config.href_regex
|
45
|
+
begin
|
46
|
+
_host = Addressable::URI.parse(_href).host
|
47
|
+
unless Hancock::Goto.config.excluded_hosts.include?(_host)
|
48
|
+
a['href'] = Rails.application.routes.url_helpers.hancock_goto_path(url: _href)
|
49
|
+
a['target'] = '_blank' if a['target'].blank?
|
50
|
+
set_rel_attribute(a)
|
51
|
+
del_attrs(a)
|
52
|
+
end
|
53
|
+
rescue
|
52
54
|
end
|
53
|
-
rescue
|
54
55
|
end
|
55
56
|
end
|
56
|
-
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
content = doc.to_html
|
59
|
+
headers['content-length'] = bytesize(content).to_s
|
60
|
+
response = [content]
|
61
|
+
end
|
61
62
|
rescue Exception => ex
|
62
63
|
# puts ex.message
|
63
64
|
# puts ex.backtrace
|
@@ -16,21 +16,37 @@ module Hancock::Goto
|
|
16
16
|
belongs_to :session, class_name: "MongoidStore::Session"
|
17
17
|
else
|
18
18
|
belongs_to :session, class_name: "MongoidStore::Session", optional: true
|
19
|
+
|
20
|
+
if relations.has_key?("updater") and defined?(::Mongoid::History)
|
21
|
+
belongs_to :updater, class_name: ::Mongoid::History.modifier_class_name, optional: true, validate: false
|
22
|
+
_validators.delete(:updater)
|
23
|
+
_validate_callbacks.each do |callback|
|
24
|
+
if callback.raw_filter.respond_to?(:attributes) and callback.raw_filter.attributes.include?(:updater)
|
25
|
+
_validate_callbacks.delete(callback)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
19
29
|
end
|
20
30
|
field :session_data, type: BSON::Binary
|
21
|
-
end
|
22
31
|
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
def session_data_extract
|
33
|
+
session_data.data if session_data
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
36
|
+
def session_data_unpack
|
37
|
+
Marshal.load(session_data_extract) if session_data
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_session(_session)
|
41
|
+
self.session_id = _session.id
|
42
|
+
self.session_data = ::BSON::Binary.new(Marshal.dump(_session.to_hash))
|
43
|
+
end
|
29
44
|
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
46
|
+
class_methods do
|
47
|
+
def track_history?
|
48
|
+
false
|
49
|
+
end
|
34
50
|
end
|
35
51
|
|
36
52
|
end
|
@@ -6,32 +6,43 @@ module Hancock::Goto
|
|
6
6
|
|
7
7
|
include Hancock::Goto.orm_specific('Transfer')
|
8
8
|
|
9
|
-
include ManualSlug
|
10
|
-
|
11
9
|
included do
|
10
|
+
end
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
|
14
|
+
def rails_admin_name_synonyms
|
15
|
+
"".freeze
|
16
|
+
end
|
17
|
+
def rails_admin_navigation_icon
|
18
|
+
''.freeze
|
19
|
+
end
|
12
20
|
|
13
|
-
def
|
14
|
-
|
21
|
+
# def manager_can_default_actions
|
22
|
+
# # [:show, :read].freeze
|
23
|
+
# super - [:new, :create, :delete, :destroy]
|
24
|
+
# end
|
25
|
+
def admin_cannot_actions
|
26
|
+
[:new, :create].freeze
|
15
27
|
end
|
16
|
-
def
|
17
|
-
[:new, :create, :edit, :update].freeze
|
28
|
+
def manager_cannot_add_actions
|
29
|
+
[:new, :create, :delete, :destroy, :edit, :update].freeze
|
18
30
|
end
|
19
31
|
|
20
|
-
def
|
32
|
+
def manager_can_add_actions
|
21
33
|
ret = []
|
22
34
|
ret << :model_settings if Hancock::Goto.config.model_settings_support
|
23
|
-
ret << :model_accesses if Hancock::Goto.config.user_abilities_support
|
35
|
+
# ret << :model_accesses if Hancock::Goto.config.user_abilities_support
|
24
36
|
ret += [:comments, :model_comments] if Hancock::Goto.config.ra_comments_support
|
25
37
|
ret.freeze
|
26
38
|
end
|
27
|
-
def
|
39
|
+
def rails_admin_add_visible_actions
|
28
40
|
ret = []
|
29
41
|
ret << :model_settings if Hancock::Goto.config.model_settings_support
|
30
42
|
ret << :model_accesses if Hancock::Goto.config.user_abilities_support
|
31
43
|
ret += [:comments, :model_comments] if Hancock::Goto.config.ra_comments_support
|
32
44
|
ret.freeze
|
33
45
|
end
|
34
|
-
|
35
46
|
end
|
36
47
|
|
37
48
|
end
|
data/lib/hancock/goto/routes.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
module ActionDispatch::Routing
|
2
2
|
class Mapper
|
3
3
|
|
4
|
-
def hancock_cms_goto_routes
|
4
|
+
def hancock_cms_goto_routes(no_params = true)
|
5
|
+
if no_params.is_a?(Hash)
|
6
|
+
no_params = no_params[:no_params] || true
|
7
|
+
end
|
5
8
|
|
6
9
|
scope module: 'hancock' do
|
7
10
|
scope module: 'goto' do
|
8
|
-
|
11
|
+
if no_params
|
12
|
+
get 'goto/*url' => 'transfers#index', as: :hancock_goto, format: false
|
13
|
+
else
|
14
|
+
get 'goto' => 'transfers#index', as: :hancock_goto, format: false
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
11
18
|
|
data/lib/hancock/goto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hancock_cms_goto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kiseliev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,20 +44,20 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.0.
|
48
|
-
- - "
|
47
|
+
version: 1.0.2
|
48
|
+
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: 2.1.x
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 1.0.
|
58
|
-
- - "
|
57
|
+
version: 1.0.2
|
58
|
+
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 2.1.x
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: nokogiri
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- app/helpers/hancock/goto/goto_helper.rb
|
107
107
|
- app/models/concerns/hancock/goto/decorators/transfer.rb
|
108
108
|
- app/models/hancock/goto/transfer.rb
|
109
|
+
- app/views/hancock/goto/transfers/index.html.slim
|
109
110
|
- bin/console
|
110
111
|
- bin/setup
|
111
112
|
- config/locales/hancock.goto.ru.yml
|