padrino-admin 0.16.0.pre4 → 0.16.0
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.
- checksums.yaml +4 -4
- data/Rakefile +5 -5
- data/lib/padrino-admin/access_control.rb +10 -9
- data/lib/padrino-admin/generators/actions.rb +8 -8
- data/lib/padrino-admin/generators/admin_app.rb +62 -62
- data/lib/padrino-admin/generators/admin_page.rb +16 -17
- data/lib/padrino-admin/generators/orm.rb +56 -65
- data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/couchrest.rb.tt +10 -10
- data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/dynamoid.rb.tt +9 -9
- data/lib/padrino-admin/generators/templates/account/minirecord.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/mongoid.rb.tt +16 -16
- data/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt +11 -11
- data/lib/padrino-admin/generators/templates/account/ohm.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/account/seeds.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app/controllers/base.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app/controllers/sessions.rb.tt +2 -2
- data/lib/padrino-admin/generators/templates/app.rb.tt +7 -7
- data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +10 -9
- data/lib/padrino-admin/generators/templates/erb/app/layouts/error.erb.tt +3 -2
- data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +8 -7
- data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +7 -7
- data/lib/padrino-admin/generators/templates/erb/page/edit.erb.tt +3 -3
- data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +12 -12
- data/lib/padrino-admin/generators/templates/erb/page/new.erb.tt +2 -2
- data/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +10 -5
- data/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt +14 -14
- data/lib/padrino-admin/generators/templates/haml/app/layouts/error.haml.tt +6 -5
- data/lib/padrino-admin/generators/templates/haml/app/sessions/new.haml.tt +12 -11
- data/lib/padrino-admin/generators/templates/haml/page/_form.haml.tt +7 -7
- data/lib/padrino-admin/generators/templates/haml/page/edit.haml.tt +3 -3
- data/lib/padrino-admin/generators/templates/haml/page/index.haml.tt +14 -14
- data/lib/padrino-admin/generators/templates/haml/page/new.haml.tt +2 -2
- data/lib/padrino-admin/generators/templates/page/controller.rb.tt +25 -25
- data/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt +9 -9
- data/lib/padrino-admin/generators/templates/slim/app/layouts/error.slim.tt +1 -1
- data/lib/padrino-admin/generators/templates/slim/app/sessions/new.slim.tt +6 -6
- data/lib/padrino-admin/generators/templates/slim/page/_form.slim.tt +6 -6
- data/lib/padrino-admin/generators/templates/slim/page/edit.slim.tt +3 -3
- data/lib/padrino-admin/generators/templates/slim/page/index.slim.tt +12 -12
- data/lib/padrino-admin/generators/templates/slim/page/new.slim.tt +2 -2
- data/lib/padrino-admin/helpers/authentication_helpers.rb +7 -7
- data/lib/padrino-admin/helpers/view_helpers.rb +11 -11
- data/lib/padrino-admin.rb +4 -3
- data/padrino-admin.gemspec +18 -18
- data/test/fixtures/sequel.rb +14 -14
- data/test/generators/test_account_model_generator.rb +4 -4
- data/test/generators/test_admin_app_generator.rb +22 -22
- data/test/generators/test_admin_page_generator.rb +30 -30
- data/test/helper.rb +6 -6
- data/test/test_admin_application.rb +114 -116
- data/test/test_locale.rb +3 -3
- metadata +8 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative '../helper'
|
|
2
|
+
require_relative '../fixtures/sequel'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
before do
|
|
4
|
+
describe 'AdminPageGenerator' do
|
|
5
|
+
before do
|
|
6
6
|
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
|
|
7
7
|
`mkdir -p #{@apptmp}`
|
|
8
8
|
end
|
|
@@ -13,7 +13,7 @@ describe "AdminPageGenerator" do
|
|
|
13
13
|
|
|
14
14
|
describe 'the admin page generator' do
|
|
15
15
|
it 'should fail outside app root' do
|
|
16
|
-
out,
|
|
16
|
+
out, = capture_io { generate(:admin_page, 'foo', "-r=#{@apptmp}/sample_project") }
|
|
17
17
|
assert_match(/not at the root/, out)
|
|
18
18
|
assert_no_file_exists("#{@apptmp}/admin")
|
|
19
19
|
end
|
|
@@ -25,82 +25,82 @@ describe "AdminPageGenerator" do
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it 'should correctly generate a new page' do
|
|
28
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=haml') }
|
|
28
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=haml') }
|
|
29
29
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
30
|
-
capture_io { generate(:model, 'friend',
|
|
30
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "--root=#{@apptmp}/sample_project") }
|
|
31
31
|
capture_io { generate(:admin_page, 'friend', "--root=#{@apptmp}/sample_project") }
|
|
32
32
|
assert_file_exists "#{@apptmp}/sample_project/admin/controllers/friends.rb"
|
|
33
|
-
assert_match_in_file
|
|
33
|
+
assert_match_in_file 'SampleProject::Admin.controllers :friends do', "#{@apptmp}/sample_project/admin/controllers/friends.rb"
|
|
34
34
|
assert_match_in_file "role.project_module :friends, '/friends'", "#{@apptmp}/sample_project/admin/app.rb"
|
|
35
|
-
assert_match_in_file
|
|
35
|
+
assert_match_in_file 'elsif Padrino.env == :development && params[:bypass]', "#{@apptmp}/sample_project/admin/controllers/sessions.rb"
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# users can override certain templates from a generators/templates folder in the destination_root
|
|
39
|
-
it
|
|
40
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=haml') }
|
|
39
|
+
it 'should use custom generator templates from the project root, if they exist' do
|
|
40
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=haml') }
|
|
41
41
|
custom_template_path = "#{@apptmp}/sample_project/generators/templates/haml/page/"
|
|
42
42
|
`mkdir -p #{custom_template_path} && echo "%h1= 'Hello, custom generator' " > #{custom_template_path}index.haml.tt`
|
|
43
43
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
44
|
-
capture_io { generate(:model, 'friend',
|
|
44
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "--root=#{@apptmp}/sample_project") }
|
|
45
45
|
capture_io { generate(:admin_page, 'friend', "--root=#{@apptmp}/sample_project") }
|
|
46
46
|
assert_match_in_file(/Hello, custom generator/, "#{@apptmp}/sample_project/admin/views/friends/index.haml")
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
describe
|
|
49
|
+
describe 'renderers' do
|
|
50
50
|
it 'should correctly generate a new page with haml' do
|
|
51
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=haml') }
|
|
51
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=haml') }
|
|
52
52
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
53
|
-
capture_io { generate(:model, 'friend',
|
|
53
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "--root=#{@apptmp}/sample_project") }
|
|
54
54
|
capture_io { generate(:admin_page, 'friend', "--root=#{@apptmp}/sample_project") }
|
|
55
55
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/_form.haml"
|
|
56
56
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/edit.haml"
|
|
57
57
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/index.haml"
|
|
58
58
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/new.haml"
|
|
59
|
-
%w
|
|
59
|
+
%w[name age email].each do |field|
|
|
60
60
|
assert_match_in_file "label :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.haml"
|
|
61
61
|
assert_match_in_file "text_field :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.haml"
|
|
62
62
|
end
|
|
63
|
-
assert_match_in_file
|
|
63
|
+
assert_match_in_file 'check_box_tag :bypass', "#{@apptmp}/sample_project/admin/views/sessions/new.haml"
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it 'should correctly generate a new page with erb' do
|
|
67
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=erb') }
|
|
67
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=erb') }
|
|
68
68
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
69
|
-
capture_io { generate(:model, 'friend',
|
|
69
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "--root=#{@apptmp}/sample_project") }
|
|
70
70
|
capture_io { generate(:admin_page, 'friend', "--root=#{@apptmp}/sample_project") }
|
|
71
71
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/_form.erb"
|
|
72
72
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/edit.erb"
|
|
73
73
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/index.erb"
|
|
74
74
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/new.erb"
|
|
75
|
-
%w
|
|
75
|
+
%w[name age email].each do |field|
|
|
76
76
|
assert_match_in_file "label :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.erb"
|
|
77
77
|
assert_match_in_file "text_field :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.erb"
|
|
78
78
|
end
|
|
79
|
-
assert_match_in_file
|
|
79
|
+
assert_match_in_file 'check_box_tag :bypass', "#{@apptmp}/sample_project/admin/views/sessions/new.erb"
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it 'should correctly generate a new page with slim' do
|
|
83
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=slim') }
|
|
83
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=slim') }
|
|
84
84
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
85
|
-
capture_io { generate(:model, 'friend',
|
|
85
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "--root=#{@apptmp}/sample_project") }
|
|
86
86
|
capture_io { generate(:admin_page, 'friend', "--root=#{@apptmp}/sample_project") }
|
|
87
87
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/_form.slim"
|
|
88
88
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/edit.slim"
|
|
89
89
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/index.slim"
|
|
90
90
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/new.slim"
|
|
91
|
-
%w
|
|
91
|
+
%w[name age email].each do |field|
|
|
92
92
|
assert_match_in_file "label :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.slim"
|
|
93
93
|
assert_match_in_file "text_field :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.slim"
|
|
94
94
|
end
|
|
95
|
-
assert_match_in_file
|
|
95
|
+
assert_match_in_file 'check_box_tag :bypass', "#{@apptmp}/sample_project/admin/views/sessions/new.slim"
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
it 'should correctly generate a new padrino admin application with multiple models at the same time' do
|
|
100
|
-
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel','-e=haml') }
|
|
100
|
+
capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=haml') }
|
|
101
101
|
capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
|
|
102
|
-
capture_io { generate(:model, 'friend',
|
|
103
|
-
capture_io { generate(:model, 'page',
|
|
102
|
+
capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'email:string', "-root=#{@apptmp}/sample_project") }
|
|
103
|
+
capture_io { generate(:model, 'page', 'name:string', 'body:string', "-root=#{@apptmp}/sample_project") }
|
|
104
104
|
capture_io { generate(:admin_page, 'friend', 'page', "--root=#{@apptmp}/sample_project") }
|
|
105
105
|
# For Friend
|
|
106
106
|
assert_file_exists "#{@apptmp}/sample_project/admin/controllers/friends.rb"
|
|
@@ -108,7 +108,7 @@ describe "AdminPageGenerator" do
|
|
|
108
108
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/edit.haml"
|
|
109
109
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/index.haml"
|
|
110
110
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/friends/new.haml"
|
|
111
|
-
%w
|
|
111
|
+
%w[name age email].each do |field|
|
|
112
112
|
assert_match_in_file "label :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.haml"
|
|
113
113
|
assert_match_in_file "text_field :#{field}", "#{@apptmp}/sample_project/admin/views/friends/_form.haml"
|
|
114
114
|
end
|
|
@@ -119,7 +119,7 @@ describe "AdminPageGenerator" do
|
|
|
119
119
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/pages/edit.haml"
|
|
120
120
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/pages/index.haml"
|
|
121
121
|
assert_file_exists "#{@apptmp}/sample_project/admin/views/pages/new.haml"
|
|
122
|
-
%w
|
|
122
|
+
%w[name body].each do |field|
|
|
123
123
|
assert_match_in_file "label :#{field}", "#{@apptmp}/sample_project/admin/views/pages/_form.haml"
|
|
124
124
|
assert_match_in_file "text_field :#{field}", "#{@apptmp}/sample_project/admin/views/pages/_form.haml"
|
|
125
125
|
end
|
data/test/helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
ENV['RACK_ENV'] = 'test'
|
|
2
|
-
PADRINO_ROOT =
|
|
2
|
+
PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
|
|
3
3
|
|
|
4
4
|
require 'minitest/autorun'
|
|
5
5
|
require 'minitest/pride'
|
|
@@ -18,8 +18,8 @@ module Kernel
|
|
|
18
18
|
def load_fixture(file)
|
|
19
19
|
Object.send(:remove_const, :Account) if defined?(Account)
|
|
20
20
|
Object.send(:remove_const, :Category) if defined?(Category)
|
|
21
|
-
file +=
|
|
22
|
-
capture_io { load File.join(
|
|
21
|
+
file += '.rb' if file !~ /.rb$/
|
|
22
|
+
capture_io { load File.join(__dir__, 'fixtures', file) }
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -29,10 +29,10 @@ class Minitest::Spec
|
|
|
29
29
|
# Sets up a Sinatra::Base subclass defined with the block
|
|
30
30
|
# given. Used in setup or individual spec methods to establish
|
|
31
31
|
# the application.
|
|
32
|
-
def mock_app(base=Padrino::Application, &block)
|
|
33
|
-
@app = Sinatra.new
|
|
32
|
+
def mock_app(base = Padrino::Application, &block)
|
|
33
|
+
@app = Sinatra.new(base) do
|
|
34
34
|
register Padrino::Helpers
|
|
35
|
-
instance_eval
|
|
35
|
+
instance_eval(&block)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
describe "AdminApplication" do
|
|
1
|
+
require_relative 'helper'
|
|
4
2
|
|
|
3
|
+
describe 'AdminApplication' do
|
|
5
4
|
def setup
|
|
6
5
|
load_fixture 'sequel'
|
|
7
6
|
end
|
|
8
7
|
|
|
9
|
-
describe
|
|
8
|
+
describe 'session id setting' do
|
|
10
9
|
it "should provide it if it doesn't exist" do
|
|
11
10
|
mock_app do
|
|
12
11
|
set :app_name, 'session_id_tester'
|
|
13
12
|
register Padrino::Admin::AccessControl
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
assert_equal
|
|
15
|
+
assert_equal '_padrino_test_session_id_tester', @app.session_id
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
it
|
|
18
|
+
it 'should preserve it if it already existed' do
|
|
20
19
|
mock_app do
|
|
21
|
-
set :session_id,
|
|
20
|
+
set :session_id, 'foo'
|
|
22
21
|
register Padrino::Admin::AccessControl
|
|
23
22
|
end
|
|
24
|
-
assert_equal
|
|
23
|
+
assert_equal 'foo', @app.session_id
|
|
25
24
|
end
|
|
26
25
|
end
|
|
27
26
|
|
|
@@ -32,24 +31,23 @@ describe "AdminApplication" do
|
|
|
32
31
|
|
|
33
32
|
# Do a simple mapping
|
|
34
33
|
access_control.roles_for :any do |role|
|
|
35
|
-
role.protect
|
|
34
|
+
role.protect '/foo'
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
get
|
|
39
|
-
|
|
37
|
+
get '/foo', provides: %i[html js] do
|
|
38
|
+
'foo'
|
|
40
39
|
end
|
|
41
40
|
|
|
42
|
-
get
|
|
43
|
-
|
|
41
|
+
get '/unauthenticated' do
|
|
42
|
+
'unauthenticated'
|
|
44
43
|
end
|
|
45
|
-
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
get
|
|
46
|
+
get '/foo'
|
|
49
47
|
assert_equal "You don't have permission for this resource", body
|
|
50
48
|
|
|
51
|
-
get
|
|
52
|
-
assert_equal
|
|
49
|
+
get '/unauthenticated'
|
|
50
|
+
assert_equal 'unauthenticated', body
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
it 'should set basic roles with store location and login page' do
|
|
@@ -58,34 +56,34 @@ describe "AdminApplication" do
|
|
|
58
56
|
register Padrino::Admin::AccessControl
|
|
59
57
|
enable :store_location
|
|
60
58
|
enable :sessions
|
|
61
|
-
set :login_page,
|
|
59
|
+
set :login_page, '/login'
|
|
62
60
|
|
|
63
61
|
access_control.roles_for :any do |role|
|
|
64
|
-
role.protect
|
|
62
|
+
role.protect '/foo'
|
|
65
63
|
end
|
|
66
64
|
|
|
67
65
|
# Prepare a basic page
|
|
68
|
-
get
|
|
69
|
-
redirect_back_or_default(
|
|
66
|
+
get '/login' do
|
|
67
|
+
redirect_back_or_default('/foo') if logged_in?
|
|
70
68
|
set_current_account(Account.admin)
|
|
71
|
-
|
|
69
|
+
'login page'
|
|
72
70
|
end
|
|
73
71
|
|
|
74
|
-
get
|
|
75
|
-
|
|
72
|
+
get '/foo' do
|
|
73
|
+
'foo'
|
|
76
74
|
end
|
|
77
75
|
end
|
|
78
76
|
|
|
79
|
-
get
|
|
77
|
+
get '/foo'
|
|
80
78
|
follow_redirect!
|
|
81
|
-
assert_equal
|
|
79
|
+
assert_equal 'login page', body
|
|
82
80
|
|
|
83
|
-
get
|
|
84
|
-
assert_equal
|
|
81
|
+
get '/foo'
|
|
82
|
+
assert_equal 'foo', body
|
|
85
83
|
|
|
86
|
-
get
|
|
84
|
+
get '/login'
|
|
87
85
|
follow_redirect!
|
|
88
|
-
assert_equal
|
|
86
|
+
assert_equal 'foo', body
|
|
89
87
|
end
|
|
90
88
|
|
|
91
89
|
it 'should set advanced roles with store location and login page' do
|
|
@@ -94,75 +92,75 @@ describe "AdminApplication" do
|
|
|
94
92
|
enable :sessions
|
|
95
93
|
|
|
96
94
|
access_control.roles_for :any do |role|
|
|
97
|
-
role.protect
|
|
98
|
-
role.allow
|
|
99
|
-
role.allow
|
|
95
|
+
role.protect '/'
|
|
96
|
+
role.allow '/login'
|
|
97
|
+
role.allow '/any'
|
|
100
98
|
end
|
|
101
99
|
|
|
102
100
|
access_control.roles_for :admin do |role|
|
|
103
|
-
role.project_module :settings,
|
|
101
|
+
role.project_module :settings, '/settings'
|
|
104
102
|
end
|
|
105
103
|
|
|
106
104
|
access_control.roles_for :editor do |role|
|
|
107
|
-
role.project_module :posts,
|
|
105
|
+
role.project_module :posts, '/posts'
|
|
108
106
|
end
|
|
109
107
|
|
|
110
108
|
# Prepare a basic page
|
|
111
|
-
get
|
|
109
|
+
get '/login(/:role)?' do
|
|
112
110
|
set_current_account(Account.send(params[:role])) if params[:role]
|
|
113
|
-
"logged as #{params[:role] ||
|
|
111
|
+
"logged as #{params[:role] || 'any'}"
|
|
114
112
|
end
|
|
115
113
|
|
|
116
|
-
get
|
|
117
|
-
get
|
|
118
|
-
get
|
|
114
|
+
get '/any' do; 'any'; end
|
|
115
|
+
get '/settings' do; 'settings'; end
|
|
116
|
+
get '/posts' do; 'posts'; end
|
|
119
117
|
end
|
|
120
118
|
|
|
121
|
-
assert @app.access_control.allowed?(Account.admin,
|
|
122
|
-
assert @app.access_control.allowed?(Account.admin,
|
|
123
|
-
assert @app.access_control.allowed?(Account.admin,
|
|
124
|
-
|
|
119
|
+
assert @app.access_control.allowed?(Account.admin, '/login')
|
|
120
|
+
assert @app.access_control.allowed?(Account.admin, '/any')
|
|
121
|
+
assert @app.access_control.allowed?(Account.admin, '/settings')
|
|
122
|
+
refute @app.access_control.allowed?(Account.admin, '/posts')
|
|
125
123
|
|
|
126
|
-
assert @app.access_control.allowed?(Account.editor,
|
|
127
|
-
assert @app.access_control.allowed?(Account.editor,
|
|
128
|
-
|
|
129
|
-
assert @app.access_control.allowed?(Account.editor,
|
|
124
|
+
assert @app.access_control.allowed?(Account.editor, '/login')
|
|
125
|
+
assert @app.access_control.allowed?(Account.editor, '/any')
|
|
126
|
+
refute @app.access_control.allowed?(Account.editor, '/settings')
|
|
127
|
+
assert @app.access_control.allowed?(Account.editor, '/posts')
|
|
130
128
|
|
|
131
|
-
get
|
|
132
|
-
assert_equal
|
|
129
|
+
get '/login'
|
|
130
|
+
assert_equal 'logged as any', body
|
|
133
131
|
|
|
134
|
-
get
|
|
135
|
-
assert_equal
|
|
132
|
+
get '/any'
|
|
133
|
+
assert_equal 'any', body
|
|
136
134
|
|
|
137
|
-
get
|
|
135
|
+
get '/settings'
|
|
138
136
|
assert_equal "You don't have permission for this resource", body
|
|
139
137
|
|
|
140
|
-
get
|
|
138
|
+
get '/posts'
|
|
141
139
|
assert_equal "You don't have permission for this resource", body
|
|
142
140
|
|
|
143
|
-
get
|
|
144
|
-
assert_equal
|
|
141
|
+
get '/login/admin'
|
|
142
|
+
assert_equal 'logged as admin', body
|
|
145
143
|
|
|
146
|
-
get
|
|
147
|
-
assert_equal
|
|
144
|
+
get '/any'
|
|
145
|
+
assert_equal 'any', body
|
|
148
146
|
|
|
149
|
-
get
|
|
150
|
-
assert_equal
|
|
147
|
+
get '/settings'
|
|
148
|
+
assert_equal 'settings', body
|
|
151
149
|
|
|
152
|
-
get
|
|
150
|
+
get '/posts'
|
|
153
151
|
assert_equal "You don't have permission for this resource", body
|
|
154
152
|
|
|
155
|
-
get
|
|
156
|
-
assert_equal
|
|
153
|
+
get '/login/editor'
|
|
154
|
+
assert_equal 'logged as editor', body
|
|
157
155
|
|
|
158
|
-
get
|
|
159
|
-
assert_equal
|
|
156
|
+
get '/any'
|
|
157
|
+
assert_equal 'any', body
|
|
160
158
|
|
|
161
|
-
get
|
|
159
|
+
get '/settings'
|
|
162
160
|
assert_equal "You don't have permission for this resource", body
|
|
163
161
|
|
|
164
|
-
get
|
|
165
|
-
assert_equal
|
|
162
|
+
get '/posts'
|
|
163
|
+
assert_equal 'posts', body
|
|
166
164
|
end
|
|
167
165
|
|
|
168
166
|
it 'should emulate an ecommerce app' do
|
|
@@ -171,49 +169,49 @@ describe "AdminApplication" do
|
|
|
171
169
|
enable :sessions
|
|
172
170
|
|
|
173
171
|
access_control.roles_for :any do |role|
|
|
174
|
-
role.protect
|
|
175
|
-
role.allow
|
|
176
|
-
role.allow
|
|
172
|
+
role.protect '/cart'
|
|
173
|
+
role.allow '/cart/add'
|
|
174
|
+
role.allow '/cart/empty'
|
|
177
175
|
end
|
|
178
176
|
|
|
179
|
-
get
|
|
177
|
+
get '/login' do
|
|
180
178
|
set_current_account(Account.admin)
|
|
181
|
-
|
|
179
|
+
'Logged in'
|
|
182
180
|
end
|
|
183
181
|
|
|
184
|
-
get
|
|
185
|
-
|
|
182
|
+
get '/cart/checkout' do
|
|
183
|
+
'Checkout'
|
|
186
184
|
end
|
|
187
185
|
|
|
188
|
-
get
|
|
189
|
-
|
|
186
|
+
get '/cart/add' do
|
|
187
|
+
'Product Added'
|
|
190
188
|
end
|
|
191
189
|
|
|
192
|
-
get
|
|
193
|
-
|
|
190
|
+
get '/cart/empty' do
|
|
191
|
+
'Cart Empty'
|
|
194
192
|
end
|
|
195
193
|
end
|
|
196
194
|
|
|
197
|
-
get
|
|
195
|
+
get '/cart/checkout'
|
|
198
196
|
assert_equal "You don't have permission for this resource", body
|
|
199
197
|
|
|
200
|
-
get
|
|
201
|
-
assert_equal
|
|
198
|
+
get '/cart/add'
|
|
199
|
+
assert_equal 'Product Added', body
|
|
202
200
|
|
|
203
|
-
get
|
|
204
|
-
assert_equal
|
|
201
|
+
get '/cart/empty'
|
|
202
|
+
assert_equal 'Cart Empty', body
|
|
205
203
|
|
|
206
|
-
get
|
|
207
|
-
assert_equal
|
|
204
|
+
get '/login'
|
|
205
|
+
assert_equal 'Logged in', body
|
|
208
206
|
|
|
209
|
-
get
|
|
210
|
-
assert_equal
|
|
207
|
+
get '/cart/checkout'
|
|
208
|
+
assert_equal 'Checkout', body
|
|
211
209
|
|
|
212
|
-
get
|
|
213
|
-
assert_equal
|
|
210
|
+
get '/cart/add'
|
|
211
|
+
assert_equal 'Product Added', body
|
|
214
212
|
|
|
215
|
-
get
|
|
216
|
-
assert_equal
|
|
213
|
+
get '/cart/empty'
|
|
214
|
+
assert_equal 'Cart Empty', body
|
|
217
215
|
end
|
|
218
216
|
|
|
219
217
|
it 'should check access control helper' do
|
|
@@ -222,63 +220,63 @@ describe "AdminApplication" do
|
|
|
222
220
|
enable :sessions
|
|
223
221
|
|
|
224
222
|
access_control.roles_for :any do |role|
|
|
225
|
-
role.project_module :foo,
|
|
226
|
-
role.project_module :bar,
|
|
223
|
+
role.project_module :foo, '/foo'
|
|
224
|
+
role.project_module :bar, '/bar'
|
|
227
225
|
end
|
|
228
226
|
|
|
229
227
|
access_control.roles_for :admin do |role|
|
|
230
|
-
role.project_module :admin,
|
|
228
|
+
role.project_module :admin, '/admin'
|
|
231
229
|
end
|
|
232
230
|
|
|
233
231
|
access_control.roles_for :editor do |role|
|
|
234
|
-
role.project_module :editor,
|
|
232
|
+
role.project_module :editor, '/editor'
|
|
235
233
|
end
|
|
236
234
|
|
|
237
|
-
get
|
|
235
|
+
get '/login' do
|
|
238
236
|
set_current_account(Account.admin)
|
|
239
|
-
|
|
237
|
+
'Logged in'
|
|
240
238
|
end
|
|
241
239
|
|
|
242
|
-
get
|
|
243
|
-
access_control.roles.join(
|
|
240
|
+
get '/roles' do
|
|
241
|
+
access_control.roles.join(', ')
|
|
244
242
|
end
|
|
245
243
|
|
|
246
|
-
get
|
|
247
|
-
project_modules.map { |pm| "#{pm.name} => #{pm.path}" }.join(
|
|
244
|
+
get '/modules' do
|
|
245
|
+
project_modules.map { |pm| "#{pm.name} => #{pm.path}" }.join(', ')
|
|
248
246
|
end
|
|
249
247
|
|
|
250
|
-
get
|
|
251
|
-
project_modules.map { |pm| "#{pm.name} => #{pm.path(
|
|
248
|
+
get '/modules-prefixed' do
|
|
249
|
+
project_modules.map { |pm| "#{pm.name} => #{pm.path('/admin')}" }.join(', ')
|
|
252
250
|
end
|
|
253
251
|
end
|
|
254
252
|
|
|
255
|
-
get
|
|
256
|
-
assert_equal
|
|
253
|
+
get '/roles'
|
|
254
|
+
assert_equal 'admin, editor', body
|
|
257
255
|
|
|
258
|
-
get
|
|
259
|
-
assert_equal
|
|
256
|
+
get '/modules'
|
|
257
|
+
assert_equal 'foo => /foo, bar => /bar', body
|
|
260
258
|
|
|
261
|
-
get
|
|
262
|
-
assert_equal
|
|
259
|
+
get '/modules-prefixed'
|
|
260
|
+
assert_equal 'foo => /admin/foo, bar => /admin/bar', body
|
|
263
261
|
|
|
264
|
-
get
|
|
265
|
-
assert_equal
|
|
262
|
+
get '/login'
|
|
263
|
+
assert_equal 'Logged in', body
|
|
266
264
|
|
|
267
|
-
get
|
|
268
|
-
assert_equal
|
|
265
|
+
get '/modules'
|
|
266
|
+
assert_equal 'admin => /admin', body
|
|
269
267
|
end
|
|
270
268
|
|
|
271
269
|
it 'should use different access control for different apps' do
|
|
272
270
|
app1 = Sinatra.new Padrino::Application do
|
|
273
271
|
register Padrino::Admin::AccessControl
|
|
274
272
|
access_control.roles_for :any do |role|
|
|
275
|
-
role.project_module :foo,
|
|
273
|
+
role.project_module :foo, '/foo'
|
|
276
274
|
end
|
|
277
275
|
end
|
|
278
276
|
app2 = Sinatra.new Padrino::Application do
|
|
279
277
|
register Padrino::Admin::AccessControl
|
|
280
278
|
access_control.roles_for :any do |role|
|
|
281
|
-
role.project_module :bar,
|
|
279
|
+
role.project_module :bar, '/bar'
|
|
282
280
|
end
|
|
283
281
|
end
|
|
284
282
|
assert_equal '/foo', app1.access_control.project_modules(:any).first.path
|
data/test/test_locale.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
Dir[File.expand_path(
|
|
3
|
+
describe 'Filters' do
|
|
4
|
+
Dir[File.expand_path('../lib/padrino-admin/locale/admin/*.yml', __dir__)].each do |file|
|
|
5
5
|
name = File.basename(file, '.yml')
|
|
6
6
|
it "should have a vaild #{name} locale for admin" do
|
|
7
7
|
base = YAML.load_file(file)
|
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.16.0
|
|
4
|
+
version: 0.16.0
|
|
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: 2025-
|
|
14
|
+
date: 2025-12-02 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.16.0
|
|
22
|
+
version: 0.16.0
|
|
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.16.0
|
|
29
|
+
version: 0.16.0
|
|
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.16.0
|
|
36
|
+
version: 0.16.0
|
|
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.16.0
|
|
43
|
+
version: 0.16.0
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
45
|
name: therubyracer
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -286,9 +286,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
286
286
|
version: '0'
|
|
287
287
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
288
|
requirements:
|
|
289
|
-
- - "
|
|
289
|
+
- - ">="
|
|
290
290
|
- !ruby/object:Gem::Version
|
|
291
|
-
version: 1.3.
|
|
291
|
+
version: 1.3.6
|
|
292
292
|
requirements: []
|
|
293
293
|
rubygems_version: 3.4.19
|
|
294
294
|
signing_key:
|