infopark_reactor 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +165 -0
- data/README.md +142 -0
- data/Rakefile +25 -0
- data/app/controllers/reactor_controller.rb +53 -0
- data/config/routes.rb +6 -0
- data/infopark_reactor.gemspec +30 -0
- data/lib/engine.rb +35 -0
- data/lib/infopark_reactor.rb +38 -0
- data/lib/reactor/already_released.rb +3 -0
- data/lib/reactor/attributes.rb +365 -0
- data/lib/reactor/attributes/date_serializer.rb +35 -0
- data/lib/reactor/attributes/html_serializer.rb +31 -0
- data/lib/reactor/attributes/link_list_extender.rb +50 -0
- data/lib/reactor/attributes/link_list_serializer.rb +27 -0
- data/lib/reactor/cache/permission.rb +36 -0
- data/lib/reactor/cache/user.rb +37 -0
- data/lib/reactor/legacy.rb +60 -0
- data/lib/reactor/link/external.rb +19 -0
- data/lib/reactor/link/internal.rb +19 -0
- data/lib/reactor/link/temporary_link.rb +43 -0
- data/lib/reactor/no_working_version.rb +1 -0
- data/lib/reactor/not_permitted.rb +1 -0
- data/lib/reactor/permission.rb +262 -0
- data/lib/reactor/persistence.rb +473 -0
- data/lib/reactor/rc_independent.rb +13 -0
- data/lib/reactor/session.rb +48 -0
- data/lib/reactor/session/observers.rb +32 -0
- data/lib/reactor/session/user.rb +22 -0
- data/lib/reactor/streaming_upload.rb +22 -0
- data/lib/reactor/sudo.rb +11 -0
- data/lib/reactor/support/link_matcher.rb +44 -0
- data/lib/reactor/tools/workflow_generator.rb +195 -0
- data/lib/reactor/validations.rb +55 -0
- data/lib/reactor/version.rb +3 -0
- data/lib/reactor/workflow.rb +19 -0
- data/lib/reactor/workflow/empty.rb +27 -0
- data/lib/reactor/workflow/standard.rb +34 -0
- metadata +204 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
REACTOR
|
2
|
+
=======
|
3
|
+
|
4
|
+
RailsConnector EnhAnCements for TCL lOveRs. You all love RailsConnector. I know you do. It delivers nice features and great performance. And yet... An yet you always knew that something is missing. You had this feeling when writing TCL code. You had this feeling when fiddling in Fiona GUI. Yes. You know it. You are a Rails coder: `BeatufiulPage.create(:name => 'Better page', :parent => '/best/pages', :title => 'Yes, it is better')`. Write layer is missing in RailsConnector. And it shows.
|
5
|
+
|
6
|
+
So, here you have it: REACTOR, writing layer for `RailsConnector`, tightly integrated with `ActiveRecord`. Maybe some of you don't like long and creative descriptions. Maybe some of you are convinced with running code:
|
7
|
+
|
8
|
+
BeatufiulPage.create(:name => 'Better page', :parent => '/best/pages', :title => 'Yes, it is better') do |page|
|
9
|
+
page.body = '<a href="/can/handle/links/too">link</a>'
|
10
|
+
page.save!
|
11
|
+
page.release!
|
12
|
+
end
|
13
|
+
|
14
|
+
other_page = OtherPage.last
|
15
|
+
other_page.take!
|
16
|
+
|
17
|
+
not_a_page = SomeObject.first
|
18
|
+
not_a_page.some_attribute = 'a value' # types: string, html, enum
|
19
|
+
not_a_page.multienum_attr = ['somevalue'] # multienum
|
20
|
+
not_a_page.some_date_attribute = Time.now # date
|
21
|
+
not_a_page.some_date_attribute = '20111011083526' # date
|
22
|
+
not_a_page.some_date_attribute = '2011-11-11'
|
23
|
+
|
24
|
+
not_a_page.release! if not_a_page.valid?(:release)
|
25
|
+
|
26
|
+
All of the above are examples of what can be done with `Persistence`, `Validations`, `Attributes`. There is more:
|
27
|
+
* all standard ActiveModel callbacks + *_release callbacks
|
28
|
+
* Validations in three contexts: create, update, release
|
29
|
+
* If something works with ActiveRecord, there is a high chance it works with REACTOR too!
|
30
|
+
* Rails 3 API
|
31
|
+
|
32
|
+
What about links? Every object on my page is linked with 1000 other objects! I need links! Don't worry, they are there. Not perfectly supported yet, but you can set them:
|
33
|
+
|
34
|
+
some_obj.link_list_attr = 'http://google.com'
|
35
|
+
some_obj.link_list_attr = Obj.last
|
36
|
+
some_obj.link_list_attr = '/path/to/obj'
|
37
|
+
|
38
|
+
And I haven't forgotten that they are lists of links:
|
39
|
+
|
40
|
+
some_obj.link_list_attr = ['http://google.com', Obj.last, '/path/to/obj']
|
41
|
+
|
42
|
+
Yes, that is nice, you say, but what if I also wan't to set a link title? No problem, here is how:
|
43
|
+
|
44
|
+
some_obj.link_list_attr = {:url => 'http://google.com', :title => 'title of my link'}
|
45
|
+
some_obj.link_list_attr = {:destination_object => Obj.last, :title => 'title of my link'}
|
46
|
+
some_obj.link_list_attr = {:destination_object => '/path/to/obj', :title => 'title of my link'}
|
47
|
+
|
48
|
+
This also works for multiple links:
|
49
|
+
|
50
|
+
some_obj.link_list_attr = [ {:url => 'http://google.com', :title => 'title of my link'}, {:destination_object => Obj.last, :title => 'other title'}]
|
51
|
+
|
52
|
+
You can also manipulate linklist with array methods (for example `#delete_at`) and
|
53
|
+
|
54
|
+
some_obj.link_list_attr << '/path/to/obj'
|
55
|
+
some_obj.link_list_attr << {:url => 'http://yahoo.com', :title => 'yahoo link'}
|
56
|
+
|
57
|
+
One more thing: you can upload files too!
|
58
|
+
|
59
|
+
binary_obj.upload(File.open('/my/file'), 'txt')
|
60
|
+
binary_obj.save!
|
61
|
+
|
62
|
+
Or:
|
63
|
+
|
64
|
+
binary_obj.upload(File.read('/my/file'), 'txt')
|
65
|
+
binary_obj.save!
|
66
|
+
|
67
|
+
**WARNING** If your are planning to upload anything larger than 10kB it is strongly advised to use `Reactor::StreamingUpload` module. This module
|
68
|
+
allows to stream files of any size (provided you supply them through `File.open` and not read them yourself into memory). It is also much,
|
69
|
+
much more efficient than the traditional method.
|
70
|
+
|
71
|
+
Permissions are checked also! And your user is automatically set according to `JSESSIONID` cookie.
|
72
|
+
|
73
|
+
KNOWN BUGS/ISSUES
|
74
|
+
=================
|
75
|
+
|
76
|
+
Awesome! What is missing/WHAT I NEED TO BE AWARE OF:
|
77
|
+
|
78
|
+
- When setting a `linklist` all links are overwritten. Don't do it like 10 million times if you don't want to risk reaching billion ids.
|
79
|
+
- Therefore link operations are slow.
|
80
|
+
- Link position cannot be directly manipulated (it is implicit through array order)
|
81
|
+
- Validations are implemented completely in Rails, there is no call to CM, so all you TCL validation callbacks aren't executed
|
82
|
+
- There are no validations for `enum`/`multienum` field (but mandatory fields are supported)
|
83
|
+
- You can change the `obj_class` of an obj, but after save you should get yourself a new instance. (it's a bug of `rails_connector_meta`)
|
84
|
+
- You have to save an object before you can upload data (i.e. upload works only on existing objects)
|
85
|
+
|
86
|
+
HOW TO INSTALL
|
87
|
+
==============
|
88
|
+
|
89
|
+
1. Include in your Gemfile
|
90
|
+
2. bundle
|
91
|
+
3. Add initializer for Reactor if you haven't done so already
|
92
|
+
4. Include modules into your Obj
|
93
|
+
|
94
|
+
Sample code for points 3. and 4.
|
95
|
+
|
96
|
+
**config/initializers/reactor.rb:**
|
97
|
+
|
98
|
+
Reactor::Configuration.xml_access = {
|
99
|
+
:host => 'localhost', # Fiona host
|
100
|
+
:port => 6001, # CM http port (TCL port + 1)
|
101
|
+
:id => '1234', # leave it as is
|
102
|
+
|
103
|
+
:username => 'root', # default user for all requests
|
104
|
+
:secret => 'password' # instance secret
|
105
|
+
}
|
106
|
+
|
107
|
+
**lib/obj_extensions.rb:**
|
108
|
+
|
109
|
+
require 'meta'
|
110
|
+
module ObjExtensions
|
111
|
+
def self.enable
|
112
|
+
Obj.class_eval do
|
113
|
+
include RailsConnector::Meta
|
114
|
+
|
115
|
+
include Reactor::Legacy::Base # core module
|
116
|
+
include Reactor::Attributes::Base # core module
|
117
|
+
include Reactor::Persistence::Base # core module
|
118
|
+
|
119
|
+
include Reactor::Validations::Base # optional module,
|
120
|
+
# enables Rails validations
|
121
|
+
|
122
|
+
include Reactor::Permission::Base # optional module,
|
123
|
+
# enables permission checking
|
124
|
+
|
125
|
+
include Reactor::Workflow::Base # optional module,
|
126
|
+
# enables workflow API
|
127
|
+
|
128
|
+
include Reactor::StreamingUpload::Base
|
129
|
+
# optional module,
|
130
|
+
# enables streaming interface for
|
131
|
+
# uploads (strongly recommended!)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
DOCUMENTATION
|
137
|
+
=============
|
138
|
+
Core and optional modules are pretty well documented. If you are looking for example usages, you will find plenty of them in test app under spec folder.
|
139
|
+
|
140
|
+
BUGS, FEATURE REQUESTS?
|
141
|
+
=======================
|
142
|
+
Open issue on github or make a pull request! Don't be shy :)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
#require 'yard'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
#YARD::Rake::YardocTask.new do |t|
|
6
|
+
# t.files = ['lib/**/*.rb'] # optional
|
7
|
+
## t.options = ['--any', '--extra', '--opts'] # optional
|
8
|
+
#end
|
9
|
+
|
10
|
+
|
11
|
+
# remove this task, when this gem is distributed as a `real` gem (and not included in Gemfile through `:path =>` )
|
12
|
+
task :update_gemspec_for_distribution do
|
13
|
+
|
14
|
+
fn = Dir[File.expand_path('../*.gemspec', __FILE__)].first
|
15
|
+
source_gemspec = File.read(fn)
|
16
|
+
|
17
|
+
source_gemspec.gsub!(/^([\t ]*)((s.files\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files`.split("\n").inspect}\n"}
|
18
|
+
source_gemspec.gsub!(/^([\t ]*)((s.test_files\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files -- {test,spec,features}/*`.split("\n").inspect}\n"}
|
19
|
+
source_gemspec.gsub!(/^([\t ]*)((s.executables\s*=)[^\n]+\n)/m) {|s| "#{$1}##{$2}#{$1}#{$3} #{`git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }.inspect}\n"}
|
20
|
+
|
21
|
+
File.open("#{fn}.resolved", 'w') do |f|
|
22
|
+
f.write source_gemspec
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class ReactorController < ApplicationController
|
2
|
+
def create_object
|
3
|
+
obj_data = params[:obj] || {}
|
4
|
+
obj_class = obj_data.delete("obj_class")
|
5
|
+
parent_id = obj_data.delete("parent_id").to_i
|
6
|
+
name = obj_data.delete("name")
|
7
|
+
|
8
|
+
o = Obj.new(:obj_class => obj_class, :name => name, :parent => parent_id) do |obj|
|
9
|
+
obj.send(:reload_attributes, obj_class)
|
10
|
+
obj.update_attributes!(obj_data)
|
11
|
+
end
|
12
|
+
respond_to do |format|
|
13
|
+
format.html { redirect_to(cms_path(o)) }
|
14
|
+
format.json { render :json => o }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def release_object
|
19
|
+
obj = Obj.find(params[:id])
|
20
|
+
obj.release!
|
21
|
+
success = true
|
22
|
+
rescue => e
|
23
|
+
flash[:error] = "#{e.class}\n\n#{e.message}"
|
24
|
+
success = false
|
25
|
+
ensure
|
26
|
+
respond_to do |format|
|
27
|
+
format.html { redirect_to(:back) }
|
28
|
+
if success
|
29
|
+
format.json { render :json => :ok }
|
30
|
+
else
|
31
|
+
format.json { render :json => flash[:error], :status => :unprocessable_entity } # something smarter would be nice
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_object
|
37
|
+
obj = Obj.find(params[:id])
|
38
|
+
obj.update_attributes!(params[:obj])
|
39
|
+
respond_to do |format|
|
40
|
+
format.html { redirect_to(:back) }
|
41
|
+
format.json { render :json => :ok }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_object
|
46
|
+
obj = Obj.find(params[:id])
|
47
|
+
obj.destroy
|
48
|
+
respond_to do |format|
|
49
|
+
format.html { redirect_to(:back) }
|
50
|
+
format.json { render :json => :ok }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
post 'reactor/object' => 'reactor#create_object', :as => :create_object
|
3
|
+
post 'reactor/release/:id' => 'reactor#release_object', :as => :release_object
|
4
|
+
delete 'reactor/object/:id' => 'reactor#delete_object', :as => :delete_object
|
5
|
+
put 'reactor/object/:id' => 'reactor#update_object', :as => :update_object
|
6
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "reactor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "infopark_reactor"
|
7
|
+
s.version = "#{Reactor::VERSION}"
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Tomasz Przedmojski"]
|
10
|
+
s.email = ["tomasz.przedmojski@infopark.de"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Write into CM in familiar, Rails-like way}
|
13
|
+
s.description = %q{Use the ActiveRecord mimicking API to write into CM and enjoy all the benefits of callbacks, validations and permission checking}
|
14
|
+
s.license = 'LGPL-3'
|
15
|
+
|
16
|
+
#s.rubyforge_project = "infopark_reactor"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib", "lib/tools"]
|
22
|
+
|
23
|
+
s.add_dependency 'rails', '<= 3.2.9', '>= 3.0.10'
|
24
|
+
s.add_dependency 'infopark_reactor_migrations', '>= 1.2.0'
|
25
|
+
s.add_dependency 'infopark_rails_connector'
|
26
|
+
s.add_dependency 'infopark_rails_connector_meta', '>= 0.0.3'
|
27
|
+
|
28
|
+
s.add_development_dependency 'rspec'
|
29
|
+
s.add_development_dependency 'yard'
|
30
|
+
end
|
data/lib/engine.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Reactor
|
2
|
+
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
|
5
|
+
initializer "reactor.rsession" do
|
6
|
+
# FIXME: extract !
|
7
|
+
AbstractController::Base.__send__(:define_method, :rsession) do
|
8
|
+
self.session[:rsession] ||= Reactor::Session.instance
|
9
|
+
end
|
10
|
+
ActionController::Base.__send__(:helper_method, :rsession)
|
11
|
+
|
12
|
+
ActionController::Base.__send__(:define_method, :rsession_auth) do
|
13
|
+
if RailsConnector::Configuration.mode == :editor && (jsessionid = cookies['JSESSIONID']).present?
|
14
|
+
# Why the gsub? It's a dirty hack! Reason: JSESSIONIDs are unescaped
|
15
|
+
# when read through Rails and hence all + are converted into spaces.
|
16
|
+
# CM Kernel though stores escaped IDs.
|
17
|
+
# From the possible generated characters only the + seems to be
|
18
|
+
# problematic.
|
19
|
+
# CGI.escape would be the solution, but it's deprecated
|
20
|
+
# URI.escape does too much
|
21
|
+
jsessionid.gsub!(' ','+')
|
22
|
+
|
23
|
+
Rails.logger.info "Trying to log in at #{Reactor::Configuration.xml_access[:host]}:#{Reactor::Configuration.xml_access[:port]} with JSESSIONID=#{jsessionid}."
|
24
|
+
rsession.login(jsessionid)
|
25
|
+
Rails.logger.info %|Logged in as "#{rsession.user_name}".| if rsession.user?
|
26
|
+
else
|
27
|
+
rsession.destroy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
ActionController::Base.__send__(:before_filter, :rsession_auth)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|