Commit 53d447a86c6d82cddb1c9372dba8f753d5b69b8f

Authored by Larissa Reis
Committed by Rodrigo Souto
1 parent da709178

Lists all roles a user has in a community

app/helpers/application_helper.rb
@@ -727,8 +727,13 @@ module ApplicationHelper @@ -727,8 +727,13 @@ module ApplicationHelper
727 end 727 end
728 728
729 def rolename_for(profile, resource) 729 def rolename_for(profile, resource)
730 - role = profile.role_assignments.find_by_resource_id(resource.id).role  
731 - content_tag('span', role.name, :style => "color: #{role_color(role, resource.environment.id)}") 730 + roles = profile.role_assignments.select{ |a| a.resource_id == resource.id }.sort_by{ |s| s.role_id }.map(&:role)
  731 + names = ''
  732 + roles.each do |role|
  733 + names += content_tag('span', role.name, :style => "color: #{role_color(role, resource.environment.id)}")
  734 + names += ', '
  735 + end
  736 + names.slice 0..-3
732 end 737 end
733 738
734 def role_color(role, env_id) 739 def role_color(role, env_id)
test/unit/application_helper_test.rb
@@ -143,6 +143,18 @@ class ApplicationHelperTest < ActiveSupport::TestCase @@ -143,6 +143,18 @@ class ApplicationHelperTest < ActiveSupport::TestCase
143 assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Member' 143 assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Member'
144 end 144 end
145 145
  146 + should 'rolenames for a member admin' do
  147 + member1 = create_user('usertest1').person
  148 + member2 = create_user('usertest2').person
  149 + community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id)
  150 + community.add_member(member1)
  151 + # member2 is both a admin and a member
  152 + community.add_member(member2)
  153 + community.add_admin(member2)
  154 + assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Member'
  155 + assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator'
  156 + end
  157 +
146 should 'get theme from environment by default' do 158 should 'get theme from environment by default' do
147 @environment = mock 159 @environment = mock
148 @environment.stubs(:theme).returns('my-environment-theme') 160 @environment.stubs(:theme).returns('my-environment-theme')