Commit cfe6f768486a38c67a03a15f4452d848fc67d6b1

Authored by Larissa Reis
1 parent f2992440

Fixes followers related controllers to use current profile instead of logged in user

Lists and edits followers and circles in control panel of profile that
is being viewed instead of logged in person. Also unfollow person in
control panel based on current viewed profile instead of current logged
in user.

This is necessary because sometimes an environment admin is editing
someone else's profile and those actions should be performed on that
profile instead of admin's profile.
app/controllers/my_profile/circles_controller.rb
... ... @@ -3,7 +3,7 @@ class CirclesController < MyProfileController
3 3 before_action :accept_only_post, :only => [:create, :update, :destroy]
4 4  
5 5 def index
6   - @circles = current_person.circles
  6 + @circles = profile.circles
7 7 end
8 8  
9 9 def new
... ... @@ -11,7 +11,7 @@ class CirclesController < MyProfileController
11 11 end
12 12  
13 13 def create
14   - @circle = Circle.new(params[:circle].merge({ :person => current_person }))
  14 + @circle = Circle.new(params[:circle].merge({ :person => profile }))
15 15 if @circle.save
16 16 redirect_to :action => 'index'
17 17 else
... ... @@ -21,7 +21,7 @@ class CirclesController < MyProfileController
21 21  
22 22 def xhr_create
23 23 if request.xhr?
24   - circle = Circle.new(params[:circle].merge({:person => current_person }))
  24 + circle = Circle.new(params[:circle].merge({:person => profile }))
25 25 if circle.save
26 26 render :partial => "circle_checkbox", :locals => { :circle => circle },
27 27 :status => 201
... ...
app/controllers/my_profile/followers_controller.rb
... ... @@ -4,7 +4,7 @@ class FollowersController < MyProfileController
4 4 before_action :accept_only_post, :only => [:update_category]
5 5  
6 6 def index
7   - @followed_people = current_person.followed_profiles.order(:type)
  7 + @followed_people = profile.followed_profiles.order(:type)
8 8 @profile_types = {_('All profiles') => nil}.merge(Circle.profile_types).to_a
9 9  
10 10 if params['filter'].present?
... ... @@ -16,9 +16,9 @@ class FollowersController < MyProfileController
16 16 end
17 17  
18 18 def set_category_modal
19   - profile = Profile.find(params[:followed_profile_id])
20   - circles = Circle.where(:person => current_person, :profile_type => profile.class.name)
21   - render :partial => 'followers/edit_circles_modal', :locals => { :circles => circles, :profile => profile }
  19 + followed_profile = Profile.find(params[:followed_profile_id])
  20 + circles = Circle.where(:person => profile, :profile_type => followed_profile.class.name)
  21 + render :partial => 'followers/edit_circles_modal', :locals => { :circles => circles, :followed_profile => followed_profile }
22 22 end
23 23  
24 24 def update_category
... ... @@ -27,7 +27,7 @@ class FollowersController < MyProfileController
27 27 selected_circles = params[:circles].map{ |circle_name, circle_id| Circle.find_by(:id => circle_id) }.select{ |c| c.present? }
28 28  
29 29 if followed_profile
30   - current_person.update_profile_circles(followed_profile, selected_circles)
  30 + profile.update_profile_circles(followed_profile, selected_circles)
31 31 render :text => _("Circles of %s updated successfully") % followed_profile.name, :status => 200
32 32 else
33 33 render :text => _("Error: No profile to follow."), :status => 400
... ...
app/controllers/public/profile_controller.rb
... ... @@ -184,8 +184,10 @@ class ProfileController < PublicController
184 184 end
185 185  
186 186 def unfollow
187   - if current_person.follows?(profile)
188   - current_person.unfollow(profile)
  187 + follower = params[:follower_id].present? ? Person.find_by(id: params[:follower_id]) : current_person
  188 +
  189 + if follower && follower.follows?(profile)
  190 + follower.unfollow(profile)
189 191 end
190 192 redirect_url = params["redirect_to"] ? params["redirect_to"] : profile.url
191 193 redirect_to redirect_url
... ...
app/views/blocks/profile_info_actions/_circles.html.erb
1 1 <div class="circles" id='circles-list'>
2 2  
3 3 <%= form_for :circles, :url => {:controller => 'profile', :action => 'follow'}, :html => {:id => "follow-circles-form"} do |f|%>
4   - <%= render partial: "blocks/profile_info_actions/select_circles", :locals => {:circles => circles} %>
  4 + <%= render partial: "blocks/profile_info_actions/select_circles", :locals => {:circles => circles, :followed_profile => profile, :follower => current_person } %>
