infopark_fiona_connector 7.0.1.beta2 → 7.0.1.5.2.3.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/cms_controller.rb +1 -1
  3. data/app/controllers/rails_connector/default_cms_controller.rb +4 -6
  4. data/app/helpers/cms_helper.rb +1 -1
  5. data/app/helpers/cms_routing_helper.rb +1 -1
  6. data/app/helpers/rails_connector/cms_asset_helper.rb +4 -5
  7. data/app/helpers/rails_connector/cms_tag_helper.rb +0 -3
  8. data/app/helpers/rails_connector/default_cms_helper.rb +0 -2
  9. data/app/helpers/rails_connector/default_cms_routing_helper.rb +15 -16
  10. data/app/helpers/rails_connector/display_helper.rb +31 -33
  11. data/app/helpers/rails_connector/editing_helper.rb +2 -8
  12. data/app/helpers/rails_connector/layout_helper.rb +2 -5
  13. data/app/helpers/rails_connector/marker_helper.rb +63 -64
  14. data/app/helpers/rails_connector/table_of_contents_helper.rb +1 -3
  15. data/config/cms_routes.rb +15 -15
  16. data/lib/gem_dependencies.rb +8 -7
  17. data/lib/generators/rails_connector/install/install_generator.rb +6 -6
  18. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +1 -1
  19. data/lib/infopark_fiona_connector.rb +7 -6
  20. data/lib/meta_eager_loader.rb +1 -0
  21. data/lib/rails_connector/attr_dict.rb +54 -31
  22. data/lib/rails_connector/attribute.rb +93 -0
  23. data/lib/rails_connector/authenticable.rb +12 -5
  24. data/lib/rails_connector/basic_obj.rb +126 -132
  25. data/lib/rails_connector/blob.rb +4 -5
  26. data/lib/rails_connector/blob_mapping.rb +15 -0
  27. data/lib/rails_connector/blob_mysql.rb +3 -5
  28. data/lib/rails_connector/blob_oracle.rb +5 -7
  29. data/lib/rails_connector/channel.rb +18 -0
  30. data/lib/rails_connector/cms_accessible.rb +21 -24
  31. data/lib/rails_connector/cms_base_model.rb +12 -4
  32. data/lib/rails_connector/cms_dispatch_controller.rb +9 -12
  33. data/lib/rails_connector/cms_env.rb +4 -7
  34. data/lib/rails_connector/cms_test_request.rb +1 -16
  35. data/lib/rails_connector/configuration.rb +14 -16
  36. data/lib/rails_connector/content.rb +7 -0
  37. data/lib/rails_connector/core_extensions/time.rb +3 -4
  38. data/lib/rails_connector/date_attribute.rb +2 -4
  39. data/lib/rails_connector/default_search_request.rb +1 -1
  40. data/lib/rails_connector/engine.rb +18 -17
  41. data/lib/rails_connector/errors.rb +2 -5
  42. data/lib/rails_connector/fiona_datetime.rb +14 -0
  43. data/lib/rails_connector/fiona_engine.rb +3 -4
  44. data/lib/rails_connector/html_string.rb +0 -2
  45. data/lib/rails_connector/job.rb +10 -0
  46. data/lib/rails_connector/link.rb +7 -4
  47. data/lib/rails_connector/link_list.rb +1 -5
  48. data/lib/rails_connector/link_resolvable.rb +1 -5
  49. data/lib/rails_connector/lucene_search_request.rb +20 -24
  50. data/lib/rails_connector/markdown_string.rb +0 -2
  51. data/lib/rails_connector/meta.rb +143 -0
  52. data/lib/rails_connector/meta/eager_loader.rb +84 -0
  53. data/lib/rails_connector/named_link.rb +25 -14
  54. data/lib/rails_connector/news.rb +8 -4
  55. data/lib/rails_connector/obj_class.rb +138 -0
  56. data/lib/rails_connector/obj_class_attr.rb +5 -0
  57. data/lib/rails_connector/object_with_meta_data.rb +13 -0
  58. data/lib/rails_connector/permission.rb +2 -6
  59. data/lib/rails_connector/rack_middlewares.rb +1 -2
  60. data/lib/rails_connector/ses.rb +3 -8
  61. data/lib/rails_connector/ses/verity_accessor.rb +43 -46
  62. data/lib/rails_connector/string_tagging.rb +0 -3
  63. data/lib/rails_connector/verity_search_request.rb +6 -9
  64. data/lib/search_request.rb +1 -1
  65. data/lib/version.rb +1 -1
  66. metadata +42 -30
@@ -0,0 +1,7 @@
1
+ module RailsConnector
2
+ # This class allows us to read out the editor of an Obj,
3
+ # if it has edited content
4
+ class Content < CmsBaseModel
5
+ self.primary_key = :content_id
6
+ end
7
+ end
@@ -1,10 +1,10 @@
1
1
  class Time
2
-
3
2
  # Returns a new Time created from the ISO date format String "YYYYMMDDhhmmss"
4
3
  def self.from_iso(t)
5
4
  return nil unless t
5
+
6
6
  if t.to_s =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
7
- utc($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i)
7
+ utc(Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i, Regexp.last_match(4).to_i, Regexp.last_match(5).to_i, Regexp.last_match(6).to_i)
8
8
  else
9
9
  raise ArgumentError, "invalid iso time format: #{t}"
10
10
  end
@@ -12,7 +12,6 @@ class Time
12
12
 
13
13
  # Returns the Time as ISO date format String "YYYYMMDDhhmmss"
14
14
  def to_iso
15
- getutc.strftime('%Y%m%d%H%M%S')
15
+ getutc.strftime("%Y%m%d%H%M%S")
16
16
  end
17
-
18
17
  end
@@ -1,11 +1,10 @@
1
1
  module RailsConnector
2
-
3
2
  # Adds support for string columns which contain ISO dates
4
3
  module DateAttribute
5
4
  module ClassMethods
6
5
  def date_attribute(*names)
7
6
  names.each do |name|
8
- module_eval %Q!
7
+ module_eval %!
9
8
  def #{name}
10
9
  DateAttribute.parse(#{name}_before_type_cast) unless #{name}_before_type_cast.nil?
11
10
  end
@@ -24,5 +23,4 @@ module RailsConnector
24
23
  raise "The value is not a valid ISO date time: #{iso_date_time.inspect}"
25
24
  end
26
25
  end
27
-
28
- end
26
+ end
@@ -3,4 +3,4 @@ module RailsConnector
3
3
  # It is used by {DefaultSearchController}.
4
4
  class DefaultSearchRequest < VeritySearchRequest
5
5
  end
6
- end
6
+ end
@@ -2,9 +2,9 @@ require "rails"
2
2
  require "active_record/railtie"
3
3
  require "action_view"
4
4
 
5
- require 'jquery-rails'
5
+ require "jquery-rails"
6
6
 
7
- require 'rails_connector/configuration'
7
+ require "rails_connector/configuration"
8
8
 
9
9
  module ::RailsConnector
10
10
  class Engine < Rails::Engine
@@ -12,21 +12,25 @@ module ::RailsConnector
12
12
  config.after_initialize { RailsConnector::Configuration.after_initialize }
13
13
 
14
14
  # make sure our exceptions cause an adequate error page and http status code
15
- config.action_dispatch.rescue_responses.merge!("RailsConnector::ResourceNotFound" => :not_found)
15
+ config.action_dispatch.rescue_responses["RailsConnector::ResourceNotFound"] = :not_found
16
16
 
17
- initializer "rails_connector.add_cms_routing_paths", :after => :add_routing_paths do |app|
18
- cms_route = File.expand_path("cms_routes.rb", paths['config'].to_a.first)
17
+ initializer "rails_connector.add_fiona_time_type" do
18
+ ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
19
+ end
20
+
21
+ initializer "rails_connector.add_cms_routing_paths", after: :add_routing_paths do |app|
22
+ cms_route = File.expand_path("cms_routes.rb", paths["config"].to_a.first)
19
23
  app.routes_reloader.paths.push(cms_route)
20
24
  end
21
25
 
22
26
  initializer "rails_connector.add_assets" do |app|
23
- app.config.assets.precompile += %w[
27
+ app.config.assets.precompile += %w(
24
28
  editmarker.css editmarker.js
25
- ]
29
+ )
26
30
  end
27
31
 
28
32
  # Expose rails connector runtime to controller for logging.
29
- initializer "rails_connector.log_runtime" do |app|
33
+ initializer "rails_connector.log_runtime" do |_app|
30
34
  runtime =
31
35
  begin
32
36
  RailsConnector::ControllerRuntime
@@ -42,23 +46,20 @@ module ::RailsConnector
42
46
  end
43
47
  end
44
48
 
45
- initializer "rails_connector.configure_database", :before => :load_config_initializers do |app|
49
+ initializer "rails_connector.configure_database", before: :load_config_initializers do |_app|
46
50
  RailsConnector::Configuration.configure_cms_database
47
51
  end
48
52
 
49
53
  initializer "rails_connector.routing_helpers" do
50
- if Rails.env == 'test'
51
- ActionDispatch::TestRequest.__send__(:include, RailsConnector::CmsTestRequest)
52
- end
54
+ ActionDispatch::TestRequest.include RailsConnector::CmsTestRequest if Rails.env == "test"
53
55
 
54
- ActionController::Base.__send__(:include, CmsRoutingHelper)
55
- ActionView::Base.__send__(:include, CmsRoutingHelper)
56
+ ActionController::Base.include CmsRoutingHelper
57
+ ActionView::Base.include CmsRoutingHelper
56
58
  end
57
59
 
58
- config.autoload_paths += paths['lib'].to_a
59
- config.autoload_once_paths += paths['lib'].to_a
60
+ config.autoload_paths += paths["lib"].to_a
61
+ config.autoload_once_paths += paths["lib"].to_a
60
62
 
61
63
  RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware }
62
64
  end
63
65
  end
64
-
@@ -1,9 +1,6 @@
1
1
  require "active_record/errors"
2
2
 
3
3
  module RailsConnector
4
-
5
- # @api public
6
- ResourceNotFound = ActiveRecord::RecordNotFound
7
-
4
+ # @api public
5
+ ResourceNotFound = ActiveRecord::RecordNotFound
8
6
  end # module RailsConnector
9
-
@@ -0,0 +1,14 @@
1
+ require "active_record/type"
2
+ class FionaDateTime < ActiveRecord::Type::Time
3
+ def type
4
+ :fiona_datetime
5
+ end
6
+
7
+ def serialize(value)
8
+ value&.to_iso
9
+ end
10
+
11
+ def deserialize(value)
12
+ Time.from_iso(value).in_time_zone if value
13
+ end
14
+ end
@@ -1,9 +1,8 @@
1
1
  module ::RailsConnector
2
2
  class FionaEngine < Rails::Engine
3
- initializer 'rails_connector.config_local', :after => :load_config_initializers,
4
- :before => :engines_blank_point do
5
- Dir[Rails.root + 'config/local/*.rb'].map &method(:require)
3
+ initializer "rails_connector.config_local", after: :load_config_initializers,
4
+ before: :engines_blank_point do
5
+ Dir[Rails.root + "config/local/*.rb"].map(&method(:require))
6
6
  end
7
7
  end
8
8
  end
9
-
@@ -1,5 +1,4 @@
1
1
  module RailsConnector
2
-
3
2
  # Include this module in order to tag the string as one with HTML content
4
3
  module HtmlString
5
4
  include LinkResolvable
@@ -8,7 +7,6 @@ module RailsConnector
8
7
  true
9
8
  end
10
9
  end
11
-
12
10
  end
13
11
 
14
12
  class String
