Commit 06f96ca80964d78c07ec03cbbed14d2971c16040

Authored by Leandro Santos
2 parents 9549e2e0 31850513

fix conflit with add_members_community

app/helpers/application_helper.rb
@@ -606,24 +606,14 @@ module ApplicationHelper @@ -606,24 +606,14 @@ module ApplicationHelper
606 trigger_class = 'enterprise-trigger' 606 trigger_class = 'enterprise-trigger'
607 end 607 end
608 end 608 end
609 -  
610 - extra_info_tag = ''  
611 - img_class = 'profile-image'  
612 -  
613 - if extra_info.is_a? Hash  
614 - extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])  
615 - img_class +=' '+extra_info[:class]  
616 - else  
617 - extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )  
618 - end  
619 - #extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) 609 + extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
620 links = links_for_balloon(profile) 610 links = links_for_balloon(profile)
621 content_tag('div', content_tag(tag, 611 content_tag('div', content_tag(tag,
622 (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + 612 (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
623 link_to( 613 link_to(
624 - content_tag( 'span', profile_image( profile, size ), :class => img_class ) + 614 + content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
625 content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + 615 content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
626 - extra_info_tag + profile_sex_icon( profile ) + profile_cat_icons( profile ), 616 + extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ),
627 profile.url, 617 profile.url,
628 :class => 'profile_link url', 618 :class => 'profile_link url',
629 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, 619 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
app/models/profile.rb
@@ -735,6 +735,29 @@ private :generate_url, :url_options @@ -735,6 +735,29 @@ private :generate_url, :url_options
735 end 735 end
736 end 736 end
737 737
  738 + # Adds many people to profile by id's
  739 + def add_members_by_id(people_ids)
  740 +
  741 + unless people_ids.nil? && people_ids.empty?
  742 +
  743 + people = Person.where(id: people_ids)
  744 + people.each do |person|
  745 +
  746 + add_member(person) unless person.is_member_of?(self)
  747 + end
  748 + end
  749 + end
  750 +
  751 + # Adds many people to profile by email's
  752 + def add_members_by_email(people_emails)
  753 +
  754 + people = User.where(email: people_emails)
  755 + people.each do |user|
  756 +
  757 + add_member(user.person) unless user.person.is_member_of?(self)
  758 + end
  759 + end
  760 +
738 def remove_member(person) 761 def remove_member(person)
739 self.disaffiliate(person, Profile::Roles.all_roles(environment.id)) 762 self.disaffiliate(person, Profile::Roles.all_roles(environment.id))
740 end 763 end
lib/add_members_job.rb
@@ -4,7 +4,12 @@ class AddMembersJob &lt; Struct.new(:people_ids, :profile_id, :locale) @@ -4,7 +4,12 @@ class AddMembersJob &lt; Struct.new(:people_ids, :profile_id, :locale)
4 Noosfero.with_locale(locale) do 4 Noosfero.with_locale(locale) do
5 5
6 profile = Profile.find(profile_id) 6 profile = Profile.find(profile_id)
7 - profile.add_members people_ids 7 +
  8 + if people_ids.first =~ /\@/
  9 + profile.add_members_by_email people_ids
  10 + else
  11 + profile.add_members_by_id people_ids
  12 + end
8 13
9 end 14 end
10 end 15 end
public/stylesheets/application.css
@@ -2232,21 +2232,6 @@ a.button.disabled, input.disabled { @@ -2232,21 +2232,6 @@ a.button.disabled, input.disabled {
2232 .profile-list .extra_info { 2232 .profile-list .extra_info {
2233 font-size: 9px; 2233 font-size: 9px;
2234 } 2234 }
2235 -  
2236 -/* New members of community added  
2237 -* by admin of environment feature  
2238 -* #issue 227  
2239 -*/  
2240 -.profile-list .extra_info.new-profile {  
2241 - margin-top: 5px;  
2242 - color: #0A0;  
2243 - font-weight: bold;  
2244 -}  
2245 -  
2246 -span.new-profile img{  
2247 - border-top: solid 2px #0A0;  
2248 - margin-top: -2px;  
2249 -}  
2250 /* ==> blocks/recent-documents-block.css <<= */ 2235 /* ==> blocks/recent-documents-block.css <<= */
2251 2236
2252 #content .recent-documents-block { 2237 #content .recent-documents-block {
test/functional/invite_controller_test.rb
@@ -284,11 +284,6 @@ class InviteControllerTest &lt; ActionController::TestCase @@ -284,11 +284,6 @@ class InviteControllerTest &lt; ActionController::TestCase
284 assert_empty json_response 284 assert_empty json_response
285 end 285 end
286 286
287 - #@todo Copy this test and create a another version  
288 - #of this, for test add members in a community  
289 - #logged as admin of environment!  
290 - # #issue227  
291 - #  
292 should 'invite registered users through profile id' do 287 should 'invite registered users through profile id' do
293 friend1 = create_user('testuser1').person 288 friend1 = create_user('testuser1').person
294 friend2 = create_user('testuser2').person 289 friend2 = create_user('testuser2').person
@@ -302,7 +297,7 @@ class InviteControllerTest &lt; ActionController::TestCase @@ -302,7 +297,7 @@ class InviteControllerTest &lt; ActionController::TestCase
302 end 297 end
303 end 298 end
304 299
305 - should 'add registered users imediatly instead invite if logged user is a environment admin' do 300 + should 'add registered users by id imediatly instead invite if logged user is a environment admin' do
306 301
307 #Add user like a environment admin 302 #Add user like a environment admin
308 Environment.default.add_admin profile 303 Environment.default.add_admin profile
@@ -313,7 +308,29 @@ class InviteControllerTest &lt; ActionController::TestCase @@ -313,7 +308,29 @@ class InviteControllerTest &lt; ActionController::TestCase
313 assert_difference 'Delayed::Job.count', 1 do 308 assert_difference 'Delayed::Job.count', 1 do
314 assert_equal 0,community.members.count 309 assert_equal 0,community.members.count
315 310
316 - post :invite_registered_friend, :profile => @community.identifier, :q => [friend1.id,friend2.id] 311 + post :invite_registered_friend, :profile => @community.identifier, :q => "#{friend1.id},#{friend2.id}"
  312 +
  313 + assert_response :redirect
  314 + assert_redirected_to :controller => 'profile', :action => 'members'
  315 + end
  316 +
  317 + Delayed::Worker.new.run(Delayed::Job.last)
  318 +
  319 + assert_equal 2,community.members.count
  320 +
  321 + end
  322 +
  323 + should 'add registered users by email imediatly instead invite if logged user is a environment admin' do
  324 +
  325 + Environment.default.add_admin profile
  326 +
  327 + friend1 = create_user('testuser1', {email: 'friend1@test.com.br'})
  328 + friend2 = create_user('testuser2', {email: 'friend2@test.com.br'})
  329 +
  330 + assert_difference 'Delayed::Job.count', 1 do
  331 + assert_equal 0,community.members.count
  332 +
  333 + post :invite_registered_friend, :profile => @community.identifier, :q => "#{friend1.email},#{friend2.email}"
317 334
318 assert_response :redirect 335 assert_response :redirect
319 assert_redirected_to :controller => 'profile', :action => 'members' 336 assert_redirected_to :controller => 'profile', :action => 'members'
vendor/plugins/access_control/lib/acts_as_accessible.rb
@@ -19,9 +19,9 @@ module ActsAsAccessible @@ -19,9 +19,9 @@ module ActsAsAccessible
19 nil 19 nil
20 end 20 end
21 21
22 - def affiliate(accessor, roles) 22 + def affiliate(accessor, roles, attributes = {})
23 roles = [roles] unless roles.kind_of?(Array) 23 roles = [roles] unless roles.kind_of?(Array)
24 - roles.map {|role| accessor.add_role(role, self)}.any? 24 + roles.map {|role| accessor.add_role(role, self, attributes)}.any?
25 end 25 end
26 26
27 def disaffiliate(accessor, roles) 27 def disaffiliate(accessor, roles)