ixtlan 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +49 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +73 -48
- data/Rakefile +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb +3 -3
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/AbstractApplicationResourceTestGwt.java +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java +2 -2
- data/generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb +1 -1
- data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb +4 -4
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/guard.rb +7 -7
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/i18n.rb +1 -1
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/layout.html.erb +20 -0
- data/ixtlan_rails_templates.rb +537 -0
- data/lib/ixtlan/audit_config.rb +5 -5
- data/lib/ixtlan/child_path.rb +2 -2
- data/lib/ixtlan/cms_script.rb +4 -4
- data/lib/ixtlan/controllers/authentications_controller.rb +7 -2
- data/lib/ixtlan/controllers/configurations_controller.rb +15 -6
- data/lib/ixtlan/controllers/domains_controller.rb +99 -0
- data/lib/ixtlan/controllers/groups_controller.rb +105 -0
- data/lib/ixtlan/controllers/locales_controller.rb +99 -0
- data/lib/ixtlan/controllers/permissions_controller.rb +5 -0
- data/lib/ixtlan/controllers/phrases_controller.rb +26 -22
- data/lib/ixtlan/controllers/search_query.rb +24 -0
- data/lib/ixtlan/controllers/texts_controller.rb +5 -5
- data/lib/ixtlan/controllers/users_controller.rb +117 -0
- data/lib/ixtlan/controllers/word_bundles_controller.rb +13 -8
- data/lib/ixtlan/digest.rb +3 -3
- data/lib/ixtlan/guard.rb +11 -12
- data/lib/ixtlan/logger_config.rb +11 -11
- data/lib/ixtlan/mailer/error_notification.erb +1 -0
- data/lib/ixtlan/mailer/password.erb +1 -0
- data/lib/ixtlan/mailer.rb +27 -0
- data/lib/ixtlan/models/authentication.rb +9 -6
- data/lib/ixtlan/models/configuration.rb +21 -37
- data/lib/ixtlan/models/configuration_locale.rb +3 -3
- data/lib/ixtlan/models/domain.rb +44 -0
- data/lib/ixtlan/models/domain_group_user.rb +22 -0
- data/lib/ixtlan/models/group.rb +82 -16
- data/lib/ixtlan/models/group_locale_user.rb +4 -4
- data/lib/ixtlan/models/group_user.rb +7 -7
- data/lib/ixtlan/models/i18n_text.rb +26 -26
- data/lib/ixtlan/models/locale.rb +17 -5
- data/lib/ixtlan/models/permission.rb +3 -2
- data/lib/ixtlan/models/phrase.rb +15 -15
- data/lib/ixtlan/models/role.rb +5 -5
- data/lib/ixtlan/models/translation.rb +9 -9
- data/lib/ixtlan/models/update_children.rb +74 -0
- data/lib/ixtlan/models/user.rb +108 -16
- data/lib/ixtlan/models/word.rb +2 -1
- data/lib/ixtlan/models.rb +1 -0
- data/lib/ixtlan/modified_by.rb +9 -7
- data/lib/ixtlan/monkey_patches.rb +5 -5
- data/lib/ixtlan/optimistic_persistence.rb +2 -2
- data/lib/ixtlan/optimistic_persistence_module.rb +3 -3
- data/lib/ixtlan/optimistic_persistence_validation.rb +2 -2
- data/lib/ixtlan/passwords.rb +15 -13
- data/lib/ixtlan/rails/error_handling.rb +41 -40
- data/lib/ixtlan/rails/guard.rb +0 -1
- data/lib/ixtlan/rails/migrations.rb +75 -0
- data/lib/ixtlan/rails/session_timeout.rb +16 -14
- data/lib/ixtlan/rails/timestamps_modified_by_filter.rb +1 -1
- data/lib/ixtlan/rails/unrestful_authentication.rb +4 -4
- data/lib/ixtlan/rolling_file.rb +3 -3
- data/lib/ixtlan/session.rb +4 -3
- data/lib/ixtlan/user_logger.rb +13 -9
- data/lib/ixtlan/version.rb +1 -1
- data/spec/authentication_spec.rb +1 -1
- data/spec/guard_spec.rb +4 -4
- data/spec/guards/samples.rb +7 -7
- data/spec/modified_by_spec.rb +82 -0
- data/spec/optimistic_persistence_spec.rb +58 -0
- data/spec/phrase_spec.rb +119 -0
- data/spec/session_timeout_spec.rb +59 -0
- data/spec/spec_helper.rb +6 -5
- data/spec/text_collection_spec.rb +88 -0
- data/spec/text_spec.rb +105 -0
- data/spec/unrestful_authentication_spec.rb +142 -0
- data/spec/user_logger_spec.rb +105 -0
- data/spec/user_spec.rb +249 -0
- data/whitespace.rb +31 -0
- metadata +76 -50
- data/lib/ixtlan/error_notifier/error_notification.rhtml +0 -1
@@ -0,0 +1,537 @@
|
|
1
|
+
# inspired by http://www.rowtheboat.com/archives/32
|
2
|
+
###################################################
|
3
|
+
|
4
|
+
# --------------
|
5
|
+
# HELPER METHODS
|
6
|
+
# --------------
|
7
|
+
|
8
|
+
def middleware(name)
|
9
|
+
log 'middleware', name
|
10
|
+
environment "config.middleware.use '#{name}'"
|
11
|
+
end
|
12
|
+
def ixtlan_model(name)
|
13
|
+
file "app/models/#{name}.rb", <<-CODE
|
14
|
+
class #{name.camelcase} < Ixtlan::Models::#{name.camelcase}; end
|
15
|
+
CODE
|
16
|
+
end
|
17
|
+
def ixtlan_controller(name, guards = {:actions => [:index,:show,:new,:create,:edit,:update,:destroy], :default => nil}, singleton = nil)
|
18
|
+
if guards
|
19
|
+
file "app/guards/#{name}_guard.rb", <<-CODE
|
20
|
+
Ixtlan::Guard.initialize(:#{name}, {
|
21
|
+
#{guards[:actions].collect {|g| ":#{g} => [#{guards[:default]}]" }.join(",\n") }
|
22
|
+
})
|
23
|
+
CODE
|
24
|
+
end
|
25
|
+
file "app/controllers/#{name}_controller.rb", <<-CODE
|
26
|
+
class #{name.camelize}Controller < ApplicationController
|
27
|
+
include Ixtlan::Controllers::#{name.camelize}Controller
|
28
|
+
end
|
29
|
+
CODE
|
30
|
+
if singleton
|
31
|
+
route "map.resource :#{singleton}"
|
32
|
+
else
|
33
|
+
route "map.resources :#{name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_gem(name, version, options = {})
|
38
|
+
gem name, options
|
39
|
+
java = name =~ /^do_/ ? "<classifier>java</classifier>\n" : ""
|
40
|
+
gsub_file 'pom.xml', /<\/dependencies>/, "<dependency>\n<groupId>rubygems</groupId>\n<artifactId>#{name}</artifactId>\n<version>#{version}</version>\n<type>gem</type>\n#{java}</dependency>\n</dependencies>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def migration(model)
|
44
|
+
@__index ||= 0
|
45
|
+
@__index = @__index + 1
|
46
|
+
file "db/migrate/#{@__index}_create_#{model}.rb", <<-CODE
|
47
|
+
require 'config/initializers/00_models.rb'
|
48
|
+
require 'ixtlan/rails/migrations'
|
49
|
+
migration #{@__index}, :create_#{model} do
|
50
|
+
up do
|
51
|
+
Ixtlan::Rails::Migrations.create_#{model}
|
52
|
+
end
|
53
|
+
|
54
|
+
down do
|
55
|
+
end
|
56
|
+
end
|
57
|
+
CODE
|
58
|
+
end
|
59
|
+
|
60
|
+
# --------
|
61
|
+
# VERSIONS
|
62
|
+
# --------
|
63
|
+
|
64
|
+
JRUBY_PLUGINS_VERSION='0.12.0'
|
65
|
+
DM_VERSION='0.10.2'
|
66
|
+
|
67
|
+
# -----------
|
68
|
+
# MAVEN SETUP
|
69
|
+
# -----------
|
70
|
+
|
71
|
+
# setup a pom.xml
|
72
|
+
inside("..") do
|
73
|
+
run("mvn archetype:generate -DarchetypeArtifactId=rails-maven-archetype -DarchetypeGroupId=de.saumya.mojo -DarchetypeVersion=#{JRUBY_PLUGINS_VERSION} -DartifactId=#{File.basename(root)} -DgroupId=com.example -Dversion=0.1.0-SNAPSHOT -B")
|
74
|
+
end
|
75
|
+
File.delete('lib/tasks/jdbc.rake')
|
76
|
+
File.delete('config/initializers/jdbc.rb')
|
77
|
+
gsub_file 'pom.xml', /<version>1.5.0<\/version>/, "<version>1.4.1<\/version>"
|
78
|
+
|
79
|
+
# ---------------------
|
80
|
+
# GWT AND ECLIPSE SETUP
|
81
|
+
# ---------------------
|
82
|
+
|
83
|
+
#if ENV['GWT'] == 'true' || (!ENV['GWT'] && yes?("install GWT interface ?"))
|
84
|
+
gwt_prefix = "gwt_"
|
85
|
+
File.rename("src/main/webapp/WEB-INF/web.xml",
|
86
|
+
"src/main/webapp/WEB-INF/web.xml.rails")
|
87
|
+
inside("..") do
|
88
|
+
run("mvn archetype:generate -DarchetypeArtifactId=gui -DarchetypeGroupId=de.saumya.gwt.translation -DarchetypeVersion=0.3.1 -DartifactId=#{File.basename(root)} -DgroupId=com.example -Dversion=0.1.0-SNAPSHOT -B")
|
89
|
+
end
|
90
|
+
File.rename("src/main/webapp/WEB-INF/web.xml.rails",
|
91
|
+
"src/main/webapp/WEB-INF/web.xml")
|
92
|
+
|
93
|
+
file '.classpath', <<-CODE
|
94
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
95
|
+
<classpath>
|
96
|
+
<classpathentry kind="src" output="war/WEB-INF/classes" path="src/main/java"/>
|
97
|
+
<classpathentry excluding="**" kind="src" output="war/WEB-INF/classes" path="src/main/resources"/>
|
98
|
+
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
99
|
+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
100
|
+
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
101
|
+
<classpathentry kind="output" path="war/WEB-INF/classes"/>
|
102
|
+
</classpath>
|
103
|
+
CODE
|
104
|
+
file '.project', <<-CODE
|
105
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
106
|
+
<projectDescription>
|
107
|
+
<name>ixtlan-test</name>
|
108
|
+
<comment></comment>
|
109
|
+
<projects>
|
110
|
+
</projects>
|
111
|
+
<buildSpec>
|
112
|
+
<buildCommand>
|
113
|
+
<name>org.eclipse.jdt.core.javabuilder</name>
|
114
|
+
<arguments>
|
115
|
+
</arguments>
|
116
|
+
</buildCommand>
|
117
|
+
<buildCommand>
|
118
|
+
<name>org.maven.ide.eclipse.maven2Builder</name>
|
119
|
+
<arguments>
|
120
|
+
</arguments>
|
121
|
+
</buildCommand>
|
122
|
+
</buildSpec>
|
123
|
+
<natures>
|
124
|
+
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
125
|
+
<nature>org.eclipse.jdt.core.javanature</nature>
|
126
|
+
</natures>
|
127
|
+
</projectDescription>
|
128
|
+
CODE
|
129
|
+
file '.settings/org.maven.ide.eclipse.prefs', <<-CODE
|
130
|
+
activeProfiles=
|
131
|
+
eclipse.preferences.version=1
|
132
|
+
fullBuildGoals=process-test-resources
|
133
|
+
includeModules=false
|
134
|
+
resolveWorkspaceProjects=true
|
135
|
+
resourceFilterGoals=process-resources resources\:testResources
|
136
|
+
skipCompilerPlugin=true
|
137
|
+
version=1
|
138
|
+
CODE
|
139
|
+
file '.settings/org.eclipse.jdt.core.prefs', <<-CODE
|
140
|
+
eclipse.preferences.version=1
|
141
|
+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
142
|
+
org.eclipse.jdt.core.compiler.compliance=1.6
|
143
|
+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
144
|
+
org.eclipse.jdt.core.compiler.source=1.6
|
145
|
+
CODE
|
146
|
+
#else
|
147
|
+
# gwt_prefix = nil
|
148
|
+
#end
|
149
|
+
|
150
|
+
# --------------------
|
151
|
+
# ADD GEM DEPENDENCIES
|
152
|
+
# --------------------
|
153
|
+
|
154
|
+
# ixtlan gems
|
155
|
+
add_gem 'rack', '1.0.1'
|
156
|
+
add_gem 'rack-datamapper', '0.2.5'
|
157
|
+
add_gem 'ixtlan', '0.2.5'
|
158
|
+
|
159
|
+
# assume sqlite3 to be database
|
160
|
+
add_gem 'do_sqlite3', '0.10.1.1'
|
161
|
+
|
162
|
+
# serialization, validations and timestamps in your models
|
163
|
+
add_gem 'dm-validations', DM_VERSION
|
164
|
+
add_gem 'dm-timestamps', DM_VERSION
|
165
|
+
add_gem 'dm-migrations', DM_VERSION
|
166
|
+
add_gem 'dm-aggregates', DM_VERSION
|
167
|
+
add_gem 'dm-core', DM_VERSION
|
168
|
+
|
169
|
+
# get all datamapper related gems
|
170
|
+
# gem 'addressable', :lib => 'addressable/uri'
|
171
|
+
|
172
|
+
# assume you prefer rspec over unit tests
|
173
|
+
add_gem 'rspec', '[1.3.0,1.4.0]', :lib => false
|
174
|
+
add_gem 'rspec-rails', '1.3.0', :lib => false
|
175
|
+
|
176
|
+
# install all gems
|
177
|
+
rake 'gems:install'
|
178
|
+
|
179
|
+
# install specs rake tasks
|
180
|
+
generate('rspec', '-f')
|
181
|
+
|
182
|
+
# install datamapper rake tasks
|
183
|
+
generate('datamapper_install')
|
184
|
+
|
185
|
+
# fix config files to work with datamapper instead of active_record
|
186
|
+
environment ''
|
187
|
+
environment 'config.frameworks -= [ :active_record ]'
|
188
|
+
environment '# deactive active_record'
|
189
|
+
gsub_file 'spec/spec_helper.rb', /^\s*config[.]/, ' #\0'
|
190
|
+
gsub_file 'test/test_helper.rb', /^[^#]*fixtures/, ' #\0'
|
191
|
+
|
192
|
+
file 'spec/support/datamapper.rb', <<-CODE
|
193
|
+
require 'datamapper4rails/rspec'
|
194
|
+
CODE
|
195
|
+
|
196
|
+
# ----------
|
197
|
+
# MIDDLEWARE
|
198
|
+
# ----------
|
199
|
+
|
200
|
+
environment ''
|
201
|
+
middleware 'DataMapper::RestfulTransactions'
|
202
|
+
middleware 'DataMapper::IdentityMaps'
|
203
|
+
middleware 'Rack::Deflater'
|
204
|
+
environment "#config.middleware.use 'Ixtlan::CmsScript'"
|
205
|
+
environment '# add middleware'
|
206
|
+
|
207
|
+
# ------------
|
208
|
+
# INITIALIZERS
|
209
|
+
# ------------
|
210
|
+
|
211
|
+
# define locale model names
|
212
|
+
initializer '00_models.rb', <<-CODE
|
213
|
+
module Ixtlan
|
214
|
+
module Models
|
215
|
+
AUTHENTICATION = "Authentication"
|
216
|
+
USER = "User"
|
217
|
+
GROUP = "Group"
|
218
|
+
LOCALE = "Locale"
|
219
|
+
DOMAIN = "Domain"
|
220
|
+
TEXT = "I18nText"
|
221
|
+
CONFIGURATION = "Configuration"
|
222
|
+
end
|
223
|
+
end
|
224
|
+
CODE
|
225
|
+
|
226
|
+
# load ixtlan classes
|
227
|
+
initializer '01_ixtlan.rb', <<-CODE
|
228
|
+
require 'ixtlan/modified_by'
|
229
|
+
if ENV['RAILS_ENV']
|
230
|
+
require 'models'
|
231
|
+
require 'ixtlan/rails/error_handling'
|
232
|
+
require 'ixtlan/rails/audit'
|
233
|
+
require 'ixtlan/rails/session_timeout'
|
234
|
+
require 'ixtlan/rails/unrestful_authentication'
|
235
|
+
require 'ixtlan/rails/guard'
|
236
|
+
require 'ixtlan/rails/timestamps_modified_by_filter'
|
237
|
+
require 'ixtlan/optimistic_persistence'
|
238
|
+
end
|
239
|
+
require 'ixtlan/monkey_patches'
|
240
|
+
# auto require to load needed libraries . . .
|
241
|
+
require 'datamapper4rails'
|
242
|
+
require 'slf4r'
|
243
|
+
CODE
|
244
|
+
|
245
|
+
# logger config
|
246
|
+
initializer '02_loggers.rb', <<-CODE
|
247
|
+
require 'ixtlan/logger_config' if ENV['RAILS_ENV']
|
248
|
+
CODE
|
249
|
+
|
250
|
+
# load the guard config
|
251
|
+
initializer '03_guard.rb', <<-CODE
|
252
|
+
# load the guard config files from RAILS_ROOT/app/guards
|
253
|
+
Ixtlan::Guard.load(Slf4r::LoggerFacade.new(Ixtlan::Guard))
|
254
|
+
CODE
|
255
|
+
|
256
|
+
# init a session store
|
257
|
+
initializer '04_datamapper_store.rb', <<-CODE
|
258
|
+
# init a session store which uses a memory cache and drops the user object
|
259
|
+
# and the flash which results into a very thin session and hardly any
|
260
|
+
# database updates !
|
261
|
+
# cleanup can be a problem. jruby uses soft-references for the cache so
|
262
|
+
# memory cleanup with jruby is no problem.
|
263
|
+
require 'ixtlan/session'
|
264
|
+
ActionController::Base.session_store = :datamapper_store
|
265
|
+
ActionController::Base.session = {
|
266
|
+
:cache => true,
|
267
|
+
:session_class => Ixtlan::Session
|
268
|
+
}
|
269
|
+
CODE
|
270
|
+
|
271
|
+
# define the date/time pattern for the xml
|
272
|
+
initializer '05_time_formats.rb', <<-CODE
|
273
|
+
Time::DATE_FORMATS[:xml] = lambda { |time| time.utc.strftime("%Y-%m-%d %H:%M:%S") }
|
274
|
+
CODE
|
275
|
+
|
276
|
+
# ----------
|
277
|
+
# MIGRATIONS
|
278
|
+
# ----------
|
279
|
+
|
280
|
+
migration("user")
|
281
|
+
migration("configuration")
|
282
|
+
migration("locale")
|
283
|
+
migration("domain")
|
284
|
+
migration("text")
|
285
|
+
|
286
|
+
# -----
|
287
|
+
# VIEWS
|
288
|
+
# -----
|
289
|
+
|
290
|
+
#some small html pages
|
291
|
+
file "app/views/sessions/login.html.erb", <<-CODE
|
292
|
+
<p style="color: darkgreen"><%= @notice %></p>
|
293
|
+
<form method="post">
|
294
|
+
<p>
|
295
|
+
<label for="login">login</label><br />
|
296
|
+
<input type="text" name="login" />
|
297
|
+
</p>
|
298
|
+
<p>
|
299
|
+
<label for="password">password</label><br />
|
300
|
+
<input type="password" name="password" />
|
301
|
+
</p>
|
302
|
+
<p>
|
303
|
+
<input type="submit" value="login" />
|
304
|
+
</p>
|
305
|
+
</form>
|
306
|
+
CODE
|
307
|
+
|
308
|
+
file 'app/views/errors/error.html.erb', <<-CODE
|
309
|
+
<h1><%= @notice %></h1>
|
310
|
+
CODE
|
311
|
+
|
312
|
+
file 'app/views/errors/stale.html.erb', <<-CODE
|
313
|
+
<h1>stale resource</h1>
|
314
|
+
<p>please reload resource and change it again</p>
|
315
|
+
CODE
|
316
|
+
|
317
|
+
|
318
|
+
# ----------------------
|
319
|
+
# MODELS AND CONTROLLERs
|
320
|
+
# ----------------------
|
321
|
+
|
322
|
+
# setup permissions controller
|
323
|
+
ixtlan_controller("permissions", {:actions => [:index]})
|
324
|
+
|
325
|
+
# user model/controller
|
326
|
+
generate "ixtlan_datamapper_rspec_scaffold", '--skip-migration', 'User', 'login:string', 'name:string', 'email:string', 'language:string'
|
327
|
+
gsub_file 'spec/models/user_spec.rb', /.*:name => "sc'?r&?ipt".*/, ''
|
328
|
+
gsub_file 'spec/models/user_spec.rb', /value for login/, 'valueForLogin'
|
329
|
+
gsub_file 'spec/models/user_spec.rb', /value for email/, 'value@for.email'
|
330
|
+
gsub_file 'spec/models/user_spec.rb', /value for language/, 'vl'
|
331
|
+
ixtlan_model 'user'
|
332
|
+
ixtlan_controller 'users'
|
333
|
+
|
334
|
+
# group model/controller
|
335
|
+
generate "ixtlan_datamapper_rspec_scaffold", '--skip-migration', 'Group', 'name:string'
|
336
|
+
ixtlan_model 'group'
|
337
|
+
ixtlan_controller 'groups'
|
338
|
+
|
339
|
+
# domain model/controller
|
340
|
+
generate "ixtlan_datamapper_rspec_scaffold", '--skip-migration', 'Domain', 'name:string'
|
341
|
+
ixtlan_model 'domain'
|
342
|
+
ixtlan_controller 'domains'
|
343
|
+
|
344
|
+
# i18n stuff: i18n model, phrases, word_bundles controller
|
345
|
+
ixtlan_model 'i18n_text'
|
346
|
+
ixtlan_controller "phrases"
|
347
|
+
ixtlan_controller "word_bundles"
|
348
|
+
|
349
|
+
# locale model/controller
|
350
|
+
generate "ixtlan_datamapper_rspec_scaffold", '--skip-migration', '--skip-modified-by', 'Locale', 'code:string'
|
351
|
+
gsub_file 'spec/models/locale_spec.rb', /value for code/, 'vc'
|
352
|
+
ixtlan_model "locale"
|
353
|
+
ixtlan_controller "locales"
|
354
|
+
|
355
|
+
# configuration guard/model/controller
|
356
|
+
file 'app/models/configuration.rb', <<-CODE
|
357
|
+
class Configuration < Ixtlan::Models::Configuration
|
358
|
+
def self.instance
|
359
|
+
get!(1)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
CODE
|
363
|
+
ixtlan_controller 'configurations', {:actions => [:show, :edit, :update]}, 'configuration'
|
364
|
+
|
365
|
+
# authentication model/controller
|
366
|
+
ixtlan_model "authentication"
|
367
|
+
ixtlan_controller "authentications", {:actions => [:create]}, 'authentication'
|
368
|
+
|
369
|
+
# modify application controller as needed
|
370
|
+
gsub_file 'app/controllers/application_controller.rb', /^\s*helper.*/, <<-CODE
|
371
|
+
filter_parameter_logging :password, :login
|
372
|
+
before_filter :check_session_expiry
|
373
|
+
|
374
|
+
# override default to use nice User (without namespace)
|
375
|
+
#def login_from_params
|
376
|
+
# User.authenticate(params[:login], params[:password])
|
377
|
+
#end
|
378
|
+
|
379
|
+
#def login_from_session
|
380
|
+
# User.get(session[:user_id])
|
381
|
+
#end
|
382
|
+
|
383
|
+
# override default to use value from configuration
|
384
|
+
#def session_timeout
|
385
|
+
# Configuration.instance.session_idle_timeout
|
386
|
+
#end
|
387
|
+
|
388
|
+
def render_error_page_with_session(status)
|
389
|
+
render :template => "errors/error_with_session", :status => status
|
390
|
+
end
|
391
|
+
|
392
|
+
def render_error_page(status)
|
393
|
+
render :template => "errors/error", :status => status
|
394
|
+
end
|
395
|
+
|
396
|
+
# needs 'optimistic_persistence'
|
397
|
+
rescue_from DataMapper::StaleResourceError, :with => :stale_resource
|
398
|
+
|
399
|
+
# needs 'guard'
|
400
|
+
rescue_from Ixtlan::GuardException, :with => :page_not_found
|
401
|
+
rescue_from Ixtlan::PermissionDenied, :with => :page_not_found
|
402
|
+
|
403
|
+
#standard rails or datamapper/dataobjects
|
404
|
+
rescue_from DataObjects::SQLError, :with => :internal_server_error
|
405
|
+
rescue_from DataMapper::ObjectNotFoundError, :with => :page_not_found
|
406
|
+
rescue_from ActionController::RoutingError, :with => :page_not_found
|
407
|
+
rescue_from ActionController::UnknownAction, :with => :page_not_found
|
408
|
+
rescue_from ActionController::MethodNotAllowed, :with => :page_not_found
|
409
|
+
rescue_from ActionController::NotImplemented, :with => :page_not_found
|
410
|
+
rescue_from ActionController::InvalidAuthenticityToken, :with => :stale_resource
|
411
|
+
|
412
|
+
# have nice stacktraces in development mode
|
413
|
+
unless consider_all_requests_local
|
414
|
+
rescue_from ActionView::MissingTemplate, :with => :internal_server_error
|
415
|
+
rescue_from ActionView::TemplateError, :with => :internal_server_error
|
416
|
+
end
|
417
|
+
|
418
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
419
|
+
CODE
|
420
|
+
|
421
|
+
# --------------------------------
|
422
|
+
# GLOBAL CONFIG VIA PREINITIALIZER
|
423
|
+
# --------------------------------
|
424
|
+
|
425
|
+
# configuration before starting rails
|
426
|
+
file 'config/preinitializer.rb', <<-CODE
|
427
|
+
require 'yaml'
|
428
|
+
require 'erb'
|
429
|
+
module Ixtlan
|
430
|
+
class Configurator
|
431
|
+
|
432
|
+
def self.symbolize_keys(h, compact)
|
433
|
+
result = {}
|
434
|
+
|
435
|
+
h.each do |k, v|
|
436
|
+
v = ' ' if v.nil?
|
437
|
+
if v.is_a?(Hash)
|
438
|
+
result[k.to_sym] = symbolize_keys(v, compact) unless compact and v.size == 0
|
439
|
+
else
|
440
|
+
result[k.to_sym] = v unless compact and k.to_sym == v.to_sym
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
result
|
445
|
+
end
|
446
|
+
|
447
|
+
def self.load(dir, file, compact = true)
|
448
|
+
symbolize_keys(YAML::load(ERB.new(IO.read(File.join(dir, file))).result), compact)
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
CONFIG = Ixtlan::Configurator.load(File.dirname(__FILE__), 'global.yml')
|
454
|
+
CODE
|
455
|
+
|
456
|
+
file 'config/global.yml', <<-CODE
|
457
|
+
# possible example to have a file with all the (production) passwords
|
458
|
+
# outside GIT/SUBVERSION/CVS/etc !!!
|
459
|
+
mysql:
|
460
|
+
database: example
|
461
|
+
host: mysql.example.com
|
462
|
+
username: rails
|
463
|
+
password: run_it
|
464
|
+
|
465
|
+
smtp:
|
466
|
+
address: smtp.gmail.com
|
467
|
+
port: 587
|
468
|
+
domain: example.com
|
469
|
+
authentication: plain
|
470
|
+
user_name: mail@example.com
|
471
|
+
password: mail_it
|
472
|
+
CODE
|
473
|
+
|
474
|
+
append_file 'config/environments/production.rb', <<-CODE
|
475
|
+
|
476
|
+
config.action_mailer.delivery_method = :smtp
|
477
|
+
|
478
|
+
require "smtp_tls"
|
479
|
+
|
480
|
+
ActionMailer::Base.smtp_settings = {
|
481
|
+
:address => CONFIG[:smtp][:address],
|
482
|
+
:port => CONFIG[:smtp][:port],
|
483
|
+
:domain => CONFIG[:smtp][:domain],
|
484
|
+
:authentication => CONFIG[:smtp][:authentication],
|
485
|
+
:user_name => CONFIG[:smtp][:user_name],
|
486
|
+
:password => CONFIG[:smtp][:password]
|
487
|
+
}
|
488
|
+
CODE
|
489
|
+
|
490
|
+
# ------
|
491
|
+
# EPILOG
|
492
|
+
# ------
|
493
|
+
|
494
|
+
logger.info
|
495
|
+
logger.info
|
496
|
+
logger.info "info mavenized rails application"
|
497
|
+
logger.info "\thttp://github.org/mkristian/rails-maven-plugin"
|
498
|
+
logger.info
|
499
|
+
logger.info "if you want to run jruby please first uninstall"
|
500
|
+
logger.info "the native extension of do_sqlite3"
|
501
|
+
logger.info "\truby -S gem uninstall do_sqlite3"
|
502
|
+
logger.info "and the install it with java extension"
|
503
|
+
logger.info "\tjruby -S rake gems:install"
|
504
|
+
logger.info "rake gems:unpack does NOT work with jruby due to a bug in rail <=2.3.5"
|
505
|
+
logger.info "you can try"
|
506
|
+
logger.info "\tmvn rails:rails-freeze-gems"
|
507
|
+
logger.info "which patches rails after freezing it"
|
508
|
+
logger.info
|
509
|
+
logger.info
|
510
|
+
|
511
|
+
# -----------------------
|
512
|
+
# SETUP AND SEED DATABASE
|
513
|
+
# -----------------------
|
514
|
+
|
515
|
+
rake 'db:migrate:down VERSION=0'
|
516
|
+
rake 'db:sessions:create'
|
517
|
+
run('rake db:migrate --trace')
|
518
|
+
rake 'db:autoupgrade RAILS_ENV=development'
|
519
|
+
logger.info
|
520
|
+
logger.info "you find the root password in the file 'root'"
|
521
|
+
logger.info
|
522
|
+
|
523
|
+
# GWT GUI installation
|
524
|
+
if gwt_prefix
|
525
|
+
logger.info
|
526
|
+
logger.info "first start rails in one console"
|
527
|
+
logger.info "\tscript/server"
|
528
|
+
logger.info
|
529
|
+
logger.info "and then start the GWT gui in another console"
|
530
|
+
logger.info "\tmvn gwt:run"
|
531
|
+
end
|
532
|
+
|
533
|
+
logger.info
|
534
|
+
logger.info
|
535
|
+
logger.info "for dm-core version 0.10.2 there are a lot of deprecated warnings but everything works as expected"
|
536
|
+
logger.info
|
537
|
+
logger.info
|
data/lib/ixtlan/audit_config.rb
CHANGED
@@ -11,11 +11,11 @@ module Ixtlan
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.reconfigure(keep, file)
|
14
|
-
audit_appender =
|
15
|
-
RollingFile.new('audit',
|
16
|
-
{ :filename_base => file,
|
17
|
-
:keep => keep,
|
18
|
-
:safe => true,
|
14
|
+
audit_appender =
|
15
|
+
RollingFile.new('audit',
|
16
|
+
{ :filename_base => file,
|
17
|
+
:keep => keep,
|
18
|
+
:safe => true,
|
19
19
|
:layout => Logging::Layouts::Pattern.new(:pattern => "%d %m\n") }
|
20
20
|
)
|
21
21
|
|
data/lib/ixtlan/child_path.rb
CHANGED
@@ -4,7 +4,7 @@ module Ixtlan
|
|
4
4
|
@app = app
|
5
5
|
@rootpath = rootpath
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def call(env)
|
9
9
|
['REQUEST_PATH','PATH_INFO','REQUEST_URI','SCRIPT_NAME'].each do |key|
|
10
10
|
if(env[key] =~ /[.]xml([?].*)?$/)
|
@@ -13,6 +13,6 @@ module Ixtlan
|
|
13
13
|
end
|
14
14
|
@app.call(env)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
18
|
end
|
data/lib/ixtlan/cms_script.rb
CHANGED
@@ -4,14 +4,14 @@ module Ixtlan
|
|
4
4
|
@app = app
|
5
5
|
@rootpath = rootpath
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def call(env)
|
9
9
|
dup._call(env)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def _call(env)
|
13
13
|
if(env['REQUEST_PATH'] =~ /^#{@rootpath}\//)
|
14
|
-
|
14
|
+
|
15
15
|
file = Rails.public_path.to_s + env['REQUEST_PATH'].sub(/^#{@rootpath}/, '')
|
16
16
|
@file = File.open(file)
|
17
17
|
[@status, {}, self]
|
@@ -19,7 +19,7 @@ module Ixtlan
|
|
19
19
|
@app.call(env)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def each(&block)
|
24
24
|
@file.each do |line|
|
25
25
|
block.call(line.sub(/<\/head>/, "<link type='text/css' rel='stylesheet' href='#{@rootpath}/embed.css'></link><script type='text/javascript' language='javascript' src='#{@rootpath}/embed.nocache.js'></script></head>"))
|
@@ -2,17 +2,22 @@ module Ixtlan
|
|
2
2
|
module Controllers
|
3
3
|
module AuthenticationsController
|
4
4
|
|
5
|
+
def self.included(base)
|
6
|
+
base.skip_before_filter :guard
|
7
|
+
base.skip_before_filter :authenticate, :only => :destroy
|
8
|
+
end
|
9
|
+
|
5
10
|
protected
|
6
11
|
def login_from_params
|
7
12
|
auth = params[:authentication]
|
8
13
|
User.authenticate(auth[:login], auth[:password])
|
9
14
|
end
|
10
|
-
|
15
|
+
|
11
16
|
public
|
12
17
|
def create
|
13
18
|
render_successful_login
|
14
19
|
end
|
15
|
-
|
20
|
+
|
16
21
|
def destroy
|
17
22
|
authentication_logger.log_user(current_user.nil? ? nil : current_user.login, "already logged out")
|
18
23
|
session.clear
|
@@ -2,11 +2,17 @@ module Ixtlan
|
|
2
2
|
module Controllers
|
3
3
|
module ConfigurationsController
|
4
4
|
|
5
|
+
private
|
6
|
+
|
7
|
+
CONFIGURATION = Object.full_const_get(::Ixtlan::Models::CONFIGURATION)
|
8
|
+
LOCALE = Object.full_const_get(::Ixtlan::Models::LOCALE)
|
9
|
+
|
10
|
+
public
|
11
|
+
|
5
12
|
# GET /configuration
|
6
13
|
# GET /configuration.xml
|
7
14
|
def show
|
8
|
-
@configuration =
|
9
|
-
|
15
|
+
@configuration = CONFIGURATION.instance
|
10
16
|
respond_to do |format|
|
11
17
|
format.html # show.html.erb
|
12
18
|
format.xml { render :xml => @configuration }
|
@@ -15,18 +21,21 @@ module Ixtlan
|
|
15
21
|
|
16
22
|
# GET /configuration/edit
|
17
23
|
def edit
|
18
|
-
@configuration =
|
24
|
+
@configuration = CONFIGURATION.instance
|
19
25
|
end
|
20
26
|
|
21
27
|
# PUT /configuration
|
22
28
|
# PUT /configuration.xml
|
23
29
|
def update
|
24
|
-
@configuration =
|
30
|
+
@configuration = CONFIGURATION.instance
|
25
31
|
@configuration.current_user = current_user
|
26
32
|
|
27
|
-
locales =
|
33
|
+
locales = params[:configuration].delete(:locales)
|
34
|
+
@configuration.update_children(locales, :locales)
|
35
|
+
@configuration.attributes = params[:configuration]
|
36
|
+
|
28
37
|
respond_to do |format|
|
29
|
-
if @configuration.
|
38
|
+
if @configuration.save() or not @configuration.dirty?
|
30
39
|
flash[:notice] = 'Configuration was successfully updated.'
|
31
40
|
format.html { redirect_to(configuration_url) }
|
32
41
|
format.xml { render :xml => @configuration }
|