adva_user 0.0.1

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 (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README +114 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/adva_user.gemspec +17 -0
  9. data/app/controllers/admin/base_account_controller.rb +13 -0
  10. data/app/controllers/admin/users_controller.rb +95 -0
  11. data/app/controllers/password_controller.rb +36 -0
  12. data/app/controllers/session_controller.rb +30 -0
  13. data/app/helpers/users_helper.rb +27 -0
  14. data/app/models/account.rb +7 -0
  15. data/app/models/membership.rb +16 -0
  16. data/app/models/password_mailer.rb +43 -0
  17. data/app/models/user.rb +106 -0
  18. data/app/views/admin/users/_form.html.erb +29 -0
  19. data/app/views/admin/users/_sidebar.html.erb +8 -0
  20. data/app/views/admin/users/edit.html.erb +7 -0
  21. data/app/views/admin/users/index.html.erb +13 -0
  22. data/app/views/admin/users/new.html.erb +5 -0
  23. data/app/views/admin/users/show.html.erb +27 -0
  24. data/app/views/layouts/login.html.erb +24 -0
  25. data/app/views/password/edit.html.erb +14 -0
  26. data/app/views/password/new.html.erb +13 -0
  27. data/app/views/password_mailer/reset_password_email.html.erb +3 -0
  28. data/app/views/password_mailer/updated_password_email.html.erb +1 -0
  29. data/app/views/session/new.html.erb +17 -0
  30. data/config/initializers/menus.rb +25 -0
  31. data/config/routes.rb +14 -0
  32. data/db/migrate/20080402000001_create_users_table.rb +33 -0
  33. data/db/migrate/20080402000005_create_memberships_table.rb +13 -0
  34. data/db/migrate/20090625124502_create_accounts.rb +13 -0
  35. data/db/migrate/20090625133231_add_account_to_user.rb +10 -0
  36. data/lib/action_controller/authenticate_anonymous.rb +70 -0
  37. data/lib/action_controller/authenticate_user.rb +201 -0
  38. data/lib/active_record/belongs_to_author.rb +37 -0
  39. data/lib/adva_user.rb +28 -0
  40. data/lib/adva_user/version.rb +3 -0
  41. data/lib/login/helper_integration.rb +11 -0
  42. data/lib/login/mail_config.rb +39 -0
  43. data/test/contexts.rb +42 -0
  44. data/test/fixtures.rb +18 -0
  45. data/test/functional/admin/users_controller_test.rb +176 -0
  46. data/test/functional/password_controller_test.rb +96 -0
  47. data/test/functional/session_controller_test.rb +1 -0
  48. data/test/functional/user_controller_test.rb +95 -0
  49. data/test/integration/anonymous_login_test.rb +39 -0
  50. data/test/integration/edit_user_test.rb +44 -0
  51. data/test/integration/memberships_test.rb +52 -0
  52. data/test/integration/user_deletion_test.rb +27 -0
  53. data/test/integration/user_login_test.rb +53 -0
  54. data/test/integration/user_login_with_remember_me_test.rb +20 -0
  55. data/test/integration/user_registration_test.rb +64 -0
  56. data/test/test_helper.rb +1 -0
  57. data/test/unit/cells/user_cell_test.rb +13 -0
  58. data/test/unit/helpers/users_helper_test.rb +52 -0
  59. data/test/unit/models/account_test.rb +21 -0
  60. data/test/unit/models/anonymous_test.rb +54 -0
  61. data/test/unit/models/password_mailer_test.rb +26 -0
  62. data/test/unit/models/user_mailer_test.rb +16 -0
  63. data/test/unit/models/user_test.rb +173 -0
  64. data/vendor/gems/authentication/.gitignore +17 -0
  65. data/vendor/gems/authentication/Gemfile +4 -0
  66. data/vendor/gems/authentication/LICENSE +22 -0
  67. data/vendor/gems/authentication/MIT-LICENSE +38 -0
  68. data/vendor/gems/authentication/README +39 -0
  69. data/vendor/gems/authentication/README.md +29 -0
  70. data/vendor/gems/authentication/RUNNING_UNIT_TESTS +13 -0
  71. data/vendor/gems/authentication/Rakefile +61 -0
  72. data/vendor/gems/authentication/authentication.gemspec +17 -0
  73. data/vendor/gems/authentication/lib/authentication.rb +270 -0
  74. data/vendor/gems/authentication/lib/authentication/active_record_extensions.rb +11 -0
  75. data/vendor/gems/authentication/lib/authentication/bogus.rb +13 -0
  76. data/vendor/gems/authentication/lib/authentication/hash_helper.rb +26 -0
  77. data/vendor/gems/authentication/lib/authentication/ldap.rb +49 -0
  78. data/vendor/gems/authentication/lib/authentication/remember_me.rb +52 -0
  79. data/vendor/gems/authentication/lib/authentication/salted_hash.rb +53 -0
  80. data/vendor/gems/authentication/lib/authentication/single_token.rb +53 -0
  81. data/vendor/gems/authentication/lib/authentication/version.rb +3 -0
  82. data/vendor/gems/authentication/lib/radius/dictionary +207 -0
  83. data/vendor/gems/authentication/test_backup/abstract_unit.rb +30 -0
  84. data/vendor/gems/authentication/test_backup/active_record_extension_test.rb +17 -0
  85. data/vendor/gems/authentication/test_backup/authentication_test.rb +231 -0
  86. data/vendor/gems/authentication/test_backup/database.yml +12 -0
  87. data/vendor/gems/authentication/test_backup/fixtures/user.rb +3 -0
  88. data/vendor/gems/authentication/test_backup/fixtures/users.yml +3 -0
  89. data/vendor/gems/authentication/test_backup/options_test.rb +100 -0
  90. data/vendor/gems/authentication/test_backup/remember_me_test.rb +41 -0
  91. data/vendor/gems/authentication/test_backup/salted_hash_test.rb +38 -0
  92. data/vendor/gems/authentication/test_backup/schema.rb +10 -0
  93. data/vendor/gems/authentication/test_backup/single_token_test.rb +44 -0
  94. data/vendor/gems/authentication/test_backup/test_helper.rb +8 -0
  95. metadata +157 -0
@@ -0,0 +1,176 @@
1
+ # FIXME implement these
2
+ require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
3
+
4
+ class AdminUsersControllerTest < ActionController::TestCase
5
+ tests Admin::UsersController
6
+
7
+ with_common :a_site, :is_superuser
8
+
9
+ test "should be an Admin::BaseController" do
10
+ @controller.should be_kind_of(Admin::BaseController)
11
+ end
12
+
13
+ describe "routing" do
14
+ with_options :path_prefix => '/admin/sites/1/', :site_id => "1" do |r|
15
+ r.it_maps :get, "users", :action => 'index'
16
+ r.it_maps :get, "users/1", :action => 'show', :id => '1'
17
+ r.it_maps :get, "users/new", :action => 'new'
18
+ r.it_maps :post, "users", :action => 'create'
19
+ r.it_maps :get, "users/1/edit", :action => 'edit', :id => '1'
20
+ r.it_maps :put, "users/1", :action => 'update', :id => '1'
21
+ r.it_maps :delete, "users/1", :action => 'destroy', :id => '1'
22
+ end
23
+
24
+ with_options :path_prefix => '/admin/' do |r|
25
+ r.it_maps :get, "users", :action => 'index'
26
+ r.it_maps :get, "users/1", :action => 'show', :id => '1'
27
+ r.it_maps :get, "users/new", :action => 'new'
28
+ r.it_maps :post, "users", :action => 'create'
29
+ r.it_maps :get, "users/1/edit", :action => 'edit', :id => '1'
30
+ r.it_maps :put, "users/1", :action => 'update', :id => '1'
31
+ r.it_maps :delete, "users/1", :action => 'destroy', :id => '1'
32
+ end
33
+ end
34
+
35
+ describe "GET to :index, with a site" do
36
+ action { get :index, default_params }
37
+
38
+ it_guards_permissions :show, :user do
39
+ it_assigns :users
40
+ it_renders_template :index
41
+ end
42
+ end
43
+
44
+ describe "GET to :index, without a site" do
45
+ action { get :index }
46
+
47
+ # FIXME this currently authorizes access in a hardcoded fashion to only :superusers
48
+ # see Admin::UsersController#authorize_access
49
+
50
+ # it_guards_permissions :show, :user do
51
+ it_assigns :users
52
+ it_renders_template :index
53
+ # end
54
+ end
55
+
56
+ describe "GET to :show" do
57
+ action { get :show, user_params }
58
+
59
+ it_guards_permissions :show, :user do
60
+ it_assigns :user
61
+ it_renders_template :show
62
+ end
63
+ end
64
+
65
+ describe "GET to :new" do
66
+ action { get :new, default_params }
67
+
68
+ it_guards_permissions :create, :user do
69
+ it_assigns :user => User
70
+ it_renders_template :new
71
+ end
72
+ end
73
+
74
+ describe "POST to :create" do
75
+ action { post :create, valid_user_params }
76
+
77
+ it_guards_permissions :create, :user do
78
+ it_assigns :user => User
79
+ it_triggers_event :user_created
80
+ it_assigns_flash_cookie :notice => :not_nil
81
+ it_redirects_to { admin_site_user_path(@site, User.last) }
82
+ end
83
+ end
84
+
85
+ describe "POST to :create, with invalid params" do
86
+ action { post :create, invalid_user_params }
87
+
88
+ it_guards_permissions :create, :user do
89
+ it_assigns :user => User
90
+ it_does_not_trigger_any_event
91
+ it_assigns_flash_cookie :error => :not_nil
92
+ it_renders_template 'new'
93
+ end
94
+ end
95
+
96
+ describe "GET to :edit" do
97
+ action { get :edit, user_params }
98
+
99
+ it_guards_permissions :update, :user do
100
+ it_assigns :user
101
+ it_renders_template :edit
102
+ end
103
+ end
104
+
105
+ describe "PUT to :update" do
106
+ action { put :update, valid_user_params.merge(:id => @user.id) }
107
+
108
+ it_guards_permissions :update, :user do
109
+ it_assigns :user
110
+ it_triggers_event :user_updated
111
+ it_assigns_flash_cookie :notice => :not_nil
112
+ it_redirects_to { admin_site_user_path(@site, @user) }
113
+ end
114
+ end
115
+
116
+ describe "PUT to :update, with invalid params" do
117
+ action { put :update, invalid_user_params.merge(:id => @user.id) }
118
+
119
+ it_guards_permissions :update, :user do
120
+ it_assigns :user
121
+ it_does_not_trigger_any_event
122
+ it_assigns_flash_cookie :error => :not_nil
123
+ it_renders_template 'edit'
124
+ end
125
+ end
126
+
127
+ describe "DELETE to :destroy" do
128
+ action { delete :destroy, user_params }
129
+
130
+ it_guards_permissions :destroy, :user do
131
+ it_assigns :user
132
+ it_assigns_flash_cookie :notice => :not_nil
133
+ it_triggers_event :user_deleted
134
+ it_redirects_to { admin_site_users_path(@site) }
135
+ end
136
+ end
137
+
138
+ # FIXME implement tests for membership removing and RBAC system (integration or functional tests?)
139
+ # describe "given valid user params (removing the user's site membership)" do
140
+ # before :each do
141
+ # @user.stub!(:is_site_member?).and_return false
142
+ # end
143
+ # it_redirects_to { @collection_path }
144
+ # it_triggers_event :user_updated
145
+ # end
146
+
147
+ # FIXME: how can destroy fail?
148
+ # describe "when destroy fails" do
149
+ # before :each do @user.stub!(:destroy).and_return false end
150
+ # it_renders_template :edit
151
+ # it_assigns_flash_cookie :error => :not_nil
152
+ # it_does_not_trigger_any_event
153
+ # end
154
+
155
+ # FIXME implement these:
156
+ # it "disallows a non-superuser to add a superuser role"
157
+ # it "disallows a non-admin to change any roles"
158
+ # it "disallows a site-admin to directly add any memberships"
159
+ # it "disallows a non-superuser to view another user's profile outside of a site scope"
160
+
161
+ def default_params
162
+ { :site_id => @site.id }
163
+ end
164
+
165
+ def user_params
166
+ default_params.merge(:id => @user.id)
167
+ end
168
+
169
+ def valid_user_params
170
+ default_params.merge(:user => { :first_name => 'John', :password => 'password', :email => 'John@test.org' })
171
+ end
172
+
173
+ def invalid_user_params
174
+ default_params.merge(:user => { :first_name => 'John', :password => 'password', :email => '' })
175
+ end
176
+ end
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+
3
+ class PasswordControllerTest < ActionController::TestCase
4
+ with_common :a_site, :a_user
5
+
6
+ test "is an BaseController" do
7
+ @controller.should be_kind_of(BaseController)
8
+ end
9
+
10
+ describe "GET to :new" do
11
+ action { get :new }
12
+
13
+ it_assigns :site
14
+ it_renders :template, :new do
15
+ has_form_posting_to password_path do
16
+ has_tag 'input[name=?]', 'user[email]'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "POST to :create" do
22
+ action { post :create, @params }
23
+
24
+ with "an email adress that belongs to a user" do
25
+ before { @params = { :user => { :email => @user.email } } }
26
+
27
+ it_triggers_event :user_password_reset_requested
28
+ it_assigns_flash_cookie :notice => :not_nil
29
+ it_redirects_to { edit_password_url }
30
+ end
31
+
32
+ with "an email adress that does not belong to a user" do
33
+ before { @params = { :user => { :email => 'none' } } }
34
+
35
+ it_does_not_trigger_any_event
36
+ it_assigns_flash_cookie :notice => :not_nil # feature, not a bug!
37
+ it_renders_template :new
38
+ end
39
+ end
40
+
41
+ describe "GET to :edit" do
42
+ action { get :edit, @params }
43
+
44
+ with "the user is logged in (via cookie or token)" do
45
+ before do
46
+ stub(@controller).current_user.returns(@user)
47
+ end
48
+
49
+ it_renders_template :edit do
50
+ has_tag 'input[name=?][type=password]', 'user[password]'
51
+ end
52
+ end
53
+
54
+ with "the user is not logged in (missing or invalid token)" do
55
+ it_renders_template :edit do
56
+ has_tag 'input[name=?][type=text]', 'token'
57
+ has_tag 'input[name=?][type=password]', 'user[password]'
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "PUT to :update" do
63
+ action { put :update, @params }
64
+
65
+ with "the user is logged in" do
66
+ before { stub(@controller).current_user.returns(@user) }
67
+
68
+ with "valid password parameters" do
69
+ before { @params = { :user => { :password => 'new password' } } }
70
+
71
+ it_triggers_event :user_password_updated
72
+ it_assigns_flash_cookie :notice => :not_nil
73
+ it_redirects_to { root_url }
74
+ end
75
+
76
+ describe "given an invalid email address" do
77
+ before { @params = { :user => { :password => nil } } }
78
+
79
+ it_does_not_trigger_any_event
80
+ it_assigns_flash_cookie :error => :not_nil
81
+ it_renders_template :edit
82
+ end
83
+ end
84
+
85
+ with "the user is not logged in" do
86
+ before { stub(@controller).current_user.returns(nil) }
87
+
88
+ it_does_not_trigger_any_event
89
+ it_assigns_flash_cookie :error => :not_nil
90
+ it_renders_template :edit do
91
+ has_tag 'input[name=?][type=?]', 'token', 'text'
92
+ has_tag 'input[name=?][type=?]', 'user[password]', 'password'
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1 @@
1
+ # FIXME ... implement
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+
3
+ class UserControllerTest < ActionController::TestCase
4
+ with_common :a_site, :a_user
5
+
6
+ view :form do
7
+ has_tag 'input[name=?]', 'user[first_name]'
8
+ has_tag 'input[name=?]', 'user[email]'
9
+ has_tag 'input[name=?]', 'user[password]'
10
+ end
11
+
12
+ test "is an BaseController" do
13
+ @controller.should be_kind_of(BaseController)
14
+ end
15
+
16
+ describe "GET to :new" do
17
+ action { get :new }
18
+
19
+ it_assigns :site
20
+ it_renders :template, :new do
21
+ has_form_posting_to user_path do
22
+ shows :form
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "POST to :create" do
28
+ action { post :create, @params }
29
+ it_assigns :user => :not_nil
30
+
31
+ with :valid_user_params do
32
+ it_saves :user
33
+ it_triggers_event :user_registered
34
+ it_triggers_event :user_created
35
+ it_redirects_to { user_verification_sent_url }
36
+
37
+ it "makes the new user a member of the current site" do
38
+ @site.users.should include(assigns(:user))
39
+ end
40
+
41
+ expect "sends a validation email to the user" do
42
+ # FIXME can't get this to behave ...
43
+ # mock(UserMailer).deliver_signup_verification_email(anything, anything)
44
+ end
45
+ end
46
+
47
+ with :invalid_user_params do
48
+ it_does_not_save :user
49
+ it_renders :template, :new
50
+ it_assigns_flash_cookie :error => :not_nil
51
+ it_does_not_trigger_any_event
52
+ end
53
+ end
54
+
55
+ describe "GET to :verification_sent" do
56
+ action { get :verification_sent }
57
+
58
+ it_renders :template, :verification_sent
59
+ end
60
+
61
+ describe "GET to :verify" do
62
+ action { get :verify }
63
+
64
+ with "the user has been logged in from params[:token]" do
65
+ before { stub(@controller).current_user.returns(@user) }
66
+
67
+ with "the user can be verified" do
68
+ before { @user.update_attributes!(:verified_at => nil) }
69
+
70
+ it_triggers_event :user_verified
71
+ it_assigns_flash_cookie :notice => :not_nil
72
+ it_redirects_to Registry.get(:redirect, :verify)
73
+ end
74
+
75
+ with "the user can not be verified" do
76
+ before { @user.update_attributes!(:verified_at => Time.now) }
77
+
78
+ it_does_not_trigger_any_event
79
+ it_assigns_flash_cookie :error => :not_nil
80
+ it_redirects_to Registry.get(:redirect, :verify)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "DELETE to :destroy" do
86
+ action { delete :destroy }
87
+
88
+ before { stub(@controller).current_user.returns(@user) }
89
+
90
+ it_destroys :user
91
+ it_redirects_to { '/' }
92
+ it_assigns_flash_cookie :notice => :not_nil
93
+ it_triggers_event :user_deleted
94
+ end
95
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
2
+
3
+ module IntegrationTests
4
+ class AnonymousLoginTest < ActionController::IntegrationTest
5
+ def setup
6
+ super
7
+ @site = use_site! 'site with pages'
8
+ @site.update_attributes! :permissions => { 'create comment' => 'anonymous' }
9
+ end
10
+
11
+ test "After posting a comment an anonymous is recognized by the system (aka anonymous login)" do
12
+ post_a_section_comment_as_anonymous
13
+ check_logged_in_as_anonymous
14
+ visit '/'
15
+ check_logged_in_as_anonymous
16
+ end
17
+
18
+ def post_a_section_comment_as_anonymous
19
+ visit '/articles/a-page-article'
20
+ fill_in "user_name", :with => "John Doe"
21
+ fill_in "user_email", :with => "john@example.com"
22
+ fill_in "comment_body", :with => "What a nice article!"
23
+ click_button "Submit comment"
24
+ end
25
+
26
+ def check_logged_in_as_anonymous
27
+ # the user is logged in as an anonymous user
28
+ current_user.should_not be_nil
29
+ current_user.anonymous?.should be_true
30
+
31
+ # a cookie containing the user id and indicating the anonymous login was set
32
+ cookies['aid'].should == current_user.id.to_s
33
+ end
34
+
35
+ def current_user
36
+ controller.current_user
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
2
+
3
+ module IntegrationTests
4
+ class EditUserTest < ActionController::IntegrationTest
5
+ def setup
6
+ super
7
+ @site = use_site! 'site with pages'
8
+ end
9
+
10
+ test "setting all global roles for a user with no global role on site, yet" do
11
+ login_as_superuser
12
+ visit_edit_user_form
13
+
14
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][0][selected]", "checked", :count => 0
15
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][1][selected]", "checked", :count => 0
16
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][2][selected]", "checked", :count => 0
17
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][3][selected]", "checked", :count => 0
18
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][4][selected]", "checked", :count => 0
19
+
20
+ check 'user[roles_attributes][0][selected]'
21
+ check 'user[roles_attributes][1][selected]'
22
+ check 'user[roles_attributes][2][selected]'
23
+ check 'user[roles_attributes][3][selected]'
24
+ check 'user[roles_attributes][4][selected]'
25
+
26
+ click_button 'commit'
27
+
28
+ visit_edit_user_form
29
+
30
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][0][selected]", "checked"
31
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][1][selected]", "checked"
32
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][2][selected]", "checked"
33
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][3][selected]", "checked"
34
+ assert_select "input[name=?][checked=?]", "user[roles_attributes][4][selected]", "checked"
35
+ end
36
+
37
+ def visit_edit_user_form
38
+ moderator = User.find_by_first_name('a moderator')
39
+ visit "/admin/sites/#{@site.id}/users/#{moderator.id}/edit"
40
+ renders_template "admin/users/edit"
41
+ end
42
+
43
+ end
44
+ end