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
9ab34362
Commit
9ab34362
authored
Apr 05, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
caea764f
30fa3cbd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
1 deletion
+53
-1
app/models/user.rb
app/models/user.rb
+1
-1
changelogs/unreleased/57493-add-limit-to-user-name.yml
changelogs/unreleased/57493-add-limit-to-user-name.yml
+5
-0
db/migrate/20190325080727_truncate_user_fullname.rb
db/migrate/20190325080727_truncate_user_fullname.rb
+21
-0
spec/migrations/truncate_user_fullname_spec.rb
spec/migrations/truncate_user_fullname_spec.rb
+21
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+5
-0
No files found.
app/models/user.rb
View file @
9ab34362
...
...
@@ -159,7 +159,7 @@ class User < ApplicationRecord
# Validations
#
# Note: devise :validatable above adds validations for :email and :password
validates
:name
,
presence:
true
validates
:name
,
presence:
true
,
length:
{
maximum:
128
}
validates
:email
,
confirmation:
true
validates
:notification_email
,
presence:
true
validates
:notification_email
,
devise_email:
true
,
if:
->
(
user
)
{
user
.
notification_email
!=
user
.
email
}
...
...
changelogs/unreleased/57493-add-limit-to-user-name.yml
0 → 100644
View file @
9ab34362
---
title
:
Set user.name limit to 128 characters
merge_request
:
26146
author
:
type
:
changed
db/migrate/20190325080727_truncate_user_fullname.rb
0 → 100644
View file @
9ab34362
# rubocop:disable Migration/UpdateLargeTable
class
TruncateUserFullname
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
truncated_name
=
Arel
.
sql
(
'SUBSTRING(name from 1 for 128)'
)
where_clause
=
Arel
.
sql
(
"LENGTH(name) > 128"
)
update_column_in_batches
(
:users
,
:name
,
truncated_name
)
do
|
table
,
query
|
query
.
where
(
where_clause
)
end
end
def
down
# noop
end
end
spec/migrations/truncate_user_fullname_spec.rb
0 → 100644
View file @
9ab34362
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20190325080727_truncate_user_fullname.rb'
)
describe
TruncateUserFullname
,
:migration
do
let
(
:users
)
{
table
(
:users
)
}
let
(
:user_short
)
{
create_user
(
name:
'abc'
,
email:
'test_short@example.com'
)
}
let
(
:user_long
)
{
create_user
(
name:
'a'
*
200
+
'z'
,
email:
'test_long@example.com'
)
}
def
create_user
(
params
)
users
.
create!
(
params
.
merge
(
projects_limit:
0
))
end
it
'truncates user full name to the first 128 characters'
do
expect
{
migrate!
}.
to
change
{
user_long
.
reload
.
name
}.
to
(
'a'
*
128
)
end
it
'does not truncate short names'
do
expect
{
migrate!
}.
not_to
change
{
user_short
.
reload
.
name
.
length
}
end
end
spec/models/user_spec.rb
View file @
9ab34362
...
...
@@ -98,6 +98,11 @@ describe User do
end
describe
'validations'
do
describe
'name'
do
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
128
)
}
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