Commit 72b7d1f5 authored by Valery Sizov's avatar Valery Sizov

emoji aliases problem

parent cd97dba2
......@@ -43,6 +43,7 @@ v 8.3.0 (unreleased)
- Prevent possible XSS attack with award-emoji
- Upgraded Sidekiq to 4.x
- Accept COPYING,COPYING.lesser, and licence as license file (Zeger-Jan van de Weg)
- Fix emoji aliases problem
v 8.2.3
- Fix application settings cache not expiring after changes (Stan Hu)
......
class @AwardsHandler
constructor: (@post_emoji_url, @noteable_type, @noteable_id) ->
constructor: (@post_emoji_url, @noteable_type, @noteable_id, @aliases) ->
addAward: (emoji) ->
emoji = @normilizeEmojiName(emoji)
@postEmoji emoji, =>
@addAwardToEmojiBar(emoji)
addAwardToEmojiBar: (emoji, custom_path = '') ->
emoji = @normilizeEmojiName(emoji)
if @exist(emoji)
if @isActive(emoji)
@decrementCounter(emoji)
......@@ -94,3 +96,6 @@ class @AwardsHandler
$('body, html').animate({
scrollTop: $('.awards').offset().top - 80
}, 200)
normilizeEmojiName: (emoji) ->
@aliases[emoji] || emoji
......@@ -377,6 +377,7 @@ class Note < ActiveRecord::Base
end
def award_emoji_name
note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1]
original_name = note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1]
AwardEmoji.normilize_emoji_name(original_name)
end
end
......@@ -19,7 +19,8 @@
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class.name.underscore}"
noteable_id = "#{votable.id}"
window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id)
aliases = #{AwardEmoji::ALIASES.to_json}
window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id, aliases)
$(".awards-menu li").click (e)->
emoji = $(this).data("emoji")
......
......@@ -6,7 +6,42 @@ class AwardEmoji
"ambulance", "anguished", "two_hearts", "wink"
]
ALIASES = {
pout: "rage",
satisfied: "laughing",
hankey: "shit",
poop: "shit",
collision: "boom",
thumbsup: "+1",
thumbsdown: "-1",
punch: "facepunch",
raised_hand: "hand",
running: "runner",
ng_woman: "no_good",
shoe: "mans_shoe",
tshirt: "shirt",
honeybee: "bee",
flipper: "dolphin",
paw_prints: "feet",
waxing_gibbous_moon: "moon",
telephone: "phone",
knife: "hocho",
envelope: "email",
pencil: "memo",
open_book: "book",
sailboat: "boat",
red_car: "car",
lantern: "izakaya_lantern",
uk: "gb",
heavy_exclamation_mark: "exclamation",
squirrel: "shipit"
}.with_indifferent_access
def self.path_to_emoji_image(name)
"emoji/#{Emoji.emoji_filename(name)}.png"
end
def self.normilize_emoji_name(name)
ALIASES[name] || name
end
end
......@@ -159,4 +159,13 @@ describe Note, models: true do
expect(note.editable?).to be_falsy
end
end
describe "set_award!" do
let(:issue) { create :issue }
it "converts aliases to actual name" do
note = create :note, note: ":thumbsup:", noteable: issue
expect(note.reload.note).to eq("+1")
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment