ixtlan 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ require 'ixtlan/mailer'
1
2
  module Ixtlan
2
3
  module Controllers
3
4
  module UsersController
@@ -12,7 +13,7 @@ module Ixtlan
12
13
 
13
14
  USER = Object.full_const_get(::Ixtlan::Models::USER)
14
15
 
15
- def adjust_params(user_params)
16
+ def adjust_params_and_return_groups(user_params)
16
17
  if user_params
17
18
  lang = user_params.delete(:preferred_language)
18
19
  user_params[:language] = lang[:code][0..1] if lang
@@ -64,7 +65,7 @@ module Ixtlan
64
65
  # POST /users.xml
65
66
  def create
66
67
  user_params = params[:user]
67
- groups = adjust_params(user_params)
68
+ groups = adjust_params_and_return_groups(user_params)
68
69
  @user = USER.new(user_params)
69
70
  @user.current_user = current_user
70
71
  @user.reset_password
@@ -72,12 +73,14 @@ module Ixtlan
72
73
 
73
74
  respond_to do |format|
74
75
  if @user.save
75
- flash[:notice] = 'User was successfully created.'
76
+ flash[:notice] = "User was successfully created: #{@user.password}"
76
77
  format.html { redirect_to(user_url(@user.id)) }
77
78
  format.xml { render :xml => @user, :status => :created, :location => user_url(@user.id) + ".xml" }
78
79
 
79
- ::Ixtlan::Mailer.deliver_new_user(@user.email, Configuration.instance.password_sender_email, @user.login, Configuration.instance.login_url)
80
- ::Ixtlan::Mailer.deliver_password(@user.email, Configuration.instance.password_sender_email, @user.password)
80
+ if Configuration.instance.password_sender_email
81
+ ::Ixtlan::Mailer.deliver_new_user(@user.email, Configuration.instance.password_sender_email, @user.login, Configuration.instance.login_url)
82
+ ::Ixtlan::Mailer.deliver_password(@user.email, Configuration.instance.password_sender_email, @user.password)
83
+ end
81
84
  else
82
85
  format.html { render :action => "new" }
83
86
  format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
@@ -91,7 +94,7 @@ module Ixtlan
91
94
  @user = USER.first_or_get!(params[:id])
92
95
  @user.current_user = current_user
93
96
  user_params = params[:user]
94
- @user.update_all_children(adjust_params(user_params))
97
+ @user.update_all_children(adjust_params_and_return_groups(user_params))
95
98
  @user.attributes = user_params
96
99
 
97
100
  respond_to do |format|
data/lib/ixtlan/models.rb CHANGED
@@ -4,6 +4,7 @@ module Ixtlan
4
4
  AUDIT = "::Audit" unless const_defined? "AUDIT"
5
5
  USER = "::User" unless const_defined? "USER"
6
6
  GROUP = "::Group" unless const_defined? "GROUP"
7
+ GROUP_USER = "::Ixtlan::Models::GroupUser" unless const_defined? "GROUP_USER"
7
8
  ROLE = "::Role" unless const_defined? "ROLE"
8
9
  PERMISSION = "::Permission" unless const_defined? "PERMISSION"
9
10
  LOCALE = "::Locale" unless const_defined? "LOCALE"
@@ -16,9 +16,10 @@ module Ixtlan
16
16
 
17
17
  model.property :name, String, :required => true , :format => /^[^<'&">]*$/, :length => 32, :field => "cn", :unique_index => true
18
18
 
19
- model.timestamps :created_at
20
-
21
- model.modified_by Ixtlan::Models::USER, :created_by
19
+ if !model.const_defined?('LDAP') || !model.const_get('LDAP')
20
+ model.timestamps :created_at
21
+ model.modified_by Ixtlan::Models::USER, :created_by
22
+ end
22
23
 
23
24
  model.class_eval <<-EOS, __FILE__, __LINE__
24
25
  if protected_instance_methods.find {|m| m == 'to_x'}.nil?
@@ -5,11 +5,13 @@ require 'ixtlan/passwords'
5
5
  require 'ixtlan/digest'
6
6
  require 'dm-serializer'
7
7
  require 'ixtlan/models/update_children'
8
+ require 'ixtlan/models/group_user'
8
9
  module Ixtlan
9
10
  module Models
10
11
  module User
11
12
 
12
13
  GROUP = Object.full_const_get(Models::GROUP)
14
+ GROUP_USER = Object.full_const_get(Models::GROUP_USER)
13
15
 
14
16
  def root?
15
17
  groups.detect { |g| g.root? } || false
@@ -41,7 +43,7 @@ module Ixtlan
41
43
  # TODO spec the empty array to make sure new relations are stored
42
44
  # in the database or the groups collection is empty before filling it
43
45
  @groups = ::DataMapper::Collection.new(::DataMapper::Query.new(self.repository, GROUP), [])
44
- GroupUser.all(:memberuid => login).each do |gu|
46
+ GROUP_USER.all(:memberuid => login).each do |gu|
45
47
  @groups << gu.group
46
48
  end
47
49
  def @groups.user=(user)
@@ -52,7 +54,7 @@ module Ixtlan
52
54
  group.locales(@user)
53
55
  group.domains(@user)
54
56
  unless member? group
55
- gu = GroupUser.create(:memberuid => @user.login, :gidnumber => group.id)
57
+ gu = GROUP_USER.create(:memberuid => @user.login, :gidnumber => group.id)
56
58
  super
57
59
  end
58
60
 
@@ -60,7 +62,7 @@ module Ixtlan
60
62
  end
61
63
 
62
64
  def @groups.delete(group)
63
- gu = GroupUser.first(:memberuid => @user.login, :gidnumber => group.id)
65
+ gu = GROUP_USER.first(:memberuid => @user.login, :gidnumber => group.id)
64
66
  if gu
65
67
  gu.destroy
66
68
  end
@@ -94,7 +96,7 @@ module Ixtlan
94
96
  def update_locales_domains(new_groups)
95
97
  if(new_groups)
96
98
  # make sure we have an array
97
- new_groups = new_groups[:group]
99
+ new_groups = new_groups.is_a?(Array) ? new_groups : new_groups[:group]
98
100
  new_groups = [new_groups] unless new_groups.is_a? Array
99
101
 
100
102
  # create a map group_id => group
@@ -152,9 +154,10 @@ module Ixtlan
152
154
 
153
155
  model.property :hashed_password, String, :required => false, :length => 128, :accessor => :private, :field => "userpassword"
154
156
 
155
- model.timestamps :at
156
-
157
- model.modified_by ::Ixtlan::Models::USER
157
+ if !model.const_defined?('LDAP') || !model.const_get('LDAP')
158
+ model.timestamps :at
159
+ model.modified_by ::Ixtlan::Models::USER
160
+ end
158
161
 
159
162
  #validates_is_unique :login
160
163
  #validates_is_unique :email
@@ -1,3 +1,3 @@
1
1
  module Ixtlan
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -29,7 +29,7 @@ describe Ixtlan::Models::Authentication do
29
29
  Ixtlan::Guard.load( Slf4r::LoggerFacade.new(:root), :root, (Pathname(__FILE__).dirname + 'guards').expand_path )
30
30
  end
31
31
 
32
- it "should" do
32
+ it "should generate the right xml" do
33
33
  xml = @authentication.to_xml
34
34
  xml.gsub!(/[0-9-]{10}T[0-9+-:]{14}/, "").gsub!(/<created_at><\/created_at>/, "<created_at/>").gsub!(/<locale><id>[0-9]*<\/id>/, "<locale>").gsub!(/<permission>.*<\/permission>/, '').gsub(/id>[0-9]+<\//,'id></').should == "<authentication><login>marvin2</login><user><id></id><login>marvin2</login><name>marvin the robot</name><email>marvin@universe.example.com</email><language>xx</language><created_at/><updated_at></updated_at><groups><group><id></id><name>marvin2_root</name><locales><locale><code>DEFAULT</code><created_by_id></created_by_id></locale><locale><code>en</code><created_by_id></created_by_id></locale></locales></group></groups><created_by><id></id><login>marvin2</login><name>marvin the robot</name><email>marvin@universe.example.com</email></created_by><updated_by><id></id><login>marvin2</login><name>marvin the robot</name><email>marvin@universe.example.com</email></updated_by></user><permissions></permissions></authentication>"
35
35
  end
@@ -21,7 +21,9 @@ end
21
21
  describe Ixtlan::ModifiedBy do
22
22
 
23
23
  before :each do
24
- @user = Crew.create(:login => 'spock')
24
+ Crew.all.destroy!
25
+ AuditedName.all.destroy!
26
+ @user = Crew.create(:login => 'spocky')
25
27
  @second = Crew.create(:login => 'dr pille')
26
28
  @name = AuditedName.create(:name => 'kirk', :current_user => @user)
27
29
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'dm-serializer'
9
9
  require 'dm-timestamps'
10
10
 
11
11
  require 'slf4r'
12
+ require 'slf4r/ruby_logger'
12
13
 
13
14
  require 'ixtlan/models'
14
15
  require 'ixtlan/modified_by'
@@ -36,6 +36,7 @@ end
36
36
  describe Ixtlan::Models::Authentication do
37
37
 
38
38
  before :all do
39
+ User.all.destroy!
39
40
  @controller = Controller.new
40
41
  @log = StringIO.new
41
42
  Slf4r::LoggerFacade4RubyLogger.file = @log
@@ -19,6 +19,7 @@ end
19
19
  describe Ixtlan::UserLogger do
20
20
 
21
21
  before :all do
22
+ User.all.destroy!
22
23
  @controller = Controller.new
23
24
  end
24
25
 
@@ -85,10 +86,10 @@ describe Ixtlan::UserLogger do
85
86
  @controller.params[:action] = "index"
86
87
  @controller.instance_variable_set(:@resource, @controller.current_user.groups[0])
87
88
  @logger.log_action(@controller)
88
- @log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]\)\s*$/
89
+ @log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]+\)\s*$/
89
90
  @controller.response.content_type = "application/xml"
