ixtlan 0.4.0.pre3 → 0.4.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module Ixtlan
2
+ class AuditRack
3
+ AUDIT = Ixtlan::Models::AUDIT.nil? ? nil : Object.full_const_get(Ixtlan::Models::AUDIT)
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ result = @app.call(env)
11
+ if AUDIT
12
+ AUDIT.pop_all.each do |audit|
13
+ audit.save
14
+ end
15
+ end
16
+ result
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Ixtlan
2
+ module Controllers
3
+ module AuditsController
4
+
5
+ def self.included(base)
6
+ base.send(:include, Ixtlan::Controllers::SearchQuery)
7
+ end
8
+
9
+ public
10
+
11
+ # GET /audits
12
+ # GET /audits.xml
13
+ def index
14
+ @audits = Audit.all(query(:login, params[:query])) + Audit.all(query(:message, params[:query]))
15
+
16
+ respond_to do |format|
17
+ format.html
18
+ format.xml { render :xml => @audits }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -5,20 +5,23 @@ module Ixtlan
5
5
  private
6
6
 
7
7
  def simple_query(search_parameter)
8
+ query(search_parameter, params[search_parameter])
9
+ end
10
+
11
+ def query(parameter, value)
8
12
  args = {}
9
13
  args[:limit] = params[:limit].to_i + 1 if params[:limit]
10
14
  args[:offset] = params[:offset].to_i if params[:offset]
11
15
 
12
- if login = params[search_parameter]
16
+ if value
13
17
  if "false" == params[:fuzzy]
14
- args[search_parameter] = login
18
+ args[parameter] = value
15
19
  else
16
- args[search_parameter.like] = "%" + login.to_s + "%"
20
+ args[parameter.like] = "%" + value.to_s + "%"
17
21
  end
18
22
  end
19
23
  args
20
24
  end
21
-
22
25
  end
23
26
  end
24
27
  end
@@ -72,7 +72,8 @@ module Ixtlan
72
72
  format.html { redirect_to(user_url(@user.id)) }
73
73
  format.xml { render :xml => @user, :status => :created, :location => user_url(@user.id) + ".xml" }
74
74
 
75
- Mailer.deliver_password(@user.email, "Configuration.instance.password_sender_email", @user.password)
75
+ ::Ixtlan::Mailer.deliver_new_user(@user.email, Configuration.instance.password_sender_email, @user.login, Configuration.instance.login_url)
76
+ ::Ixtlan::Mailer.deliver_password(@user.email, Configuration.instance.password_sender_email, @user.password)
76
77
  else
77
78
  format.html { render :action => "new" }
78
79
  format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
@@ -46,12 +46,19 @@ module Ixtlan
46
46
  DataMapper.logger = logger([appender,rails_appender], DataMapper)
47
47
 
48
48
  #TODO better find out which database !!!
49
- DataObjects::Sqlite3.logger = logger([appender,rails_appender], DataObjects)
49
+ if DataObjects.const_defined?("Sqlite3")
50
+ DataObjects::Sqlite3.logger = logger([appender,rails_appender], DataObjects)
51
+ elsif DataObjects.const_defined?("Mysql")
52
+ DataObjects::Mysql.logger = logger([appender,rails_appender], DataObjects)
53
+ elsif DataObjects.const_defined?("Postgres")
54
+ DataObjects::Postgres.logger = logger([appender,rails_appender], DataObjects)
55
+ end
50
56
 
51
57
  # configure audit logger
52
58
  Ixtlan::AuditConfig.configure(Object.full_const_get(Ixtlan::Models::CONFIGURATION).instance.keep_audit_logs,
53
59
  log_filebase('audit'),
54
60
  [
61
+ Ixtlan::AuditConfig,
55
62
  Ixtlan::Models::User,
56
63
  Ixtlan::Rails::Audit,
57
64
  Ixtlan::Rails::SessionTimeout,
@@ -0,0 +1,5 @@
1
+ a new user has been added.
2
+
3
+ URL : <%= @url %>
4
+ username: <%= @username %>
5
+ password: will be sent in a separate email
data/lib/ixtlan/mailer.rb CHANGED
@@ -3,7 +3,6 @@ module Ixtlan
3
3
 
4
4
  require 'pathname'
5
5
  path = Pathname(__FILE__).parent.dirname.to_s
6
- p path
7
6
  view_paths << path unless view_paths.member? path
8
7
 
9
8
  def password(email_to, email_from, password)
@@ -15,8 +14,17 @@ module Ixtlan
15
14
  @headers = {}
16
15
  end
17
16
 
17
+ def new_user(email_to, email_from, login, url)
18
+ @subject = "details for #{url}"
19
+ @body = {:username => login, :url => url}
20
+ @recipients = email_to
21
+ @from = email_from
22
+ @sent_on = Time.now
23
+ @headers = {}
24
+ end
25
+
18
26
  def error_notification(email_from, email_to, exception, error_file)
19
- @subject = exception.to_s
27
+ @subject = exception.message
20
28
  @body = {:text => "#{error_file}"}
21
29
  @recipients = email_to
22
30
  @from = email_from
@@ -0,0 +1,43 @@
1
+ require 'dm-serializer'
2
+ module Ixtlan
3
+ module Models
4
+ module Audit
5
+ def self.included(model)
6
+ model.send(:include, DataMapper::Resource)
7
+
8
+ model.property :id, ::DataMapper::Types::Serial
9
+
10
+ model.property :date, DateTime, :required => true
11
+
12
+ model.property :login, String, :required => true, :format => /^[a-zA-Z0-9]+$/, :length => 32, :auto_validation => false #required => true does not allow empty string :-( so skip validation
13
+
14
+ model.property :message, String, :required => true, :length => 255
15
+
16
+ model.class_eval <<-EOS, __FILE__, __LINE__
17
+ unless const_defined? "CONFIGURATION"
18
+ CONFIGURATION = Object.full_const_get(Models::CONFIGURATION)
19
+ end
20
+ def self.pop_all
21
+ result = Thread.current[:audit] || []
22
+ Thread.current[:audit] = nil
23
+ if(!@last_cleanup.nil? && @last_cleanup < 1.days.ago)
24
+ @last_cleanup = Date.today
25
+ begin
26
+ self.class.all(:date.lt => CONFIGURATION.keep_audit_log.days.ago).destroy!
27
+ rescue Error
28
+ # TODO log this !!
29
+ end
30
+ end
31
+ result
32
+ end
33
+ EOS
34
+ end
35
+
36
+ def push
37
+ list = (Thread.current[:audit] ||= [])
38
+ list << self
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -22,6 +22,8 @@ module Ixtlan
22
22
 
23
23
  model.property :password_sender_email, String, :format => :email_address, :required => false, :length => 64
24
24
 
25
+ model.property :login_url, String, :required => false, :length => 128
26
+
25
27
  model.property :notification_sender_email, String, :format => :email_address, :required => false, :length => 64
26
28
 
27
29
  model.property :notification_recipient_emails, String, :format => Proc.new { |email| emails = email.split(','); emails.find_all { |e| e =~ DataMapper::Validate::Format::Email::EmailAddress }.size == emails.size}, :required => false, :length => 254 #honour mysql max varchar length
data/lib/ixtlan/models.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  module Ixtlan
2
2
  module Models
3
- AUTHENTICATION = "::Ixtlan::Models::Authentication" unless const_defined? "AUTHENTICATION"
4
- USER = "::Ixtlan::Models::User" unless const_defined? "USER"
5
- GROUP = "::Ixtlan::Models::Group" unless const_defined? "GROUP"
6
- ROLE = "::Ixtlan::Models::Role" unless const_defined? "ROLE"
7
- PERMISSION = "::Ixtlan::Models::Permission" unless const_defined? "PERMISSION"
8
- LOCALE = "::Ixtlan::Models::Locale" unless const_defined? "LOCALE"
9
- DOMAIN = "::Ixtlan::Models::Domain" unless const_defined? "DOMAIN"
10
- CONFIGURATION = "::Ixtlan::Models::Configuration" unless const_defined? "CONFIGURATION"
11
- TRANSLATION = "::Ixtlan::Models::Translation" unless const_defined? "TRANSLATION"
12
- TEXT = "::Ixtlan::Models::I18nText" unless const_defined? "TEXT"
3
+ AUTHENTICATION = "::Authentication" unless const_defined? "AUTHENTICATION"
4
+ AUDIT = "::Audit" unless const_defined? "AUDIT"
5
+ USER = "::User" unless const_defined? "USER"
6
+ GROUP = "::Group" unless const_defined? "GROUP"
7
+ ROLE = "::Role" unless const_defined? "ROLE"
8
+ PERMISSION = "::Permission" unless const_defined? "PERMISSION"
9
+ LOCALE = "::Locale" unless const_defined? "LOCALE"
10
+ DOMAIN = "::Domain" unless const_defined? "DOMAIN"
11
+ CONFIGURATION = "::Configuration" unless const_defined? "CONFIGURATION"
12
+ TRANSLATION = "::Translation" unless const_defined? "TRANSLATION"
13
+ TEXT = "::I18nText" unless const_defined? "TEXT"
13
14
  end
14
15
  end
@@ -90,7 +90,7 @@ module Ixtlan
90
90
  logger = Logger.new(log_file)
91
91
 
92
92
  dump_environment(logger, exception, controller)
93
- Ixtlan::Mailer.deliver_error_notification(@email_from, @email_to, exception, log_file) unless (@email_to.blank? || @email_from.blank?)
93
+ ::Ixtlan::Mailer.deliver_error_notification(@email_from, @email_to, exception, log_file) unless (@email_to.blank? || @email_from.blank?)
94
94
  log_file
95
95
  end
96
96
 
@@ -75,6 +75,10 @@ module Ixtlan
75
75
  def self.create_text
76
76
  TEXT.auto_migrate!
77
77
  end
78
+
79
+ def self.create_audit
80
+ Object.const_get(Ixtlan::Models::AUDIT.sub(/^::/, '')).auto_migrate! if Ixtlan::Models::AUDIT
81
+ end
78
82
  end
79
83
  end
80
84
  end
@@ -0,0 +1,28 @@
1
+ module Ixtlan
2
+ module Rails
3
+ module RescueModule
4
+ def self.included(controller)
5
+ # needs 'optimistic_persistence'
6
+ controller.rescue_from ::Ixtlan::StaleResourceError, :with => :stale_resource
7
+
8
+ # needs 'guard'
9
+ controller.rescue_from ::Ixtlan::GuardException, :with => :page_not_found
10
+ controller.rescue_from ::Ixtlan::PermissionDenied, :with => :page_not_found
11
+
12
+ # rest is standard rails or datamapper
13
+ controller.rescue_from ::DataMapper::ObjectNotFoundError, :with => :page_not_found
14
+ controller.rescue_from ::ActionController::RoutingError, :with => :page_not_found
15
+ controller.rescue_from ::ActionController::UnknownAction, :with => :page_not_found
16
+ controller.rescue_from ::ActionController::MethodNotAllowed, :with => :page_not_found
17
+ controller.rescue_from ::ActionController::NotImplemented, :with => :page_not_found
18
+ controller.rescue_from ::ActionController::InvalidAuthenticityToken, :with => :stale_resource
19
+
20
+ # have nice stacktraces in development mode
21
+ unless controller.consider_all_requests_local
22
+ controller.rescue_from ::ActionView::MissingTemplate, :with => :internal_server_error
23
+ controller.rescue_from ::ActionView::TemplateError, :with => :internal_server_error
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,8 @@ module Ixtlan
2
2
 
3
3
  class UserLogger
4
4
 
5
+ AUDIT = Ixtlan::Models::AUDIT.nil? ? nil : Object.full_const_get(Ixtlan::Models::AUDIT)
6
+
5
7
  def initialize(arg)
6
8
  @logger = Slf4r::LoggerFacade.new(arg)
7
9
  end
@@ -46,7 +48,11 @@ module Ixtlan
46
48
 
47
49
  def log_user(user, message = nil, &block)
48
50
  user ||= "???"
49
- @logger.info {"[#{user}] #{message}#{block.call if block}" }
51
+ msg = "#{message}#{block.call if block}"
52
+ if AUDIT
53
+ AUDIT.new(:date => DateTime.now, :message => msg, :login => user).push
54
+ end
55
+ @logger.info {"[#{user}] #{msg}" }
50
56
  end
51
57
  end
52
58
  end
@@ -1,3 +1,3 @@
1
1
  class Ixtlan
2
- VERSION = '0.4.0.pre3'.freeze
2
+ VERSION = '0.4.0.pre4'.freeze
3
3
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 4
8
8
  - 0
9
- - pre3
10
- version: 0.4.0.pre3
9
+ - pre4
10
+ version: 0.4.0.pre4
11
11
  platform: ruby
12
12
  authors:
13
13
  - mkristian
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-29 00:00:00 +05:30
18
+ date: 2010-07-05 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -170,6 +170,7 @@ files:
170
170
  - lib/ixtlan/logger_config.rb
171
171
  - lib/ixtlan/models.rb
172
172
  - lib/ixtlan/audit_config.rb
173
+ - lib/ixtlan/audit_rack.rb
173
174
  - lib/ixtlan/session.rb
174
175
  - lib/ixtlan/optimistic_persistence.rb
175
176
  - lib/ixtlan/mailer.rb
@@ -188,6 +189,7 @@ files:
188
189
  - lib/ixtlan/models/phrase.rb
189
190
  - lib/ixtlan/models/update_children.rb
190
191
  - lib/ixtlan/models/translation.rb
192
+ - lib/ixtlan/models/audit.rb
191
193
  - lib/ixtlan/models/user.rb
192
194
  - lib/ixtlan/models/permission.rb
193
195
  - lib/ixtlan/models/locale.rb
@@ -206,13 +208,16 @@ files:
206
208
  - lib/ixtlan/controllers/texts_controller.rb
207
209
  - lib/ixtlan/controllers/locales_controller.rb
208
210
  - lib/ixtlan/controllers/word_bundles_controller.rb
211
+ - lib/ixtlan/controllers/audits_controller.rb
209
212
  - lib/ixtlan/controllers/search_query.rb
210
213
  - lib/ixtlan/controllers/authentications_controller.rb
211
214
  - lib/ixtlan/controllers/domains_controller.rb
212
215
  - lib/ixtlan/controllers/users_controller.rb
216
+ - lib/ixtlan/mailer/new_user.erb
213
217
  - lib/ixtlan/mailer/error_notification.erb
214
218
  - lib/ixtlan/mailer/password.erb
215
219
  - lib/ixtlan/rails/timestamps_modified_by_filter.rb
220
+ - lib/ixtlan/rails/rescue_module.rb
216
221
  - lib/ixtlan/rails/audit.rb
217
222
  - lib/ixtlan/rails/error_handling.rb
218
223
  - lib/ixtlan/rails/migrations.rb
@@ -283,7 +288,7 @@ rubyforge_project:
283
288
  rubygems_version: 1.3.6
284
289
  signing_key:
285
290
  specification_version: 3
286
- summary: this is set of rails and datamapper plugins for setting up a little more advanced rails application then the default rails generator does
291
+ summary: ixtlan plugins for rails and datamapper
287
292
  test_files:
288
293
  - spec/text_collection_spec.rb
289
294
  - spec/optimistic_persistence_spec.rb