padrino-admin 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1238e9f669ced57bc85bc0a563318fcfc3143684
4
- data.tar.gz: cef952fcecae26cc6721ce66d17fc4a59ce98165
3
+ metadata.gz: 6aa5241218d4e62f8664281acaf75964a7b5b662
4
+ data.tar.gz: 089b931c4d3e737172ef6232a9c93ac620197e36
5
5
  SHA512:
6
- metadata.gz: a7c1af2bf490cc4239a838b0f7f3b4b5b3aeef7a070ac131454c401d0a55de39ee0b59242b9bc3fd8e2c7165805f7b8f9dce32b9e609218c5b04a34764247a63
7
- data.tar.gz: 7a84f878e10d037f99fbe0a4ff3cdcc260e833466da8c698008cd7fc8cb9fc248a03b4c24108fffe6dc73557bd24cb1e8382ea2977a560bb68a42c62bddbf083
6
+ metadata.gz: b5945cd2a39ba565ed28e72162f60f697f6d80e6614127bf2fca30a7ab699eb70d4a856f334c2534528e35b571308a5cb6871eeed0be75345181bfc76978a58d
7
+ data.tar.gz: c937c3b00babd88d49325a6edc47d98ba9637343c958c2c98155fd063f48ad36c541471ac8b93c217e0d3477acf2e20d75bbe666263434a55420dd133bc19ee3
@@ -4,7 +4,7 @@
4
4
 
5
5
  Padrino has a beautiful Admin management dashboard with these features:
6
6
 
7
- Orm Agnostic:: Data Adapters for Datamapper, Activerecord, Sequel, Mongomapper, Mongoid, Couchrest
7
+ Orm Agnostic:: Data Adapters for Datamapper, Activerecord, Sequel, Mongomapper, Mongoid, Couchrest, Dynamoid
8
8
  Template Agnostic:: Erb, Erubis and Haml Renderer
9
9
  Authentication:: Support for Account authentication, Account Permission management
10
10
  Scaffold:: You can simply create a new "admin interface" by providing a Model
@@ -27,7 +27,7 @@ module Padrino
27
27
  # Tell us for now which orm we support
28
28
  #
29
29
  def supported_orm
30
- [:minirecord, :datamapper, :activerecord, :mongomapper, :mongoid, :couchrest, :sequel, :ohm]
30
+ [:minirecord, :datamapper, :activerecord, :mongomapper, :mongoid, :couchrest, :sequel, :ohm, :dynamoid]
31
31
  end
32
32
 
33
33
  ##
@@ -34,7 +34,7 @@ module Padrino
34
34
  # class_option :models_path, :desc => 'The models destination path', :default => '.', :type => :string
35
35
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
36
36
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
37
- class_option :renderer, :aliases => '-e', :desc => "Rendering engine (erb, haml)", :type => :string
37
+ class_option :renderer, :aliases => '-e', :desc => "Rendering engine (erb, haml, slim)", :type => :string
38
38
  class_option :admin_model, :aliases => '-m', :desc => "The name of model for access controlling", :default => 'Account', :type => :string
39
39
  class_option :admin_name, :aliases => '-a', :desc => 'The admin application name and path', :default => 'admin', :type => :string
40
40
 
@@ -131,7 +131,7 @@ module Padrino
131
131
 
132
132
  unless options[:destroy]
133
133
  add_project_module @model_plural
134
- require_dependencies('bcrypt-ruby', :require => 'bcrypt')
134
+ require_dependencies('bcrypt')
135
135
  end
136
136
 
137
137
  # A nicer select box.
@@ -144,7 +144,10 @@ module Padrino
144
144
 
145
145
  instructions = []
146
146
  instructions << "Run 'bundle'"