@@ -0,0 +1,10 @@
1
+ module RailsConnector
2
+ # This class allows us to read out basic information about jobs
3
+ class Job < CmsBaseModel
4
+ self.primary_key = "job_id"
5
+
6
+ def self.table_name
7
+ "#{table_name_prefix}" "jobs"
8
+ end
9
+ end
10
+ end
@@ -3,7 +3,6 @@ module RailsConnector
3
3
  # To format a link for rendering in an html page, use the +cms_path+ or +cms_url+ methods.
4
4
  # @api public
5
5
  class Link
6
-
7
6
  extend ActiveModel::Naming
8
7
 
9
8
  def initialize(link_data, destination_object = nil)
@@ -67,7 +66,7 @@ module RailsConnector
67
66
  end
68
67
 
69
68
  def markdown?
70
- 'markdown' == @link_data[:source_format]
69
+ "markdown" == @link_data[:source_format]
71
70
  end
72
71
 
73
72
  # Returns the file extension (e.g. zip, pdf) of this link's (internal or external) target.
@@ -77,7 +76,11 @@ module RailsConnector
77
76
  if internal?
78
77
  destination_object ? destination_object.file_extension : ""
79
78
  else
80
- path = URI.parse(url).path rescue nil
79
+ path = begin
80
+ URI.parse(url).path
81
+ rescue StandardError
82
+ nil
83
+ end
81
84
  path.blank? ? "" : File.extname(path)[1..-1] || ""
82
85
  end
83
86
  end
@@ -115,7 +118,7 @@ module RailsConnector
115
118
  # An external Link is always active.
116
119
  # @api public
117
120
  def active?
118
- external? || (destination_object && destination_object.active?)
121
+ external? || destination_object&.active?
119
122
  end
120
123
 
121
124
  def external_prefix?
@@ -1,8 +1,6 @@
1
1
  module RailsConnector
2
-
3
2
  # @api public
4
3
  class LinkList < Array
5
-
6
4
  def initialize(link_definitions)
7
5
  if link_definitions.blank?
8
6
  super([])
@@ -13,7 +11,7 @@ module RailsConnector
13
11
 
14
12
  # @api public
15
13
  def destination_objects
16
- self.map {|link| link.destination_object}.compact
14
+ map { |link| link.destination_object }.compact
17
15
  end
18
16
 
19
17
  private
@@ -26,7 +24,5 @@ module RailsConnector
26
24
  links << link if link.active?
27
25
  end
28
26
  end
29
-
30
27
  end
31
-
32
28
  end
@@ -1,9 +1,5 @@
1
1
  module RailsConnector
2
-
3
2
  module LinkResolvable
4
3
  attr_accessor :source
5
-
6
4
  end
7
-
8
-
9
- end
5
+ end
@@ -1,7 +1,6 @@
1
- require 'rsolr'
1
+ require "rsolr"
2
2
 
3
3
  module RailsConnector
4
-
5
4
  # This class provides a basic implementation for accessing a Solr search server.
6
5
  # It can be activated by making it the superclass of SearchRequest
7
6
  # (instead of DefaultSearchRequest).
@@ -28,15 +27,15 @@ module RailsConnector
28
27
  #
29
28
  # Uses the #filter_query and +options+ given in #new.
30
29
  def fetch_hits
31
- solr = RSolr.connect(:url => @options[:solr_url])
32
- solr_result = solr.get("select", :params => solr_query_parameters)
33
- solr_response = solr_result['response']
34
- build_search_result(solr_response['numFound'], solr_response['docs'], solr_response['maxScore'])
30
+ solr = RSolr.connect(url: @options[:solr_url])
31
+ solr_result = solr.get("select", params: solr_query_parameters)
32
+ solr_response = solr_result["response"]
33
+ build_search_result(solr_response["numFound"], solr_response["docs"], solr_response["maxScore"])
35
34
  end
36
35
 
37
36
  # Removes unwanted characters from +text+.
38
37
  def self.sanitize(text)
