rules_engine_users 0.0.2 → 0.0.3
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.
- data/VERSION +1 -1
- data/lib/rules_engine/controller_users.rb +14 -2
- data/rails_generators/templates/app/controllers/users_controller.rb +35 -11
- data/rails_generators/templates/app/views/users/_login_form.html.erb +3 -1
- data/rails_generators/templates/config/initializers/rules_engine_users.rb +2 -0
- data/rails_generators/templates/doc/README.rules_engine_users +2 -2
- data/rails_generators/templates/spec/controllers/users_controller_spec.rb +27 -11
- data/spec/rules_engine/controller_users_spec.rb +10 -1
- metadata +4 -4
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.3
|
|
@@ -2,7 +2,7 @@ module RulesEngine
|
|
|
2
2
|
module ControllerUsers
|
|
3
3
|
######### Requires the following paths
|
|
4
4
|
######### root_path
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
USER_ACCESS_LEVEL = [
|
|
7
7
|
["Administrator", User::ACCESS_LEVEL_ADMIN],
|
|
8
8
|
["Account Disabled", User::ACCESS_LEVEL_DISABLED]
|
|
@@ -11,7 +11,7 @@ module RulesEngine
|
|
|
11
11
|
# Inclusion hook to make #current_user #logged_in? and #logged_in_as_admin?
|
|
12
12
|
# available as ActionView helper methods.
|
|
13
13
|
def self.included(base)
|
|
14
|
-
base.send :helper_method, :current_user, :logged_in?, :logged_in_as_admin?, :logged_in_disabled?, :user_access_level, :user_access_levels
|
|
14
|
+
base.send :helper_method, :current_user, :logged_in?, :logged_in_as_admin?, :logged_in_disabled?, :user_access_level, :user_access_levels, :can_signup?
|
|
15
15
|
base.send :before_filter, :set_timezone
|
|
16
16
|
|
|
17
17
|
base.class_eval do
|
|
@@ -70,6 +70,10 @@ module RulesEngine
|
|
|
70
70
|
Time.zone = logged_in? ? current_user.time_zone : "Eastern Time (US & Canada)"
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
def can_signup?
|
|
74
|
+
ActionController::Base.can_signup?
|
|
75
|
+
end
|
|
76
|
+
|
|
73
77
|
module ClassMethods
|
|
74
78
|
def define_access_level name, access_level
|
|
75
79
|
(class << self; self end).instance_eval do
|
|
@@ -97,6 +101,14 @@ module RulesEngine
|
|
|
97
101
|
|
|
98
102
|
self.send :helper_method, "#{name}?"
|
|
99
103
|
end
|
|
104
|
+
|
|
105
|
+
def can_signup=(can_signup)
|
|
106
|
+
@can_signup = can_signup
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def can_signup?
|
|
110
|
+
@can_signup || false
|
|
111
|
+
end
|
|
100
112
|
end
|
|
101
113
|
|
|
102
114
|
protected
|
|
@@ -59,10 +59,22 @@ class UsersController < ApplicationController
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def signup_form
|
|
62
|
-
|
|
62
|
+
if can_signup?
|
|
63
|
+
@user = User.new(:time_zone => 'Eastern Time (US & Canada)', :access_level => UsersController.rules_engine_reader_access_level)
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
if logged_in?
|
|
66
|
+
flash[:success] = "User already logged in"
|
|
67
|
+
respond_to do |format|
|
|
68
|
+
format.html do
|
|
69
|
+
redirect_to(root_path)
|
|
70
|
+
end
|
|
71
|
+
format.js do
|
|
72
|
+
render :inline => "window.location.href = '#{root_path}';"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
else
|
|
77
|
+
flash[:error] = "Signup not supported"
|
|
66
78
|
respond_to do |format|
|
|
67
79
|
format.html do
|
|
68
80
|
redirect_to(root_path)
|
|
@@ -70,14 +82,28 @@ class UsersController < ApplicationController
|
|
|
70
82
|
format.js do
|
|
71
83
|
render :inline => "window.location.href = '#{root_path}';"
|
|
72
84
|
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
75
87
|
end
|
|
76
88
|
|
|
77
89
|
def signup
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
if can_signup?
|
|
91
|
+
@user = User.new(params[:user].merge(:access_level => UsersController.rules_engine_reader_access_level))
|
|
92
|
+
if @user.save
|
|
93
|
+
flash[:success] = "A welcome email has been sent to confirm login details"
|
|
94
|
+
respond_to do |format|
|
|
95
|
+
format.html do
|
|
96
|
+
redirect_to(root_path)
|
|
97
|
+
end
|
|
98
|
+
format.js do
|
|
99
|
+
render :inline => "window.location.href = '#{root_path}';"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
else
|
|
103
|
+
render :action => 'signup_form'
|
|
104
|
+
end
|
|
105
|
+
else
|
|
106
|
+
flash[:error] = "Signup not supported"
|
|
81
107
|
respond_to do |format|
|
|
82
108
|
format.html do
|
|
83
109
|
redirect_to(root_path)
|
|
@@ -85,9 +111,7 @@ class UsersController < ApplicationController
|
|
|
85
111
|
format.js do
|
|
86
112
|
render :inline => "window.location.href = '#{root_path}';"
|
|
87
113
|
end
|
|
88
|
-
end
|
|
89
|
-
else
|
|
90
|
-
render :action => 'signup_form'
|
|
114
|
+
end
|
|
91
115
|
end
|
|
92
116
|
end
|
|
93
117
|
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
<div class="span-8">
|
|
12
12
|
<div class="float-left">
|
|
13
|
-
|
|
13
|
+
<% if can_signup? %>
|
|
14
|
+
<%= re_button_link_blue("Signup ?", user_signup_path, :class => "fancybox-link") %>
|
|
15
|
+
<% end %>
|
|
14
16
|
<%= re_button_link_blue("Forgot Password ?", user_pswd_forgot_path, :class => "fancybox-link") %>
|
|
15
17
|
</div>
|
|
16
18
|
</div>
|
|
@@ -2,3 +2,5 @@ ActionController::Base.define_access_level(:rules_engine_editor, 10)
|
|
|
2
2
|
ActionController::Base.define_access_level(:rules_engine_reader, 5)
|
|
3
3
|
# ActionController::Base.define_access_level(:more_access, 7)
|
|
4
4
|
# ActionController::Base.define_access_level(:less_access, 3)
|
|
5
|
+
|
|
6
|
+
ActionController::Base.can_signup = false
|
|
@@ -76,8 +76,8 @@ ActionController::Routing::Routes.draw do |map|
|
|
|
76
76
|
map.with_options :controller => 'users', :path_prefix => '/user', :name_prefix => 'user_' do |user|
|
|
77
77
|
user.login '/', :action => 'login_form', :conditions => { :method => :get }
|
|
78
78
|
user.login '/', :action => 'login', :conditions => { :method => :post }
|
|
79
|
-
user.signup '/signup', :action => 'signup_form', :conditions => { :method => :get }
|
|
80
|
-
user.signup '/signup', :action => 'signup', :conditions => { :method => :post }
|
|
79
|
+
# user.signup '/signup', :action => 'signup_form', :conditions => { :method => :get }
|
|
80
|
+
# user.signup '/signup', :action => 'signup', :conditions => { :method => :post }
|
|
81
81
|
user.logout '/logout', :action => 'logout'
|
|
82
82
|
user.pswd_forgot '/pswd_forgot', :action => 'pswd_forgot_form', :conditions => { :method => :get }
|
|
83
83
|
user.pswd_forgot '/pswd_forgot', :action => 'pswd_forgot', :conditions => { :method => :post }
|
|
@@ -153,32 +153,48 @@ describe UsersController do
|
|
|
153
153
|
describe "GET signup_form" do
|
|
154
154
|
it "should render the 'signup_form' template" do
|
|
155
155
|
get :signup_form
|
|
156
|
-
|
|
156
|
+
if controller.can_signup?
|
|
157
|
+
response.should render_template(:signup_form)
|
|
158
|
+
else
|
|
159
|
+
response.should redirect_to(root_path)
|
|
160
|
+
end
|
|
157
161
|
end
|
|
158
162
|
|
|
159
163
|
it "should render 'signup_form' template for JAVASCRIPT" do
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
if controller.can_signup?
|
|
165
|
+
xhr :get, :signup_form
|
|
166
|
+
if controller.can_signup?
|
|
167
|
+
response.should render_template(:signup_form)
|
|
168
|
+
else
|
|
169
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
162
172
|
end
|
|
163
|
-
|
|
173
|
+
|
|
164
174
|
describe "already logged in" do
|
|
165
175
|
before(:each) do
|
|
166
176
|
controller.stub!(:logged_in?).and_return(true)
|
|
167
177
|
end
|
|
168
178
|
|
|
169
179
|
it "should set a success message if already lodded in" do
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
if controller.can_signup?
|
|
181
|
+
get :signup_form
|
|
182
|
+
flash[:success].should_not be_blank
|
|
183
|
+
end
|
|
172
184
|
end
|
|
173
185
|
|
|
174
186
|
it "should redirect to the root_path" do
|
|
175
|
-
|
|
176
|
-
|
|
187
|
+
if controller.can_signup?
|
|
188
|
+
get :signup_form
|
|
189
|
+
response.should redirect_to(root_path)
|
|
190
|
+
end
|
|
177
191
|
end
|
|
178
|
-
|
|
192
|
+
|
|
179
193
|
it "should redirect to the root_path JAVASCRIPT" do
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
if controller.can_signup?
|
|
195
|
+
xhr :get, :signup_form
|
|
196
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
|
197
|
+
end
|
|
182
198
|
end
|
|
183
199
|
end
|
|
184
200
|
end
|
|
@@ -224,7 +224,7 @@ describe "ControllerUsers", :type => :controller do
|
|
|
224
224
|
|
|
225
225
|
describe "_access_level" do
|
|
226
226
|
it "should return the access level" do
|
|
227
|
-
|
|
227
|
+
MockControllerUsersController.reporter_access_level.should == 200
|
|
228
228
|
end
|
|
229
229
|
end
|
|
230
230
|
|
|
@@ -316,6 +316,15 @@ describe "ControllerUsers", :type => :controller do
|
|
|
316
316
|
end
|
|
317
317
|
end
|
|
318
318
|
|
|
319
|
+
describe "can_signup?" do
|
|
320
|
+
it "should be able to set the value" do
|
|
321
|
+
ActionController::Base.can_signup = true
|
|
322
|
+
controller.should be_can_signup
|
|
323
|
+
ActionController::Base.can_signup = false
|
|
324
|
+
controller.should_not be_can_signup
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
319
328
|
describe "user time zone" do
|
|
320
329
|
it "Set the time zone to the user's timezone" do
|
|
321
330
|
controller.stub!(:current_user).and_return(@current_user)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rules_engine_users
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.0.3
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Chris Douglas
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-09-02 00:00:00 +10:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|