147
- instructions << "Run 'bundle exec rake db:migrate'" if (orm == :activerecord || orm == :datamapper || orm == :sequel)
147
+ if [:activerecord, :datamapper, :sequel].include?(orm)
148
+ instructions << "Run 'bundle exec rake db:create' if you have not created a database yet"
149
+ instructions << "Run 'bundle exec rake db:migrate'"
150
+ end
148
151
  instructions << "Now repeat after me... 'ohm mani padme hum', 'ohm mani padme hum'... :)" if orm == :ohm
149
152
  instructions << "Run 'bundle exec rake db:seed'"
150
153
  instructions << "Visit the admin panel in the browser at '/#{@admin_path}'"
@@ -56,6 +56,7 @@ module Padrino
56
56
  when :mongomapper then @klass.keys.values.reject { |key| key.name == "_id" } # On MongoMapper keys are an hash
57
57
  when :sequel then @klass.db_schema.map { |k,v| v[:type] = :text if v[:db_type] =~ /^text/i; Column.new(k, v[:type]) }
58
58
  when :ohm then @klass.attributes.map { |a| Column.new(a.to_s, :string) } # ohm has strings
59
+ when :dynamoid then @klass.attributes.map { |k,v| Column.new(k.to_s, v[:type]) }
59
60
  else raise OrmError, "Adapter #{orm} is not yet supported!"
60
61
  end
61
62
  end
@@ -99,7 +100,7 @@ module Padrino
99
100
 
100
101
  def find(params=nil)
101
102
  case orm
102
- when :activerecord, :minirecord, :mongomapper, :mongoid then "#{klass_name}.find(#{params})"
103
+ when :activerecord, :minirecord, :mongomapper, :mongoid, :dynamoid then "#{klass_name}.find(#{params})"
103
104
  when :datamapper, :couchrest then "#{klass_name}.get(#{params})"
104
105
  when :sequel, :ohm then "#{klass_name}[#{params}]"
105
106
  else raise OrmError, "Adapter #{orm} is not yet supported!"
@@ -123,7 +124,7 @@ module Padrino
123
124
 
124
125
  def update_attributes(params=nil)
125
126
  case orm
126
- when :activerecord, :minirecord, :mongomapper, :mongoid, :couchrest then "@#{name_singular}.update_attributes(#{params})"
127
+ when :activerecord, :minirecord, :mongomapper, :mongoid, :couchrest, :dynamoid then "@#{name_singular}.update_attributes(#{params})"
127
128
  when :datamapper, :ohm then "@#{name_singular}.update(#{params})"
128
129
  when :sequel then "@#{name_singular}.modified! && @#{name_singular}.update(#{params})"
129
130
  else raise OrmError, "Adapter #{orm} is not yet supported!"
@@ -144,6 +145,7 @@ module Padrino
144
145
  when :sequel then "#{klass_name}.where(:id => #{params})"
145
146
  when :mongoid then "#{klass_name}.find(#{params})"
146
147
  when :couchrest then "#{klass_name}.all(:keys => #{params})"
148
+ when :dynamoid then "#{klass_name}.find(#{params})"
147
149
  else find(params)
148
150
  end
149
151
  end
@@ -153,7 +155,7 @@ module Padrino
153
155
  when :ohm then "#{params}.each(&:delete)"
154
156
  when :sequel then "#{params}.destroy"
155
157
  when :datamapper then "#{params}.destroy"
156
- when :couchrest, :mongoid, :mongomapper then "#{params}.each(&:destroy)"
158
+ when :couchrest, :mongoid, :mongomapper, :dynamoid then "#{params}.each(&:destroy)"
157
159
  else "#{klass_name}.destroy #{params}"
158
160
  end
159
161
  end
