lipsiadmin 4.1.2 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 2009-05-21
2
+ * Removed some grids defaults
3
+ * Added attacher_name in before_save
4
+ * Started a new task for translate models for I18n
5
+ * Fix a bug in account.rb
6
+ * Added ImageMagick requirements to gem
7
+ * Improved doc
8
+ * Allow models to have multiple attachments definitions
9
+
1
10
  2009-05-18
2
11
  * Small fix in generation of account access
3
12
  * Fix an issue in backend_page generator
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Lipsiadmin is a new revolutionary admin for your projects.
4
4
 
5
- Is developped by http://www.lipsiasoft.com that use it from 2 years in production enviroments.
5
+ Is developped by http://www.lipsiasoft.com that use it from 3 years in production enviroments.
6
6
 
7
7
  Lipsiadmin is based on Ext Js 2.2 framework (with prototype adapter) works with Rails 2+
8
8
 
@@ -21,8 +21,8 @@ Twitter:: http://twitter.com/daddye
21
21
 
22
22
  ==Requirements
23
23
 
24
- Rails 2+
25
- Haml 2+
24
+ * Rails 2+
25
+ * Haml 2+
26
26
 
27
27
  ==Installation
28
28
 
@@ -38,8 +38,12 @@ Simply because we mantain backward compatibility until a 5.0 version.
38
38
  This mean that before v 5.0 we only do small improvemets, bug fix, doc etc...
39
39
 
40
40
  If you want install the edge version you can simply do:
41
-
41
+
42
+ gem install haml
42
43
  script/plugin install git://github.com/Lipsiasoft/lipsiadmin.git
44
+
45
+ Remember that for use your attachment processor (Paperclip) you need ImageMagick installed
46
+ on your sistem
43
47
 
44
48
  ==Examples
45
49
 
data/Rakefile CHANGED
@@ -45,6 +45,7 @@ spec = Gem::Specification.new do |s|
45
45
  s.summary = "Lipsiadmin is a new revolutionary admin for your projects.Lipsiadmin is based on Ext Js 2.0. framework (with prototype adapter) and is ready for Rails 2.0. This admin is for newbie developper but also for experts, is not entirely written in javascript because the aim of developper wose build in a agile way web/site apps so we use extjs in a new intelligent way a mixin of 'old' html and new ajax functions, for example ext manage the layout of page, grids, tree and errors, but form are in html code."
46
46
  s.files = FileList["CHANGELOG", "README.rdoc", "MIT-LICENSE", "Rakefile", "init.rb", "{lipsiadmin_generators,lib,resources,tasks}/**/*"].to_a
47
47
  s.has_rdoc = true
48
+ s.requirements << "ImageMagick"
48
49
  s.add_dependency('haml')
49
50
  s.add_dependency('rails', '>= 2.2.1')
50
51
  end
@@ -47,6 +47,12 @@ module Lipsiadmin
47
47
  def has_one_attachment(name, options={})
48
48
  options[:as] ||= :attacher
49
49
  options[:class_name] ||= "Attachment"
50
+
51
+ # We need to check if the attachment model allow multiple attachments
52
+ multi_attachments = options[:class_name].constantize.column_names.include?("attacher_name")
53
+
54
+ options[:conditions] = "attacher_name = '#{name}'" if multi_attachments
55
+
50
56
  has_one name, options
51
57
  before_save "before_save_for_#{name}"
52
58
  attr_accessor "#{name}_attributes"
@@ -75,6 +81,9 @@ module Lipsiadmin
75
81
 
76
82
  attributes.merge!(:attachment_definitions => self.class.attachment_definitions[name])
77
83
 
84
+ # We need to add the new attacher_name
85
+ attributes.merge!(:attacher_name => name.to_s) if multi_attachments
86
+
78
87
  if file_column = self.send(name)
79
88
  file_column.update_attributes(attributes)
80
89
  else
@@ -103,6 +112,11 @@ module Lipsiadmin
103
112
  options[:as] ||= :attacher
104
113
  options[:class_name] ||= "Attachment"
105
114
 
115
+ # We need to check if the attachment model allow multiple attachments
116
+ multi_attachments = options[:class_name].constantize.column_names.include?("attacher_name")
117
+
118
+ options[:conditions] = "attacher_name = '#{name}'" if multi_attachments
119
+
106
120
  has_many name, options
107
121
  before_save "before_save_for_#{name}"
108
122
  attr_accessor "#{name}_attributes"
@@ -135,6 +149,8 @@ module Lipsiadmin
135
149
  for attribute in attributes
136
150
  next if attribute["file"].blank?
137
151
  attribute.merge!(:attachment_definitions => self.class.attachment_definitions[name])
152
+ # We need to add the new attacher_name
153
+ attribute.merge!(:attacher_name => name.to_s) if multi_attachments
138
154
  self.send(name).build(attribute)
139
155
  end
140
156
 
data/lib/lipsiadmin.rb CHANGED
@@ -71,6 +71,7 @@ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :backend => ["
71
71
  I18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', 'backend', '*.{rb,yml}')]
72
72
  I18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', 'frontend', '*.{rb,yml}')]
73
73
  I18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', 'models', '*.{rb,yml}')]
74
+ I18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', 'models', '**/*.{rb,yml}')]
74
75
  I18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', 'rails', '*.{rb,yml}')]
75
76
 
76
77
  # Load generator languages
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Lipsiadmin
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 4
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,9 +1,10 @@
1
1
  class CreateAttachments < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :attachments, :force => true do |t|
4
- t.string :attached_file_name, :attached_content_type
5
- t.integer :attached_file_size
4
+ t.string :attached_file_name, :attached_content_type
5
+ t.integer :attached_file_size
6
6
  t.references :attacher, :polymorphic => true
7
+ t.string :attacher_name
7
8
  t.timestamps
8
9
  end
9
10
  end
@@ -5,6 +5,7 @@ class Account < ActiveRecord::Base
5
5
 
6
6
  serialize :modules
7
7
 
8
+ # Validations
8
9
  validates_presence_of :name, :surname, :email
9
10
  validates_presence_of :password, :if => :password_required?
10
11
  validates_presence_of :password_confirmation, :if => :password_required?
@@ -13,31 +14,33 @@ class Account < ActiveRecord::Base
13
14
  validates_length_of :email, :within => 3..100
14
15
  validates_uniqueness_of :email, :case_sensitive => false
15
16
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
17
+ validates_inclusion_of :role, :in => AccountAccess.roles
18
+
19
+ # Relations
20
+ # go here
21
+
22
+ # Callbacks
16
23
  before_save :encrypt_password
24
+ after_create :deliver_registration
17
25
 
18
- def after_create
19
- Notifier.deliver_registration(self)
20
- end
26
+ # Named Scopes
27
+ # go here
21
28
 
22
29
  def full_name
23
30
  "#{name} #{surname}".strip
24
31
  end
25
32
 
33
+ # If we don't found a module we need to
34
+ # to return an empty array
26
35
  def modules
27
36
  read_attribute(:modules) || []
28
37
  end
29
38
 
39
+ # We need to perform a little rewrite
30
40
  def modules=(perms)
31
41
  perms = perms.collect {|p| p.to_sym unless p.blank? }.compact if perms
32
42
  write_attribute(:modules, perms)
33
43
  end
34
-
35
- # Activates the user in the database.
36
- def activate
37
- @activated = true
38
- self.activated_at = Time.now.utc
39
- self.activation_code = nil
40
- end
41
44
 
42
45
  # Authenticates a user by their email and unencrypted password. Returns the user or nil.
43
46
  def self.authenticate(email, password)
@@ -54,7 +57,8 @@ class Account < ActiveRecord::Base
54
57
  rescue
55
58
  nil
56
59
  end
57
-
60
+
61
+ # Get the uncripted password
58
62
  def password_clean
59
63
  unless @password
60
64
  enc = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
@@ -67,8 +71,9 @@ class Account < ActiveRecord::Base
67
71
  nil
68
72
  end
69
73
 
74
+ # If you want you can integrate you custom activation/blocking system
75
+ # Our auth system already check this method so don't delete it
70
76
  def active?
71
- # If you want you can integrate you custom activation/blocking system
72
77
  true
73
78
  end
74
79
 
@@ -77,11 +82,12 @@ class Account < ActiveRecord::Base
77
82
  self.class.encrypt(password, salt)
78
83
  end
79
84
 
85
+ # Check if the db password
80
86
  def authenticated?(password)
81
- crypted_password.chomp == encrypt(password).chomp
87
+ crypted_password.chomp == encrypt(password).chomp rescue false
82
88
  end
83
89
 
84
-
90
+ # Gets the project modules for this accounts
85
91
  def maps
86
92
  if modules && modules.split(",").size > 0
87
93
  maps = AccountAccess.find_by_project_modules(modules.split(","))
@@ -100,17 +106,20 @@ class Account < ActiveRecord::Base
100
106
  # def administrator?
101
107
  # role == "administrator"
102
108
  # end
103
- AccountAccess.roles.each { |r| define_method("#{r.to_s.downcase.gsub(" ","_").to_sym}?") { role.to_s.downcase.gsub(" ","_").to_sym == r.to_s.downcase.gsub(" ","_").to_sym } }
109
+ AccountAccess.roles.each { |r| define_method("#{r.to_s.downcase.gsub(" ","_").to_sym}?") { role.to_s.downcase == r.to_s.downcase } }
104
110
 
105
- protected
106
- # before filter
107
- def encrypt_password
108
- return if password.blank?
109
- self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
110
- self.crypted_password = encrypt(password)
111
- end
112
-
113
- def password_required?
114
- crypted_password.blank? || !password.blank?
115
- end
111
+ protected
112
+ def encrypt_password
113
+ return if password.blank?
114
+ self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
115
+ self.crypted_password = encrypt(password)
116
+ end
117
+
118
+ def password_required?
119
+ crypted_password.blank? || !password.blank?
120
+ end
121
+
122
+ def deliver_registration
123
+ Notifier.deliver_registration(self)
124
+ end
116
125
  end
@@ -9,20 +9,65 @@ namespace :lipsiadmin do
9
9
  end
10
10
  end
11
11
 
12
- desc "Updated the current rails locale and backend locale"
13
- task :locales do
14
- Dir[File.join(File.dirname(__FILE__), '..', '/lipsiadmin_generators/backend/templates/config/locales/rails/*.yml')].each do |yml|
15
- puts "Coping config/locales/rails/#{File.basename(yml)} ... DONE"
16
- FileUtils.cp(yml, RAILS_ROOT + '/config/locales/rails')
17
- end
12
+
13
+ namespace :locales do
14
+ desc "Updated the current rails locale and backend locale"
15
+ task :system do
16
+ Dir[File.join(File.dirname(__FILE__), '..', '/lipsiadmin_generators/backend/templates/config/locales/rails/*.yml')].each do |yml|
17
+ puts "Coping config/locales/rails/#{File.basename(yml)} ... DONE"
18
+ FileUtils.cp(yml, RAILS_ROOT + '/config/locales/rails')
19
+ end
18
20
 
19
- Dir[File.join(File.dirname(__FILE__), '..', '/lipsiadmin_generators/backend/templates/config/locales/backend/*.yml')].each do |yml|
20
- puts "Coping config/locales/backend/#{File.basename(yml)} ... DONE"
21
- FileUtils.cp(yml, RAILS_ROOT + '/config/locales/backend')
21
+ Dir[File.join(File.dirname(__FILE__), '..', '/lipsiadmin_generators/backend/templates/config/locales/backend/*.yml')].each do |yml|
22
+ puts "Coping config/locales/backend/#{File.basename(yml)} ... DONE"
23
+ FileUtils.cp(yml, RAILS_ROOT + '/config/locales/backend')
24
+ end
25
+ end
26
+
27
+ desc "Updated the current models locales. Use LANGS=en,it,cz"
28
+ task :models => :environment do
29
+ langs = ENV['LANGS'] ? ENV['LANGS'].split(",") : [:en]
30
+ models = Dir["#{RAILS_ROOT}/app/models/*"].collect { |model| File.basename(model, ".rb") }
31
+
32
+ for model in models
33
+ # Get the model class
34
+ klass = model.camelize.constantize
35
+ next unless klass.respond_to?(:columns)
36
+
37
+ # Init the processing
38
+ print "Processing #{model.humanize}: "
39
+ FileUtils.mkdir_p("#{RAILS_ROOT}/config/locales/models/#{model}")
40
+
41
+ # Create models for it and en locales
42
+ langs.each do |lang|
43
+ filename = "#{RAILS_ROOT}/config/locales/models/#{model}/#{lang}.yml"
44
+ columns = klass.columns.collect(&:name)
45
+ # If the lang file already exist we need to check it
46
+ if File.exist?(filename)
47
+ locale = File.open(filename).read
48
+ columns.each do |c|
49
+ locale += " #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
50
+ end
51
+ print "#{lang} already exist ... "; $stdout.flush
52
+ # Do some ere
53
+ else
54
+ locale = "#{lang}:" + "\n" +
55
+ " activerecord:" + "\n" +
56
+ " models:" + "\n" +
57
+ " #{model}: #{klass.human_name}" + "\n" +
58
+ " attributes:" + "\n" +
59
+ " #{model}:" + "\n" +
60
+ columns.collect { |c| " #{c}: #{klass.human_attribute_name(c)}" }.join("\n")
61
+ print "#{lang} created new one ... "; $stdout.flush
62
+ end
63
+ File.open(filename, "w") { |f| f.puts locale }
64
+ end
65
+ puts
66
+ end
22
67
  end
23
68
  end
24
- end
25
- end
69
+ end # namespace :update
70
+ end # namespace :lipsiadmin
26
71
 
27
72
  desc "Init the test env and autotest them"
28
73
  task :autotest => "test:init" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lipsiadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davide D'Agostino
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-19 00:00:00 +02:00
12
+ date: 2009-05-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -556,8 +556,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
556
556
  - !ruby/object:Gem::Version
557
557
  version: "0"
558
558
  version:
559
- requirements: []
560
-
559
+ requirements:
560
+ - ImageMagick
561
561
  rubyforge_project: lipsiadmin
562
562
  rubygems_version: 1.3.3
563
563
  signing_key: