lockdown 1.6.5 → 2.0.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.
Files changed (80) hide show
  1. data/.gitignore +1 -0
  2. data/README.txt +8 -5
  3. data/Rakefile +43 -26
  4. data/lib/lockdown/access.rb +108 -0
  5. data/lib/lockdown/configuration.rb +201 -0
  6. data/lib/lockdown/database.rb +31 -36
  7. data/lib/lockdown/delivery.rb +26 -0
  8. data/lib/lockdown/errors.rb +3 -7
  9. data/lib/lockdown/frameworks/rails/controller.rb +21 -59
  10. data/lib/lockdown/frameworks/rails/view.rb +1 -1
  11. data/lib/lockdown/frameworks/rails.rb +7 -43
  12. data/lib/lockdown/helper.rb +14 -85
  13. data/lib/lockdown/orms/active_record.rb +7 -9
  14. data/lib/lockdown/permission.rb +37 -203
  15. data/lib/lockdown/resource.rb +54 -0
  16. data/lib/lockdown/session.rb +16 -25
  17. data/lib/lockdown/user_group.rb +16 -0
  18. data/lib/lockdown.rb +15 -60
  19. data/lockdown.gemspec +29 -69
  20. data/test/helper.rb +9 -0
  21. data/test/lockdown/test_access.rb +80 -0
  22. data/test/lockdown/test_configuration.rb +194 -0
  23. data/test/lockdown/test_delivery.rb +163 -0
  24. data/test/lockdown/test_helper.rb +33 -0
  25. data/test/lockdown/test_permission.rb +73 -0
  26. data/test/lockdown/test_resource.rb +47 -0
  27. data/test/lockdown/test_session.rb +31 -0
  28. data/test/lockdown/test_user_group.rb +17 -0
  29. data/test/test_lockdown.rb +11 -0
  30. metadata +41 -78
  31. data/lib/lockdown/context.rb +0 -41
  32. data/lib/lockdown/references.rb +0 -19
  33. data/lib/lockdown/rspec_helper.rb +0 -118
  34. data/lib/lockdown/rules.rb +0 -372
  35. data/lib/lockdown/system.rb +0 -58
  36. data/rails_generators/lockdown/lockdown_generator.rb +0 -274
  37. data/rails_generators/lockdown/templates/app/controllers/permissions_controller.rb +0 -22
  38. data/rails_generators/lockdown/templates/app/controllers/sessions_controller.rb +0 -39
  39. data/rails_generators/lockdown/templates/app/controllers/user_groups_controller.rb +0 -122
  40. data/rails_generators/lockdown/templates/app/controllers/users_controller.rb +0 -117
  41. data/rails_generators/lockdown/templates/app/helpers/permissions_helper.rb +0 -2
  42. data/rails_generators/lockdown/templates/app/helpers/user_groups_helper.rb +0 -2
  43. data/rails_generators/lockdown/templates/app/helpers/users_helper.rb +0 -2
  44. data/rails_generators/lockdown/templates/app/models/permission.rb +0 -13
  45. data/rails_generators/lockdown/templates/app/models/profile.rb +0 -10
  46. data/rails_generators/lockdown/templates/app/models/user.rb +0 -95
  47. data/rails_generators/lockdown/templates/app/models/user_group.rb +0 -15
  48. data/rails_generators/lockdown/templates/app/views/permissions/index.html.erb +0 -16
  49. data/rails_generators/lockdown/templates/app/views/permissions/show.html.erb +0 -26
  50. data/rails_generators/lockdown/templates/app/views/sessions/new.html.erb +0 -12
  51. data/rails_generators/lockdown/templates/app/views/user_groups/edit.html.erb +0 -33
  52. data/rails_generators/lockdown/templates/app/views/user_groups/index.html.erb +0 -20
  53. data/rails_generators/lockdown/templates/app/views/user_groups/new.html.erb +0 -31
  54. data/rails_generators/lockdown/templates/app/views/user_groups/show.html.erb +0 -29
  55. data/rails_generators/lockdown/templates/app/views/users/edit.html.erb +0 -51
  56. data/rails_generators/lockdown/templates/app/views/users/index.html.erb +0 -22
  57. data/rails_generators/lockdown/templates/app/views/users/new.html.erb +0 -50
  58. data/rails_generators/lockdown/templates/app/views/users/show.html.erb +0 -33
  59. data/rails_generators/lockdown/templates/config/initializers/lockit.rb +0 -1
  60. data/rails_generators/lockdown/templates/db/migrate/create_admin_user.rb +0 -17
  61. data/rails_generators/lockdown/templates/db/migrate/create_permissions.rb +0 -19
  62. data/rails_generators/lockdown/templates/db/migrate/create_profiles.rb +0 -26
  63. data/rails_generators/lockdown/templates/db/migrate/create_user_groups.rb +0 -19
  64. data/rails_generators/lockdown/templates/db/migrate/create_users.rb +0 -17
  65. data/rails_generators/lockdown/templates/lib/lockdown/README +0 -42
  66. data/rails_generators/lockdown/templates/lib/lockdown/init.rb +0 -131
  67. data/spec/lockdown/context_spec.rb +0 -191
  68. data/spec/lockdown/database_spec.rb +0 -162
  69. data/spec/lockdown/frameworks/rails/controller_spec.rb +0 -215
  70. data/spec/lockdown/frameworks/rails/view_spec.rb +0 -96
  71. data/spec/lockdown/frameworks/rails_spec.rb +0 -163
  72. data/spec/lockdown/permission_spec.rb +0 -156
  73. data/spec/lockdown/rspec_helper_spec.rb +0 -40
  74. data/spec/lockdown/rules_spec.rb +0 -245
  75. data/spec/lockdown/session_spec.rb +0 -112
  76. data/spec/lockdown/system_spec.rb +0 -51
  77. data/spec/lockdown_spec.rb +0 -19
  78. data/spec/rcov.opts +0 -5
  79. data/spec/spec.opts +0 -3
  80. data/spec/spec_helper.rb +0 -8
@@ -1,112 +0,0 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
-
3
- class TestAController
4
- include Lockdown::Session
5
- end
6
-
7
- describe Lockdown::Session do
8
- before do
9
- @controller = TestAController.new
10
-
11
- @actions = %w(posts/index posts/show posts/new posts/edit posts/create posts/update posts/destroy)
12
-
13
- @session = {:access_rights => @actions}
14
-
15
- @controller.stub!(:session).and_return(@session)
16
- end
17
-
18
- describe "#logged_in?" do
19
- it "should return false withou current_user_id" do
20
- @controller.send(:logged_in?).should == false
21
- end
22
- end
23
-
24
- describe "#current_user_id" do
25
- it "should return false withou current_user_id" do
26
- @session[:current_user_id] = 2
27
- @controller.send(:current_user_id).should == 2
28
- end
29
- end
30
-
31
- describe "#nil_lockdown_values" do
32
- it "should nil access_rights" do
33
- @controller.send :nil_lockdown_values
34
- @session[:access_rights].should == nil
35
- end
36
- end
37
-
38
- describe "#current_user_access_in_group?" do
39
- it "should return true if current user is admin" do
40
- @actions = :all
41
- @session = {:access_rights => @actions}
42
- @controller.stub!(:session).and_return(@session)
43
-
44
- @controller.send(:current_user_access_in_group?,:group).should == true
45
- end
46
-
47
- it "should return true if current_user has access" do
48
- user_groups = {:public_group => [:public_access]}
49
- hash = {:public_access => ["posts/index", "posts/show"]}
50
- Lockdown::System.stub!(:permissions).and_return(hash)
51
-
52
- Lockdown::System.stub!(:user_groups).and_return(user_groups)
53
- @controller.send(:current_user_access_in_group?,:public_group).should be_true
54
- end
55
-
56
- it "should return false if current_user has access" do
57
- user_groups = {:public_group => [:public_access]}
58
- hash = {:public_access => ["books/edit", "books/update"]}
59
- Lockdown::System.stub!(:permissions).and_return(hash)
60
-
61
- Lockdown::System.stub!(:user_groups).and_return(user_groups)
62
- @controller.send(:current_user_access_in_group?,:public_group).should be_false
63
- end
64
- end
65
-
66
- describe "#current_user_is_admin?" do
67
- it "should return true if access_rights == :all" do
68
- @actions = :all
69
- @session = {:access_rights => @actions}
70
- @controller.stub!(:session).and_return(@session)
71
-
72
- @controller.send(:current_user_is_admin?).should == true
73
- end
74
- end
75
-
76
- describe "#add_lockdown_session_values" do
77
- it "should set the access_rights from the user list" do
78
- array = ["posts/index", "posts/show"]
79
- Lockdown::System.stub!(:access_rights_for_user).and_return(array)
80
- usr = mock('user')
81
- usr.should_receive(:id).and_return(1234)
82
- @controller.send(:add_lockdown_session_values, usr)
83
- @session[:access_rights].should == array
84
- end
85
- end
86
-
87
-
88
- describe "#access_in_perm" do
89
- it "should return false if permissions nil" do
90
- Lockdown::System.stub!(:permissions).and_return({})
91
- @controller.send(:access_in_perm?,:dummy).should be_false
92
- end
93
-
94
- it "should return true if permission found" do
95
- hash = {:public => ["posts/index", "posts/show"]}
96
- Lockdown::System.stub!(:permissions).and_return(hash)
97
- @controller.send(:access_in_perm?,:public).should be_true
98
- end
99
- end
100
-
101
- describe "#session_access_rights_include?" do
102
- it "should return true for posts/index" do
103
- @controller.send(:session_access_rights_include?,'posts/index').
104
- should == true
105
- end
106
-
107
- it "should return false for pages/index" do
108
- @controller.send(:session_access_rights_include?,'pages/index').
109
- should == false
110
- end
111
- end
112
- end
@@ -1,51 +0,0 @@
1
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
- require File.join(File.dirname(__FILE__), %w[.. .. lib lockdown rules])
3
-
4
- describe Lockdown::System do
5
- it "should fetch the option" do
6
- Lockdown::System.options = {}
7
- Lockdown::System.options['test'] = "my test"
8
- Lockdown::System.fetch('test').should == "my test"
9
- end
10
-
11
- describe "#configure" do
12
- it "should call the methods responsible for defining the rules" do
13
- Lockdown::System.stub!(:skip_sync?).and_return(false)
14
-
15
- Lockdown::System.should_receive :set_defaults
16
-
17
- Lockdown::System.should_receive :instance_eval
18
-
19
- Lockdown::System.should_receive :process_rules
20
-
21
- Lockdown::Database.should_receive :sync_with_db
22
-
23
- Lockdown.should_receive :caching?
24
-
25
- Lockdown::System.configure do
26
- end
27
- end
28
- end
29
-
30
- describe "#paths_for" do
31
- it "should join the str_sym to the methods" do
32
- Lockdown::System.paths_for(:users, :show, :edit).
33
- should == ["users/show", "users/edit"]
34
- end
35
-
36
- it "should add users to the array if access is granted on index" do
37
- Lockdown::System.paths_for(:users, :index, :show, :edit).
38
- should == ["users/index", "users/show", "users/edit", "users"]
39
- end
40
-
41
- it "should build the paths from the controller class if no methods specified" do
42
- methods = ["new","edit","create","update"]
43
- Lockdown.stub!(:fetch_controller_class)
44
- Lockdown::System.stub!(:available_actions).
45
- and_return(methods)
46
-
47
- Lockdown::System.paths_for(:users).
48
- should == ["users/new","users/edit","users/create","users/update"]
49
- end
50
- end
51
- end
@@ -1,19 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe Lockdown do
4
- before do
5
- Lockdown.stub!(:version).and_return('1.2.3')
6
- end
7
-
8
- it "should return the correct major version" do
9
- Lockdown.major_version.should equal(1)
10
- end
11
-
12
- it "should return the correct minor version" do
13
- Lockdown.minor_version.should equal(2)
14
- end
15
-
16
- it "should return the correct patch version" do
17
- Lockdown.patch_version.should equal(3)
18
- end
19
- end
data/spec/rcov.opts DELETED
@@ -1,5 +0,0 @@
1
- --text-summary
2
- --exclude
3
- json,FakeWeb,rcov.rb,rspec,spec
4
- --sort
5
- coverage
data/spec/spec.opts DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format
3
- progress
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib lockdown]))
2
-
3
- class Mikey
4
- def method_missing(method, *args)
5
- true
6
- end
7
- end
8
-