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
036f3297
Commit
036f3297
authored
Aug 24, 2021
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract emoji validation rules to a custom validator
parent
aa87fcd0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
4 deletions
+23
-4
app/finders/award_emojis_finder.rb
app/finders/award_emojis_finder.rb
+1
-1
app/models/award_emoji.rb
app/models/award_emoji.rb
+1
-1
app/models/user_status.rb
app/models/user_status.rb
+1
-1
app/validators/gitlab/emoji_name_validator.rb
app/validators/gitlab/emoji_name_validator.rb
+19
-0
spec/services/users/update_service_spec.rb
spec/services/users/update_service_spec.rb
+1
-1
No files found.
app/finders/award_emojis_finder.rb
View file @
036f3297
...
@@ -40,7 +40,7 @@ class AwardEmojisFinder
...
@@ -40,7 +40,7 @@ class AwardEmojisFinder
def
validate_name_param
def
validate_name_param
return
unless
params
[
:name
]
return
unless
params
[
:name
]
raise
ArgumentError
,
'Invalid name param'
unless
params
[
:name
].
to_s
.
in?
(
Gitlab
::
Emoji
.
emojis_name
s
)
raise
ArgumentError
,
'Invalid name param'
unless
TanukiEmoji
.
find_by_alpha_code
(
params
[
:name
].
to_
s
)
end
end
def
validate_awarded_by_param
def
validate_awarded_by_param
...
...
app/models/award_emoji.rb
View file @
036f3297
...
@@ -14,7 +14,7 @@ class AwardEmoji < ApplicationRecord
...
@@ -14,7 +14,7 @@ class AwardEmoji < ApplicationRecord
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:awardable
,
presence:
true
,
unless: :importing?
validates
:awardable
,
presence:
true
,
unless: :importing?
validates
:name
,
presence:
true
,
inclusion:
{
in:
Gitlab
::
Emoji
.
emojis_names
}
validates
:name
,
presence:
true
,
'gitlab/emoji_name'
:
true
validates
:name
,
uniqueness:
{
scope:
[
:user
,
:awardable_type
,
:awardable_id
]
},
unless:
->
{
ghost_user?
||
importing?
}
validates
:name
,
uniqueness:
{
scope:
[
:user
,
:awardable_type
,
:awardable_id
]
},
unless:
->
{
ghost_user?
||
importing?
}
participant
:user
participant
:user
...
...
app/models/user_status.rb
View file @
036f3297
...
@@ -22,7 +22,7 @@ class UserStatus < ApplicationRecord
...
@@ -22,7 +22,7 @@ class UserStatus < ApplicationRecord
enum
availability:
{
not_set:
0
,
busy:
1
}
enum
availability:
{
not_set:
0
,
busy:
1
}
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:emoji
,
inclusion:
{
in:
Gitlab
::
Emoji
.
emojis_names
}
validates
:emoji
,
'gitlab/emoji_name'
:
true
validates
:message
,
length:
{
maximum:
100
},
allow_blank:
true
validates
:message
,
length:
{
maximum:
100
},
allow_blank:
true
scope
:scheduled_for_cleanup
,
->
{
where
(
arel_table
[
:clear_status_at
].
lteq
(
Time
.
current
))
}
scope
:scheduled_for_cleanup
,
->
{
where
(
arel_table
[
:clear_status_at
].
lteq
(
Time
.
current
))
}
...
...
app/validators/gitlab/emoji_name_validator.rb
0 → 100644
View file @
036f3297
# frozen_string_literal: true
# Gitlab::EmojiNameValidator
#
# Validates that the provided value matches an indexed emoji alpha code
#
# @example Usage
# class AwardEmoji < ApplicationRecord
# validate :name, 'gitlab/emoji_name': true
# end
module
Gitlab
class
EmojiNameValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
unless
TanukiEmoji
.
find_by_alpha_code
(
value
.
to_s
)
record
.
errors
.
add
(
attribute
,
(
options
[
:message
]
||
'is not a valid emoji name'
))
end
end
end
end
spec/services/users/update_service_spec.rb
View file @
036f3297
...
@@ -53,7 +53,7 @@ RSpec.describe Users::UpdateService do
...
@@ -53,7 +53,7 @@ RSpec.describe Users::UpdateService do
result
=
update_user
(
user
,
status:
{
emoji:
"Moo!"
})
result
=
update_user
(
user
,
status:
{
emoji:
"Moo!"
})
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
"Emoji is not
included in the list
"
)
expect
(
result
[
:message
]).
to
eq
(
"Emoji is not
a valid emoji name
"
)
end
end
it
'updates user detail with provided attributes'
do
it
'updates user detail with provided attributes'
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