BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3531ea09
Commit
3531ea09
authored
May 05, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Devise can assign trackable fields, but only allow writes once/hour
Not assigning the trackable fields seems to cause strange side-effects.
parent
6a915d6f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
7 deletions
+18
-7
user.rb
app/models/user.rb
+5
-4
sorting_spec.rb
spec/features/groups/members/sorting_spec.rb
+2
-2
user_spec.rb
spec/models/user_spec.rb
+11
-1
No files found.
app/models/user.rb
View file @
3531ea09
...
@@ -40,14 +40,15 @@ class User < ActiveRecord::Base
...
@@ -40,14 +40,15 @@ class User < ActiveRecord::Base
devise
:lockable
,
:recoverable
,
:rememberable
,
:trackable
,
devise
:lockable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:omniauthable
,
:confirmable
,
:registerable
:validatable
,
:omniauthable
,
:confirmable
,
:registerable
# Limit trackable fields to update at most once every hour
# Override Devise::Models::Trackable#update_tracked_fields!
alias_method
:devise_update_tracked_fields!
,
:update_tracked_fields!
# to limit database writes to at most once every hour
def
update_tracked_fields!
(
request
)
def
update_tracked_fields!
(
request
)
update_tracked_fields
(
request
)
lease
=
Gitlab
::
ExclusiveLease
.
new
(
"user_update_tracked_fields:
#{
id
}
"
,
timeout:
1
.
hour
.
to_i
)
lease
=
Gitlab
::
ExclusiveLease
.
new
(
"user_update_tracked_fields:
#{
id
}
"
,
timeout:
1
.
hour
.
to_i
)
return
unless
lease
.
try_obtain
return
unless
lease
.
try_obtain
devise_update_tracked_fields!
(
request
)
save
(
validate:
false
)
end
end
attr_accessor
:force_random_password
attr_accessor
:force_random_password
...
...
spec/features/groups/members/sorting_spec.rb
View file @
3531ea09
...
@@ -68,7 +68,7 @@ feature 'Groups > Members > Sorting', feature: true do
...
@@ -68,7 +68,7 @@ feature 'Groups > Members > Sorting', feature: true do
expect
(
page
).
to
have_css
(
'.member-sort-dropdown .dropdown-toggle-text'
,
text:
'Name, descending'
)
expect
(
page
).
to
have_css
(
'.member-sort-dropdown .dropdown-toggle-text'
,
text:
'Name, descending'
)
end
end
scenario
'sorts by recent sign in'
do
scenario
'sorts by recent sign in'
,
:redis
do
visit_members_list
(
sort: :recent_sign_in
)
visit_members_list
(
sort: :recent_sign_in
)
expect
(
first_member
).
to
include
(
owner
.
name
)
expect
(
first_member
).
to
include
(
owner
.
name
)
...
@@ -76,7 +76,7 @@ feature 'Groups > Members > Sorting', feature: true do
...
@@ -76,7 +76,7 @@ feature 'Groups > Members > Sorting', feature: true do
expect
(
page
).
to
have_css
(
'.member-sort-dropdown .dropdown-toggle-text'
,
text:
'Recent sign in'
)
expect
(
page
).
to
have_css
(
'.member-sort-dropdown .dropdown-toggle-text'
,
text:
'Recent sign in'
)
end
end
scenario
'sorts by oldest sign in'
do
scenario
'sorts by oldest sign in'
,
:redis
do
visit_members_list
(
sort: :oldest_sign_in
)
visit_members_list
(
sort: :oldest_sign_in
)
expect
(
first_member
).
to
include
(
developer
.
name
)
expect
(
first_member
).
to
include
(
developer
.
name
)
...
...
spec/models/user_spec.rb
View file @
3531ea09
...
@@ -359,7 +359,17 @@ describe User, models: true do
...
@@ -359,7 +359,17 @@ describe User, models: true do
expect
do
expect
do
user
.
update_tracked_fields!
(
request
)
user
.
update_tracked_fields!
(
request
)
end
.
not_to
change
{
user
.
current_sign_in_at
}
end
.
not_to
change
{
user
.
reload
.
current_sign_in_at
}
end
it
'writes trackable attributes for a different user'
do
user2
=
create
(
:user
)
user
.
update_tracked_fields!
(
request
)
expect
do
user2
.
update_tracked_fields!
(
request
)
end
.
to
change
{
user2
.
reload
.
current_sign_in_at
}
end
end
end
end
...
...
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