refinerycms-authentication-devise 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +89 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +50 -0
  5. data/Rakefile +20 -0
  6. data/app/controllers/refinery/authentication/devise/admin/users_controller.rb +147 -0
  7. data/app/controllers/refinery/authentication/devise/passwords_controller.rb +58 -0
  8. data/app/controllers/refinery/authentication/devise/sessions_controller.rb +39 -0
  9. data/app/controllers/refinery/authentication/devise/users_controller.rb +50 -0
  10. data/app/decorators/controllers/action_controller_base_decorator.rb +25 -0
  11. data/app/decorators/controllers/refinery/admin_controller_decorator.rb +20 -0
  12. data/app/decorators/controllers/refinery/application_controller_decorator.rb +7 -0
  13. data/app/mailers/refinery/authentication/devise/user_mailer.rb +26 -0
  14. data/app/models/refinery/authentication/devise/nil_user.rb +31 -0
  15. data/app/models/refinery/authentication/devise/role.rb +22 -0
  16. data/app/models/refinery/authentication/devise/roles_users.rb +12 -0
  17. data/app/models/refinery/authentication/devise/user.rb +166 -0
  18. data/app/models/refinery/authentication/devise/user_plugin.rb +11 -0
  19. data/app/views/refinery/authentication/devise/admin/users/_actions.html.erb +7 -0
  20. data/app/views/refinery/authentication/devise/admin/users/_form.html.erb +94 -0
  21. data/app/views/refinery/authentication/devise/admin/users/_records.html.erb +10 -0
  22. data/app/views/refinery/authentication/devise/admin/users/_user.html.erb +23 -0
  23. data/app/views/refinery/authentication/devise/admin/users/_users.html.erb +4 -0
  24. data/app/views/refinery/authentication/devise/admin/users/edit.html.erb +1 -0
  25. data/app/views/refinery/authentication/devise/admin/users/index.html.erb +6 -0
  26. data/app/views/refinery/authentication/devise/admin/users/new.html.erb +1 -0
  27. data/app/views/refinery/authentication/devise/passwords/edit.html.erb +26 -0
  28. data/app/views/refinery/authentication/devise/passwords/new.html.erb +17 -0
  29. data/app/views/refinery/authentication/devise/sessions/new.html.erb +27 -0
  30. data/app/views/refinery/authentication/devise/user_mailer/reset_notification.html.erb +12 -0
  31. data/app/views/refinery/authentication/devise/user_mailer/reset_notification.text.plain.erb +7 -0
  32. data/app/views/refinery/authentication/devise/users/new.html.erb +29 -0
  33. data/app/views/refinery/layouts/login.html.erb +22 -0
  34. data/bin/rails +5 -0
  35. data/bin/rake +21 -0
  36. data/bin/rspec +22 -0
  37. data/bin/spring +18 -0
  38. data/config/locales/bg.yml +73 -0
  39. data/config/locales/ca.yml +75 -0
  40. data/config/locales/cs.yml +77 -0
  41. data/config/locales/da.yml +73 -0
  42. data/config/locales/de.yml +73 -0
  43. data/config/locales/el.yml +73 -0
  44. data/config/locales/en.yml +77 -0
  45. data/config/locales/es.yml +73 -0
  46. data/config/locales/fi.yml +73 -0
  47. data/config/locales/fr.yml +73 -0
  48. data/config/locales/hu.yml +73 -0
  49. data/config/locales/it.yml +77 -0
  50. data/config/locales/ja.yml +73 -0
  51. data/config/locales/ko.yml +73 -0
  52. data/config/locales/lt.yml +56 -0
  53. data/config/locales/lv.yml +73 -0
  54. data/config/locales/nb.yml +73 -0
  55. data/config/locales/nl.yml +77 -0
  56. data/config/locales/pl.yml +73 -0
  57. data/config/locales/pt-BR.yml +69 -0
  58. data/config/locales/pt.yml +73 -0
  59. data/config/locales/rs.yml +73 -0
  60. data/config/locales/ru.yml +70 -0
  61. data/config/locales/sk.yml +73 -0
  62. data/config/locales/sl.yml +62 -0
  63. data/config/locales/sv.yml +65 -0
  64. data/config/locales/tr.yml +73 -0
  65. data/config/locales/uk.yml +71 -0
  66. data/config/locales/vi.yml +73 -0
  67. data/config/locales/zh-CN.yml +73 -0
  68. data/config/locales/zh-TW.yml +74 -0
  69. data/config/routes.rb +49 -0
  70. data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +43 -0
  71. data/db/migrate/20120301234455_add_slug_to_refinery_users.rb +7 -0
  72. data/db/migrate/20130805143059_add_full_name_to_refinery_users.rb +5 -0
  73. data/db/migrate/20150503125200_rename_tables_to_new_namespace.rb +17 -0
  74. data/lib/generators/refinery/authentication/devise/generator.rb +18 -0
  75. data/lib/generators/refinery/authentication/devise/templates/config/initializers/refinery/authentication/devise.rb.erb +8 -0
  76. data/lib/refinery/authentication/devise/authorisation_adapter.rb +36 -0
  77. data/lib/refinery/authentication/devise/authorisation_manager.rb +30 -0
  78. data/lib/refinery/authentication/devise/configuration.rb +22 -0
  79. data/lib/refinery/authentication/devise/engine.rb +43 -0
  80. data/lib/refinery/authentication/devise/initialiser.rb +228 -0
  81. data/lib/refinery/authentication/devise/system.rb +63 -0
  82. data/lib/refinery/authentication/devise.rb +26 -0
  83. data/lib/refinerycms-authentication-devise.rb +1 -0
  84. data/license.md +21 -0
  85. data/readme.md +11 -0
  86. data/refinerycms-authentication-devise.gemspec +22 -0
  87. data/spec/controllers/refinery/authentication/devise/admin/users_controller_spec.rb +90 -0
  88. data/spec/factories/user.rb +27 -0
  89. data/spec/features/refinery/authentication/devise/admin/users_spec.rb +88 -0
  90. data/spec/features/refinery/authentication/devise/passwords_spec.rb +71 -0
  91. data/spec/features/refinery/authentication/devise/sessions_spec.rb +103 -0
  92. data/spec/lib/refinery/authentication/devise/configuration_spec.rb +41 -0
  93. data/spec/models/refinery/user_spec.rb +285 -0
  94. data/spec/spec_helper.rb +27 -0
  95. data/spec/support/refinery/authentication/devise/controller_macros.rb +48 -0
  96. data/spec/support/refinery/authentication/devise/feature_macros.rb +26 -0
  97. data/tasks/rspec.rake +4 -0
  98. metadata +225 -0
@@ -0,0 +1,228 @@
1
+ require 'devise'
2
+
3
+ # Use this hook to configure devise mailer, warden hooks and so forth.
4
+ # Many of these configuration options can be set straight in your model.
5
+ ::Devise.setup do |config|
6
+ config.secret_key = ENV['DEVISE_SECRET_KEY'] || SecureRandom.hex
7
+
8
+ # ==> Mailer Configuration
9
+ # Configure the e-mail address which will be shown in Devise::Mailer,
10
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
11
+ # config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
12
+
13
+ # Configure the class responsible to send e-mails.
14
+ # config.mailer = "Devise::Mailer"
15
+
16
+ # ==> ORM configuration
17
+ # Load and configure the ORM. Supports :active_record (default) and
18
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
19
+ # available as additional gems.
20
+ ActiveSupport.on_load(:active_record) do
21
+ ::Devise.setup do
22
+ require 'devise/orm/active_record'
23
+ end
24
+ end
25
+
26
+ # ==> Configuration for any authentication mechanism
27
+ # Configure which keys are used when authenticating a user. The default is
28
+ # just :email. You can configure it to use [:username, :subdomain], so for
29
+ # authenticating a user, both parameters are required. Remember that those
30
+ # parameters are used only when authenticating and not when retrieving from
31
+ # session. If you need permissions, you should implement that in a before filter.
32
+ # You can also supply a hash where the value is a boolean determining whether
33
+ # or not authentication should be aborted when the value is not present.
34
+ config.authentication_keys = [ :login ]
35
+
36
+ # Configure parameters from the request object used for authentication. Each entry
37
+ # given should be a request method and it will automatically be passed to the
38
+ # find_for_authentication method and considered in your model lookup. For instance,
39
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
40
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
41
+ # config.request_keys = []
42
+
43
+ # Configure which authentication keys should be case-insensitive.
44
+ # These keys will be downcased upon creating or modifying a user and when used
45
+ # to authenticate or find a user. Default is :email.
46
+ config.case_insensitive_keys = []
47
+
48
+ # Configure which authentication keys should have whitespace stripped.
49
+ # These keys will have whitespace before and after removed upon creating or
50
+ # modifying a user and when used to authenticate or find a user. Default is :email.
51
+ # config.strip_whitespace_keys = [ :email ]
52
+
53
+ # Tell if authentication through request.params is enabled. True by default.
54
+ # It can be set to an array that will enable params authentication only for the
55
+ # given stratragies, for example, `config.params_authenticatable = [:database]` will
56
+ # enable it only for database (email + password) authentication.
57
+ # config.params_authenticatable = true
58
+
59
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
60
+ # It can be set to an array that will enable http authentication only for the
61
+ # given stratragies, for example, `config.http_authenticatable = [:token]` will
62
+ # enable it only for token authentication.
63
+ # config.http_authenticatable = false
64
+
65
+ # If http headers should be returned for AJAX requests. True by default.
66
+ # config.http_authenticatable_on_xhr = true
67
+
68
+ # The realm used in Http Basic Authentication. "Application" by default.
69
+ # config.http_authentication_realm = "Application"
70
+
71
+ # It will change confirmation, password recovery and other workflows
72
+ # to behave the same regardless if the e-mail provided was right or wrong.
73
+ # Does not affect registerable.
74
+ # config.paranoid = true
75
+
76
+ # By default Devise will store the user in session. You can skip storage for
77
+ # :http_auth and :token_auth by adding those symbols to the array below.
78
+ # Notice that if you are skipping storage for all authentication paths, you
79
+ # may want to disable generating routes to Devise's sessions controller by
80
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
81
+ config.skip_session_storage = [:http_auth]
82
+
83
+ # ==> Configuration for :database_authenticatable
84
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
85
+ # using other encryptors, it sets how many times you want the password re-encrypted.
86
+ #
87
+ # Limiting the stretches to just one in testing will increase the performance of
88
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
89
+ # a value less than 10 in other environments.
90
+ config.stretches = Rails.env.test? ? 1 : 10
91
+
92
+ # Setup a pepper to generate the encrypted password.
93
+ # config.pepper = <%= SecureRandom.hex(64).inspect %>
94
+
95
+ # ==> Configuration for :confirmable
96
+ # A period that the user is allowed to access the website even without
97
+ # confirming his account. For instance, if set to 2.days, the user will be
98
+ # able to access the website for two days without confirming his account,
99
+ # access will be blocked just in the third day. Default is 0.days, meaning
100
+ # the user cannot access the website without confirming his account.
101
+ # config.allow_unconfirmed_access_for = 2.days
102
+
103
+ # If true, requires any email changes to be confirmed (exctly the same way as
104
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
105
+ # db field (see migrations). Until confirmed new email is stored in
106
+ # unconfirmed email column, and copied to email column on successful confirmation.
107
+ # config.reconfirmable = true
108
+
109
+ # Defines which key will be used when confirming an account
110
+ # config.confirmation_keys = [ :email ]
111
+
112
+ # ==> Configuration for :rememberable
113
+ # The time the user will be remembered without asking for credentials again.
114
+ # config.remember_for = 2.weeks
115
+
116
+ # If true, extends the user's remember period when remembered via cookie.
117
+ # config.extend_remember_period = false
118
+
119
+ # Options to be passed to the created cookie. For instance, you can set
120
+ # :secure => true in order to force SSL only cookies.
121
+ # config.cookie_options = {}
122
+
123
+ # ==> Configuration for :validatable
124
+ # Range for password length. Default is 6..128.
125
+ config.password_length = 4..128
126
+
127
+ # Email regex used to validate email formats. It simply asserts that
128
+ # an one (and only one) @ exists in the given string. This is mainly
129
+ # to give user feedback and not to assert the e-mail validity.
130
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
131
+
132
+ # ==> Configuration for :timeoutable
133
+ # The time you want to timeout the user session without activity. After this
134
+ # time the user will be asked for credentials again. Default is 30 minutes.
135
+ # config.timeout_in = 30.minutes
136
+
137
+ # ==> Configuration for :lockable
138
+ # Defines which strategy will be used to lock an account.
139
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
140
+ # :none = No lock strategy. You should handle locking by yourself.
141
+ # config.lock_strategy = :failed_attempts
142
+
143
+ # Defines which key will be used when locking and unlocking an account
144
+ # config.unlock_keys = [ :email ]
145
+
146
+ # Defines which strategy will be used to unlock an account.
147
+ # :email = Sends an unlock link to the user email
148
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
149
+ # :both = Enables both strategies
150
+ # :none = No unlock strategy. You should handle unlocking by yourself.
151
+ # config.unlock_strategy = :both
152
+
153
+ # Number of authentication tries before locking an account if lock_strategy
154
+ # is failed attempts.
155
+ # config.maximum_attempts = 20
156
+
157
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
158
+ # config.unlock_in = 1.hour
159
+
160
+ # ==> Configuration for :recoverable
161
+ #
162
+ # Defines which key will be used when recovering the password for an account
163
+ # config.reset_password_keys = [ :email ]
164
+
165
+ # Time interval you can reset your password with a reset password key.
166
+ # Don't put a too small interval or your users won't have the time to
167
+ # change their passwords.
168
+ config.reset_password_within = 6.hours
169
+
170
+ # ==> Configuration for :encryptable
171
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
172
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
173
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
174
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
175
+ # REST_AUTH_SITE_KEY to pepper)
176
+ # config.encryptor = :sha512
177
+
178
+ # ==> Configuration for :token_authenticatable
179
+ # Defines name of the authentication token params key
180
+ # config.token_authentication_key = :auth_token
181
+
182
+ # ==> Scopes configuration
183
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
184
+ # "users/sessions/new". It's turned off by default because it's slower if you
185
+ # are using only default views.
186
+ # config.scoped_views = false
187
+
188
+ # Configure the default scope given to Warden. By default it's the first
189
+ # devise role declared in your routes (usually :user).
190
+ # config.default_scope = :user
191
+
192
+ # Configure sign_out behavior.
193
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
194
+ # The default is true, which means any logout action will sign out all active scopes.
195
+ # config.sign_out_all_scopes = true
196
+
197
+ # ==> Navigation configuration
198
+ # Lists the formats that should be treated as navigational. Formats like
199
+ # :html, should redirect to the sign in page when the user does not have
200
+ # access, but formats like :xml or :json, should return 401.
201
+ #
202
+ # If you have any extra navigational formats, like :iphone or :mobile, you
203
+ # should add them to the navigational formats lists.
204
+ #
205
+ # The "*/*" below is required to match Internet Explorer requests.
206
+ # config.navigational_formats = ["*/*", :html]
207
+
208
+ # The default HTTP method used to sign out a resource. Default is :delete.
209
+ config.sign_out_via = :delete
210
+
211
+ # ==> OmniAuth
212
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
213
+ # up on your models and hooks.
214
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
215
+
216
+ # ==> Warden configuration
217
+ # If you want to use other strategies, that are not supported by Devise, or
218
+ # change the failure app, you can configure them inside the config.warden block.
219
+ #
220
+ # config.warden do |manager|
221
+ # manager.intercept_401 = false
222
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
223
+ # end
224
+
225
+ # Please do not change the router_name away from :refinery
226
+ # otherwise Refinery may not function properly. Thanks!
227
+ config.router_name = :refinery
228
+ end
@@ -0,0 +1,63 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ module System
5
+ # Store the URI of the current request in the session.
6
+ #
7
+ # We can return to this location by calling #redirect_back_or_default.
8
+ def store_location
9
+ session[:return_to] = request.fullpath
10
+ end
11
+
12
+ # Clear and return the stored location
13
+ def pop_stored_location
14
+ session.delete(:return_to)
15
+ end
16
+
17
+ # Redirect to the URI stored by the most recent store_location call or
18
+ # to the passed default.
19
+ def redirect_back_or_default(default)
20
+ redirect_to(pop_stored_location || default)
21
+ end
22
+
23
+ # This defines the devise method for refinery routes
24
+ def signed_in_root_path(resource_or_scope)
25
+ scope = ::Devise::Mapping.find_scope!(resource_or_scope)
26
+ home_path = "#{scope}_root_path"
27
+ if respond_to?(home_path, true)
28
+ refinery.send(home_path)
29
+ else
30
+ Refinery::Core.backend_path
31
+ end
32
+ end
33
+
34
+ # Pops the stored url, trims the sneaky "//" from it, and returns it.
35
+ #
36
+ # Making sure bad urls aren't stored in the first place should probably be
37
+ # a part of the Devise::FailureApp
38
+ def sanitized_stored_location_for(resource_or_scope)
39
+ # `stored_location_for` is the devise method that pops the
40
+ # scoped `return_to` key
41
+ location = stored_location_for(resource_or_scope)
42
+ location.sub!("//", "/") if location.respond_to?(:sub!)
43
+ location
44
+ end
45
+
46
+ # This just defines the devise method for after sign in to support
47
+ # extension namespace isolation...
48
+ def after_sign_in_path_for(resource_or_scope)
49
+ pop_stored_location ||
50
+ sanitized_stored_location_for(resource_or_scope) ||
51
+ signed_in_root_path(resource_or_scope)
52
+ end
53
+
54
+ def after_sign_out_path_for(resource_or_scope)
55
+ refinery.root_path
56
+ end
57
+
58
+ protected :store_location, :pop_stored_location, :redirect_back_or_default,
59
+ :sanitized_stored_location_for
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ require 'refinerycms-core'
2
+ require 'action_mailer'
3
+ require 'devise'
4
+ require 'friendly_id'
5
+
6
+ module Refinery
7
+ autoload :AuthenticationDeviseGenerator, 'generators/refinery/authentication/devise/authentication_generator'
8
+ autoload :AuthenticationSystem, 'refinery/authenticated_system'
9
+
10
+ module Authentication
11
+ module Devise
12
+ require 'refinery/authentication/devise/engine'
13
+ require 'refinery/authentication/devise/configuration'
14
+
15
+ class << self
16
+ def factory_paths
17
+ @factory_paths ||= [ root.join("spec/factories").to_s ]
18
+ end
19
+
20
+ def root
21
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/authentication/devise'
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2015 [Philip Arndt](http://p.arndt.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,11 @@
1
+ # Refinery CMS Authentication Extension for Devise
2
+
3
+ This extension allows you to use Devise with Refinery CMS 3.0 and later.
4
+
5
+ ## Usage
6
+
7
+ Simply put this in the Gemfile of your Refinery application:
8
+
9
+ ```ruby
10
+ gem 'refinerycms-authentication-devise', '~> 1.0.0'
11
+ ```
@@ -0,0 +1,22 @@
1
+ # Encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = %q{refinerycms-authentication-devise}
5
+ s.version = %q{1.0.0}
6
+ s.summary = %q{Devise based authentication extension for Refinery CMS}
7
+ s.description = %q{A Devise authentication extension for Refinery CMS}
8
+ s.homepage = %q{http://refinerycms.com}
9
+ s.authors = ['Philip Arndt', 'Rob Yurkowski']
10
+ s.license = %q{MIT}
11
+ s.require_paths = %w(lib)
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- spec/*`.split("\n")
15
+
16
+ s.add_dependency 'refinerycms-core', ['~> 3.0', '>= 3.0.0']
17
+ s.add_dependency 'actionmailer', ['~> 4.2', '>= 4.2.0']
18
+ s.add_dependency 'devise', ['~> 3.0', '>= 3.2.4']
19
+ s.add_dependency 'friendly_id', '~> 5.1.0'
20
+
21
+ s.required_ruby_version = '>= 2.0.0'
22
+ end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe Refinery::Authentication::Devise::Admin::UsersController, :type => :controller do
4
+ refinery_login_with_devise [:refinery, :superuser]
5
+
6
+ shared_examples_for "new, create, update, edit and update actions" do
7
+ it "loads roles" do
8
+ get :new
9
+ end
10
+
11
+ it "loads plugins" do
12
+ user_plugin = Refinery::Plugins.registered.detect { |plugin| plugin.name == "refinery_authentication_devise" }
13
+ plugins = Refinery::Plugins.new
14
+ plugins << user_plugin
15
+ expect(plugins).to receive(:in_menu).once{ [user_plugin] }
16
+
17
+ expect(Refinery::Plugins).to receive(:registered).at_least(1).times{ plugins }
18
+ get :new
19
+ end
20
+ end
21
+
22
+ describe "#new" do
23
+ it "renders the new template" do
24
+ get :new
25
+ expect(response).to be_success
26
+ expect(response).to render_template("refinery/authentication/devise/admin/users/new")
27
+ end
28
+
29
+ it_should_behave_like "new, create, update, edit and update actions"
30
+ end
31
+
32
+ describe "#create" do
33
+ it "creates a new user with valid params" do
34
+ user = Refinery::Authentication::Devise::User.new :username => "bob"
35
+ expect(user).to receive(:save).once{ true }
36
+ expect(Refinery::Authentication::Devise::User).to receive(:new).once.with(instance_of(ActionController::Parameters)){ user }
37
+ post :create, :user => {:username => 'bobby'}
38
+ expect(response).to be_redirect
39
+ end
40
+
41
+ it_should_behave_like "new, create, update, edit and update actions"
42
+
43
+ it "re-renders #new if there are errors" do
44
+ user = Refinery::Authentication::Devise::User.new :username => "bob"
45
+ expect(user).to receive(:save).once{ false }
46
+ expect(Refinery::Authentication::Devise::User).to receive(:new).once.with(instance_of(ActionController::Parameters)){ user }
47
+ post :create, :user => {:username => 'bobby'}
48
+ expect(response).to be_success
49
+ expect(response).to render_template("refinery/authentication/devise/admin/users/new")
50
+ end
51
+ end
52
+
53
+ describe "#edit" do
54
+ refinery_login_with_devise [:refinery, :superuser]
55
+
56
+ it "renders the edit template" do
57
+ get :edit, :id => logged_in_user.id
58
+ expect(response).to be_success
59
+ expect(response).to render_template("refinery/authentication/devise/admin/users/edit")
60
+ end
61
+
62
+ it_should_behave_like "new, create, update, edit and update actions"
63
+ end
64
+
65
+ describe "#update" do
66
+ refinery_login_with_devise [:refinery, :superuser]
67
+
68
+ let(:additional_user) { FactoryGirl.create :authentication_devise_refinery_user }
69
+ it "updates a user" do
70
+ patch "update", :id => additional_user.id.to_s, :user => {:username => 'bobby'}
71
+ expect(response).to be_redirect
72
+ end
73
+
74
+ context "when specifying plugins" do
75
+ it "won't allow to remove 'Users' plugin from self" do
76
+ patch "update", :id => logged_in_user.id.to_s, :user => {:plugins => ["some plugin"]}
77
+
78
+ expect(flash[:error]).to eq("You cannot remove the 'Users' plugin from the currently logged in account.")
79
+ end
80
+
81
+ it "will update to the plugins supplied" do
82
+ expect(logged_in_user).to receive(:update_attributes).with({"plugins" => %w(refinery_authentication_devise some_plugin)})
83
+ allow(Refinery::Authentication::Devise::User).to receive_message_chain(:includes, :find) { logged_in_user }
84
+ patch "update", :id => logged_in_user.id.to_s, :user => {:plugins => %w(refinery_authentication_devise some_plugin)}
85
+ end
86
+ end
87
+
88
+ it_should_behave_like "new, create, update, edit and update actions"
89
+ end
90
+ end
@@ -0,0 +1,27 @@
1
+ FactoryGirl.define do
2
+ factory :authentication_devise_user, :class => Refinery::Authentication::Devise::User do
3
+ sequence(:username) { |n| "refinery#{n}" }
4
+ sequence(:email) { |n| "refinery#{n}@example.com" }
5
+ password "refinerycms"
6
+ password_confirmation "refinerycms"
7
+ end
8
+
9
+ factory :authentication_devise_refinery_user, :parent => :authentication_devise_user do
10
+ roles { [ ::Refinery::Authentication::Devise::Role[:refinery] ] }
11
+
12
+ after(:create) do |user|
13
+ ::Refinery::Plugins.registered.each_with_index do |plugin, index|
14
+ user.plugins.create(:name => plugin.name, :position => index)
15
+ end
16
+ end
17
+ end
18
+
19
+ factory :authentication_devise_refinery_superuser, :parent => :authentication_devise_refinery_user do
20
+ roles {
21
+ [
22
+ ::Refinery::Authentication::Devise::Role[:refinery],
23
+ ::Refinery::Authentication::Devise::Role[:superuser]
24
+ ]
25
+ }
26
+ end
27
+ end
@@ -0,0 +1,88 @@
1
+ require "spec_helper"
2
+
3
+ describe "User admin page", :type => :feature do
4
+ refinery_login_with_devise :authentication_devise_refinery_superuser
5
+
6
+ describe "new/create" do
7
+ def visit_and_fill_form
8
+ visit refinery.authentication_devise_admin_users_path
9
+ click_link "Add new user"
10
+
11
+ fill_in "user[username]", :with => "test"
12
+ fill_in "user[email]", :with => "test@example.com"
13
+ fill_in "user[password]", :with => "123456"
14
+ fill_in "user[password_confirmation]", :with => "123456"
15
+ end
16
+
17
+ it "can create a user" do
18
+ visit_and_fill_form
19
+
20
+ click_button "Save"
21
+
22
+ expect(page).to have_content("test was successfully added.")
23
+ expect(page).to have_content("test (test@example.com)")
24
+ end
25
+
26
+ context "when assigning roles config is enabled" do
27
+ before do
28
+ allow(Refinery::Authentication::Devise).to receive(:superuser_can_assign_roles).and_return(true)
29
+ end
30
+
31
+ it "allows superuser to assign roles" do
32
+ visit_and_fill_form
33
+
34
+ within "#roles" do
35
+ check "roles_#{Refinery::Authentication::Devise::Role.first.title.downcase}"
36
+ end
37
+ click_button "Save"
38
+
39
+ expect(page).to have_content("test was successfully added.")
40
+ expect(page).to have_content("test (test@example.com)")
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "edit/update" do
46
+ it "can update a user" do
47
+ visit refinery.authentication_devise_admin_users_path
48
+ click_link "Edit this user"
49
+
50
+ fill_in "Username", :with => "cmsrefinery"
51
+ fill_in "Email", :with => "cms@example.com"
52
+ click_button "Save"
53
+
54
+ expect(page).to have_content("cmsrefinery was successfully updated.")
55
+ expect(page).to have_content("cmsrefinery (cms@example.com)")
56
+ end
57
+
58
+ let(:dotty_user) { FactoryGirl.create(:authentication_devise_refinery_user, :username => 'user.name.with.lots.of.dots') }
59
+ it "accepts a username with a '.' in it" do
60
+ dotty_user # create the user
61
+ visit refinery.authentication_devise_admin_users_path
62
+
63
+ expect(page).to have_css("#sortable_#{dotty_user.id}")
64
+
65
+ within "#sortable_#{dotty_user.id}" do
66
+ click_link "Edit this user"
67
+ end
68
+
69
+ expect(page).to have_css("form#edit_user_#{dotty_user.id}")
70
+ end
71
+ end
72
+
73
+ describe "destroy" do
74
+ let!(:user) {
75
+ FactoryGirl.create(:authentication_devise_refinery_user, username: "ugisozols")
76
+ }
77
+
78
+ it "can only destroy regular users" do
79
+ visit refinery.authentication_devise_admin_users_path
80
+ expect(page).to have_selector("a[href='/refinery/users/#{user.username}']")
81
+ expect(page).to have_no_selector("a[href='/refinery/users/#{logged_in_user.username}']")
82
+
83
+ click_link "Remove this user"
84
+ expect(page).to have_content("'#{user.username}' was successfully removed.")
85
+ expect(page).to have_content("#{logged_in_user.username} (#{logged_in_user.email})")
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ describe "password recovery", :type => :feature do
4
+ let!(:user) { FactoryGirl.create(:authentication_devise_refinery_user, :email => "refinery@example.com") }
5
+
6
+ it "asks user to specify email address" do
7
+ visit refinery.login_path
8
+ click_link "I forgot my password"
9
+ expect(page).to have_content("Please enter the email address for your account.")
10
+ end
11
+
12
+ context "when existing email specified" do
13
+ it "shows success message" do
14
+ visit refinery.new_authentication_devise_user_password_path
15
+ fill_in "authentication_devise_user_email", :with => user.email
16
+ click_button "Reset password"
17
+ expect(page).to have_content("An email has been sent to you with a link to reset your password.")
18
+ end
19
+ end
20
+
21
+ context "when non-existing email specified" do
22
+ it "shows failure message" do
23
+ visit refinery.new_authentication_devise_user_password_path
24
+ fill_in "authentication_devise_user_email", :with => "none@example.com"
25
+ click_button "Reset password"
26
+ expect(page).to have_content("Sorry, 'none@example.com' isn't associated with any accounts.")
27
+ expect(page).to have_content("Are you sure you typed the correct email address?")
28
+ end
29
+ end
30
+
31
+ context "when good reset code" do
32
+ let!(:token) { user.generate_reset_password_token! }
33
+
34
+ it "allows to change password" do
35
+ visit refinery.edit_authentication_devise_user_password_path(:reset_password_token => token)
36
+ expect(page).to have_content("Pick a new password for #{user.email}")
37
+
38
+ fill_in "authentication_devise_user_password", :with => "123456"
39
+ fill_in "authentication_devise_user_password_confirmation", :with => "123456"
40
+ click_button "Reset password"
41
+
42
+ expect(page).to have_content("Password reset successfully for '#{user.email}'")
43
+ end
44
+ end
45
+
46
+ context "when invalid reset code" do
47
+ let!(:token) { user.generate_reset_password_token! }
48
+
49
+ it "shows error message" do
50
+ visit refinery.edit_authentication_devise_user_password_path(:reset_password_token => "hmmm")
51
+ expect(page).to have_content("Reset password token is invalid")
52
+ end
53
+ end
54
+
55
+ context "when expired reset code" do
56
+ let!(:token) { user.generate_reset_password_token! }
57
+ before do
58
+ user.update_attribute(:reset_password_sent_at, 1.day.ago)
59
+ end
60
+
61
+ it "shows error message" do
62
+ visit refinery.edit_authentication_devise_user_password_path(:reset_password_token => token)
63
+
64
+ fill_in "authentication_devise_user_password", :with => "123456"
65
+ fill_in "authentication_devise_user_password_confirmation", :with => "123456"
66
+ click_button "Reset password"
67
+
68
+ expect(page).to have_content("Reset password token has expired, please request a new one")
69
+ end
70
+ end
71
+ end