start of making nickname optional

This commit is contained in:
wvengen 2013-09-20 22:40:13 +02:00
parent a77c3b59b1
commit e4f0a1e3ed
33 changed files with 92 additions and 48 deletions

View file

@ -139,13 +139,6 @@ module ApplicationHelper
:target => "_blank" :target => "_blank"
end end
# offers a link for writing message to user
# checks for nil (useful for relations)
def link_to_user_message_if_valid(user)
user.nil? ? '??' : link_to(user.nick, new_message_path('message[mail_to]' => user.id),
:title => I18n.t('helpers.application.write_message'))
end
def bootstrap_flash def bootstrap_flash
flash_messages = [] flash_messages = []
flash.each do |type, message| flash.each do |type, message|
@ -167,4 +160,31 @@ module ApplicationHelper
render :partial => 'shared/base_errors', :locals => {:error_messages => messages} render :partial => 'shared/base_errors', :locals => {:error_messages => messages}
end end
# show a user, depending on settings
def show_user(user=@current_user, options = {})#full: false, markup: false, unique: false)
if user.nil?
"?"
elsif FoodsoftConfig[:use_nick]
if options[:full] and options[:markup]
raw "<b>#{h user.nick}</b> (#{h user.first_name} #{h user.last_name})"
elsif options[:full]
"#{user.nick} (#{user.first_name} #{user.last_name})"
else
user.nick
end
else
"#{user.first_name} #{user.last_name}" + (options[:unique] ? " (\##{user.id})" : '')
end
end
# render user presentation linking to default action (write message)
def show_user_link(user=@current_user)
if user.nil?
show_user user
else
link_to show_user(user), new_message_path('message[mail_to]' => user.id),
:title => I18n.t('helpers.application.write_message')
end
end
end end

View file

@ -9,13 +9,15 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
- if FoodsoftConfig[:use_nick]
%th= t '.username' %th= t '.username'
%th= t '.name' %th= t '.name'
%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 user.nick, [:admin, user] %td= link_to show_user(user, full: true), [:admin, user]
%td=h user.name - if FoodsoftConfig[:use_nick]
%td= link_to user.name
%td= format_date(user.created_on) %td= format_date(user.created_on)
= link_to t('.all_users'), admin_users_path = link_to t('.all_users'), admin_users_path
| |

View file

@ -4,6 +4,7 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
- if FoodsoftConfig[:use_nick]
%th= t '.login' %th= t '.login'
%th= t '.name' %th= t '.name'
%th= t '.email' %th= t '.email'
@ -13,7 +14,8 @@
%tbody %tbody
- for user in @users - for user in @users
%tr %tr
%td= link_to user.nick, [:admin, user] %td= link_to show_user(user, full: true), [:admin, user]
- if FoodsoftConfig[:use_nick]
%td= user.name %td= user.name
%td= user.email %td= user.email
%td= format_roles(user) %td= format_roles(user)

View file

@ -1,4 +1,4 @@
- title @user.nick - title show_user(@user)
.row-fluid .row-fluid
.span3 .span3
@ -6,6 +6,7 @@
%h4= t '.person' %h4= t '.person'
%p= t '.member_since', time: distance_of_time_in_words(Time.now, @user.created_on) %p= t '.member_since', time: distance_of_time_in_words(Time.now, @user.created_on)
%dl %dl
- if FoodsoftConfig[:use_nick]
%dt= t '.nick' %dt= t '.nick'
%dd= @user.nick %dd= @user.nick
%dt= t '.name' %dt= t '.name'

View file

@ -16,7 +16,7 @@
%td= link_to truncate(order.name), new_finance_order_path(order_id: order.id) %td= link_to truncate(order.name), new_finance_order_path(order_id: order.id)
%td=h format_time(order.ends) unless order.ends.nil? %td=h format_time(order.ends) unless order.ends.nil?
%td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended') %td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended')
%td= order.updated_by.nil? ? '??' : order.updated_by.nick %td= show_user(order.updated_by)
%td %td
- unless order.closed? - unless order.closed?
= link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary'

View file

@ -12,6 +12,6 @@
- @financial_transactions.each do |t| - @financial_transactions.each do |t|
%tr %tr
%td= format_time(t.created_on) %td= format_time(t.created_on)
%td= h t.user.nil? ? '??' : t.user.nick %td= h show_user(t.user)
%td= h t.note %td= h t.note
%td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount) %td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount)

