fallback for when nick is nil

This commit is contained in:
wvengen 2013-10-29 18:58:04 +01:00
parent e968919cce
commit 9ba425aafa
6 changed files with 12 additions and 6 deletions

View file

@ -170,7 +170,8 @@ module ApplicationHelper
elsif options[:full] elsif options[:full]
"#{user.nick} (#{user.first_name} #{user.last_name})" "#{user.nick} (#{user.first_name} #{user.last_name})"
else else
user.nick # when use_nick was changed from false to true, users may exist without nick
user.nick.nil? ? I18n.t('helpers.application.nick_fallback') : user.nick
end end
else else
"#{user.first_name} #{user.last_name}" + (options[:unique] ? " (\##{user.id})" : '') "#{user.first_name} #{user.last_name}" + (options[:unique] ? " (\##{user.id})" : '')

View file

@ -161,8 +161,12 @@ class User < ActiveRecord::Base
# XXX this is view-related; need to move out things like token_attributes # XXX this is view-related; need to move out things like token_attributes
# then this can be removed # then this can be removed
def display def display
# would be sensible to match ApplicationController#show_user # would be sensible to match ApplicationHelper#show_user
FoodsoftConfig[:use_nick] ? nick : name if FoodsoftConfig[:use_nick]
nick.nil? ? I18n.t('helpers.application.nick_fallback') : nick
else
name
end
end end
def token_attributes def token_attributes

View file

@ -15,7 +15,7 @@
%th= t '.created_at' %th= t '.created_at'
- for user in @users - for user in @users
%tr{:class => cycle('even','odd', :name => 'users')} %tr{:class => cycle('even','odd', :name => 'users')}
%td= link_to show_user(user, full: true), [:admin, user] %td= link_to show_user(user), [:admin, user]
- if FoodsoftConfig[:use_nick] - if FoodsoftConfig[:use_nick]
%td= link_to user.name %td= link_to user.name
%td= format_date(user.created_on) %td= format_date(user.created_on)

View file

@ -14,7 +14,7 @@
%tbody %tbody
- for user in @users - for user in @users
%tr %tr
%td= link_to show_user(user, full: true), [:admin, user] %td= link_to show_user(user), [:admin, user]
- if FoodsoftConfig[:use_nick] - if FoodsoftConfig[:use_nick]
%td= user.name %td= user.name
%td= user.email %td= user.email

View file

@ -15,7 +15,7 @@
- for user in @users - for user in @users
%tr %tr
- if FoodsoftConfig[:use_nick] - if FoodsoftConfig[:use_nick]
%td= user.nick %td= show_user user
%td= user.name if @current_user.role_admin? || user.settings.profile["name_is_public"] || !FoodsoftConfig[:use_nick] %td= user.name if @current_user.role_admin? || user.settings.profile["name_is_public"] || !FoodsoftConfig[:use_nick]
%td= user.email if @current_user.role_admin? || user.settings.profile["email_is_public"] %td= user.email if @current_user.role_admin? || user.settings.profile["email_is_public"]
%td= user.phone if @current_user.role_admin? || user.settings.profile["phone_is_public"] %td= user.phone if @current_user.role_admin? || user.settings.profile["phone_is_public"]

View file

@ -864,6 +864,7 @@ en:
helpers: helpers:
application: application:
edit_user: Edit user edit_user: Edit user
nick_fallback: (empty username)
role_admin: Admin role_admin: Admin
role_article_meta: Articles role_article_meta: Articles
role_finance: Finance role_finance: Finance