@@ -0,0 +1,55 @@
1
+ class <%= @model_name %>
2
+ include Dynamoid::Document
3
+ attr_accessor :password, :password_confirmation
4
+
5
+ # Fields
6
+ field :name
7
+ field :surname
8
+ field :email
9
+ field :crypted_password
10
+ field :role
11
+
12
+ # Validations
13
+ validates_presence_of :email, :role
14
+ validates_presence_of :password, :if => :password_required
15
+ validates_presence_of :password_confirmation, :if => :password_required
16
+ validates_length_of :password, :within => 4..40, :if => :password_required
17
+ validates_confirmation_of :password, :if => :password_required
18
+ validates_length_of :email, :within => 3..100
19
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
20
+ validates_format_of :role, :with => /[A-Za-z]/
21
+
22
+ # Callbacks
23
+ before_save :encrypt_password, :if => :password_required
24
+
25
+ ##
26
+ # This method is for authentication purpose.
27
+ #
28
+ def self.authenticate(email, password)
29
+ account = find_by_email(email) if email.present?
30
+ account && account.has_password?(password) ? account : nil
31
+ end
32
+
33
+ ##
34
+ # This method is used by AuthenticationHelper.
35
+ #
36
+ def self.find_by_id(id, options = {})
37
+ id ? super(id, options) : nil
38
+ end
39
+
40
+ def has_password?(password)
41
+ ::BCrypt::Password.new(crypted_password) == password
42
+ end
43
+
44
+ private
45
+
46
+ def encrypt_password
47
+ value = ::BCrypt::Password.create(password)
48
+ value = value.force_encoding(Encoding::UTF_8) if value.encoding == Encoding::ASCII_8BIT
49
+ self.crypted_password = value
50
+ end
51
+
52
+ def password_required
53
+ crypted_password.blank? || password.present?
54
+ end
55
+ end
@@ -1,6 +1,5 @@
1
1
  module <%= @app_name %>
2
2
  class <%= @admin_name %> < Padrino::Application
3
- register Padrino::Rendering
4
3
  register Padrino::Mailer
5
4
  register Padrino::Helpers
6
5
  register Padrino::Admin::AccessControl
@@ -209,6 +209,12 @@ footer p {
209
209
  font-size: 2.5em;
210
210
  line-height: 1em;
211
211
  }
212
+ .navbar .navbar-nav > .active > a,
213
+ .navbar .navbar-nav > .active > a:hover,
214
+ .navbar .navbar-nav > .active > a:focus {
215
+ color: #555;
216
+ background-color: #e7e7e7;
217
+ }
212
218
  /* --- End Application::TopBar --- */
213
219
 
214
220
  /* --- Begin Application::List --- */
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../helper')
2
2
 
3
3
  describe "AccountModelGenerator" do
4
4
  before do