View file

@ -13,7 +13,7 @@
- for ordergroup in @ordergroups - for ordergroup in @ordergroups
%tr %tr
%td= ordergroup.name %td= ordergroup.name
%td=h ordergroup.users.collect { |u| u.nick }.join(", ") %td=h ordergroup.users.collect { |u| show_user(u) }.join(", ")
%td= format_date ordergroup.orders.order('orders.starts DESC').first.try(:starts) %td= format_date ordergroup.orders.order('orders.starts DESC').first.try(:starts)
%td= link_to_new_message(message_params: {group_id: ordergroup.id}) %td= link_to_new_message(message_params: {group_id: ordergroup.id})

View file

@ -4,6 +4,7 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
- if FoodsoftConfig[:use_nick]
%th= t 'simple_form.labels.user.nick' %th= t 'simple_form.labels.user.nick'
%th= t 'simple_form.labels.user.name' %th= t 'simple_form.labels.user.name'
%th= t 'simple_form.labels.user.email' %th= t 'simple_form.labels.user.email'
@ -13,6 +14,7 @@
%tbody %tbody
- for user in @users - for user in @users
%tr %tr
- if FoodsoftConfig[:use_nick]
%td= user.nick %td= user.nick
%td= user.name if @current_user.role_admin? || user.settings.profile["name_is_public"] %td= user.name if @current_user.role_admin? || user.settings.profile["name_is_public"]
%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"]

View file

@ -19,7 +19,7 @@
%dt= t '.note' %dt= t '.note'
%dd= @order.note %dd= @order.note
%dt= t '.created_by' %dt= t '.created_by'
%dd= link_to_user_message_if_valid(@order.created_by) %dd= show_user_link(@order.created_by)
%dt= t '.ending' %dt= t '.ending'
%dd= format_time(@order.ends) %dd= format_time(@order.ends)
- unless @order.stockit? or @order.supplier.min_order_quantity.blank? - unless @order.stockit? or @order.supplier.min_order_quantity.blank?
@ -29,7 +29,7 @@
%dd= number_to_currency @order.sum %dd= number_to_currency @order.sum
%dt= t '.last_update' %dt= t '.last_update'
%dd %dd
= @group_order.updated_by.nick if @group_order.updated_by = show_user(@group_order.updated_by) if @group_order.updated_by
(#{format_time(@group_order.updated_on)}) (#{format_time(@group_order.updated_on)})
%dt= t '.funds' %dt= t '.funds'
%dd= number_to_currency(@ordering_data[:available_funds]) %dd= number_to_currency(@ordering_data[:available_funds])

View file

@ -22,7 +22,7 @@
- else - else
= t '.not_ordered' = t '.not_ordered'
- if @order.closed? - if @order.closed?
%p= t '.closed_by', user: @order.updated_by.nick %p= t '.closed_by', user: show_user(@order.updated_by)
= link_to t('.comment'), "#comments" = link_to t('.comment'), "#comments"
// Article box // Article box

View file

@ -57,7 +57,7 @@
- for ft in current_user.ordergroup.financial_transactions.limit(5).order('created_on DESC') - for ft in current_user.ordergroup.financial_transactions.limit(5).order('created_on DESC')
%tr %tr
%td= format_time(ft.created_on) %td= format_time(ft.created_on)
%td= h(ft.user.nil? ? '?' : ft.user.nick) %td= h(show_user(ft.user))
%td= h(ft.note) %td= h(ft.note)
- color = ft.amount < 0 ? 'red' : 'black' - color = ft.amount < 0 ? 'red' : 'black'
%td{:style => "color:#{color}; width:5em", :class => "currency"}= number_to_currency(ft.amount) %td{:style => "color:#{color}; width:5em", :class => "currency"}= number_to_currency(ft.amount)

View file

@ -13,7 +13,7 @@
%h2= t '.people' %h2= t '.people'
%ul %ul
- for membership in @ordergroup.memberships - for membership in @ordergroup.memberships
%li= membership.user.nick %li= show_user membership.user
= link_to t('.invite'), new_invite_path(:id => @ordergroup), :remote => true, class: 'btn btn-primary' = link_to t('.invite'), new_invite_path(:id => @ordergroup), :remote => true, class: 'btn btn-primary'
.span8 .span8
%h2= t('.account_summary') %h2= t('.account_summary')

View file

@ -3,7 +3,7 @@
.row-fluid .row-fluid
.span7 .span7
%h3 %h3
= h(t('.user.title', user: @current_user.nick)) = h(t('.user.title', user: show_user))
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on) %small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
= simple_form_for(@current_user, :url => { :action => 'update_profile'}) do |f| = simple_form_for(@current_user, :url => { :action => 'update_profile'}) do |f|
= render :partial => 'shared/user_form_fields', :locals => {:f => f} = render :partial => 'shared/user_form_fields', :locals => {:f => f}

