goldencobra 1.4.0 → 1.4.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +3 -2
- data/app/assets/images/goldencobra/Jcrop.gif +0 -0
- data/app/assets/javascripts/goldencobra/active_admin.js +145 -84
- data/app/assets/javascripts/goldencobra/jquery.Jcrop.min.js +22 -0
- data/app/assets/javascripts/goldencobra/jquery.color.js +661 -0
- data/app/assets/stylesheets/goldencobra/active_admin.css.scss +375 -252
- data/app/assets/stylesheets/goldencobra/{application.css → application.css.scss} +0 -0
- data/app/assets/stylesheets/goldencobra/ikusei_active_admin.scss +35 -26
- data/app/assets/stylesheets/goldencobra/jquery.Jcrop.min.css +29 -0
- data/app/controllers/goldencobra/api/v2/articles_controller.rb +221 -0
- data/app/controllers/goldencobra/api/v2/locales_controller.rb +31 -0
- data/app/controllers/goldencobra/api/v2/settings_controller.rb +31 -0
- data/app/controllers/goldencobra/articles_controller.rb +42 -16
- data/app/controllers/goldencobra/sessions_controller.rb +8 -1
- data/app/helpers/goldencobra/application_helper.rb +3 -1
- data/app/helpers/goldencobra/articles_helper.rb +14 -8
- data/app/middleware/goldencobra/handle_invalid_percent_encoding.rb +40 -0
- data/app/models/ability.rb +43 -48
- data/app/models/goldencobra/article.rb +292 -218
- data/app/models/goldencobra/article_author.rb +19 -0
- data/app/models/goldencobra/article_image.rb +2 -0
- data/app/models/goldencobra/articletype.rb +30 -28
- data/app/models/goldencobra/author.rb +5 -3
- data/app/models/goldencobra/domain.rb +2 -0
- data/app/models/goldencobra/import.rb +2 -2
- data/app/models/goldencobra/link_checker.rb +64 -0
- data/app/models/goldencobra/menue.rb +4 -2
- data/app/models/goldencobra/permission.rb +3 -1
- data/app/models/goldencobra/redirector.rb +131 -0
- data/app/models/goldencobra/setting.rb +29 -3
- data/app/models/goldencobra/upload.rb +60 -1
- data/app/models/goldencobra/url_builder.rb +58 -0
- data/app/models/goldencobra/vita.rb +4 -0
- data/app/models/goldencobra/widget.rb +10 -0
- data/app/models/user.rb +1 -1
- data/app/views/goldencobra/admin/articles/_article_type.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_articles_index.html.erb +3 -3
- data/app/views/goldencobra/admin/articles/_image_module_sidebar.html.erb +19 -7
- data/app/views/goldencobra/admin/articles/_layout_sidebar.html.erb +2 -2
- data/app/views/goldencobra/admin/articles/_link_checker.html.erb +4 -4
- data/app/views/goldencobra/admin/articles/_link_checker_index.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_select_article_type.html.erb +8 -8
- data/app/views/goldencobra/admin/articles/_sort_articles_index.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_widgets_sidebar.html.erb +2 -2
- data/app/views/goldencobra/admin/articles/toggle_expert_mode.js.erb +2 -2
- data/app/views/goldencobra/admin/settings/_index.html.erb +14 -0
- data/app/views/goldencobra/admin/settings/_key_value.html.erb +12 -0
- data/app/views/goldencobra/admin/settings/_settings_group.html.erb +14 -0
- data/app/views/goldencobra/admin/shared/_help.html.erb +12 -10
- data/app/views/goldencobra/admin/shared/_item.html.erb +4 -4
- data/app/views/goldencobra/admin/shared/_overview.html.erb +14 -4
- data/app/views/goldencobra/admin/shared/load_overviewtree.js.erb +6 -0
- data/app/views/goldencobra/admin/uploads/_jcrop.html.erb +23 -0
- data/app/views/goldencobra/articles/_edit_article_link.html.erb +1 -1
- data/app/views/goldencobra/articles/show.rss.builder +5 -0
- data/app/views/goldencobra/articles/sitemap.xml.builder +15 -1
- data/app/views/goldencobra/manage/_admin_article_management.html.erb +1 -1
- data/app/views/goldencobra/manage/_admin_article_management_content.html.erb +4 -4
- data/app/views/goldencobra/manage/render_admin_menue.html.erb +1 -0
- data/app/views/goldencobra/manage/render_admin_menue.js.erb +0 -1
- data/app/views/goldencobra/sessions/_login.html.erb +4 -4
- data/app/views/goldencobra/sessions/_register.html.erb +6 -6
- data/app/views/layouts/goldencobra/active_admin_resque.html.erb +1 -1
- data/app/worker/articles_cache_worker.rb +1 -1
- data/config/initializers/check_for_missing_articletypes.rb +40 -37
- data/config/initializers/devise.rb +3 -1
- data/config/initializers/http_validator.rb +9 -2
- data/config/initializers/liquid_tags.rb +2 -2
- data/config/locales/active_admin.de.yml +509 -3
- data/config/locales/active_admin.en.yml +580 -64
- data/config/locales/de.yml +478 -4
- data/config/locales/en.yml +406 -10
- data/config/pre-commit.rb +3 -0
- data/config/routes.rb +12 -1
- data/config/settings.yml +51 -50
- data/db/migrate/20130114154115_add_sorter_to_goldencobra_permissions.rb +4 -1
- data/db/migrate/20140204221345_add_operator_to_goldencobra_permissions.rb +5 -0
- data/db/migrate/20140411152728_add_creator_id_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140505144517_add_taggingcounter.rb +15 -0
- data/db/migrate/20140603084537_add_domain_to_goldencobra_permissions.rb +7 -0
- data/db/migrate/20140615200342_resize_link_checkfield.rb +13 -0
- data/db/migrate/20140626135753_add_externalreferee_to_goldencobra_articles.rb +6 -0
- data/db/migrate/20140702103024_add_externaldate_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140702105550_add_remoteurl_to_goldencobra_uploads.rb +5 -0
- data/db/migrate/20140702142818_add_image_gallery_type_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140819101033_add_urlpath_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20141009104216_set_db_and_tables_to_utf8.rb +20 -0
- data/db/migrate/20141104115144_create_goldencobra_redirectors.rb +15 -0
- data/db/migrate/20141112124531_add_globalsorting_to_goldencobra_articles.rb +7 -0
- data/db/migrate/20141124170930_add_indiex_to_gc.rb +26 -0
- data/db/migrate/20150115111024_create_goldencobra_article_authors.rb +28 -0
- data/db/migrate/20150115134707_add_remove_author_stuff.rb +11 -0
- data/db/migrate/20150417153454_add_status_to_goldencobra_vita_steps.rb +5 -0
- data/db/seeds.rb +4 -153
- data/lib/generators/goldencobra/articletype/templates/edit_index.html.erb +1 -1
- data/lib/generators/goldencobra/articletype/templates/initializer.rb +4 -2
- data/lib/generators/goldencobra/install_generator.rb +3 -0
- data/lib/generators/goldencobra/server_generator.rb +67 -0
- data/lib/generators/goldencobra/templates/active_admin.rb.erb +3 -0
- data/lib/generators/goldencobra/templates/robots.txt +5 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_edit_index.html.erb +9 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_edit_show.html.erb +0 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_index.html.erb +31 -18
- data/lib/generators/goldencobra/templates/views/articletypes/default/_show.html.erb +22 -15
- data/lib/goldencobra/engine.rb +19 -3
- data/lib/goldencobra/version.rb +1 -1
- data/lib/tasks/article_cache.rake +19 -0
- data/lib/tasks/i18n.rake +1 -1
- data/lib/tasks/import.rake +31 -3
- data/lib/tasks/link_checker.rake +4 -2
- metadata +217 -23
- data/config/locales/activerecord.de.yml +0 -227
- data/config/locales/activerecord.en.yml +0 -148
- data/config/locales/devise.de.yml +0 -54
- data/config/locales/devise.en.yml +0 -57
- data/config/locales/formtastic.de.yml +0 -10
- data/config/locales/formtastic.en.yml +0 -10
- data/config/locales/goldencobra.de.yml +0 -40
- data/config/locales/goldencobra.en.yml +0 -3
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: goldencobra_article_authors
|
6
|
+
#
|
7
|
+
# id :integer not null, primary key
|
8
|
+
# article_id :integer
|
9
|
+
# author_id :integer
|
10
|
+
# created_at :datetime not null
|
11
|
+
# updated_at :datetime not null
|
12
|
+
#
|
13
|
+
|
14
|
+
module Goldencobra
|
15
|
+
class ArticleAuthor < ActiveRecord::Base
|
16
|
+
belongs_to :article
|
17
|
+
belongs_to :author
|
18
|
+
end
|
19
|
+
end
|
@@ -6,46 +6,48 @@ module Goldencobra
|
|
6
6
|
has_many :articles, :class_name => Goldencobra::Article, :foreign_key => :article_type, :primary_key => :name
|
7
7
|
validates_uniqueness_of :name
|
8
8
|
|
9
|
-
has_many :fieldgroups, :class_name => Goldencobra::ArticletypeGroup
|
9
|
+
has_many :fieldgroups, :class_name => Goldencobra::ArticletypeGroup, :dependent => :destroy
|
10
10
|
accepts_nested_attributes_for :fieldgroups, :allow_destroy => true
|
11
11
|
|
12
12
|
ArticleFieldOptions = {
|
13
|
-
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
13
|
+
:global_sorting_id => %{<% f.input :global_sorting_id, :hint => I18n.t("goldencobra.article_field_hints.global_sorting_id") %>},
|
14
|
+
:title => %{<% f.input :title, :hint => I18n.t("goldencobra.article_field_hints.title") %>},
|
15
|
+
:subtitle => %{<% f.input :subtitle %>},
|
16
|
+
:content => %{<% f.input :content, :input_html => { :class => "tinymce" } %>},
|
17
|
+
:teaser => %{<% f.input :teaser, :hint => I18n.t("goldencobra.article_field_hints.teaser"), :input_html => { :rows => 5 } %>},
|
18
|
+
:summary => %{<% f.input :summary, :hint => I18n.t("goldencobra.article_field_hints.summary"), :input_html => { :rows => 5 } %>},
|
19
|
+
:tag_list => %{<% f.input :tag_list, :hint => I18n.t("goldencobra.article_field_hints.tag_list"), :wrapper_html => { class: '' } %>},
|
20
|
+
:frontend_tag_list => %{<% f.input :frontend_tag_list, hint: I18n.t("goldencobra.article_field_hints.frontend_tag_list"), :wrapper_html => { class: '' } %>},
|
21
|
+
:active => %{<% f.input :active, :hint => I18n.t("goldencobra.article_field_hints.active"), :wrapper_html => { class: '' } %>},
|
22
|
+
:active_since => %{<% f.input :active_since, :hint => I18n.t("goldencobra.article_field_hints.active_since"), as: :string, :input_html => { class: "", :size => "20" }, :wrapper_html => { class: 'expert' } %>},
|
23
|
+
:context_info => %{<% f.input :context_info, :input_html => { :class => "tinymce" }, :hint => I18n.t("goldencobra.article_field_hints.context_info") %>},
|
23
24
|
:metatags => %{<% f.has_many :metatags do |m|
|
24
|
-
m.input :name, :
|
25
|
-
m.input :value, :
|
26
|
-
m.input :_destroy, :label => "entfernen/zurücksetzen", :hint => "
|
25
|
+
m.input :name, :as => :select, :collection => Goldencobra::Article::MetatagNames, :input_html => { :class => 'metatag_names'}, :hint => I18n.t("goldencobra.article_field_hints.metatags_name")
|
26
|
+
m.input :value, :input_html => { :class => 'metatag_values'}
|
27
|
+
m.input :_destroy, :label => "entfernen/zurücksetzen", :hint => I18n.t("goldencobra.article_field_hints.metatags_destroy"), :as => :boolean
|
27
28
|
end %>},
|
28
|
-
:breadcrumb => %{<% f.input :breadcrumb, :
|
29
|
-
:url_name => %{<% f.input :url_name, :
|
30
|
-
:parent_id => %{<% f.input :parent_id, :
|
31
|
-
:canonical_url => %{<% f.input :canonical_url, :
|
32
|
-
:enable_social_sharing => %{<% f.input :enable_social_sharing, :
|
33
|
-
:robots_no_index => %{<% f.input :robots_no_index, :
|
34
|
-
:cacheable => %{<% f.input :cacheable, :
|
35
|
-
:commentable => %{<% f.input :commentable, :
|
36
|
-
:dynamic_redirection => %{<% f.input :dynamic_redirection, :
|
37
|
-
:external_url_redirect => %{<% f.input :external_url_redirect
|
38
|
-
:redirect_link_title => %{<% f.input :redirect_link_title
|
39
|
-
:redirection_target_in_new_window => %{<% f.input :redirection_target_in_new_window
|
40
|
-
:author => %{<% f.input :
|
29
|
+
:breadcrumb => %{<% f.input :breadcrumb, :hint => I18n.t("goldencobra.article_field_hints.breadcrumb") %>},
|
30
|
+
:url_name => %{<% f.input :url_name, :hint => I18n.t("goldencobra.article_field_hints.url_name"), required: false %>},
|
31
|
+
:parent_id => %{<% f.input :parent_id, :hint => I18n.t("goldencobra.article_field_hints.parent_id"), :as => :select, :collection => Goldencobra::Article.where("id = ?", f.object.parent_id).select([:id,:title, :ancestry]).map{|c| [c.parent_path, c.id]}.sort{|a,b| a[0] <=> b[0]}, :include_blank => true, :input_html => { :class => 'chzn-select-deselect get_goldencobra_articles_per_remote', :style => 'width: 70%;', 'data-placeholder' => 'Elternelement auswählen' } %>},
|
32
|
+
:canonical_url => %{<% f.input :canonical_url, :hint => I18n.t("goldencobra.article_field_hints.canonical_url") %>},
|
33
|
+
:enable_social_sharing => %{<% f.input :enable_social_sharing, :hint => I18n.t("goldencobra.article_field_hints.enable_social_sharing") %>},
|
34
|
+
:robots_no_index => %{<% f.input :robots_no_index, :hint => I18n.t("goldencobra.article_field_hints.robots_no_index") %>},
|
35
|
+
:cacheable => %{<% f.input :cacheable, :as => :boolean, :hint => I18n.t("goldencobra.article_field_hints.cacheable") %>},
|
36
|
+
:commentable => %{<% f.input :commentable, :as => :boolean, :hint => I18n.t("goldencobra.article_field_hints.commentable") %>},
|
37
|
+
:dynamic_redirection => %{<% f.input :dynamic_redirection, :as => :select, :collection => Goldencobra::Article::DynamicRedirectOptions.map{|a| [a[1], a[0]]}, :include_blank => false %>},
|
38
|
+
:external_url_redirect => %{<% f.input :external_url_redirect %>},
|
39
|
+
:redirect_link_title => %{<% f.input :redirect_link_title %>},
|
40
|
+
:redirection_target_in_new_window => %{<% f.input :redirection_target_in_new_window %>},
|
41
|
+
:author => %{<% f.input :authors, :as => :select, :collection => Goldencobra::Author.order("lastname ASC").map{ |a| [a.lastname.to_s + ", " + a.firstname.to_s, a.id] }, :input_html => { :class => "chzn-select", :style => "width: 70%;", "data-placeholder" => I18n.t("goldencobra.article_field_placeholder.author") }, :hint => I18n.t("goldencobra.article_field_hints.author") %>},
|
41
42
|
:permissions => %{<% f.has_many :permissions do |p|
|
43
|
+
p.input :domain, :include_blank => "Alle"
|
42
44
|
p.input :role, :include_blank => "Alle"
|
43
45
|
p.input :action, :as => :select, :collection => Goldencobra::Permission::PossibleActions, :include_blank => false
|
44
46
|
p.input :_destroy, :as => :boolean
|
45
47
|
end %>},
|
46
48
|
:article_images => %{<% f.has_many :article_images do |ai|
|
47
49
|
ai.input :image, :as => :select, :collection => Goldencobra::Upload.order("updated_at DESC").map{|c| [c.complete_list_name, c.id]}, :input_html => { :class => 'article_image_file chzn-select', :style => 'width: 70%;', 'data-placeholder' => 'Medium auswählen' }, :label => "Medium wählen"
|
48
|
-
ai.input :position, :as => :select, :collection => Goldencobra::Setting.for_key("goldencobra.article.image_positions").split(",").map(&:strip), :include_blank => false
|
50
|
+
ai.input :position, :as => :select, :collection => Goldencobra::Setting.for_key("goldencobra.article.image_positions").to_s.split(",").map(&:strip), :include_blank => false
|
49
51
|
ai.input :_destroy, :as => :boolean
|
50
52
|
end %>}
|
51
53
|
}
|
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
module Goldencobra
|
4
4
|
class Author < ActiveRecord::Base
|
5
|
-
has_many
|
6
|
-
|
5
|
+
has_many :article_authors
|
6
|
+
has_many :articles, :through => :article_authors
|
7
|
+
|
8
|
+
web_url :googleplus
|
7
9
|
|
8
10
|
def title
|
9
|
-
[self.try(:firstname),self.try(:lastname)].join(" ")
|
11
|
+
[self.try(:firstname), self.try(:lastname)].join(" ")
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -82,7 +82,7 @@ module Goldencobra
|
|
82
82
|
def run!
|
83
83
|
self.result = []
|
84
84
|
count = 0
|
85
|
-
all_data_attribute_assignments =
|
85
|
+
all_data_attribute_assignments = remove_empty_assignments
|
86
86
|
master_data_attribute_assignments = all_data_attribute_assignments[self.target_model]
|
87
87
|
import_data_attribute_assignments = all_data_attribute_assignments["Goldencobra::ImportMetadata"]
|
88
88
|
#all_data_attribute_assignments.delete("Goldencobra::ImportMetadata")
|
@@ -247,7 +247,7 @@ module Goldencobra
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
def
|
250
|
+
def remove_empty_assignments
|
251
251
|
self.assignment.each do |key, values|
|
252
252
|
self.assignment[key].delete_if{|k,v| v['data_function'] == "Default" && v['csv'].blank?} if self.assignment[key].present? && self.assignment[key].class == Array
|
253
253
|
if self.assignment[key].blank?
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Goldencobra
|
4
|
+
class LinkChecker
|
5
|
+
def initialize(article)
|
6
|
+
@article = article
|
7
|
+
end
|
8
|
+
|
9
|
+
#get all links of a page and make a check for response status and time
|
10
|
+
def set_link_checker
|
11
|
+
links_to_check = []
|
12
|
+
status_for_links = {}
|
13
|
+
doc = Nokogiri::HTML(open(@article.absolute_public_url))
|
14
|
+
#find all links and stylesheets
|
15
|
+
doc.css('a,link').each do |link|
|
16
|
+
if add_link_to_checklist(link, "href").present?
|
17
|
+
links_to_check << {"link" => add_link_to_checklist(link, "href"), "pos" => link.path}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
#find all images and javascripts
|
21
|
+
doc.css('img,script').each do |link|
|
22
|
+
if add_link_to_checklist(link,"src").present?
|
23
|
+
links_to_check << {"link" => add_link_to_checklist(link,"src"), "pos" => link.path}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
links_to_check = links_to_check.compact.delete_if{|a| a.blank?}
|
27
|
+
links_to_check.each_with_index do |linkpos|
|
28
|
+
status_for_links[linkpos["link"]] = {"position" => linkpos["pos"]}
|
29
|
+
begin
|
30
|
+
start = Time.now
|
31
|
+
response = open(linkpos["link"])
|
32
|
+
status_for_links[linkpos["link"]]["response_code"] = response.status[0]
|
33
|
+
status_for_links[linkpos["link"]]["response_time"] = Time.now - start
|
34
|
+
rescue Exception => e
|
35
|
+
status_for_links[linkpos["link"]]["response_code"] = "404"
|
36
|
+
status_for_links[linkpos["link"]]["response_error"] = e.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@article.link_checker = status_for_links
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
private
|
44
|
+
#helper method for finding links in html document
|
45
|
+
def add_link_to_checklist(link, src_type)
|
46
|
+
begin
|
47
|
+
if link.blank? || link[src_type].blank?
|
48
|
+
return nil
|
49
|
+
elsif link[src_type][0 .. 6] == "http://" || link[src_type][0 .. 6] == "https:/"
|
50
|
+
return "#{link[src_type]}"
|
51
|
+
elsif link[src_type] && link[src_type][0 .. 1] == "//"
|
52
|
+
return "http:/#{link[src_type][/.(.*)/m,1]}"
|
53
|
+
elsif link[src_type] && link[src_type][0] == "/"
|
54
|
+
return "#{Goldencobra::Setting.absolute_base_url}/#{link[src_type][/.(.*)/m,1]}"
|
55
|
+
elsif link[src_type] && !link[src_type].include?("mailto:")
|
56
|
+
return "#{@article.absolute_public_url}/#{link[src_type]}"
|
57
|
+
end
|
58
|
+
rescue
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -61,7 +61,7 @@ module Goldencobra
|
|
61
61
|
|
62
62
|
def is_active?(request)
|
63
63
|
@is_active_result ||= {}
|
64
|
-
@is_active_result[request.path.squeeze("/").split("?")[0]] ||= request.path.squeeze("/").split("?")[0] == self.target.gsub("\"",'')
|
64
|
+
@is_active_result[request.path.squeeze("/").chomp("/").split("?")[0]] ||= request.path.squeeze("/").chomp("/").split("?")[0] == self.target.gsub("\"",'')
|
65
65
|
end
|
66
66
|
|
67
67
|
def has_active_child?(request, subtree_menues)
|
@@ -74,7 +74,9 @@ module Goldencobra
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def mapped_to_article?
|
77
|
-
|
77
|
+
#TODO Anfrage dauert zu lange bei 2000 Artikeln
|
78
|
+
#@mapped_to_article_result ||= Goldencobra::Article.select([:url_name, :startpage, :ancestry, :id]).map{|a| a.public_url}.uniq.include?(self.target)
|
79
|
+
false
|
78
80
|
end
|
79
81
|
|
80
82
|
end
|
@@ -9,6 +9,7 @@
|
|
9
9
|
# subject_class :string(255)
|
10
10
|
# subject_id :string(255)
|
11
11
|
# role_id :integer
|
12
|
+
# domain_id :integer
|
12
13
|
# created_at :datetime not null
|
13
14
|
# updated_at :datetime not null
|
14
15
|
# sorter_id :integer default(0)
|
@@ -16,8 +17,9 @@
|
|
16
17
|
|
17
18
|
module Goldencobra
|
18
19
|
class Permission < ActiveRecord::Base
|
19
|
-
attr_accessible :role_id, :action, :subject_class, :subject_id, :sorter_id
|
20
|
+
attr_accessible :role_id, :action, :subject_class, :subject_id, :sorter_id, :operator_id, :domain_id
|
20
21
|
belongs_to :role
|
22
|
+
belongs_to :domain
|
21
23
|
PossibleSubjectClasses = [":all"] + ActiveRecord::Base.descendants.map(&:name)
|
22
24
|
PossibleActions = ["read", "not_read", "manage", "not_manage", "update", "not_update", "destroy", "not_destroy"]
|
23
25
|
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Goldencobra
|
4
|
+
class Redirector < ActiveRecord::Base
|
5
|
+
attr_accessible :active, :redirection_code, :source_url, :target_url, :ignore_url_params, :include_subdirs, :import_csv_data
|
6
|
+
|
7
|
+
attr_accessor :import_csv_data
|
8
|
+
|
9
|
+
validates_presence_of :source_url, :if => proc { |obj| obj.import_csv_data.blank? }
|
10
|
+
validates_presence_of :target_url, :if => proc { |obj| obj.active == true && obj.import_csv_data.blank? }
|
11
|
+
|
12
|
+
validates_uniqueness_of :source_url
|
13
|
+
|
14
|
+
web_url :source_url, :target_url
|
15
|
+
|
16
|
+
scope :active, where(:active => true)
|
17
|
+
|
18
|
+
validate :check_csv_data
|
19
|
+
after_create :create_multiples_from_csv_data
|
20
|
+
|
21
|
+
# Creates multiple new Redirections based on 'import_csv_data'
|
22
|
+
# and deletes this single, new, invalid record afterwards
|
23
|
+
#
|
24
|
+
# @return [Goldencobra::Redirector]
|
25
|
+
def create_multiples_from_csv_data
|
26
|
+
if import_csv_data.present?
|
27
|
+
data = CSV.parse(import_csv_data, { :col_sep => "," })
|
28
|
+
Goldencobra::Redirector.transaction do
|
29
|
+
data.each do |row|
|
30
|
+
Goldencobra::Redirector.create(source_url: row[0].strip, target_url: row[1].strip, redirection_code: redirection_code, active: active, ignore_url_params: ignore_url_params )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
self.destroy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Validator wenn es csv Daten zum importierne gibt
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
def check_csv_data
|
41
|
+
if import_csv_data.present?
|
42
|
+
begin
|
43
|
+
all_source_urls = Goldencobra::Redirector.where(:active => true).pluck(:source_url)
|
44
|
+
data = CSV.parse(import_csv_data, { :col_sep => "," })
|
45
|
+
source_urls_from_data = data.map{|a| a[0].strip}
|
46
|
+
if source_urls_from_data.length != source_urls_from_data.uniq.length
|
47
|
+
errors.add(:import_csv_data, "Die CSV Daten enthalten mehrere Zeilen mit gleichen Source URLs<br>" )
|
48
|
+
end
|
49
|
+
data.each_with_index do |row, index|
|
50
|
+
if row.length != 2
|
51
|
+
errors.add(:import_csv_data, "Format der CSV Datei hat nicht 2 Spalten in Zeile #{index + 1}<br>" )
|
52
|
+
end
|
53
|
+
if all_source_urls.include?(row[0].strip)
|
54
|
+
errors.add(:import_csv_data, "Source URL in Zeile #{index + 1} existiert bereits<br>" )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
rescue
|
58
|
+
errors.add(:import_csv_data, "Die CSV Daten sind leider ungültig")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Returns a target url where to redirect of a given url
|
65
|
+
# @param request_original_url [String] SourceURl of Request
|
66
|
+
#
|
67
|
+
# @return [Array] target url to rewrite to | status code for redirection
|
68
|
+
def self.get_by_request(request_original_url)
|
69
|
+
begin
|
70
|
+
uri = URI.parse(request_original_url)
|
71
|
+
rescue
|
72
|
+
uri = nil
|
73
|
+
end
|
74
|
+
if uri.present?
|
75
|
+
uri_params = Rack::Utils.parse_nested_query(uri.query.to_s)
|
76
|
+
request_path = "#{uri.scheme}://#{uri.host}#{uri.path}%"
|
77
|
+
redirects = Goldencobra::Redirector.active.where("source_url LIKE ?", request_path)
|
78
|
+
if redirects.any?
|
79
|
+
#if multiple redirectors found, select the first
|
80
|
+
redirect = redirects.first
|
81
|
+
redirecter_source_uri = URI.parse(redirect.source_url)
|
82
|
+
if redirecter_source_uri.path == uri.path
|
83
|
+
#Wenn die url parameter egal sind
|
84
|
+
if redirect.ignore_url_params
|
85
|
+
return [redirect.rewrite_target_url(uri.query), redirect.redirection_code]
|
86
|
+
else
|
87
|
+
#wenn die urlparameter nicht egal sind und identisch sind
|
88
|
+
source_params = Rack::Utils.parse_nested_query(redirecter_source_uri.query.to_s)
|
89
|
+
if !source_params.map{|k,v| uri_params[k] == v}.include?(false)
|
90
|
+
return [redirect.rewrite_target_url(uri.query), redirect.redirection_code]
|
91
|
+
else
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
else
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
else
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# Helper Method for rewriting urls
|
106
|
+
# @param uri_params [String] foo=bar&test=12
|
107
|
+
#
|
108
|
+
# @return [String] TargetURl of given Redirector merged with source params
|
109
|
+
def rewrite_target_url(uri_params)
|
110
|
+
Goldencobra::Redirector.add_param_to_url(self.target_url, uri_params)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Add a url-params tu an url
|
114
|
+
# @param url [string] "http://www.test.de" || "http://www.test.de?test=a"
|
115
|
+
# @param uri_params [string] "foo=bar"
|
116
|
+
#
|
117
|
+
# @return [string] "http://www.test.de?test=a&foo=bar"
|
118
|
+
def self.add_param_to_url(url, uri_params)
|
119
|
+
target_uri = URI.parse(url)
|
120
|
+
target_params = Rack::Utils.parse_nested_query(target_uri.query.to_s)
|
121
|
+
request_params = Rack::Utils.parse_nested_query(uri_params)
|
122
|
+
merged_params = target_params.merge(request_params)
|
123
|
+
if merged_params.present?
|
124
|
+
return "#{target_uri.scheme}://#{target_uri.host}#{target_uri.path}?#{merged_params.to_param}"
|
125
|
+
else
|
126
|
+
return "#{target_uri.scheme}://#{target_uri.host}#{target_uri.path}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -15,6 +15,10 @@
|
|
15
15
|
|
16
16
|
module Goldencobra
|
17
17
|
class Setting < ActiveRecord::Base
|
18
|
+
|
19
|
+
# TODO cache invalidate über touch /temp/settings_updated.txt
|
20
|
+
|
21
|
+
|
18
22
|
@@key_value = {}
|
19
23
|
attr_accessible :title, :value, :ancestry, :parent_id, :data_type
|
20
24
|
SettingsDataTypes = ["string","date","datetime","boolean","array"]
|
@@ -50,14 +54,19 @@ module Goldencobra
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
53
|
-
|
57
|
+
# Goldencobra::Setting.for_key("test.foo.bar")
|
54
58
|
def self.for_key(name, cacheable=true)
|
55
|
-
|
59
|
+
@@mtime_setting ||= {}
|
60
|
+
mtime = get_cache_modification_time(name)
|
61
|
+
|
62
|
+
if cacheable && @@mtime_setting[name].present? && @@mtime_setting[name] >= mtime
|
56
63
|
@@key_value ||= {}
|
57
64
|
@@key_value[name] ||= for_key_helper(name)
|
58
65
|
else
|
66
|
+
@@mtime_setting[name] = mtime
|
59
67
|
for_key_helper(name)
|
60
68
|
end
|
69
|
+
|
61
70
|
end
|
62
71
|
|
63
72
|
def self.for_key_helper(name)
|
@@ -114,6 +123,10 @@ module Goldencobra
|
|
114
123
|
self.ancestors.map(&:title).join(".")
|
115
124
|
end
|
116
125
|
|
126
|
+
def path_name
|
127
|
+
self.path.map(&:title).join(".")
|
128
|
+
end
|
129
|
+
|
117
130
|
|
118
131
|
private
|
119
132
|
def self.generate_default_setting(key, yml_data, parent_id=nil)
|
@@ -162,7 +175,20 @@ module Goldencobra
|
|
162
175
|
end
|
163
176
|
|
164
177
|
def update_cache
|
165
|
-
@@key_value
|
178
|
+
@@key_value ||= {}
|
179
|
+
@@key_value[self.path_name] = nil
|
180
|
+
FileUtils.mkdir_p("tmp/settings")
|
181
|
+
FileUtils.touch("tmp/settings/updated_#{self.path_name}.txt")
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.get_cache_modification_time(name)
|
185
|
+
if File.exists?("tmp/settings/updated_#{name}.txt")
|
186
|
+
File.mtime("tmp/settings/updated_#{name}.txt")
|
187
|
+
else
|
188
|
+
FileUtils.mkdir_p("tmp/settings")
|
189
|
+
FileUtils.touch("tmp/settings/updated_#{name}.txt")
|
190
|
+
return Time.now
|
191
|
+
end
|
166
192
|
end
|
167
193
|
|
168
194
|
end
|