diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d505cef8c..5c5e68741 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,8 @@ class UsersController < ApplicationController - has_filters %w{proposals debates comments}, only: :show + has_filters %w{proposals debates comments spending_proposals}, only: :show load_and_authorize_resource + helper_method :authorized_for_filter? def show load_filtered_activity if valid_access? @@ -12,7 +13,8 @@ class UsersController < ApplicationController @activity_counts = HashWithIndifferentAccess.new( proposals: Proposal.where(author_id: @user.id).count, debates: Debate.where(author_id: @user.id).count, - comments: Comment.not_as_admin_or_moderator.where(user_id: @user.id).count) + comments: Comment.not_as_admin_or_moderator.where(user_id: @user.id).count, + spending_proposals: SpendingProposal.where(author_id: @user.id).count) end def load_filtered_activity @@ -21,6 +23,7 @@ class UsersController < ApplicationController when "proposals" then load_proposals when "debates" then load_debates when "comments" then load_comments + when "spending_proposals" then load_spending_proposals else load_available_activity end end @@ -35,6 +38,9 @@ class UsersController < ApplicationController elsif @activity_counts[:comments] > 0 load_comments @current_filter = "comments" + elsif @activity_counts[:spending_proposals] > 0 && author_or_admin? + load_spending_proposals + @current_filter = "spending_proposals" end end @@ -50,11 +56,23 @@ class UsersController < ApplicationController @comments = Comment.not_as_admin_or_moderator.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page]) end + def load_spending_proposals + @spending_proposals = SpendingProposal.where(author_id: @user.id).order(created_at: :desc).page(params[:page]) + end + def valid_access? @user.public_activity || authorized_current_user? end + def author_or_admin? + @author_or_admin ||= current_user && (current_user == @user || current_user.administrator?) + end + def authorized_current_user? @authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?) end + + def authorized_for_filter?(filter) + filter == "spending_proposals" ? author_or_admin? : true + end end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 90d2b06f6..c023f83f4 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -64,4 +64,8 @@ class SpendingProposal < ActiveRecord::Base end end + def description + super.try :html_safe + end + end diff --git a/app/views/comments/_flag_actions.html.erb b/app/views/comments/_flag_actions.html.erb index 007ab90b4..b68b31038 100644 --- a/app/views/comments/_flag_actions.html.erb +++ b/app/views/comments/_flag_actions.html.erb @@ -1,24 +1,44 @@ <% if show_flag_action? comment %>  |  - -