View file

@ -4,7 +4,7 @@
%ul.nav.nav-pills.pull-right %ul.nav.nav-pills.pull-right
%li.dropdown %li.dropdown
%a.dropdown-toggle(data-toggle="dropdown" href="#") %a.dropdown-toggle(data-toggle="dropdown" href="#")
= current_user.nick = show_user current_user
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
%li= link_to t('.profile'), my_profile_path %li= link_to t('.profile'), my_profile_path

View file

@ -1,6 +1,6 @@
- content_for :javascript do - content_for :javascript do
:javascript :javascript
$('user_nick').focus(); $(#{FoodsoftConfig[:use_nick ? 'user_nick' : 'user_first_name'}).focus();
- title t('.title', name: FoodsoftConfig[:name]) - title t('.title', name: FoodsoftConfig[:name])
= t('.body', group: h(@invite.group.name), foodcoop: h(FoodsoftConfig[:name])).html_safe = t('.body', group: h(@invite.group.name), foodcoop: h(FoodsoftConfig[:name])).html_safe

View file

@ -1,5 +1,5 @@
- title t('.title') - title t('.title')
= t('.body', user: h(@user.nick)).html_safe = raw t('.body', user: h(show_user(@user)))
= simple_form_for @user, :url => {:action => 'update_password', :id => @user.id, :token => @user.reset_password_token} do |form| = simple_form_for @user, :url => {:action => 'update_password', :id => @user.id, :token => @user.reset_password_token} do |form|
= form.input :password = form.input :password
= form.input :password_confirmation = form.input :password_confirmation

View file

@ -1,3 +1,3 @@
= t '.header', user: @user.nick, date: I18n.l(Time.now, :format => :short) = t '.header', user: show_user(@user), date: I18n.l(Time.now, :format => :short)
\ \
= @feedback = @feedback

View file

@ -1 +1 @@
= t '.text', group: @group.name, when: @transaction.created_on.strftime('%d.%m.%Y um %H:%M'), balance: @group.account_balance, amount:@transaction.amount, note: @transaction.note, user: @transaction.user.nick, foodcoop: FoodsoftConfig[:name] = t '.text', group: @group.name, when: @transaction.created_on.strftime('%d.%m.%Y um %H:%M'), balance: @group.account_balance, amount:@transaction.amount, note: @transaction.note, user: show_user(@transaction.user), foodcoop: FoodsoftConfig[:name]

View file

@ -1,4 +1,4 @@
= raw t '.text0', ordergroup: @group_order.ordergroup.name, order: @order.name, when: I18n.l(@order.ends), user: @order.updated_by.nick = raw t '.text0', ordergroup: @group_order.ordergroup.name, order: @order.name, when: I18n.l(@order.ends), user: show_user(@order.updated_by)
- for group_order_article in @group_order.group_order_articles.ordered.all(:include => :order_article) - for group_order_article in @group_order.group_order_articles.ordered.all(:include => :order_article)
- article = group_order_article.order_article.article - article = group_order_article.order_article.article
\- #{article.name}: #{group_order_article.result} x #{article.unit} = #{group_order_article.result * article.fc_price} \- #{article.name}: #{group_order_article.result} x #{article.unit} = #{group_order_article.result * article.fc_price}

View file

@ -1 +1 @@
= raw t '.text', user: @user.nick, link: @link, expires: I18n.l(@user.reset_password_expires) = raw t '.text', user: show_user(@user), link: @link, expires: I18n.l(@user.reset_password_expires)

View file

@ -13,7 +13,7 @@
%dt= t '.note' %dt= t '.note'
%dd= @order.note %dd= @order.note
%dt= t '.created_by' %dt= t '.created_by'
%dd= link_to_user_message_if_valid(@order.created_by) %dd= show_user_link(@order.created_by)
%dt= t '.begin' %dt= t '.begin'
%dd= format_time(@order.starts) %dd= format_time(@order.starts)
%dt= t '.ending' %dt= t '.ending'

View file

@ -2,7 +2,7 @@
%tr %tr
%td{:style => "padding-left: #{ident}px"} %td{:style => "padding-left: #{ident}px"}
= link_to page.title, wiki_page_path(page.permalink) = link_to page.title, wiki_page_path(page.permalink)
%td #{page.user.try(:nick)} (#{format_datetime_timespec(page.updated_at, t('.date_format'))}) %td #{show_user page.user} (#{format_datetime_timespec(page.updated_at, t('.date_format'))})
-if siteMap == 1 -if siteMap == 1
-for child in page.children.all -for child in page.children.all
= render :partial => 'page_list_item', :locals => {:page => child, :level => level+1, :siteMap => 1} = render :partial => 'page_list_item', :locals => {:page => child, :level => level+1, :siteMap => 1}

View file

@ -17,7 +17,7 @@
- @page.versions.reverse.each do |version| - @page.versions.reverse.each do |version|
%li %li
= link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version) = link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version)
= "(#{User.find_by_id(version.updated_by).try(:nick)})" = "(#{show_user(User.find_by_id(version.updated_by))})"
- unless @page.children.empty? - unless @page.children.empty?
#subpages.well.well-small{:style => "display:none"} #subpages.well.well-small{:style => "display:none"}
@ -48,4 +48,4 @@
%i.icon-edit= t '.edit' %i.icon-edit= t '.edit'
= link_to t('.delete'), @page, class: 'btn btn-danger', :method => :delete, = link_to t('.delete'), @page, class: 'btn btn-danger', :method => :delete,
:confirm => t('.delete_confirm') :confirm => t('.delete_confirm')
!= '| ' + t('.last_updated', user: h(@page.user.try(:nick)), when: format_datetime(@page.updated_at)) != '| ' + t('.last_updated', user: show_user(@page.user), when: format_datetime(@page.updated_at))