39
- text.gsub(/[^\w\*]/, ' ').gsub(/\s+/, ' ').strip
38
+ text.gsub(/[^\w*]/, " ").gsub(/\s+/, " ").strip
40
39
  end
41
40
 
42
41
  def solr_query_for_query_string
@@ -65,8 +64,8 @@ module RailsConnector
65
64
  # end
66
65
  def filter_query_conditions
67
66
  conditions = {}
68
- conditions[:object_type] = 'NOT object_type:image'
69
- conditions[:suppress_export] = 'NOT suppress_export:1'
67
+ conditions[:object_type] = "NOT object_type:image"
68
+ conditions[:suppress_export] = "NOT suppress_export:1"
70
69
  now = Time.now
71
70
  conditions[:valid_from] = "NOT valid_from:[#{(now + 1.second).to_iso} TO *]"
72
71
  conditions[:valid_until] = "NOT valid_until:[* TO #{now.to_iso}]"
@@ -77,30 +76,27 @@ module RailsConnector
77
76
 
78
77
  def solr_query_parameters
79
78
  {
80
- :q => solr_query_for_query_string,
81
- :fq => filter_query,
82
- :fl => 'id,score',
83
- :start => @options[:offset],
84
- :rows => @options[:limit]
79
+ q: solr_query_for_query_string,
80
+ fq: filter_query,
81
+ fl: "id,score",
82
+ start: @options[:offset],
83
+ rows: @options[:limit]
85
84
  }.merge(@options[:solr_parameters] || {})
86
85
  end
87
86
 
88
87
  def build_search_result(total_hits, docs, max_score)
89
88
  result = SES::SearchResult.new(total_hits)
90
89
  docs.each do |doc|
91
- begin
92
- id = doc['id']
93
- score = doc['score'] / max_score
94
- hit = SES::Hit.new(id, score, doc)
95
- if @options[:lazy_load].blank? && hit.obj.blank?
96
- Rails.logger.warn("OBJ with ID ##{doc['id']} not found: This search result will not be shown")
97
- else
98
- result << hit
99
- end
90
+ id = doc["id"]
91
+ score = doc["score"] / max_score
92
+ hit = SES::Hit.new(id, score, doc)
93
+ if @options[:lazy_load].blank? && hit.obj.blank?
94
+ Rails.logger.warn("OBJ with ID ##{doc["id"]} not found: This search result will not be shown")
95
+ else
96
+ result << hit
100
97
  end
101
98
  end
102
99
  result
103
100
  end
104
101
  end
105
-
106
102
  end
@@ -1,5 +1,4 @@
1
1
  module RailsConnector
2
-
3
2
  # Include this module in order to tag the string as one with Markdown content
4
3
  module MarkdownString
5
4
  include LinkResolvable
@@ -8,7 +7,6 @@ module RailsConnector
8
7
  true
9
8
  end
10
9
  end
11
-
12
10
  end
13
11
 
14
12
  class String
