summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/issue_note_awards_list.vue
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-06-15 03:58:46 +0300
committerFatih Acet <acetfatih@gmail.com>2017-07-21 22:35:25 +0300
commit7433377adf6e716696f9cc7521053d8ec97810b7 (patch)
treee161008749fbb2cf97d6bb8f40e013b4481bd1e4 /app/assets/javascripts/notes/components/issue_note_awards_list.vue
parent36f84ce79e6d1fefdfd4c3c1b18d76874160e66a (diff)
downloadgitlab-ce-7433377adf6e716696f9cc7521053d8ec97810b7.tar.gz
IssueNotesRefactor: Restrict :+1: and :-1: on your own note.
Diffstat (limited to 'app/assets/javascripts/notes/components/issue_note_awards_list.vue')
-rw-r--r--app/assets/javascripts/notes/components/issue_note_awards_list.vue39
1 files changed, 29 insertions, 10 deletions
diff --git a/app/assets/javascripts/notes/components/issue_note_awards_list.vue b/app/assets/javascripts/notes/components/issue_note_awards_list.vue
index 5765445a73d..825ebb7e740 100644
--- a/app/assets/javascripts/notes/components/issue_note_awards_list.vue
+++ b/app/assets/javascripts/notes/components/issue_note_awards_list.vue
@@ -10,13 +10,20 @@ export default {
type: Array,
required: true,
},
+ noteAuthorId: {
+ type: Number,
+ required: true,
+ },
},
data() {
+ const userId = window.gon.current_user_id;
+
return {
emojiSmiling,
emojiSmile,
emojiSmiley,
- canAward: !!window.gon.current_user_id,
+ canAward: !!userId,
+ myUserId: userId,
};
},
computed: {
@@ -48,9 +55,11 @@ export default {
delete awards.thumbsdown;
}
- for (let key in awards) {
+ // Because for-in forbidden
+ const keys = Object.keys(awards);
+ keys.forEach((key) => {
orderedAwards[key] = awards[key];
- };
+ });
return orderedAwards;
},
@@ -59,27 +68,37 @@ export default {
getAwardHTML(name) {
return glEmojiTag(name);
},
- getAwardClassBindings(awardList) {
+ getAwardClassBindings(awardList, awardName) {
return {
active: this.amIAwarded(awardList),
- disabled: !this.canAward,
+ disabled: !this.canInteractWithEmoji(awardList, awardName),
};
},
+ canInteractWithEmoji(awardList, awardName) {
+ let isAllowed = true;
+ const restrictedEmojis = ['thumbsup', 'thumbsdown'];
+ const { myUserId, noteAuthorId } = this;
+
+ // Users can not add :+1: and :-1: to their notes
+ if (myUserId === noteAuthorId && restrictedEmojis.indexOf(awardName) > -1) {
+ isAllowed = false;
+ }
+
+ return this.canAward && isAllowed;
+ },
amIAwarded(awardList) {
- const myUserId = window.gon.current_user_id;
- const isAwarded = awardList.filter(award => award.user.id === myUserId);
+ const isAwarded = awardList.filter(award => award.user.id === this.myUserId);
return isAwarded.length;
},
awardTitle(awardsList) {
const amIAwarded = this.amIAwarded(awardsList);
- const myUserId = window.gon.current_user_id;
const TOOLTIP_NAME_COUNT = amIAwarded ? 9 : 10;
let awardList = awardsList;
// Filter myself from list if I am awarded.
if (amIAwarded) {
- awardList = awardList.filter(award => award.user.id !== myUserId);
+ awardList = awardList.filter(award => award.user.id !== this.myUserId);
}
// Get only 9-10 usernames to show in tooltip text.
@@ -120,7 +139,7 @@ export default {
<button
v-for="(awardList, awardName) in groupedAwards"
class="btn award-control has-tooltip"
- :class="getAwardClassBindings(awardList)"
+ :class="getAwardClassBindings(awardList, awardName)"
:title="awardTitle(awardList)"
data-placement="bottom"
type="button">