UX: Display translated group name for automatic groups.
This commit is contained in:
parent
441e0059af
commit
2b21e5ea7e
|
@ -33,9 +33,9 @@ export default Ember.Controller.extend({
|
|||
return !automatic && isGroupOwner;
|
||||
},
|
||||
|
||||
@computed('model.name', 'model.full_name')
|
||||
groupName(name, fullName) {
|
||||
return (fullName || name).capitalize();
|
||||
@computed('model.displayName', 'model.full_name')
|
||||
groupName(displayName, fullName) {
|
||||
return (fullName || displayName).capitalize();
|
||||
},
|
||||
|
||||
@computed('model.name', 'model.flair_url', 'model.flair_bg_color', 'model.flair_color')
|
||||
|
|
|
@ -94,6 +94,10 @@ const Group = RestModel.extend({
|
|||
});
|
||||
},
|
||||
|
||||
@computed("display_name", "name")
|
||||
displayName(groupDisplayName, name) {
|
||||
return groupDisplayName || name;
|
||||
},
|
||||
|
||||
@computed('flair_bg_color')
|
||||
flairBackgroundHexColor() {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
{{/if}}
|
||||
|
||||
<span>
|
||||
<span class='groups-info-name'>{{group.name}}</span>
|
||||
<span class='groups-info-name'>{{group.displayName}}</span>
|
||||
|
||||
{{#if group.full_name}}
|
||||
<span class='groups-info-full-name'>{{group.full_name}}</span>
|
||||
|
|
|
@ -114,8 +114,8 @@ class Group < ActiveRecord::Base
|
|||
|
||||
incoming_email.split("|").each do |email|
|
||||
escaped = Rack::Utils.escape_html(email)
|
||||
if !Email.is_valid?(email)
|
||||
self.errors.add(:base, I18n.t('groups.errors.invalid_incoming_email', email: escaped))
|
||||
if !Email.is_valid?(email)
|
||||
elsif group = Group.where.not(id: self.id).find_by_email(email)
|
||||
self.errors.add(:base, I18n.t('groups.errors.email_already_used_in_group', email: escaped, group_name: Rack::Utils.escape_html(group.name)))
|
||||
elsif category = Category.find_by_email(email)
|
||||
|
|
|
@ -2,6 +2,7 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
attributes :id,
|
||||
:automatic,
|
||||
:name,
|
||||
:display_name,
|
||||
:user_count,
|
||||
:alias_level,
|
||||
:visible,
|
||||
|
@ -22,6 +23,16 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
:full_name,
|
||||
:default_notification_level
|
||||
|
||||
def include_display_name?
|
||||
object.automatic
|
||||
end
|
||||
|
||||
def display_name
|
||||
if auto_group_name = Group::AUTO_GROUP_IDS[object.id]
|
||||
I18n.t("groups.default_names.#{auto_group_name}")
|
||||
end
|
||||
end
|
||||
|
||||
def include_incoming_email?
|
||||
staff?
|
||||
end
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe BasicGroupSerializer do
|
||||
subject { described_class.new(group, scope: Guardian.new, root: false) }
|
||||
|
||||
describe '#display_name' do
|
||||
describe 'automatic group' do
|
||||
let(:group) { Group.find(1) }
|
||||
|
||||
it 'should include the display name' do
|
||||
expect(subject.display_name).to eq(I18n.t('groups.default_names.admins'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'normal group' do
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
it 'should not include the display name' do
|
||||
expect(subject.display_name).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
import Group from 'discourse/models/group';
|
||||
|
||||
module("model:group");
|
||||
|
||||
test('displayName', function() {
|
||||
const group = Group.create({ name: "test", display_name: 'donkey' });
|
||||
|
||||
ok(group.get('displayName'), "donkey", 'it should return the display name');
|
||||
|
||||
group.set('display_name', null);
|
||||
|
||||
ok(group.get('displayName'), "test", "it should return the group's name");
|
||||
});
|
Loading…
Reference in New Issue