View file

@ -4,7 +4,7 @@
%h3= t '.title_version' %h3= t '.title_version'
%b= "#{format_datetime_timespec(@version.updated_at, t('.date_format'))}" %b= "#{format_datetime_timespec(@version.updated_at, t('.date_format'))}"
%ul %ul
%li= t '.author', user: User.find(@version.updated_by).nick %li= t '.author', user: show_user(User.find(@version.updated_by))
%li= link_to t('.view_current'), wiki_page_path(:permalink => @page.permalink) %li= link_to t('.view_current'), wiki_page_path(:permalink => @page.permalink)
%li= link_to t('.revert'), revert_page_path(@page, :version => @version.lock_version) %li= link_to t('.revert'), revert_page_path(@page, :version => @version.lock_version)

View file

@ -1,5 +1,5 @@
- comments.each do |comment| - comments.each do |comment|
.comment[comment] .comment[comment]
%strong= comment.user.try(:ordergroup_name) %strong= comment.user.try(:ordergroup_name)
%small (#{comment.user.try(:nick)} am #{format_time(comment.created_at)}): %small (#{show_user comment.user} am #{format_time(comment.created_at)}):
= simple_format(comment.text) = simple_format(comment.text)

View file

@ -12,7 +12,7 @@
%dd %dd
- members = group.users - members = group.users
= "(#{members.size})" = "(#{members.size})"
= members.collect(&:nick).join(", ") = members.collect{|u| show_user(u)}.join(", ")
- unless group.is_a?(Workgroup) - unless group.is_a?(Workgroup)
%dt= t '.apple_limit' %dt= t '.apple_limit'
%dd= group.ignore_apple_restriction ? t('.deactivated') : t('.activated') %dd= group.ignore_apple_restriction ? t('.deactivated') : t('.activated')

View file

@ -19,7 +19,7 @@
%td= format_time(order.ends) unless order.ends.nil? %td= format_time(order.ends) unless order.ends.nil?
- if group_order = order.group_order(ordergroup) - if group_order = order.group_order(ordergroup)
- total += group_order.price - total += group_order.price
%td= "#{group_order.updated_by.nick} (#{format_time(group_order.updated_on)})" %td= "#{show_user group_order.updated_by} (#{format_time(group_order.updated_on)})"
%td.numeric= number_to_currency(group_order.price) %td.numeric= number_to_currency(group_order.price)
- else - else
%td{:colspan => 2} %td{:colspan => 2}

View file

@ -1,4 +1,5 @@
= f.input :nick - unless FoodsoftConfig[:use_nick] == false
= f.input :nick
= f.input :first_name = f.input :first_name
= f.input :last_name = f.input :last_name
= f.input :email = f.input :email
@ -19,6 +20,7 @@
= t 'simple_form.labels.settings.settings_group.privacy' = t 'simple_form.labels.settings.settings_group.privacy'
= profile.input 'phone_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['phone_is_public'] } = profile.input 'phone_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['phone_is_public'] }
= profile.input 'email_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['email_is_public'] } = profile.input 'email_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['email_is_public'] }
- if FoodsoftConfig[:use_nick]
= profile.input 'name_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['name_is_public'] } = profile.input 'name_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['name_is_public'] }
.settings-group .settings-group

