diff --git a/app/controllers/spending_proposals_controller.rb b/app/controllers/spending_proposals_controller.rb index a07783d3d..7e32b0a93 100644 --- a/app/controllers/spending_proposals_controller.rb +++ b/app/controllers/spending_proposals_controller.rb @@ -1,11 +1,12 @@ class SpendingProposalsController < ApplicationController include FeatureFlags - before_action :authenticate_user!, except: [:index] - before_action :verify_valuator, only: [:show] - load_and_authorize_resource + before_action :authenticate_user!, except: [:index] + before_action :verify_access, only: [:show] + before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] } + feature_flag :spending_proposals def index @@ -20,7 +21,8 @@ class SpendingProposalsController < ApplicationController @spending_proposal.author = current_user if @spending_proposal.save_with_captcha - redirect_to spending_proposals_path, notice: t("flash.actions.create.spending_proposal") + notice = t('flash.actions.create.spending_proposal', activity: "#{t('layouts.header.my_activity_link')}") + redirect_to @spending_proposal, notice: notice, flash: { html_safe: true } else render :new end @@ -32,8 +34,8 @@ class SpendingProposalsController < ApplicationController params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :association_name, :terms_of_service, :captcha, :captcha_key) end - def verify_valuator - raise CanCan::AccessDenied unless current_user.try(:valuator?) || current_user.try(:administrator?) + def verify_access + raise CanCan::AccessDenied unless current_user.try(:valuator?) || current_user.try(:administrator?) || @spending_proposal.author == current_user end end 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 %>  |  - -