5 5  
6 6 <div id="circle-actions">
7 7 <%= submit_button :ok, _("Follow") %>
... ...
app/views/blocks/profile_info_actions/_select_circles.html.erb
1 1 <div class="circles" id='circles-list'>
2   - <p><%= _("Select the circles for %s") % profile.name %></p>
  2 + <p><%= _("Select the circles for %s") % followed_profile.name %></p>
3 3 <div id="circles-checkboxes">
4 4 <% circles.each do |circle| %>
5 5 <div class="circle">
6   - <%= labelled_check_box circle.name, "circles[#{circle.name}]", circle.id, profile.in_circle?(circle, current_person) %>
  6 + <%= labelled_check_box circle.name, "circles[#{circle.name}]", circle.id, followed_profile.in_circle?(circle, follower) %>
7 7 </div>
8 8 <% end %>
9 9 </div>
... ... @@ -12,10 +12,10 @@
12 12  
13 13 <div id="new-circle-form" style="display: none;">
14 14 <%= labelled_text_field _('Circle name') , 'circle[name]', "",:id => 'text-field-name-new-circle'%>
15   - <%= hidden_field_tag('circle[profile_type]', profile.class.name) %>
  15 + <%= hidden_field_tag('circle[profile_type]', followed_profile.class.name) %>
16 16  
17 17 <%= button_bar do %>
18   - <%= button(:save, _('Create'), {:profile => profile.identifier, :controller => 'circles', :action => 'xhr_create'}, :id => "new-circle-submit") %>
  18 + <%= button(:save, _('Create'), {:profile => follower.identifier, :controller => 'circles', :action => 'xhr_create'}, :id => "new-circle-submit") %>
19 19 <%= button(:cancel, _('Cancel'), '#', :id => "new-circle-cancel") %>
20 20 <% end %>
21 21 </div>
... ...
app/views/followers/_edit_circles_modal.html.erb
1 1 <div class="circles" id='circles-list'>
2 2 <%= form_for :circles, :url => {:controller => 'followers', :action => 'update_category'}, :html => {:id => "follow-circles-form"} do |f|%>
3   - <%= render partial: "blocks/profile_info_actions/select_circles", :locals => {:circles => circles, :profile => profile} %>
  3 + <%= render partial: "blocks/profile_info_actions/select_circles", :locals => {:circles => circles, :followed_profile => followed_profile, :follower => profile } %>
4 4  
5   - <%= hidden_field_tag('followed_profile_id', profile.id) %>
  5 + <%= hidden_field_tag('followed_profile_id', followed_profile.id) %>
6 6  
7 7 <div id="circle-actions">
8 8 <div id="actions-container">
... ...
app/views/followers/_profile_list.html.erb
1 1 <ul class="profile-list">
2   - <% profiles.each do |profile| %>
  2 + <% profiles.each do |followed_profile| %>
3 3 <li>
4   - <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name,
5   - profile.identifier, :class => 'profile-link' %>
  4 + <%= link_to_profile profile_image(followed_profile) + tag('br') + followed_profile.short_name,
  5 + followed_profile.identifier, :class => 'profile-link' %>
6 6 <div class="controll">
7 7 <%= button_without_text :remove, content_tag('span',_('unfollow')),
8   - { :controller => "profile", :profile => profile.identifier , :action => 'unfollow', :redirect_to => url_for({:controller => "followers", :profile => user.identifier}) },
9   - :title => _('remove') %>
  8 + { :controller => "profile", :profile => followed_profile.identifier, :follower_id => profile.id,
  9 + :action => 'unfollow', :redirect_to => url_for({:controller => "followers", :profile => profile.identifier}) },
  10 + :title => _('remove') %>
10 11 <%= modal_icon_button :edit, _('change category'),
11 12 url_for(:controller => 'followers', :action => 'set_category_modal',
12   - :followed_profile_id => profile.id) %>
  13 + :followed_profile_id => followed_profile.id) %>
13 14 </div><!-- end class="controll" -->
14 15 </li>
15 16 <% end %>
... ...