View file

@ -8,7 +8,7 @@
<ul style=""> <ul style="">
<% for membership in memberships %> <% for membership in memberships %>
<li style="margin-left:-15px"> <li style="margin-left:-15px">
<b><%= membership.user.nick %></b> (<%=h membership.user.first_name + ' ' + membership.user.last_name %>) <%= show_user membership.user, full: true, markup: true %>
| <%= link_to_remote t('.drop'), | <%= link_to_remote t('.drop'),
:url => { :controller => '/memberships', :action => 'drop_member', :id => @group, :membership_id => membership }, :url => { :controller => '/memberships', :action => 'drop_member', :id => @group, :membership_id => membership },
:before => "Element.show('loader')", :before => "Element.show('loader')",

View file

@ -1,7 +1,7 @@
<ul> <ul>
<% for user in @group.non_members %> <% for user in @group.non_members %>
<li> <li>
<b><%= user.nick %></b> (<%=h user.first_name + ' ' + user.last_name %>) <%= show_user user, full: true, markup: true %>
| <%= link_to_remote t('.add'), | <%= link_to_remote t('.add'),
:url => { :controller => '/memberships', :action => 'add_member', :id => @group, :user_id => user }, :url => { :controller => '/memberships', :action => 'add_member', :id => @group, :user_id => user },
:before => "Element.show('loader')", :before => "Element.show('loader')",

View file

@ -7,7 +7,7 @@
= simple_form_for(@stock_taking) do |f| = simple_form_for(@stock_taking) do |f|
= f.input :date, as: :date_picker = f.input :date, as: :date_picker
= f.input :note, :input_html => {:size => "28x7", :value => "#{@current_user.nick}: ..."} = f.input :note, :input_html => {:size => "28x7", :value => "#{show_user @current_user, unique: true}: ..."}
%h2= t '.stock_articles' %h2= t '.stock_articles'
#stock_changes #stock_changes

View file

@ -52,6 +52,11 @@ default: &defaults
# not fully enforced right now, since the check is only client-side # not fully enforced right now, since the check is only client-side
# minimum_balance: 0 # minimum_balance: 0
# When use_nick is enabled, there will be a nickname field in the user form,
# and the option to show a nickname instead of full name to foodcoop members.
# Members of a user's groups and administrators can still see full names.
use_nick: false
# email address to be used as sender # email address to be used as sender
email_sender: foodsoft@foodcoop.test email_sender: foodsoft@foodcoop.test

View file

@ -9,6 +9,8 @@ class FoodsoftConfig
set_config Rails.env set_config Rails.env
# Overwrite scope to have a better namescope than 'production' # Overwrite scope to have a better namescope than 'production'
self.scope = config[:default_scope] or raise "No default_scope is set" self.scope = config[:default_scope] or raise "No default_scope is set"
# Set defaults for backward-compatibility
set_missing
end end
# Set config and database connection for specific foodcoop # Set config and database connection for specific foodcoop
@ -46,5 +48,13 @@ class FoodsoftConfig
ActiveRecord::Base.establish_connection(database_config) ActiveRecord::Base.establish_connection(database_config)
end end
# When new options are introduced, put backward-compatible defaults here, so that
# configuration files that haven't been updated, still work as they did.
def set_missing
config.replace({
use_nick: true
}.merge(config))
end
end end
end end