90
91
  @logger.log_action(@controller)
91
- @log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]\) - xml\s*$/
92
+ @log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]+\) - xml\s*$/
92
93
  end
93
94
 
94
95
  it 'should log action - resources variable' do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - mkristian
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-02 00:00:00 +05:30
17
+ date: 2011-01-28 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,13 +78,20 @@ dependencies:
78
78
  prerelease: false
79
79
  requirement: &id005 !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  segments:
84
84
  - 0
85
85
  - 3
86
86
  - 0
87
87
  version: 0.3.0
88
+ - - <
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ - 3
93
+ - 3
94
+ version: 0.3.3
88
95
  type: :runtime
89
96
  version_requirements: *id005
90
97
  - !ruby/object:Gem::Dependency
@@ -172,114 +179,114 @@ files:
172
179
  - History.txt
173
180
  - README.txt
174
181
  - Rakefile
182
+ - lib/dm-serializer.rb
175
183
  - lib/models.rb
176
184
  - lib/ixtlan.rb
177
- - lib/dm-serializer.rb
185
+ - lib/dm-serializer/to_xml.rb
178
186
  - lib/dm-serializer/common.rb
179
187
  - lib/dm-serializer/xml_serializers.rb
180
- - lib/dm-serializer/to_xml.rb
181
- - lib/dm-serializer/xml_serializers/libxml.rb
182
188
  - lib/dm-serializer/xml_serializers/nokogiri.rb
189
+ - lib/dm-serializer/xml_serializers/libxml.rb
183
190
  - lib/dm-serializer/xml_serializers/rexml.rb
191
+ - lib/ixtlan/session.rb
192
+ - lib/ixtlan/version.rb
193
+ - lib/ixtlan/audit_config.rb
184
194
  - lib/ixtlan/rails.rb
195
+ - lib/ixtlan/digest.rb
196
+ - lib/ixtlan/version.rb.errors
197
+ - lib/ixtlan/mailer.rb
198
+ - lib/ixtlan/configurator.rb
199
+ - lib/ixtlan/modified_by.rb
200
+ - lib/ixtlan/optimistic_persistence_validation.rb
185
201
  - lib/ixtlan/child_path.rb
186
- - lib/ixtlan/rolling_file.rb
187
- - lib/ixtlan/cms_script.rb
188
- - lib/ixtlan/simple_client.rb
189
202
  - lib/ixtlan/logger_config.rb
190
- - lib/ixtlan/models.rb
191
- - lib/ixtlan/audit_config.rb
203
+ - lib/ixtlan/rolling_file.rb
192
204
  - lib/ixtlan/session_with_cache.rb
193
- - lib/ixtlan/configurator.rb
205
+ - lib/ixtlan/monkey_patches.rb
206
+ - lib/ixtlan/passwords.rb
194
207
  - lib/ixtlan/audit_rack.rb
195
- - lib/ixtlan/session.rb
196
- - lib/ixtlan/optimistic_persistence.rb
197
- - lib/ixtlan/mailer.rb
198
- - lib/ixtlan/modified_by.rb
208
+ - lib/ixtlan/models.rb
209
+ - lib/ixtlan/simple_client.rb
199
210
  - lib/ixtlan/optimistic_persistence_module.rb
