Merge pull request #1750 from rockandror/followable-user-activity
User page: new following section
This commit is contained in:
@@ -3,15 +3,15 @@ class FollowsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
|
||||
def create
|
||||
@followable = find_followable
|
||||
@follow = Follow.create(user: current_user, followable: @followable)
|
||||
@follow = Follow.create(user: current_user, followable: find_followable)
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
def destroy
|
||||
@follow = Follow.find(params[:id])
|
||||
@followable = @follow.followable
|
||||
@follow.destroy
|
||||
flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice_html")
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
@@ -20,4 +20,9 @@ class FollowsController < ApplicationController
|
||||
def find_followable
|
||||
params[:followable_type].constantize.find(params[:followable_id])
|
||||
end
|
||||
|
||||
def followable_translation_key(followable)
|
||||
followable.class.name.parameterize("_")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
class UsersController < ApplicationController
|
||||
has_filters %w{proposals debates budget_investments comments}, only: :show
|
||||
has_filters %w{proposals debates budget_investments comments follows}, only: :show
|
||||
|
||||
load_and_authorize_resource
|
||||
helper_method :author?
|
||||
helper_method :author_or_admin?
|
||||
helper_method :valid_interests_access?
|
||||
|
||||
def show
|
||||
load_filtered_activity if valid_access?
|
||||
load_interests if valid_interests_access?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -17,7 +16,8 @@ class UsersController < ApplicationController
|
||||
proposals: Proposal.where(author_id: @user.id).count,
|
||||
debates: (Setting['feature.debates'] ? Debate.where(author_id: @user.id).count : 0),
|
||||
budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0),
|
||||
comments: only_active_commentables.count)
|
||||
comments: only_active_commentables.count,
|
||||
follows: @user.follows.count)
|
||||
end
|
||||
|
||||
def load_filtered_activity
|
||||
@@ -26,7 +26,8 @@ class UsersController < ApplicationController
|
||||
when "proposals" then load_proposals
|
||||
when "debates" then load_debates
|
||||
when "budget_investments" then load_budget_investments
|
||||
when "comments" then load_comments
|
||||
when "comments" then load_comments
|
||||
when "follows" then load_follows
|
||||
else load_available_activity
|
||||
end
|
||||
end
|
||||
@@ -44,6 +45,9 @@ class UsersController < ApplicationController
|
||||
elsif @activity_counts[:comments] > 0
|
||||
load_comments
|
||||
@current_filter = "comments"
|
||||
elsif @activity_counts[:follows] > 0
|
||||
load_follows
|
||||
@current_filter = "follows"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,8 +67,8 @@ class UsersController < ApplicationController
|
||||
@budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def load_interests
|
||||
@user.interests
|
||||
def load_follows
|
||||
@follows = @user.follows.group_by(&:followable_type)
|
||||
end
|
||||
|
||||
def valid_access?
|
||||
@@ -75,12 +79,8 @@ class UsersController < ApplicationController
|
||||
@user.public_interests || authorized_current_user?
|
||||
end
|
||||
|
||||
def author?
|
||||
@author ||= current_user && (current_user == @user)
|
||||
end
|
||||
|
||||
def author_or_admin?
|
||||
@author_or_admin ||= current_user && (author? || current_user.administrator?)
|
||||
def author?(proposal)
|
||||
proposal.author_id == current_user.id if current_user
|
||||
end
|
||||
|
||||
def authorized_current_user?
|
||||
|
||||
Reference in New Issue
Block a user