Merge pull request #1722 from vikhyat/enable-names

enable_names site setting functionality
This commit is contained in:
Robin Ward 2013-12-09 10:03:55 -08:00
commit 17110ead98
8 changed files with 51 additions and 16 deletions

View File

@ -16,11 +16,15 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({
saveDisabled: function() {
if (this.get('saving')) return true;
if (this.blank('name')) return true;
if (Discourse.SiteSettings.enable_names && this.blank('name')) return true;
if (this.blank('email')) return true;
return false;
}.property('saving', 'name', 'email'),
canEditName: function() {
return Discourse.SiteSettings.enable_names;
}.property(),
digestFrequencies: [{ name: I18n.t('user.email_digests.daily'), value: 1 },
{ name: I18n.t('user.email_digests.weekly'), value: 7 },
{ name: I18n.t('user.email_digests.bi_weekly'), value: 14 }],

View File

@ -35,6 +35,20 @@ Discourse.User = Discourse.Model.extend({
};
}.property('username_lower'),
/**
This user's display name. Returns the name if possible, otherwise returns the
username.
@property displayName
@type {String}
**/
displayName: function() {
if (Discourse.SiteSettings.enable_names && !this.blank('name')) {
return this.get('name');
}
return this.get('username');
}.property('username', 'name'),
/**
This user's website.

View File

@ -85,7 +85,7 @@ Discourse.UserAction = Discourse.Model.extend({
post_number: '#' + this.get('reply_to_post_number'),
user1Url: this.get('userUrl'),
user2Url: this.get('targetUserUrl'),
another_user: this.get('target_name')
another_user: this.get('targetDisplayName')
}));
}.property('descriptionKey'),
@ -99,6 +99,9 @@ Discourse.UserAction = Discourse.Model.extend({
}.property('target_username'),
presentName: Em.computed.any('name', 'username'),
targetDisplayName: Em.computed.any('target_name', 'target_username'),
actingDisplayName: Em.computed.any('acting_name', 'acting_username'),
targetUserUrl: Discourse.computed.url('target_username', '/users/%@'),
usernameLower: function() {
@ -170,7 +173,7 @@ Discourse.UserAction = Discourse.Model.extend({
this.setProperties({
username: this.get('acting_username'),
avatar_template: this.get('acting_avatar_template'),
name: this.get('acting_name')
name: this.get('actingDisplayName')
});
}
});

View File

@ -30,7 +30,7 @@
{{#unless showExtraInfo}}
<div class='current-username'>
{{#if currentUser}}
<span class='username'><a {{bindAttr href="currentUser.path"}}>{{currentUser.name}}</a></span>
<span class='username'><a {{bindAttr href="currentUser.path"}}>{{currentUser.displayName}}</a></span>
{{else}}
<button {{action showLogin}} class='btn btn-primary btn-small'>{{i18n log_in}}</button>
{{/if}}

View File

@ -15,6 +15,7 @@
</div>
</div>
{{#if canEditName}}
<div class="control-group">
<label class="control-label">{{i18n user.name.title}}</label>
<div class="controls">
@ -24,6 +25,7 @@
{{i18n user.name.instructions}}
</div>
</div>
{{/if}}
<div class="control-group">
<label class="control-label">{{i18n user.email.title}}</label>

View File

@ -1,3 +1,7 @@
class BasicUserSerializer < ApplicationSerializer
attributes :id, :username, :avatar_template
def include_name?
SiteSetting.enable_names?
end
end

View File

@ -45,6 +45,18 @@ class UserActionSerializer < ApplicationSerializer
)
end
def include_name?
SiteSetting.enable_names?
end
def include_target_name?
include_name?
end
def include_acting_name?
include_name?
end
def slug
Slug.for(object.title)
end

View File

@ -94,10 +94,6 @@ class UserSerializer < BasicUserSerializer
User.gravatar_template(object.email)
end
def include_name?
SiteSetting.enable_names?
end
def include_suspended?
object.suspended?
end