200
- - lib/ixtlan/optimistic_persistence_validation.rb
201
- - lib/ixtlan/version.rb.errors
202
- - lib/ixtlan/guard.rb
203
- - lib/ixtlan/passwords.rb
204
- - lib/ixtlan/monkey_patches.rb
205
- - lib/ixtlan/digest.rb
206
- - lib/ixtlan/version.rb
207
211
  - lib/ixtlan/user_logger.rb
208
- - lib/ixtlan/models/domain.rb
209
- - lib/ixtlan/models/group_locale_user.rb
210
- - lib/ixtlan/models/role.rb
211
- - lib/ixtlan/models/phrase.rb
212
- - lib/ixtlan/models/update_children.rb
213
- - lib/ixtlan/models/translation.rb
214
- - lib/ixtlan/models/audit.rb
215
- - lib/ixtlan/models/user.rb
216
- - lib/ixtlan/models/permission.rb
217
- - lib/ixtlan/models/locale.rb
218
- - lib/ixtlan/models/i18n_text.rb
219
- - lib/ixtlan/models/domain_group_user.rb
220
- - lib/ixtlan/models/configuration_locale.rb
221
- - lib/ixtlan/models/word.rb
222
- - lib/ixtlan/models/configuration.rb
223
- - lib/ixtlan/models/authentication.rb
224
- - lib/ixtlan/models/group_user.rb
225
- - lib/ixtlan/models/group.rb
226
- - lib/ixtlan/controllers/groups_controller.rb
212
+ - lib/ixtlan/guard.rb
213
+ - lib/ixtlan/optimistic_persistence.rb
214
+ - lib/ixtlan/cms_script.rb
227
215
  - lib/ixtlan/controllers/permissions_controller.rb
216
+ - lib/ixtlan/controllers/authentications_controller.rb
217
+ - lib/ixtlan/controllers/texts_controller.rb
228
218
  - lib/ixtlan/controllers/phrases_controller.rb
219
+ - lib/ixtlan/controllers/word_bundles_controller.rb
229
220
  - lib/ixtlan/controllers/configurations_controller.rb
230
- - lib/ixtlan/controllers/texts_controller.rb
221
+ - lib/ixtlan/controllers/users_controller.rb
231
222
  - lib/ixtlan/controllers/locales_controller.rb
232
- - lib/ixtlan/controllers/word_bundles_controller.rb
233
223
  - lib/ixtlan/controllers/audits_controller.rb
234
224
  - lib/ixtlan/controllers/search_query.rb
235
- - lib/ixtlan/controllers/authentications_controller.rb
225
+ - lib/ixtlan/controllers/groups_controller.rb
236
226
  - lib/ixtlan/controllers/domains_controller.rb
237
- - lib/ixtlan/controllers/users_controller.rb
227
+ - lib/ixtlan/mailer/password.erb
238
228
  - lib/ixtlan/mailer/new_user.erb
239
229
  - lib/ixtlan/mailer/error_notification.erb
240
- - lib/ixtlan/mailer/password.erb
241
- - lib/ixtlan/rails/timestamps_modified_by_filter.rb
242
- - lib/ixtlan/rails/rescue_module.rb
243
- - lib/ixtlan/rails/cache_headers.rb
244
- - lib/ixtlan/rails/audit.rb
245
- - lib/ixtlan/rails/error_handling.rb
230
+ - lib/ixtlan/models/domain.rb
231
+ - lib/ixtlan/models/user.rb
232
+ - lib/ixtlan/models/role.rb
233
+ - lib/ixtlan/models/group_locale_user.rb
234
+ - lib/ixtlan/models/group.rb
235
+ - lib/ixtlan/models/audit.rb
236
+ - lib/ixtlan/models/authentication.rb
237
+ - lib/ixtlan/models/domain_group_user.rb
238
+ - lib/ixtlan/models/word.rb
239
+ - lib/ixtlan/models/locale.rb
240
+ - lib/ixtlan/models/update_children.rb
241
+ - lib/ixtlan/models/i18n_text.rb
242
+ - lib/ixtlan/models/translation.rb
243
+ - lib/ixtlan/models/configuration.rb
244
+ - lib/ixtlan/models/group_user.rb
245
+ - lib/ixtlan/models/configuration_locale.rb
246
+ - lib/ixtlan/models/permission.rb
247
+ - lib/ixtlan/models/phrase.rb
246
248
  - lib/ixtlan/rails/migrations.rb
