Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
fc84783d
Commit
fc84783d
authored
Aug 01, 2011
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#124
] Validate user status changes
parent
bf13b0f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
user.rb
app/models/user.rb
+19
-0
user_test.rb
test/unit/user_test.rb
+8
-0
No files found.
app/models/user.rb
View file @
fc84783d
...
...
@@ -69,6 +69,7 @@ class User < Principal
validates_length_of
:mail
,
:maximum
=>
60
,
:allow_nil
=>
true
validates_confirmation_of
:password
,
:allow_nil
=>
true
validates_inclusion_of
:mail_notification
,
:in
=>
MAIL_NOTIFICATION_OPTIONS
.
collect
(
&
:first
),
:allow_blank
=>
true
validates_inclusion_of
:status
,
:in
=>
[
STATUS_ANONYMOUS
,
STATUS_ACTIVE
,
STATUS_REGISTERED
,
STATUS_LOCKED
]
named_scope
:in_group
,
lambda
{
|
group
|
group_id
=
group
.
is_a?
(
Group
)
?
group
.
id
:
group
.
to_i
...
...
@@ -525,6 +526,24 @@ class User < Principal
if
!
password
.
nil?
&&
password
.
size
<
Setting
.
password_min_length
.
to_i
errors
.
add
(
:password
,
:too_short
,
:count
=>
Setting
.
password_min_length
.
to_i
)
end
# Status
if
!
new_record?
&&
status_changed?
case
status_was
when
nil
# initial setting is always save
true
when
STATUS_ANONYMOUS
# never allow a state change of the anonymous user
false
when
STATUS_REGISTERED
[
STATUS_ACTIVE
,
STATUS_LOCKED
].
include?
status
when
STATUS_ACTIVE
[
STATUS_LOCKED
].
include?
status
when
STATUS_LOCKED
[
STATUS_ACTIVE
].
include?
status
end
||
errors
.
add
(
:status
,
:inclusion
)
end
end
private
...
...
test/unit/user_test.rb
View file @
fc84783d
...
...
@@ -173,6 +173,14 @@ class UserTest < ActiveSupport::TestCase
assert_equal
nil
,
user
end
def
test_error_on_active_to_registered
user
=
User
.
try_to_login
(
"jsmith"
,
"jsmith"
)
assert_equal
@jsmith
,
user
@jsmith
.
status
=
User
::
STATUS_REGISTERED
assert
!
@jsmith
.
save
end
context
".try_to_login"
do
context
"with good credentials"
do
should
"return the user"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment