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
f31ba9e7
Commit
f31ba9e7
authored
Jan 03, 2022
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AwardEmoji: Validate custom emoji as valid name
When validating award emoji, a custom emoji name is also valid.
parent
7a71c0f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
app/validators/gitlab/emoji_name_validator.rb
app/validators/gitlab/emoji_name_validator.rb
+18
-3
spec/models/award_emoji_spec.rb
spec/models/award_emoji_spec.rb
+13
-0
No files found.
app/validators/gitlab/emoji_name_validator.rb
View file @
f31ba9e7
...
...
@@ -11,9 +11,24 @@
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
return
if
valid_tanuki_emoji?
(
value
)
return
if
valid_custom_emoji?
(
record
,
value
)
record
.
errors
.
add
(
attribute
,
(
options
[
:message
]
||
'is not a valid emoji name'
))
end
private
def
valid_tanuki_emoji?
(
value
)
TanukiEmoji
.
find_by_alpha_code
(
value
.
to_s
)
end
def
valid_custom_emoji?
(
record
,
value
)
namespace
=
record
.
try
(
:awardable
).
try
(
:namespace
)
return
unless
namespace
namespace
.
custom_emoji
&
.
by_name
(
value
.
to_s
)
&
.
any?
end
end
end
spec/models/award_emoji_spec.rb
View file @
f31ba9e7
...
...
@@ -58,6 +58,19 @@ RSpec.describe AwardEmoji do
end
end
end
it
'accepts custom emoji'
do
user
=
create
(
:user
)
group
=
create
(
:group
)
group
.
add_maintainer
(
user
)
project
=
create
(
:project
,
namespace:
group
)
issue
=
create
(
:issue
,
project:
project
)
emoji
=
create
(
:custom_emoji
,
name:
'partyparrot'
,
namespace:
group
)
new_award
=
build
(
:award_emoji
,
user:
user
,
awardable:
issue
,
name:
emoji
.
name
)
expect
(
new_award
).
to
be_valid
end
end
describe
'scopes'
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