5
- @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
6
6
  %x[mkdir -p #{@apptmp}]
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../helper')
2
2
 
3
3
  describe "AdminAppGenerator" do
4
4
  before do
5
- @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
6
6
  `mkdir -p #{@apptmp}`
7
7
  end
8
8
 
@@ -11,6 +11,12 @@ describe "AdminAppGenerator" do
11
11
  end
12
12
 
13
13
  describe 'the admin app generator' do
14
+ before do
15
+ # Account gets created by Datamapper's migration and then gets
16
+ # rejected by model generator as already defined
17
+ Object.send(:remove_const, :Account) if defined?(Account)
18
+ end
19
+
14
20
  it 'should fail outside app root' do
15
21
  out, err = capture_io { generate(:admin_app, "-r=#{@apptmp}") }
16
22
  assert_match(/not at the root/, out)
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  describe "AdminPageGenerator" do
16
16
  before do
17
- @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
17
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
18
18
  `mkdir -p #{@apptmp}`
19
19
  end
20
20
 
@@ -2,12 +2,12 @@ ENV['RACK_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
3
3
 
4
4
  require File.expand_path('../../../load_paths', __FILE__)
5
- require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda')
5
+ require 'minitest/autorun'
6
+ require 'minitest/pride'
7
+ require 'mocha/setup'
6
8
  require 'rack/test'
7
9
  require 'rack'
8
- require 'uuid'
9
10
  require 'thor/group'
10
- require 'padrino-core/support_lite' unless defined?(SupportLite)
11
11
  require 'padrino-admin'
12
12
  require 'dm-core'
13
13
  require 'dm-migrations'
@@ -25,11 +25,6 @@ module Kernel
25
25
  end
26
26
  end
27
27
 
28
- class Class
29
- # Allow assertions in request context
30
- include MiniTest::Assertions
31
- end
32
-
33
28
  class MiniTest::Spec
34
29
  include Rack::Test::Methods
35
30
 
@@ -38,7 +33,6 @@ class MiniTest::Spec
38
33
  # the application.
39
34
  def mock_app(base=Padrino::Application, &block)
40
35
  @app = Sinatra.new(base, &block)
41
- @app.send :include, MiniTest::Assertions
42
36
  @app.register Padrino::Helpers
43
37
  end
44
38
 
@@ -67,7 +61,7 @@ class MiniTest::Spec
67
61
  end
68
62
 
69
63
  def assert_no_match_in_file(pattern, file)
70
- File.exist?(file) ? assert_no_match(pattern, File.read(file)) : assert_file_exists(file)
64
+ File.exist?(file) ? refute_match(pattern, File.read(file)) : assert_file_exists(file)
71
65
  end
72
66
 
73
67
  # Delegate other missing methods to response.
@@ -108,16 +108,6 @@ describe "AdminApplication" do
108
108
  role.project_module :posts, "/posts"
109
109
  end
110
110
 
111
- assert access_control.allowed?(Account.admin, "/login")
112
- assert access_control.allowed?(Account.admin, "/any")
113
- assert access_control.allowed?(Account.admin, "/settings")
114
- assert ! access_control.allowed?(Account.admin, "/posts")
115
-
116
- assert access_control.allowed?(Account.editor, "/login")
117
- assert access_control.allowed?(Account.editor, "/any")
118
- assert ! access_control.allowed?(Account.editor, "/settings")
119
- assert access_control.allowed?(Account.editor, "/posts")
120
-
121
111
  # Prepare a basic page
122
112
  get "/login(/:role)" do
123
113
  set_current_account(Account.send(params[:role])) if params[:role]
@@ -129,6 +119,16 @@ describe "AdminApplication" do
129
119
  get "/posts" do; "posts"; end
130
120
  end
131
121
 
122
+ assert @app.access_control.allowed?(Account.admin, "/login")
123
+ assert @app.access_control.allowed?(Account.admin, "/any")
124
+ assert @app.access_control.allowed?(Account.admin, "/settings")
125
+ assert ! @app.access_control.allowed?(Account.admin, "/posts")
126
+
127
+ assert @app.access_control.allowed?(Account.editor, "/login")
128
+ assert @app.access_control.allowed?(Account.editor, "/any")
129
+ assert ! @app.access_control.allowed?(Account.editor, "/settings")
130
+ assert @app.access_control.allowed?(Account.editor, "/posts")
131
+
132
132
  get "/login"
133
133
  assert_equal "logged as any", body
134
134
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-02-09 00:00:00.000000000 Z
14
+ date: 2014-04-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,28 +19,28 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.12.0
22
+ version: 0.12.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.0
29
+ version: 0.12.1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: padrino-helpers
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 0.12.0
36
+ version: 0.12.1
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.12.0
43
+ version: 0.12.1
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: therubyracer
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +144,7 @@ files:
144
144
  - lib/padrino-admin/generators/templates/account/activerecord.rb.tt
145
145
  - lib/padrino-admin/generators/templates/account/couchrest.rb.tt
146
146
  - lib/padrino-admin/generators/templates/account/datamapper.rb.tt
147
+ - lib/padrino-admin/generators/templates/account/dynamoid.rb.tt
147
148
  - lib/padrino-admin/generators/templates/account/minirecord.rb.tt
148
149
  - lib/padrino-admin/generators/templates/account/mongoid.rb.tt
149
150
  - lib/padrino-admin/generators/templates/account/mongomapper.rb.tt