Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
06e895b7
Commit
06e895b7
authored
Jul 21, 2020
by
Kassio Borges
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure `preferred_language` always have a value
parent
00b75ff4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
app/models/user.rb
app/models/user.rb
+6
-0
changelogs/unreleased/kassio-ensure-user-preferred-language.yml
...logs/unreleased/kassio-ensure-user-preferred-language.yml
+5
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+16
-0
No files found.
app/models/user.rb
View file @
06e895b7
...
...
@@ -355,6 +355,12 @@ class User < ApplicationRecord
scope
:order_recent_last_activity
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'last_activity_on'
,
'DESC'
))
}
scope
:order_oldest_last_activity
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_first_order
(
'last_activity_on'
,
'ASC'
))
}
def
preferred_language
read_attribute
(
'preferred_language'
)
||
I18n
.
default_locale
.
to_s
.
presence_in
(
Gitlab
::
I18n
::
AVAILABLE_LANGUAGES
.
keys
)
||
'en'
end
def
active_for_authentication?
super
&&
can?
(
:log_in
)
end
...
...
changelogs/unreleased/kassio-ensure-user-preferred-language.yml
0 → 100644
View file @
06e895b7
---
title
:
Ensure User's preferred_language always has a value.
merge_request
:
37464
author
:
type
:
fixed
spec/models/user_spec.rb
View file @
06e895b7
...
...
@@ -241,6 +241,22 @@ RSpec.describe User do
it
{
is_expected
.
to
validate_length_of
(
:last_name
).
is_at_most
(
127
)
}
end
describe
'preferred_language'
do
context
'when its value is nil in the database'
do
let
(
:user
)
{
build
(
:user
,
preferred_language:
nil
)
}
it
'falls back to I18n.default_locale when empty in the database'
do
expect
(
user
.
preferred_language
).
to
eq
I18n
.
default_locale
.
to_s
end
it
'falls back to english when I18n.default_locale is not an available language'
do
I18n
.
default_locale
=
:kl
expect
(
user
.
preferred_language
).
to
eq
'en'
end
end
end
describe
'username'
do
it
'validates presence'
do
expect
(
subject
).
to
validate_presence_of
(
:username
)
...
...
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