Commit bcb8a1fbcae6f3bcb60ff0a960fb7fc6d9f8e35d

Authored by JoenioCosta
1 parent 3b91d87a

ActionItem441: options to affiliate user to a role on add member task


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2013 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/profile_members_controller.rb
@@ -6,11 +6,6 @@ class ProfileMembersController < MyProfileController @@ -6,11 +6,6 @@ class ProfileMembersController < MyProfileController
6 @member_role = Role.find_by_name('member') 6 @member_role = Role.find_by_name('member')
7 end 7 end
8 8
9 - def change_roles  
10 - @member = Person.find(params[:id])  
11 - @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) }  
12 - end  
13 -  
14 def update_roles 9 def update_roles
15 @roles = params[:roles] ? Role.find(params[:roles]) : [] 10 @roles = params[:roles] ? Role.find(params[:roles]) : []
16 @roles = @roles.select{|r| r.has_kind?('Profile') } 11 @roles = @roles.select{|r| r.has_kind?('Profile') }
app/models/add_member.rb
@@ -12,8 +12,11 @@ class AddMember < Task @@ -12,8 +12,11 @@ class AddMember < Task
12 alias :enterprise :target 12 alias :enterprise :target
13 alias :enterprise= :target= 13 alias :enterprise= :target=
14 14
  15 + acts_as_having_settings :roles, :field => :data
  16 +
15 def perform 17 def perform
16 - target.affiliate(requestor, Profile::Roles.member) 18 + self.roles ||= [Profile::Roles.member.id]
  19 + target.affiliate(requestor, self.roles.map{|i| Role.find(i)})
17 end 20 end
18 21
19 # FIXME should send email to community admin? 22 # FIXME should send email to community admin?
app/views/tasks/_add_friend.rhtml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <%= link_to( profile_image(task.requestor, :minor, :border => 0), task.requestor.public_profile_url ) %> 3 <%= link_to( profile_image(task.requestor, :minor, :border => 0), task.requestor.public_profile_url ) %>
4 4
5 <%= _('%s wants to connect to you as a friend.') % 5 <%= _('%s wants to connect to you as a friend.') %
6 - content_tag('b', link_to( task.requestor.name, task.requestor.public_profile_url ) ) %> 6 + content_tag('strong', link_to( task.requestor.name, task.requestor.public_profile_url ) ) %>
7 7
8 <% form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %> 8 <% form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %>
9 9
app/views/tasks/_add_member.rhtml 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +<h2><%= _('New member') %></h2>
  2 +
  3 +<%= link_to( profile_image(task.requestor, :minor, :border => 0), task.requestor.public_profile_url ) %>
  4 +
  5 +<%= _('%s wants to be a member of %s.') %
  6 + [content_tag('strong', link_to( task.requestor.name, task.requestor.public_profile_url ) ),
  7 + content_tag('strong', link_to( task.target.name, task.target.public_profile_url ) )] %>
  8 +
  9 +<% form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %>
  10 +
  11 + <div>
  12 + <%= radio_button_tag(:decision, 'finish', true,
  13 + :id => "decision-finish-#{task.id}",
  14 + :onclick => "Element.show('group-for-friend-#{task.id}')") %>
  15 + <label for="<%= "decision-finish-#{task.id}" %>"><b><%= _('Accept') %></b></label>
  16 +
  17 + &nbsp; &nbsp;
  18 +
  19 + <%= radio_button_tag(:decision, 'cancel', false,
  20 + :id => "decision-cancel-#{task.id}",
  21 + :onclick => "Element.hide('group-for-friend-#{task.id}')") %>
  22 + <label for="<%= "decision-cancel-#{task.id}" %>"><b><%= _('Ignore') %></b></label>
  23 +
  24 + <p class="member-classify-suggestions">
  25 + <%= _('Roles:') %> <br>
  26 + <%
  27 + @roles = Role.find(:all).select{ |r| r.has_kind?('Profile') }
  28 + %>
  29 + <% @roles.each do |r| %>
  30 + <%= labelled_check_box(r.name, 'task[roles][]', r.id, true) %><br/>
  31 + <% end %>
  32 + </p>
  33 + </div>
  34 +
  35 + <% button_bar do %>
  36 + <%= submit_button(:ok, _('Ok!')) %>
  37 + <% end %>
  38 +<% end %>
test/functional/tasks_controller_test.rb
@@ -62,4 +62,6 @@ class TasksControllerTest &lt; Test::Unit::TestCase @@ -62,4 +62,6 @@ class TasksControllerTest &lt; Test::Unit::TestCase
62 ok('task should be cancelled') { t.status == Task::Status::CANCELLED } 62 ok('task should be cancelled') { t.status == Task::Status::CANCELLED }
63 end 63 end
64 64
  65 + should 'affiliate roles to user after finish add member task'
  66 +
65 end 67 end
test/unit/add_member_test.rb
@@ -71,4 +71,24 @@ class AddMemberTest &lt; ActiveSupport::TestCase @@ -71,4 +71,24 @@ class AddMemberTest &lt; ActiveSupport::TestCase
71 assert_equal :manage_memberships, t.permission 71 assert_equal :manage_memberships, t.permission
72 end 72 end
73 73
  74 + should 'have roles' do
  75 + p = create_user('testuser1').person
  76 + c = Community.create!(:name => 'community_test')
  77 + task = AddMember.create!(:roles => [1,2,3], :person => p, :community => c)
  78 + assert_equal [1,2,3], task.roles
  79 + end
  80 +
  81 + should 'put member with the right roles' do
  82 + p = create_user('testuser1').person
  83 + c = Community.create!(:name => 'community_test')
  84 +
  85 + roles = [Profile::Roles.member, Profile::Roles.admin]
  86 + task = AddMember.create!(:roles => roles.map(&:id), :person => p, :community => c)
  87 + task.finish
  88 +
  89 + current_roles = p.find_roles(c).map(&:role)
  90 + assert_includes current_roles, roles[0]
  91 + assert_includes current_roles, roles[1]
  92 + end
  93 +
74 end 94 end