Skip to content

Commit

Permalink
refinement: On the user profile page, and member lists, only show the…
Browse files Browse the repository at this point in the history
… login in addition to the user name when the current_user is a site admin. Also fixing bug in user_name extended_content code and writing unit tests.
  • Loading branch information
Kieran Pilkington committed Jan 11, 2009
1 parent d86eb1c commit 568f10f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/user.rb
Expand Up @@ -189,9 +189,9 @@ def user_name
user_name_field = EXTENDED_FIELD_FOR_USER_NAME
extended_content_hash = self.xml_attributes_without_position
@user_name = self.login
if !extended_content_hash.blank? && !extended_content_hash[user_name_field].blank? && !extended_content_hash[user_name_field].to_s.match("xml_element_name")
if !extended_content_hash.blank? && !extended_content_hash[user_name_field].blank? && !extended_content_hash[user_name_field]['value'].blank?
# most likely have to pull the other attributes out
@user_name = extended_content_hash[user_name_field].strip
@user_name = extended_content_hash[user_name_field]['value'].strip
end
return @user_name
end
Expand Down
5 changes: 3 additions & 2 deletions app/views/account/show.rhtml
Expand Up @@ -53,8 +53,9 @@

<div class="profile_content_left">
<p>
<strong>Login:</strong>
<%= h(@user.login) -%>
<strong>User name:</strong>
<%= h(@user.user_name) -%>
<%= "(#{@user.login})" if @site_admin && @user.user_name != @user.login -%>
</p>

<% if @user.show_email? || @viewer_is_user -%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/members/_list_members.rhtml
Expand Up @@ -11,7 +11,7 @@
<td class="member-avatar"><%= avatar_for user -%></td>
<td>
<%= link_to_contributions_of(user,'Topic') -%>
<%= "<br />(#{user.login})" unless user.user_name == user.login -%>
<%= "<br />(#{user.login})" if @site_admin && user.user_name != user.login -%>
</td>
<% if @basket_admin -%>
<td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/members/_list_members_in.html.erb
Expand Up @@ -8,7 +8,7 @@
<td class="member_avatar"><%= avatar_for user -%></td>
<td class="member_username">
<%= link_to_contributions_of(user,'Topic') -%>
<%= "<br />(#{user.login})" unless user.user_name == user.login -%>
<%= "<br />(#{user.login})" if @site_admin && user.user_name != user.login -%>
</td>
<td class="member_joined">
<%= get_user_role_creation_date_for(user, @listing_type, @current_basket) -%>
Expand Down
14 changes: 14 additions & 0 deletions test/unit/user_test.rb
Expand Up @@ -141,6 +141,20 @@ def test_user_should_have_baskets
assert_kind_of Basket, user.baskets.first
end

# Lets make sure that the extended content code is working correctly for user.user_name
def test_user_should_have_username
user = create_user({ :login => 'user100', :extended_content => '<user_name xml_element_name="dc:subject">User 100</user_name>' })
assert 'user100', user.login
assert 'User 100', user.user_name
end

# Lets make sure that we fall back to the login name if user_name extended content isn't set
def test_user_should_use_login_if_no_user_name
user = create_user({ :login => 'user101', :extended_content => '' })
assert 'user101', user.login
assert 'user101', user.user_name
end

protected

def create_user(options = {})
Expand Down

0 comments on commit 568f10f

Please sign in to comment.