247
- - lib/ixtlan/rails/unrestful_authentication.rb
249
+ - lib/ixtlan/rails/error_handling.rb
248
250
  - lib/ixtlan/rails/session_timeout.rb
251
+ - lib/ixtlan/rails/audit.rb
252
+ - lib/ixtlan/rails/rescue_module.rb
253
+ - lib/ixtlan/rails/timestamps_modified_by_filter.rb
249
254
  - lib/ixtlan/rails/guard.rb
255
+ - lib/ixtlan/rails/cache_headers.rb
256
+ - lib/ixtlan/rails/unrestful_authentication.rb
250
257
  - generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb
251
258
  - generators/ixtlan_datamapper_rspec_model/templates/model_spec.rb
252
259
  - generators/ixtlan_datamapper_model/ixtlan_datamapper_model_generator.rb
253
- - generators/ixtlan_datamapper_model/templates/migration.rb
254
260
  - generators/ixtlan_datamapper_model/templates/model.rb
261
+ - generators/ixtlan_datamapper_model/templates/migration.rb
255
262
  - generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb
263
+ - generators/ixtlan_datamapper_rspec_scaffold/templates/controller_spec.rb
256
264
  - generators/ixtlan_datamapper_rspec_scaffold/templates/layout.html.erb
257
265
  - generators/ixtlan_datamapper_rspec_scaffold/templates/controller.rb
258
- - generators/ixtlan_datamapper_rspec_scaffold/templates/controller_spec.rb
259
- - generators/ixtlan_datamapper_rspec_scaffold/templates/i18n.rb
260
266
  - generators/ixtlan_datamapper_rspec_scaffold/templates/guard.rb
267
+ - generators/ixtlan_datamapper_rspec_scaffold/templates/i18n.rb
261
268
  - generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb
262
- - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java
263
- - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java
264
- - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java
269
+ - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java
265
270
  - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/AbstractApplicationResourceTestGwt.java
266
271
  - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java
272
+ - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java
267
273
  - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/GwtTestSuite.java
268
- - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java
269
- - spec/text_collection_spec.rb
270
- - spec/optimistic_persistence_spec.rb
274
+ - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java
275
+ - generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java
276
+ - spec/user_spec.rb
271
277
  - spec/phrase_spec.rb
272
- - spec/guard_spec.rb
278
+ - spec/spec_helper.rb
279
+ - spec/text_collection_spec.rb
273
280
  - spec/authentication_spec.rb
281
+ - spec/unrestful_authentication_spec.rb
282
+ - spec/user_logger_spec.rb
283
+ - spec/spec.opts
284
+ - spec/optimistic_persistence_spec.rb
274
285
  - spec/session_timeout_spec.rb
275
- - spec/spec_helper.rb
286
+ - spec/passwords_spec.rb
276
287
  - spec/modified_by_spec.rb
277
- - spec/user_spec.rb
278
- - spec/spec.opts
279
288
  - spec/text_spec.rb
280
- - spec/user_logger_spec.rb
281
- - spec/unrestful_authentication_spec.rb
282
- - spec/passwords_spec.rb
289
+ - spec/guard_spec.rb
283
290
  - spec/guards/samples.rb
284
291
  has_rdoc: true
285
292
  homepage: http://github.com/mkristian/ixtlan/ixtlan-core
@@ -313,15 +320,15 @@ signing_key:
313
320
  specification_version: 3
314
321
  summary: ixtlan plugins for rails and datamapper
315
322
  test_files:
316
- - spec/text_collection_spec.rb
317
- - spec/optimistic_persistence_spec.rb
323
+ - spec/user_spec.rb
318
324
  - spec/phrase_spec.rb
319
- - spec/guard_spec.rb
325
+ - spec/text_collection_spec.rb
320
326
  - spec/authentication_spec.rb
327
+ - spec/unrestful_authentication_spec.rb
328
+ - spec/user_logger_spec.rb
329
+ - spec/optimistic_persistence_spec.rb
321
330
  - spec/session_timeout_spec.rb
331
+ - spec/passwords_spec.rb
322
332
  - spec/modified_by_spec.rb
323
- - spec/user_spec.rb
324
333
  - spec/text_spec.rb
325
- - spec/user_logger_spec.rb
326
- - spec/unrestful_authentication_spec.rb
327
- - spec/passwords_spec.rb
334
+ - spec/guard_spec.rb