FEATURE: allow admins to enter badge long descriptions

FIX: fallback to description if badge long description is missing

Also moves all badge localization into server.en, this slims the client down

serializers pass down localized names/descriptions/long descriptions
This commit is contained in:
Sam 2016-03-28 18:38:38 +11:00
parent 94f831f7e7
commit fe51f84aa7
20 changed files with 284 additions and 283 deletions

View file

@ -14,7 +14,6 @@ export default Ember.Controller.extend(BufferedContent, {
readOnly: Ember.computed.alias('buffered.system'),
showDisplayName: propertyNotEqual('name', 'displayName'),
canEditDescription: Em.computed.none('buffered.translatedDescription'),
hasQuery: function() {
const bQuery = this.get('buffered.query');
@ -37,6 +36,7 @@ export default Ember.Controller.extend(BufferedContent, {
'listable', 'auto_revoke',
'enabled', 'show_posts',
'target_posts', 'name', 'description',
'long_description',
'icon', 'image', 'query', 'badge_grouping_id',
'trigger', 'badge_type_id'],
self = this;

View file

@ -61,7 +61,7 @@ export default Ember.ArrayController.extend({
}
});
return _.sortBy(badges, badge => badge.get('displayName'));
return _.sortBy(badges, badge => badge.get('name'));
}.property('badges.@each', 'model.@each'),
/**

View file

@ -44,10 +44,19 @@
<div>
<label for="description">{{i18n 'admin.badges.description'}}</label>
{{#if canEditDescription}}
{{textarea name="description" value=buffered.description}}
{{else}}
{{#if buffered.system}}
{{textarea name="description" value=buffered.displayDescription disabled=true}}
{{else}}
{{textarea name="description" value=buffered.description}}
{{/if}}
</div>
<div>
<label for="long_description">{{i18n 'admin.badges.long_description'}}</label>
{{#if buffered.system}}
{{textarea name="long_description" value=buffered.long_description disabled=true}}
{{else}}
{{textarea name="long_description" value=buffered.long_description}}
{{/if}}
</div>

View file

@ -1,7 +1,7 @@
export default Ember.Component.extend({
tagName: 'span',
classNameBindings: [':user-badge', 'badge.badgeTypeClassName'],
title: Em.computed.alias('badge.displayDescription'),
title: Em.computed.alias('badge.description'),
attributeBindings: ['data-badge-name', 'title'],
'data-badge-name': Em.computed.alias('badge.name')
});

View file

@ -15,9 +15,12 @@ export default Ember.Component.extend({
@computed('size')
summary(size) {
if (size === 'large') {
return Discourse.Emoji.unescape(this.get('badge.long_description') || '');
const longDescription = this.get('badge.long_description');
if (!_.isEmpty(longDescription)) {
return Discourse.Emoji.unescape(longDescription);
}
}
return this.get('badge.displayDescriptionHtml');
return this.get('badge.description');
}
});

View file

@ -3,7 +3,7 @@ export default Ember.Controller.extend({
var sorted = _.sortBy(this.get('model'), function(badge){
var pos = badge.get('badge_grouping.position');
var type = badge.get('badge_type_id');
var name = badge.get('displayName');
var name = badge.get('name');
return ("000" + pos).slice(-4) + (10-type) + name;
});

View file

@ -9,56 +9,6 @@ const Badge = RestModel.extend({
return Discourse.getURL(`/badges/${this.get('id')}/${this.get('slug')}`);
}.property(),
/**
@private
The name key to use for fetching i18n translations.
@property i18nNameKey
@type {String}
**/
i18nNameKey: function() {
return this.get('name').toLowerCase().replace(/\s/g, '_');
}.property('name'),
/**
The display name of this badge. Attempts to use a translation and falls back to
the actual name.
@property displayName
@type {String}
**/
displayName: function() {
const i18nKey = "badges.badge." + this.get('i18nNameKey') + ".name";
return I18n.t(i18nKey, {defaultValue: this.get('name')});
}.property('name', 'i18nNameKey'),
translatedDescription: function() {
const i18nKey = "badges.badge." + this.get('i18nNameKey') + ".description";
let translation = I18n.t(i18nKey);
if (translation.indexOf(i18nKey) !== -1) {
translation = null;
}
return translation;
}.property('i18nNameKey'),
displayDescription: function(){
// we support html in description but in most places do not need it
return this.get('displayDescriptionHtml').replace(/<[^>]*>/g, "");
}.property('displayDescriptionHtml'),
/**
Display-friendly description string. Returns either a translation or the
original description string.
@property displayDescription
@type {String}
**/
displayDescriptionHtml: function() {
const translated = this.get('translatedDescription');
return (translated === null ? this.get('description') : translated) || "";
}.property('description', 'translatedDescription'),
/**
Update this badge with the response returned by the server on save.

View file

@ -37,7 +37,7 @@ export default Discourse.Route.extend({
titleToken() {
const model = this.modelFor("badges.show");
if (model) {
return model.get("displayName");
return model.get("name");
}
},

View file

@ -2,7 +2,7 @@
<h1>
{{#link-to 'badges.index'}}{{i18n 'badges.title'}}{{/link-to}}
/
{{model.displayName}}
{{model.name}}
</h1>
<div class='show-badge-details'>

View file

@ -1,3 +1,3 @@
{{icon-or-image badge.icon}}
<span class="badge-display-name">{{badge.displayName}}</span>
<span class="badge-display-name">{{badge.name}}</span>
{{yield}}

View file

@ -10,7 +10,7 @@
</div>
<div class='badge-info'>
<div class='badge-info-item'>
<h3>{{badge.displayName}}</h3>
<h3>{{badge.name}}</h3>
<div class='badge-summary'>{{{summary}}}</div>
</div>
</div>

View file

@ -10,7 +10,7 @@
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.displayName" content=selectableUserBadges}}
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.name" content=selectableUserBadges}}
</div>
</div>

View file

@ -10,7 +10,7 @@
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.displayName" content=selectableUserBadges}}
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.name" content=selectableUserBadges}}
</div>
</div>

View file

@ -322,7 +322,11 @@ SQL
# fields that can not be edited on system badges
def self.protected_system_fields
[:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable]
[
:badge_type_id, :multiple_grant,
:target_posts, :show_posts, :query,
:trigger, :auto_revoke, :listable
]
end
def self.trust_level_badge_ids
@ -386,11 +390,37 @@ SQL
if self[:long_description].present?
self[:long_description]
else
key = "badges.long_descriptions.#{i18n_name}"
key = "badges.#{i18n_name}.long_description"
I18n.t(key, default: '')
end
end
def long_description=(val)
if val != long_description
self[:long_description] = val
end
val
end
def description
if self[:description].present?
self[:description]
else
key = "badges.#{i18n_name}.description"
I18n.t(key, default: '')
end
end
def description=(val)
if val != description
self[:description] = val
end
val
end
def slug
Slug.for(self.display_name, '-')
end

View file

@ -1,3 +1,7 @@
class AdminBadgeSerializer < BadgeSerializer
attributes :query, :trigger, :target_posts, :auto_revoke, :show_posts
def include_long_description?
true
end
end

View file

@ -12,4 +12,8 @@ class BadgeSerializer < ApplicationSerializer
def include_long_description?
options[:include_long_description]
end
def name
object.display_name
end
end

View file

@ -2685,6 +2685,7 @@ en:
badge: Badge
display_name: Display Name
description: Description
long_description: Long Description
badge_type: Badge Type
badge_grouping: Group
badge_groupings:
@ -2882,124 +2883,6 @@ en:
name: Other
posting:
name: Posting
badge:
editor:
name: Editor
description: First post edit
basic_user:
name: Basic
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/4">Granted</a> all essential community functions
member:
name: Member
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/5">Granted</a> invitations, group messaging, more likes
regular:
name: Regular
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/6">Granted</a> recategorize, rename, followed links, wiki, more likes
leader:
name: Leader
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/7">Granted</a> global edit, pin, close, archive, split and merge, more likes
welcome:
name: Welcome
description: Received a like
autobiographer:
name: Autobiographer
description: Filled out <a href="/my/preferences">profile</a> information
anniversary:
name: Anniversary
description: Active member for a year, posted at least once
nice_post:
name: Nice Reply
description: Received 10 likes on a reply
good_post:
name: Good Reply
description: Received 25 likes on a reply
great_post:
name: Great Reply
description: Received 50 likes on a reply
nice_topic:
name: Nice Topic
description: Received 10 likes on a topic
good_topic:
name: Good Topic
description: Received 25 likes on a topic
great_topic:
name: Great Topic
description: Received 50 likes on a topic
nice_share:
name: Nice Share
description: Shared a post with 25 unique visitors
good_share:
name: Good Share
description: Shared a post with 300 unique visitors
great_share:
name: Great Share
description: Shared a post with 1000 unique visitors
first_like:
name: First Like
description: Liked a post
first_flag:
name: First Flag
description: Flagged a post
promoter:
name: Promoter
description: Invited a user
campaigner:
name: Campaigner
description: Invited 3 basic users
champion:
name: Champion
description: Invited 5 members
first_share:
name: First Share
description: Shared a post
first_link:
name: First Link
description: Added a link to another topic
first_quote:
name: First Quote
description: Quoted a post
read_guidelines:
name: Read Guidelines
description: Read the <a href="/guidelines">community guidelines</a>
reader:
name: Reader
description: Read every reply in a topic with more than 100 replies
popular_link:
name: Popular Link
description: Posted an external link with 50 clicks
hot_link:
name: Hot Link
description: Posted an external link with 300 clicks
famous_link:
name: Famous Link
description: Posted an external link with 1000 clicks
appreciated:
name: Appreciated
description: Received 1 like on 20 posts
respected:
name: Respected
description: Received 2 likes on 100 posts
admired:
name: Admired
description: Received 5 likes on 300 posts
out_of_love:
name: Out of Love
description: Used 50 likes in a day
higher_love:
name: Higher Love
description: Used 50 likes in a day 5 times
crazy_in_love:
name: Crazy in Love
description: Used 50 likes in a day 20 times
thank_you:
name: Thank You
description: Has 20 liked posts and gave 10 likes
gives_back:
name: Gives Back
description: Has 100 liked posts and gave 100 likes
empathetic:
name: Empathetic
description: Has 500 liked posts and gave 1000 likes
google_search: |
<h3>Search with Google</h3>

View file

@ -2761,86 +2761,201 @@ en:
</p>
badges:
long_descriptions:
autobiographer: |
This badge is granted for filling out <a href="/my/preferences">your user profile</a> and selecting a profile picture. Letting the community know a bit more about who you are and what you're interested in makes for a better, more connected community. Join us!
first_like: |
This badge is granted the first time you like a post using the :heart: button. Liking posts is a great way to let your fellow community members know that what they posted was interesting, useful, cool, or fun. Share the love!
first_link: |
This badge is granted the first time you add a link to another topic. Linking topics helps fellow readers find interesting related conversations, by showing the connections between topics in both directions. Link freely!
first_quote: |
This badge is granted the first time you quote a post in your reply. Quoting relevant sections of earlier posts in your reply helps keep discussions focused and on topic. And it's easy: you can quickly quote by highlighting a section of any post and using the Quote Reply button that appears near the selection. Quote generously!
first_share: |
This badge is granted the first time you share a link to a reply or topic using the share button. Sharing links is a great way to show off interesting discussions with the rest of the world and grow your community.
read_guidelines: |
This badge is granted for <a href="/guidelines">reading the community guidelines</a>. Following and sharing these simple guidelines helps build a safe, fun, and sustainable community for everyone. Always remember there's another human being, one very much like yourself, on the other side of that screen. Be nice!
reader: |
This badge is granted the first time you read a long topic with more than 100 replies. Reading a conversation closely helps you follow the discussion, understand different viewpoints, and leads to more interesting conversations. The more you read, the better the conversation gets. As we like to say, Reading is Fundamental! :slight_smile:
editor: |
editor:
name: Editor
description: First post edit
long_description: |
This badge is granted the first time you edit one of your posts. While you won't be able to edit your posts forever, editing is always a good idea — you can improve your posts, fix small mistakes, or add anything you missed when you originally posted. Edit to make your posts even better!
first_flag: |
This badge is granted the first time you flag a post. Flagging is how we all help keep this a clean, well lit place for everyone. If you notice any posts that require moderator attention for any reason please don't hesitate to flag. You can also flag to send <b>personal messages</b> to fellow users if you see an issue with their post. If you see a problem, :flag_black: flag it!
welcome: |
This badge is granted when you receive your first like on a post. Congratulations, you've posted something that your fellow community members found interesting, cool, or useful!
anniversary: |
This badge is granted when you've been a member for a year with at least one post in that year. Thank you for sticking around and contributing to our community. We couldn't do it without you.
nice_share: |
This badge is granted for sharing a link that was clicked by 25 outside visitors. Thanks for spreading the word about our discussions, and this community.
good_share: |
This badge is granted for sharing a link that was clicked by 300 outside visitors. Good work! You've shown off a great discussion to a bunch of new people and helped this community grow.
great_share: |
This badge is granted for sharing a link that was clicked by 1000 outside visitors. Wow! You've promoted an interesting discussion to a huge new audience, and helped us grow our community in a big way!
nice_topic: |
This badge is granted when your topic gets 10 likes. Hey, you started an interesting conversation that the community enjoyed!
nice_post: |
This badge is granted when your reply gets 10 likes. Your reply really made an impression on the community and helped move the conversation forward!
good_topic: |
This badge is granted when your topic gets 25 likes. You launched a vibrant conversation that the community rallied around and loved!
good_post: |
This badge is granted when your reply gets 25 likes. Your reply was exceptional and made the conversation a whole lot better for everyone!
great_topic: |
This badge is granted when your topic gets 50 likes. You kicked off a fascinating conversation and the community enjoyed the dynamic discussion that resulted!
great_post: |
This badge is granted when your reply gets 50 likes. Wow! Your reply was inspiring, fascinating, hilarious, or insightful and the community loved it.
appreciated: |
This badge is granted when you receive at least one like on 20 different posts. The community is enjoying your contributions to the conversations here!
respected: |
This badge is granted when you receive at least 2 likes on 100 different posts. The community is growing to respect your many contributions to the conversations here.
admired: |
This badge is granted when you receive at least 5 likes on 300 different posts. Wow! The community admires your frequent, high quality contributions to the conversations here.
out_of_love: |
This badge is granted when you use all 50 of your daily likes. Remembering to take a moment and like the posts you enjoy and appreciate encourages your fellow community members to create even more great discussions in the future.
higher_love: |
This badge is granted when you use all 50 of your daily likes for 5 days. Thanks for taking the time actively encouraging the best conversations every day!
crazy_in_love: |
This badge is granted when you use all 50 of your daily likes for 20 days. Wow! You're a model of regularly encouraging your fellow community members!
promoter: |
This badge is granted when you invite someone to join the community via the invite button on your user page, or at the bottom of a topic. Inviting friends who might be interested in specific discussions is an great way to introduce new people to our community, so thanks!
campaigner: |
This badge is granted when you've invited 3 people who subsequently spent enough time on the site to become basic users. A vibrant community needs a regular infusion of newcomers who regularly participate and add new voices to the conversationss.
champion: |
This badge is granted when you've invited 5 people who subsequently spent enough time on the site to become full members. Wow! Thanks for expanding the diversity of our community with new members!
thank_you: |
This badge is granted when you've received 20 likes on your posts and have given 10 or more likes in return. When someone likes your posts, you find the time to like what other people are posting in return.
gives_back: |
This badge is granted when you've received 100 likes and have given 100 or more likes in return. Thanks for paying it forward, and liking in return!
empathetic: |
This badge is granted when you've received 500 likes and have given 1000 or more likes in return. Wow! You're a model of generosity and mutual love :two_hearts:.
basic_user: |
basic_user:
name: Basic
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/4">Granted</a> all essential community functions
long_description: |
This badge is granted when you reach trust level 1. Thanks for sticking around a little while and reading a few topics to learn what our community is about. Your new user restrictions have been lifted; you've been granted all essential community abilities, such as personal messaging, flagging, wiki editing, and the ability to post multiple images and links.
member: |
member:
name: Member
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/5">Granted</a> invitations, group messaging, more likes
long_description: |
This badge is granted when you reach trust level 2. Thanks for participating over a period of weeks to truly join our community. You can now send invitations from your user page or individual topics, create group personal messages, and have a few more likes per day.
regular: |
regular:
name: Regular
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/6">Granted</a> recategorize, rename, followed links, wiki, more likes
long_description: |
This badge is granted when you reach trust level 3. Thanks for being a regular part of our community over a period of months. You're now one of the most active readers, and a reliable contributor that makes our community great. You can now recategorize and rename topics, take advantage of more powerful spam flags, access a private lounge area, and you'll also get lots more likes per day.
leader: |
leader:
name: Leader
description: <a href="https://meta.discourse.org/t/what-do-user-trust-levels-do/4924/7">Granted</a> global edit, pin, close, archive, split and merge, more likes
long_description: |
This badge is granted when you reach trust level 4. You're a leader in this community as selected by staff, and you set a positive example for the rest of the community in your actions and words here. You have the ability to edit all posts, take common topic moderator actions such as pin, close, unlist, archive, split, and merge, and you have tons of likes per day.
popular_link: |
welcome:
name: Welcome
description: Received a like
long_description: |
This badge is granted when you receive your first like on a post. Congratulations, you've posted something that your fellow community members found interesting, cool, or useful!
autobiographer:
name: Autobiographer
description: Filled out <a href="/my/preferences">profile</a> information
long_description: |
This badge is granted for filling out <a href="/my/preferences">your user profile</a> and selecting a profile picture. Letting the community know a bit more about who you are and what you're interested in makes for a better, more connected community. Join us!
anniversary:
name: Anniversary
description: Active member for a year, posted at least once
long_description: |
This badge is granted when you've been a member for a year with at least one post in that year. Thank you for sticking around and contributing to our community. We couldn't do it without you.
nice_post:
name: Nice Reply
description: Received 10 likes on a reply
long_description: |
This badge is granted when your reply gets 10 likes. Your reply really made an impression on the community and helped move the conversation forward!
good_post:
name: Good Reply
description: Received 25 likes on a reply
long_description: |
This badge is granted when your reply gets 25 likes. Your reply was exceptional and made the conversation a whole lot better for everyone!
great_post:
name: Great Reply
description: Received 50 likes on a reply
long_description: |
This badge is granted when your reply gets 50 likes. Wow! Your reply was inspiring, fascinating, hilarious, or insightful and the community loved it.
nice_topic:
name: Nice Topic
description: Received 10 likes on a topic
long_description: |
This badge is granted when your topic gets 10 likes. Hey, you started an interesting conversation that the community enjoyed!
good_topic:
name: Good Topic
description: Received 25 likes on a topic
long_description: |
This badge is granted when your topic gets 25 likes. You launched a vibrant conversation that the community rallied around and loved!
great_topic:
name: Great Topic
description: Received 50 likes on a topic
long_description: |
This badge is granted when your topic gets 50 likes. You kicked off a fascinating conversation and the community enjoyed the dynamic discussion that resulted!
nice_share:
name: Nice Share
description: Shared a post with 25 unique visitors
long_description: |
This badge is granted for sharing a link that was clicked by 25 outside visitors. Thanks for spreading the word about our discussions, and this community.
good_share:
name: Good Share
description: Shared a post with 300 unique visitors
long_description: |
This badge is granted for sharing a link that was clicked by 300 outside visitors. Good work! You've shown off a great discussion to a bunch of new people and helped this community grow.
great_share:
name: Great Share
description: Shared a post with 1000 unique visitors
long_description: |
This badge is granted for sharing a link that was clicked by 1000 outside visitors. Wow! You've promoted an interesting discussion to a huge new audience, and helped us grow our community in a big way!
first_like:
name: First Like
description: Liked a post
long_description: |
This badge is granted the first time you like a post using the :heart: button. Liking posts is a great way to let your fellow community members know that what they posted was interesting, useful, cool, or fun. Share the love!
first_flag:
name: First Flag
description: Flagged a post
long_description: |
This badge is granted the first time you flag a post. Flagging is how we all help keep this a clean, well lit place for everyone. If you notice any posts that require moderator attention for any reason please don't hesitate to flag. You can also flag to send <b>personal messages</b> to fellow users if you see an issue with their post. If you see a problem, :flag_black: flag it!
promoter:
name: Promoter
description: Invited a user
long_description: |
This badge is granted when you invite someone to join the community via the invite button on your user page, or at the bottom of a topic. Inviting friends who might be interested in specific discussions is an great way to introduce new people to our community, so thanks!
campaigner:
name: Campaigner
description: Invited 3 basic users
long_description: |
This badge is granted when you've invited 3 people who subsequently spent enough time on the site to become basic users. A vibrant community needs a regular infusion of newcomers who regularly participate and add new voices to the conversationss.
champion:
name: Champion
description: Invited 5 members
long_description: |
This badge is granted when you've invited 5 people who subsequently spent enough time on the site to become full members. Wow! Thanks for expanding the diversity of our community with new members!
first_share:
name: First Share
description: Shared a post
long_description: |
This badge is granted the first time you share a link to a reply or topic using the share button. Sharing links is a great way to show off interesting discussions with the rest of the world and grow your community.
first_link:
name: First Link
description: Added a link to another topic
long_description: |
This badge is granted the first time you add a link to another topic. Linking topics helps fellow readers find interesting related conversations, by showing the connections between topics in both directions. Link freely!
first_quote:
name: First Quote
description: Quoted a post
long_description: |
This badge is granted the first time you quote a post in your reply. Quoting relevant sections of earlier posts in your reply helps keep discussions focused and on topic. And it's easy: you can quickly quote by highlighting a section of any post and using the Quote Reply button that appears near the selection. Quote generously!
read_guidelines:
name: Read Guidelines
description: Read the <a href="/guidelines">community guidelines</a>
long_description: |
This badge is granted for <a href="/guidelines">reading the community guidelines</a>. Following and sharing these simple guidelines helps build a safe, fun, and sustainable community for everyone. Always remember there's another human being, one very much like yourself, on the other side of that screen. Be nice!
reader:
name: Reader
description: Read every reply in a topic with more than 100 replies
long_description: |
This badge is granted the first time you read a long topic with more than 100 replies. Reading a conversation closely helps you follow the discussion, understand different viewpoints, and leads to more interesting conversations. The more you read, the better the conversation gets. As we like to say, Reading is Fundamental! :slight_smile:
popular_link:
name: Popular Link
description: Posted an external link with 50 clicks
long_description: |
This badge is granted when a link you shared gets 50 clicks. Thanks for posting a useful link that added interesting context to the conversation!
hot_link: |
hot_link:
name: Hot Link
description: Posted an external link with 300 clicks
long_description: |
This badge is granted when a link you shared gets 300 clicks. Thanks for posting a fascinating link that drove the conversation forward and illuminated the discussion!
famous_link: |
famous_link:
name: Famous Link
description: Posted an external link with 1000 clicks
long_description: |
This badge is granted when a link you shared gets 1000 clicks. Wow! You posted a link that significantly improved the conversation by addding essential detail, context, and information. Great work!
appreciated:
name: Appreciated
description: Received 1 like on 20 posts
long_description: |
This badge is granted when you receive at least one like on 20 different posts. The community is enjoying your contributions to the conversations here!
respected:
name: Respected
description: Received 2 likes on 100 posts
long_description: |
This badge is granted when you receive at least 2 likes on 100 different posts. The community is growing to respect your many contributions to the conversations here.
admired:
name: Admired
description: Received 5 likes on 300 posts
long_description: |
This badge is granted when you receive at least 5 likes on 300 different posts. Wow! The community admires your frequent, high quality contributions to the conversations here.
out_of_love:
name: Out of Love
description: Used 50 likes in a day
long_description: |
This badge is granted when you use all 50 of your daily likes. Remembering to take a moment and like the posts you enjoy and appreciate encourages your fellow community members to create even more great discussions in the future.
higher_love:
name: Higher Love
description: Used 50 likes in a day 5 times
long_description: |
This badge is granted when you use all 50 of your daily likes for 5 days. Thanks for taking the time actively encouraging the best conversations every day!
crazy_in_love:
name: Crazy in Love
description: Used 50 likes in a day 20 times
long_description: |
This badge is granted when you use all 50 of your daily likes for 20 days. Wow! You're a model of regularly encouraging your fellow community members!
thank_you:
name: Thank You
description: Has 20 liked posts and gave 10 likes
long_description: |
This badge is granted when you've received 20 likes on your posts and have given 10 or more likes in return. When someone likes your posts, you find the time to like what other people are posting in return.
gives_back:
name: Gives Back
description: Has 100 liked posts and gave 100 likes
long_description: |
This badge is granted when you've received 100 likes and have given 100 or more likes in return. Thanks for paying it forward, and liking in return!
empathetic:
name: Empathetic
description: Has 500 liked posts and gave 1000 likes
long_description: |
This badge is granted when you've received 500 likes and have given 1000 or more likes in return. Wow! You're a model of generosity and mutual love :two_hearts:.
admin_login:
success: "Email Sent"

View file

@ -14,5 +14,34 @@ describe Badge do
expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false
end
it 'auto translates name' do
badge = Badge.find_by_name("Basic User")
name_english = badge.name
I18n.locale = 'fr'
expect(badge.display_name).not_to eq(name_english)
end
it 'handles changes on badge description and long description correctly for system badges' do
badge = Badge.find_by_name("Basic User")
badge.description = badge.description.dup
badge.long_description = badge.long_description.dup
badge.save
badge.reload
expect(badge[:description]).to eq(nil)
expect(badge[:long_description]).to eq(nil)
badge.description = "testing"
badge.long_description = "testing it"
badge.save
badge.reload
expect(badge[:description]).to eq("testing")
expect(badge[:long_description]).to eq("testing it")
end
end

View file

@ -9,32 +9,6 @@ test('newBadge', function() {
ok(!badge2.get('newBadge'), "badges with ids are not new");
});
test('displayName', function() {
const badge1 = Badge.create({id: 1, name: "Test Badge 1"});
equal(badge1.get('displayName'), "Test Badge 1", "falls back to the original name in the absence of a translation");
sandbox.stub(I18n, "t").returnsArg(0);
const badge2 = Badge.create({id: 2, name: "Test Badge 2"});
equal(badge2.get('displayName'), "badges.badge.test_badge_2.name", "uses translation when available");
});
test('translatedDescription', function() {
const badge1 = Badge.create({id: 1, name: "Test Badge 1", description: "TEST"});
equal(badge1.get('translatedDescription'), null, "returns null when no translation exists");
const badge2 = Badge.create({id: 2, name: "Test Badge 2 **"});
sandbox.stub(I18n, "t").returns("description translation");
equal(badge2.get('translatedDescription'), "description translation", "users translated description");
});
test('displayDescription', function() {
const badge1 = Badge.create({id: 1, name: "Test Badge 1", description: "TEST"});
equal(badge1.get('displayDescription'), "TEST", "returns original description when no translation exists");
const badge2 = Badge.create({id: 2, name: "Test Badge 2 **"});
sandbox.stub(I18n, "t").returns("description translation");
equal(badge2.get('displayDescription'), "description translation", "users translated description");
});
test('createFromJson array', function() {
const badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]};