infopark_fiona7 0.30.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/Rakefile +21 -0
- data/app/assets/images/fiona7-logo.png +0 -0
- data/app/assets/images/fiona7-marker.png +0 -0
- data/app/assets/javascripts/fiona7.js +284 -0
- data/app/assets/stylesheets/fiona7-login.css.scss +15 -0
- data/app/assets/stylesheets/fiona7.css.scss +83 -0
- data/app/controllers/fiona7/blobs_controller.rb +35 -0
- data/app/controllers/fiona7/default_scrivito_cms_controller.rb +16 -0
- data/app/controllers/fiona7/release_controller.rb +24 -0
- data/app/controllers/fiona7/sessions_controller.rb +49 -0
- data/app/controllers/fiona7_login_page_controller.rb +27 -0
- data/app/helpers/fiona7_login_helper.rb +18 -0
- data/app/helpers/fiona7_override_helper.rb +47 -0
- data/app/models/fiona7/edited_obj.rb +15 -0
- data/app/models/fiona7/internal_released_obj.rb +18 -0
- data/app/models/fiona7/released_obj.rb +18 -0
- data/app/models/fiona7/write_obj.rb +63 -0
- data/app/models/fiona7_login_page.rb +5 -0
- data/app/models/x_container.rb +5 -0
- data/app/models/x_generic.rb +5 -0
- data/app/models/x_image.rb +5 -0
- data/app/views/fiona7_login_page/index.html.erb +14 -0
- data/app/views/layouts/fiona7_login_page_layout.html.erb +23 -0
- data/config/locales/login.yml +19 -0
- data/config/locales/permissions.yml +7 -0
- data/config/routes.rb +9 -0
- data/lib/fiona7/assert.rb +17 -0
- data/lib/fiona7/builder/batch_widget_writer.rb +107 -0
- data/lib/fiona7/builder/obj_builder.rb +297 -0
- data/lib/fiona7/builder/obj_class_builder.rb +111 -0
- data/lib/fiona7/builder/obj_class_updater.rb +69 -0
- data/lib/fiona7/builder/obj_updater.rb +25 -0
- data/lib/fiona7/builder/widget_builder.rb +13 -0
- data/lib/fiona7/builder/widget_building.rb +35 -0
- data/lib/fiona7/builder/widget_updater.rb +13 -0
- data/lib/fiona7/controllers/content_service/obj_controller.rb +125 -0
- data/lib/fiona7/controllers/content_service/workspace_controller.rb +19 -0
- data/lib/fiona7/controllers/rest_api/blob_controller.rb +11 -0
- data/lib/fiona7/controllers/rest_api/obj_class_controller.rb +39 -0
- data/lib/fiona7/controllers/rest_api/obj_controller.rb +175 -0
- data/lib/fiona7/controllers/rest_api/workspace_controller.rb +58 -0
- data/lib/fiona7/engine.rb +138 -0
- data/lib/fiona7/fiona_connector_patches/basic_obj.rb +9 -0
- data/lib/fiona7/initializer.rb +78 -0
- data/lib/fiona7/json/obj_class_decorator.rb +45 -0
- data/lib/fiona7/json/obj_decorator.rb +153 -0
- data/lib/fiona7/json/typeless_obj_decorator.rb +30 -0
- data/lib/fiona7/json/widget_decorator.rb +18 -0
- data/lib/fiona7/link_converter/fiona_to_scrivito.rb +37 -0
- data/lib/fiona7/link_converter/scrivito_to_fiona.rb +42 -0
- data/lib/fiona7/mode_switch.rb +7 -0
- data/lib/fiona7/mode_switch/abstract_mode_switch.rb +19 -0
- data/lib/fiona7/mode_switch/cms_routes.rb +33 -0
- data/lib/fiona7/mode_switch/cms_routes/fiona_connector.rb +17 -0
- data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk.rb +20 -0
- data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk_slave.rb +20 -0
- data/lib/fiona7/mode_switch/composite.rb +33 -0
- data/lib/fiona7/mode_switch/constants.rb +86 -0
- data/lib/fiona7/mode_switch/views.rb +37 -0
- data/lib/fiona7/naive_search_engine.rb +111 -0
- data/lib/fiona7/recursive_link_resolver.rb +93 -0
- data/lib/fiona7/routers/content_service.rb +19 -0
- data/lib/fiona7/routers/rest_api.rb +135 -0
- data/lib/fiona7/routing_monkey_patch.rb +33 -0
- data/lib/fiona7/scrivito_patches/attribute_content.rb +19 -0
- data/lib/fiona7/scrivito_patches/basic_obj.rb +92 -0
- data/lib/fiona7/scrivito_patches/basic_widget.rb +14 -0
- data/lib/fiona7/scrivito_patches/binary.rb +55 -0
- data/lib/fiona7/scrivito_patches/client_config.rb +19 -0
- data/lib/fiona7/scrivito_patches/cms_dispatch_controller.rb +31 -0
- data/lib/fiona7/scrivito_patches/cms_rest_api.rb +11 -0
- data/lib/fiona7/scrivito_patches/cms_routing.rb +66 -0
- data/lib/fiona7/scrivito_patches/controller_actions.rb +14 -0
- data/lib/fiona7/scrivito_patches/link_parser.rb +22 -0
- data/lib/fiona7/scrivito_patches/migrator.rb +13 -0
- data/lib/fiona7/scrivito_patches/obj_class.rb +16 -0
- data/lib/fiona7/scrivito_patches/type_computer.rb +25 -0
- data/lib/fiona7/scrivito_patches/workspace.rb +12 -0
- data/lib/fiona7/scrivito_user.rb +44 -0
- data/lib/fiona7/search_engine.rb +20 -0
- data/lib/fiona7/type_register.rb +140 -0
- data/lib/fiona7/type_register_mixin.rb +9 -0
- data/lib/fiona7/version.rb +3 -0
- data/lib/fiona7/version_helper.rb +84 -0
- data/lib/fiona7/widget_resolver.rb +37 -0
- data/lib/fiona7/workspace.rb +76 -0
- data/lib/infopark_fiona7.rb +4 -0
- data/lib/tasks/fiona7_tasks.rake +13 -0
- metadata +216 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
module Fiona7
|
2
|
+
class RecursiveLinkResolver
|
3
|
+
attr_reader :id_map, :path_map
|
4
|
+
|
5
|
+
def initialize(klass)
|
6
|
+
@processed_ids = Set[]
|
7
|
+
@id_map = {}
|
8
|
+
@path_map = {}
|
9
|
+
@klass = klass
|
10
|
+
end
|
11
|
+
|
12
|
+
def resolve(obj)
|
13
|
+
resolve_recursive([obj])
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def resolve_recursive(remaining_objects)
|
18
|
+
return if remaining_objects.empty?
|
19
|
+
return resolve_recursive(process_objects(remaining_objects))
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def process_objects(objects)
|
24
|
+
found_objects = []
|
25
|
+
|
26
|
+
widget_id_to_obj_id_map = {}
|
27
|
+
|
28
|
+
objects.each do |object|
|
29
|
+
widget_id_to_obj_id_map.merge!(widget_id_to_obj_id_map_from_object(object))
|
30
|
+
end
|
31
|
+
|
32
|
+
@processed_ids.merge(objects.map(&:id))
|
33
|
+
|
34
|
+
unprocessed_object_ids = filter_unprocessed_ids(widget_id_to_obj_id_map.values)
|
35
|
+
if !unprocessed_object_ids.empty?
|
36
|
+
found_objects = @klass.find(unprocessed_object_ids)
|
37
|
+
|
38
|
+
id_object_map = create_id_object_map(found_objects)
|
39
|
+
|
40
|
+
widget_id_to_obj_id_map.each do |widget_id, obj_id|
|
41
|
+
if fetched_object = id_object_map[obj_id]
|
42
|
+
@id_map[widget_id] = fetched_object.id
|
43
|
+
@path_map[widget_id] = fetched_object.path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
found_objects
|
49
|
+
end
|
50
|
+
|
51
|
+
def widget_id_to_obj_id_map_from_object(object)
|
52
|
+
widget_id_to_obj_id_map = {}
|
53
|
+
|
54
|
+
object.attr_values.each do |_, value|
|
55
|
+
links_from_attribute = gather_links(value)
|
56
|
+
widget_id_to_obj_id_map.merge!(links_from_attribute)
|
57
|
+
end
|
58
|
+
|
59
|
+
widget_id_to_obj_id_map
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def gather_links(attribute_value)
|
64
|
+
links = {}
|
65
|
+
|
66
|
+
if attribute_value.kind_of?(Array) && !attribute_value.empty? && attribute_value.all? {|c| c.kind_of?(Hash)}
|
67
|
+
attribute_value.each do |link|
|
68
|
+
if (title = link['title'].presence) && (id = link['destination'].to_i) != 0
|
69
|
+
links[title] = id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
links
|
75
|
+
end
|
76
|
+
|
77
|
+
def filter_unprocessed_ids(object_ids)
|
78
|
+
unprocessed_ids = []
|
79
|
+
object_ids.each do |object_id|
|
80
|
+
unprocessed_ids << object_id unless @processed_ids.include?(object_id)
|
81
|
+
end
|
82
|
+
unprocessed_ids
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_id_object_map(objects)
|
86
|
+
id_object_map = {}
|
87
|
+
objects.each do |object|
|
88
|
+
id_object_map[object.id] = object
|
89
|
+
end
|
90
|
+
id_object_map
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "fiona7/controllers/content_service/obj_controller"
|
2
|
+
require "fiona7/controllers/content_service/workspace_controller"
|
3
|
+
|
4
|
+
class Scrivito::ContentService
|
5
|
+
class << self
|
6
|
+
alias_method :original_query, :query
|
7
|
+
def query(path, payload, options={})
|
8
|
+
#$stdout.puts "DEBUG CS GET: #{path} < #{payload.inspect} >"
|
9
|
+
case path
|
10
|
+
when /\Aworkspaces\/query/
|
11
|
+
Fiona7::Controllers::ContentService::WorkspaceController.new.fetch(payload)
|
12
|
+
when /\Aobjs\/query/
|
13
|
+
Fiona7::Controllers::ContentService::ObjController.new.fetch_multiple(payload)
|
14
|
+
else
|
15
|
+
original_query(path, payload, options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "fiona7/controllers/rest_api/obj_class_controller"
|
2
|
+
require "fiona7/controllers/rest_api/obj_controller"
|
3
|
+
require "fiona7/controllers/rest_api/blob_controller"
|
4
|
+
require "fiona7/controllers/rest_api/workspace_controller"
|
5
|
+
|
6
|
+
class Scrivito::CmsRestApi
|
7
|
+
class << self
|
8
|
+
alias_method :original_task_unaware_request, :task_unaware_request
|
9
|
+
def task_unaware_request(method, resource_path, payload = nil)
|
10
|
+
raise "Unexpected method #{method}" unless [:delete, :get, :post, :put].include?(method)
|
11
|
+
self.send(method, resource_path, payload)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :original_get, :get
|
15
|
+
def get(resource_path, payload = nil, options = nil)
|
16
|
+
@number_of_requests += 1 if resource_path == @count_requests
|
17
|
+
|
18
|
+
if !resource_path.start_with?('/')
|
19
|
+
resource_path = '/' + resource_path
|
20
|
+
end
|
21
|
+
|
22
|
+
#$stdout.puts "DEBUG GET: #{resource_path}"
|
23
|
+
case resource_path
|
24
|
+
when /\A\/?revisions\/[a-zA-Z0-9_-]+\/obj_classes\Z/, /\A\/?workspaces\/[a-zA-Z0-9_-]+\/obj_classes\Z/
|
25
|
+
Fiona7::Controllers::RestAPI::ObjClassController.new.all
|
26
|
+
when /\A\/?revisions\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/
|
27
|
+
_, _, revision_id, _, obj_id = *resource_path.split("/")
|
28
|
+
Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id_from_revision(revision_id, obj_id)
|
29
|
+
when /\A\/?workspaces\Z/
|
30
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.all
|
31
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/find_by_path/
|
32
|
+
_, _, workspace_id = *resource_path.split("/")
|
33
|
+
path = resource_path.match(/path=(.*)\Z/)[1]
|
34
|
+
Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_path(workspace_id, path)
|
35
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/search/
|
36
|
+
_, _, workspace_id = *resource_path.split("/")
|
37
|
+
Fiona7::Controllers::RestAPI::ObjController.new.search(workspace_id, payload)
|
38
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/obj_classes\/[a-zA-z0-9_-]+\Z/
|
39
|
+
_, _, workspace_id, _, obj_class_name = *resource_path.split("/")
|
40
|
+
Fiona7::Controllers::RestAPI::ObjClassController.new.fetch(workspace_id, obj_class_name)
|
41
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\Z/
|
42
|
+
_, _, workspace_id = *resource_path.split("/")
|
43
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.fetch(workspace_id)
|
44
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/
|
45
|
+
_, _, workspace_id, _, obj_id = *resource_path.split("/")
|
46
|
+
Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id(workspace_id, obj_id)
|
47
|
+
when /\A\/?blobs\/[a-zA-Z0-9_-]+\Z/
|
48
|
+
_, _, blob_id = *resource_path.split("/")
|
49
|
+
Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id)
|
50
|
+
else
|
51
|
+
#$stdout.puts "GET: #{resource_path}"
|
52
|
+
original_get(resource_path, payload, options)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :original_delete, :delete
|
57
|
+
def delete(resource_path, payload = nil, options = nil)
|
58
|
+
@number_of_requests += 1 if resource_path == @count_requests
|
59
|
+
|
60
|
+
if !resource_path.start_with?('/')
|
61
|
+
resource_path = '/' + resource_path
|
62
|
+
end
|
63
|
+
|
64
|
+
case resource_path
|
65
|
+
when /\A\/?workspaces\Z/
|
66
|
+
true
|
67
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\Z/
|
68
|
+
raise Scrivito::ScrivitoError, 'Delete operation unsupported for workspaces'
|
69
|
+
_, _, workspace_id = *resource_path.split("/")
|
70
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.delete(workspace_id)
|
71
|
+
when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/
|
72
|
+
_, _, workspace_id, _, obj_id = *resource_path.split("/")
|
73
|
+
Fiona7::Controllers::RestAPI::ObjController.new.destroy(workspace_id, obj_id)
|
74
|
+
else
|
75
|
+
#$stdout.puts "DELETE: #{resource_path}"
|
76
|
+
original_delete(resource_path, payload, options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
alias_method :original_post, :post
|
81
|
+
def post(resource_path, payload, options = nil)
|
82
|
+
@number_of_requests += 1 if resource_path == @count_requests
|
83
|
+
|
84
|
+
if !resource_path.start_with?('/')
|
85
|
+
resource_path = '/' + resource_path
|
86
|
+
end
|
87
|
+
|
88
|
+
#$stdout.puts "DEBUG POST: #{resource_path}"
|
89
|
+
case resource_path
|
90
|
+
when /\A\/?workspaces\Z/
|
91
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.create(payload)
|
92
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/obj_classes/
|
93
|
+
_, _, workspace_id = *resource_path.split("/")
|
94
|
+
Fiona7::Controllers::RestAPI::ObjClassController.new.create(workspace_id, payload)
|
95
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/objs/
|
96
|
+
_, _, workspace_id = *resource_path.split("/")
|
97
|
+
Fiona7::Controllers::RestAPI::ObjController.new.create(workspace_id, payload)
|
98
|
+
else
|
99
|
+
#$stdout.puts "POST: #{resource_path}"
|
100
|
+
original_post(resource_path, payload, options)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
alias_method :original_put, :put
|
105
|
+
def put(resource_path, payload, options = nil)
|
106
|
+
@number_of_requests += 1 if resource_path == @count_requests
|
107
|
+
|
108
|
+
if !resource_path.start_with?('/')
|
109
|
+
resource_path = '/' + resource_path
|
110
|
+
end
|
111
|
+
|
112
|
+
#$stdout.puts "DEBUG PUT: #{resource_path}"
|
113
|
+
case resource_path
|
114
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/objs\/[a-zA-Z0-9]+\Z/
|
115
|
+
_, _, workspace_id, _, obj_id = *resource_path.split("/")
|
116
|
+
payload[:obj][:_id] = obj_id
|
117
|
+
Fiona7::Controllers::RestAPI::ObjController.new.update(workspace_id, payload)
|
118
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/obj_classes\/[a-zA-z0-9_-]+\Z/
|
119
|
+
_, _, workspace_id, _, obj_class_name = *resource_path.split("/")
|
120
|
+
payload[:obj_class][:name] = obj_class_name
|
121
|
+
Fiona7::Controllers::RestAPI::ObjClassController.new.update(workspace_id, payload)
|
122
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/publish/
|
123
|
+
_, _, workspace_id = *resource_path.split("/")
|
124
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.publish(workspace_id)
|
125
|
+
when /\A\/?workspaces\/[a-zA-Z0-9]+\/rebase/
|
126
|
+
raise Scrivito::ScrivitoError, 'Rebase operation unsupported for workspaces'
|
127
|
+
_, _, workspace_id = *resource_path.split("/")
|
128
|
+
Fiona7::Controllers::RestAPI::WorkspaceController.new.publish(workspace_id)
|
129
|
+
else
|
130
|
+
#$stdout.puts "PUT: #{resource_path}"
|
131
|
+
original_put(resource_path, payload, options)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
module Routing
|
3
|
+
class RouteSet #:nodoc:
|
4
|
+
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
|
5
|
+
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
|
6
|
+
|
7
|
+
forbidden_paths = [::File.join(Gem.loaded_specs['scrivito_sdk'].full_gem_path, "config/cms_routes.rb"),
|
8
|
+
::File.join(Gem.loaded_specs['infopark_fiona_connector'].full_gem_path, "config/cms_routes.rb")]
|
9
|
+
|
10
|
+
if caller.any? {|path| forbidden_paths.any? {|fp| path.include?(fp) } }
|
11
|
+
return # bad dog scrivito/fiona_connector, bad dog! no cms_routes for you
|
12
|
+
end
|
13
|
+
|
14
|
+
if name && named_routes[name]
|
15
|
+
|
16
|
+
raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \
|
17
|
+
"You may have defined two routes with the same name using the `:as` option, or " \
|
18
|
+
"you may be overriding a route already defined by a resource with the same naming. " \
|
19
|
+
"For the latter, you can restrict the routes created with `resources` as explained here: \n" \
|
20
|
+
"http://guides.rubyonrails.org/routing.html#restricting-the-routes-created"
|
21
|
+
end
|
22
|
+
|
23
|
+
path = build_path(conditions.delete(:path_info), requirements, SEPARATORS, anchor)
|
24
|
+
conditions = build_conditions(conditions, path.names.map { |x| x.to_sym })
|
25
|
+
|
26
|
+
route = @set.add_route(app, path, conditions, defaults, name)
|
27
|
+
named_routes[name] = route if name
|
28
|
+
route
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'scrivito/attribute_content'
|
2
|
+
|
3
|
+
module Scrivito
|
4
|
+
module AttributeContent
|
5
|
+
module ClassMethods
|
6
|
+
# This is new. It returns the obj class name for given subclass of BasicObj or nil
|
7
|
+
def obj_class_name
|
8
|
+
self.name.split('::').last if self != Obj && self != ::Obj
|
9
|
+
end
|
10
|
+
|
11
|
+
# Patch to work-around Scrivito::... classes in legacy mode
|
12
|
+
def with_default_obj_class(attributes)
|
13
|
+
return attributes if attributes[:_obj_class] || attributes["_obj_class"]
|
14
|
+
return attributes if type_computer.special_class?(self)
|
15
|
+
attributes.merge("_obj_class" => self.obj_class_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'scrivito/basic_obj'
|
2
|
+
|
3
|
+
module Scrivito
|
4
|
+
class BasicObj
|
5
|
+
# Type computer computes with global Obj by default
|
6
|
+
# which in legacy mode belongs to fiona_connector
|
7
|
+
# Therefore we limit the scope of the search to Scrivito::Obj
|
8
|
+
def self.type_computer
|
9
|
+
@_type_computer ||= TypeComputer.new(Scrivito::BasicObj, Obj)
|
10
|
+
end
|
11
|
+
|
12
|
+
# to_param should only return strings and our ids are numbers
|
13
|
+
def to_param
|
14
|
+
id.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
# Originally this method checks for conflicts
|
18
|
+
# which are impossible here, hence the method is stubbed out
|
19
|
+
def publishable?
|
20
|
+
# TODO: implement CM validations here
|
21
|
+
# FIXME: this can be solved much faster in PublishChecker
|
22
|
+
self.id && Fiona7::EditedObj.find(self.id).permission.release?
|
23
|
+
end
|
24
|
+
|
25
|
+
# Original implentation reads file extension from name
|
26
|
+
# but since dots are not allowed in the names
|
27
|
+
# it has to be worked around.
|
28
|
+
def file_extension
|
29
|
+
if (blob = find_blob)
|
30
|
+
blob.file_extension
|
31
|
+
else
|
32
|
+
""
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fiona_obj
|
37
|
+
@fiona_obj ||= ::RailsConnector::BasicObj.find(self.id)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Patch to allow reverting in rtc workspace
|
41
|
+
def assert_revertable
|
42
|
+
if workspace.id != 'rtc'
|
43
|
+
raise ScrivitoError, "cannot revert changes, since obj is not from valid revertable workspace."
|
44
|
+
end
|
45
|
+
if modification == Modification::NEW || modification == Modification::DELETED
|
46
|
+
raise ScrivitoError, "cannot revert changes, since obj is #{modification}."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# This method may be called like this: image_tag(obj) in a view
|
51
|
+
# which is fundamentally broken. image_tag(scrivito_path(obj))
|
52
|
+
# should be called instead.
|
53
|
+
def body_data_url
|
54
|
+
if binary? && read_attribute('blob')
|
55
|
+
raise "This method is not supported by Fiona7 and should not be called, try using Scrivito::Binary#content or scrivito_url(obj) when appropriate"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Originally this method refers to the global Obj via ::Obj
|
60
|
+
def self.where(field, operator, value, boost = nil)
|
61
|
+
assert_not_basic_obj('.where')
|
62
|
+
if self == Obj || self == ::Obj
|
63
|
+
Workspace.current.objs.where(field, operator, value, boost)
|
64
|
+
else
|
65
|
+
assert_has_obj_class('.where')
|
66
|
+
Workspace.current.objs.where(:_obj_class, :equals, obj_class_name)
|
67
|
+
.and(field, operator, value, boost)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Originally this method refers to the global Obj via ::Obj
|
72
|
+
def self.all
|
73
|
+
assert_not_basic_obj('.all')
|
74
|
+
if self == Obj || self == ::Obj
|
75
|
+
Workspace.current.objs.all
|
76
|
+
else
|
77
|
+
assert_has_obj_class('.all')
|
78
|
+
find_all_by_obj_class(obj_class_name)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class << self
|
83
|
+
|
84
|
+
def assert_has_obj_class(method_name)
|
85
|
+
unless Workspace.current.obj_classes[obj_class_name].present?
|
86
|
+
raise ScrivitoError, "#{name} has no corresponding ObjClass."
|
87
|
+
+ " Please use Obj.#{method_name} instead."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'scrivito/binary'
|
2
|
+
|
3
|
+
module Scrivito
|
4
|
+
# This class had been reworked to support uploads directly
|
5
|
+
# into CMS and not into S3
|
6
|
+
class Binary
|
7
|
+
# new implementation
|
8
|
+
def content_type
|
9
|
+
if shadow_obj
|
10
|
+
shadow_obj.mime_type
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def content_length
|
15
|
+
if shadow_obj
|
16
|
+
shadow_obj.body_length
|
17
|
+
else
|
18
|
+
0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def filename
|
23
|
+
if shadow_obj
|
24
|
+
shadow_obj.name + '.' + shadow_obj.file_extension
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# New API call. Allows to read the extension of the stored file.
|
29
|
+
def file_extension
|
30
|
+
if shadow_obj
|
31
|
+
shadow_obj.file_extension
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# New API call. Allows to access the contents of the blob.
|
36
|
+
def content
|
37
|
+
if shadow_obj
|
38
|
+
shadow_obj.body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def url
|
43
|
+
ActiveSupport::Deprecation.warn("This method should never be called. Use scrivito_path or scrvito_url whenever possible")
|
44
|
+
if shadow_obj
|
45
|
+
Rails.application.routes.url_helpers.fiona7_blob_path(id: @id, name: self.filename)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def shadow_obj
|
51
|
+
@shadow_obj ||= Fiona7::InternalReleasedObj.find(@id.to_i) if @id.to_i != 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|