@@ -0,0 +1,143 @@
1
+ module RailsConnector
2
+ module Meta
3
+ # This method is an equivalent of Rails.logger.silence, which has been deprecated
4
+ def self.hello_im_rails_and_im_retarted_so_please_be_patient
5
+ old_logger_level = Rails.logger.level
6
+ Rails.logger.level = Logger::ERROR
7
+ yield self
8
+ ensure
9
+ Rails.logger.level = old_logger_level
10
+ end
11
+
12
+ def self.included(base) #:nodoc:
13
+ # Class enhancements
14
+ base.extend(ClassMethods)
15
+ end
16
+
17
+ # The RailsConnector::ObjClass object for this file format.
18
+ # This will always return a proper object, even if no custom
19
+ # Ruby class exists.
20
+ def obj_class_definition
21
+ @obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class)
22
+ end
23
+ alias_method :obj_class_def, :obj_class_definition
24
+
25
+ # Returns true, if there is a custom Ruby class defined for the object
26
+ # or false, if it is represented by RailsConnector::Obj
27
+ def has_custom_ruby_class?
28
+ self.class.is_custom_ruby_class?
29
+ end
30
+
31
+ # Returns the custom attributes in the form of a Hash.
32
+ def custom_attributes
33
+ obj_class_definition.custom_attributes
34
+ end
35
+
36
+ # Returns true, if the file format has an attribute of the given name.
37
+ def custom_attribute?(attr)
38
+ obj_class_definition.custom_attribute?(attr)
39
+ end
40
+
41
+ # Returns an Array of String of all mandatory attributes, no mather if it's
42
+ # custom or built-in. Built-in attributes are underscored (valid_from,
43
+ # not validFrom).
44
+ # Possible +options+ are:
45
+ # <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
46
+ # built-in attributes like content_type or valid_from.
47
+ def mandatory_attribute_names(options = {})
48
+ obj_class_definition.mandatory_attribute_names(options)
49
+ end
50
+
51
+ # Returns true, if the file format has an mandatory attribute of the given name.
52
+ def mandatory_attribute?(attr)
53
+ obj_class_definition.mandatory_attribute?(attr)
54
+ end
55
+
56
+ # Returns the version of this object. This number is increased every time
57
+ # this object is released.
58
+ def version
59
+ load_meta_details
60
+ @object_with_meta_data.version.presence.to_i || 0
61
+ end
62
+
63
+ # Returns the time of the reminder, if it is set.
64
+ def reminder_from
65
+ load_meta_details
66
+ @object_with_meta_data.reminder_from.presence &&
67
+ ::ActiveModel::Type::DateTime.new.deserialize(@object_with_meta_data.reminder_from)
68
+ end
69
+
70
+ # Returns the reminder comment, if a reminder is set.
71
+ def reminder_comment
72
+ load_meta_details
73
+ @object_with_meta_data.reminder_comment
74
+ end
75
+
76
+ # Return the name of the workflow, that is assigned to this object.
77
+ def workflow_name
78
+ load_meta_details
79
+ @object_with_meta_data.workflow_name
80
+ end
81
+
82
+ # Return the current editor as a String. If there is no edited content,
83
+ # which is always the case in live mode, an empty String is returned.
84
+ # The 'contents' table is queried for this information.
85
+ def editor
86
+ return @editor if @editor
87
+
88
+ load_meta_details
89
+
90
+ content_id =
91
+ if edited?
92
+ @object_with_meta_data.edited_content_id
93
+ else
94
+ @object_with_meta_data.released_cont_id
95
+ end
96
+
97
+ if content_id
98
+ content = RailsConnector::Content.find(content_id)
99
+ @editor = content.editor
100
+ else
101
+ @editor = ""
102
+ end
103
+ end
104
+
105
+ def committed?
106
+ load_meta_details
107
+ !@object_with_meta_data.committed_cont_id.nil?
108
+ end
109
+
110
+ private
111
+
112
+ # Load the objects details from the `objects' tables.
113
+ def load_meta_details #:nodoc:
114
+ return if @object_with_meta_data
115
+
116
+ @object_with_meta_data = RailsConnector::ObjectWithMetaData.find(id)
117
+
118
+ # reset depending instance variables
119
+ @editor = nil
120
+ end
121
+
122
+ # the methods in this module will become class methods
123
+ module ClassMethods
124
+ # The RailsConnector::ObjClass object for this file format.
125
+ # This will only return a proper object if a custom Ruby class exists
126
+ # and will throw a RuntimeError otherwise.
127
+ def obj_class_definition
128
+ unless is_custom_ruby_class?
129
+ raise "Obtaining the obj_class_definition of an Obj without custom Ruby class " \
130
+ "is logically impossible."
131
+ end
132
+ @obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(name)
133
+ end
134
+ alias_method :obj_class_def, :obj_class_definition
135
+
136
+ # RailsConnector::AbstractObj returns false, everything else true.
137
+ # TODO: RailsConnector::AbstractObj does not exist here
138
+ def is_custom_ruby_class?
139
+ self != RailsConnector::BasicObj
140
+ end
141
+ end
142
+ end
143
+ end