allows authors and admins to view their spending proposals in my activity
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -64,4 +64,8 @@ class SpendingProposal < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
<span class="flag-content">
|
||||
<% if show_flag_action? comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a class="button" id="flag-expand-comment-<%= comment.id %>" data-dropdown="flag-drop-comment-<%= comment.id %>" aria-controls="flag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.flag') %>">
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
<a class="button" id="flag-expand-comment-<%= comment.id %>"
|
||||
data-dropdown="flag-drop-comment-<%= comment.id %>"
|
||||
aria-controls="flag-drop-comment-<%= comment.id %>"
|
||||
aria-expanded="false"
|
||||
title="<%= t('shared.flag') %>">
|
||||
|
||||
<i class="icon-flag flag-disable"></i>
|
||||
</a>
|
||||
<ul id="flag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<ul id="flag-drop-comment-<%= comment.id %>"
|
||||
class="f-dropdown"
|
||||
data-dropdown-content
|
||||
aria-hidden="true"
|
||||
tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t("shared.flag"), flag_comment_path(comment), method: :put, remote: true, id: "flag-comment-#{comment.id}" %>
|
||||
<%= link_to t("shared.flag"), flag_comment_path(comment), method: :put,
|
||||
remote: true, id: "flag-comment-#{comment.id}" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% if show_unflag_action? comment %>
|
||||
<span class="divider"> | </span>
|
||||
<a class="button" id="unflag-expand-comment-<%= comment.id %>" data-dropdown="unflag-drop-comment-<%= comment.id %>" aria-controls="unflag-drop-comment-<%= comment.id %>" aria-expanded="false" title="<%= t('shared.unflag') %>">
|
||||
<i class="icon-flag flag-active"></i>
|
||||
<a class="button" id="unflag-expand-comment-<%= comment.id %>"
|
||||
data-dropdown="unflag-drop-comment-<%= comment.id %>"
|
||||
aria-controls="unflag-drop-comment-<%= comment.id %>"
|
||||
aria-expanded="false"
|
||||
title="<%= t('shared.unflag') %>">
|
||||
|
||||
<i class="icon-flag flag-active"></i>
|
||||
</a>
|
||||
<ul id="unflag-drop-comment-<%= comment.id %>" class="f-dropdown" data-dropdown-content aria-hidden="true" tabindex="-1">
|
||||
<ul id="unflag-drop-comment-<%= comment.id %>"
|
||||
class="f-dropdown"
|
||||
data-dropdown-content
|
||||
aria-hidden="true"
|
||||
tabindex="-1">
|
||||
<li>
|
||||
<%= link_to t("shared.unflag"), unflag_comment_path(comment), method: :put, remote: true, id: "unflag-comment-#{comment.id}" %>
|
||||
<%= link_to t("shared.unflag"), unflag_comment_path(comment), method: :put,
|
||||
remote: true, id: "unflag-comment-#{comment.id}" %>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<%= render "proposals" if @proposals.present? %>
|
||||
<%= render "debates" if @debates.present? && feature?(:debates) %>
|
||||
<%= render "comments" if @comments.present? %>
|
||||
<%= render "spending_proposals" if @spending_proposals.present? %>
|
||||
|
||||
13
app/views/users/_spending_proposals.html.erb
Normal file
13
app/views/users/_spending_proposals.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<table class="clear activity-proposals">
|
||||
<% @spending_proposals.each do |spending_proposal| %>
|
||||
<tr id="spending_proposal_<%= spending_proposal.id %>">
|
||||
<td>
|
||||
<%= link_to spending_proposal.title, spending_proposal %>
|
||||
<br>
|
||||
<%= spending_proposal.description %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @spending_proposals %>
|
||||
@@ -14,11 +14,17 @@
|
||||
<dl class="sub-nav margin-top">
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @activity_counts[filter] > 0 %>
|
||||
<% if @current_filter == filter %>
|
||||
<dd class="active"> <%= t("users.show.filters.#{filter}", count: @activity_counts[filter]) %></dd>
|
||||
<% else %>
|
||||
<dd><%= link_to t("users.show.filters.#{filter}", count: @activity_counts[filter]),
|
||||
current_path_with_query_params(filter: filter, page: 1) %></dd>
|
||||
<% if authorized_for_filter?(filter) %>
|
||||
<% if @current_filter == filter %>
|
||||
<dd class="active">
|
||||
<%= t("users.show.filters.#{filter}", count: @activity_counts[filter]) %>
|
||||
</dd>
|
||||
<% else %>
|
||||
<dd>
|
||||
<%= link_to t("users.show.filters.#{filter}", count: @activity_counts[filter]),
|
||||
current_path_with_query_params(filter: filter, page: 1) %>
|
||||
</dd>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -453,6 +453,9 @@ en:
|
||||
proposals:
|
||||
one: 1 Proposal
|
||||
other: "%{count} Proposals"
|
||||
spending_proposals:
|
||||
one: 1 Spending proposal
|
||||
other: "%{count} Spending proposals"
|
||||
no_activity: User has no public activity
|
||||
private_activity: This user decided to keep the activity list private
|
||||
votes:
|
||||
|
||||
@@ -454,6 +454,9 @@ es:
|
||||
proposals:
|
||||
one: 1 Propuesta
|
||||
other: "%{count} Propuestas"
|
||||
spending_proposals:
|
||||
one: 1 Propuesta de inversión
|
||||
other: "%{count} Propuestas de inversión"
|
||||
no_activity: Usuario sin actividad pública
|
||||
private_activity: Este usuario ha decidido mantener en privado su lista de actividades
|
||||
votes:
|
||||
|
||||
@@ -198,6 +198,43 @@ feature 'Users' do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
feature 'Spending proposals' do
|
||||
|
||||
background do
|
||||
@author = create(:user)
|
||||
create(:spending_proposal, author: @author, title: 'Build a school')
|
||||
end
|
||||
|
||||
scenario 'is not shown if no user logged in' do
|
||||
visit user_path(@user)
|
||||
expect(page).to_not have_content('Build a school')
|
||||
end
|
||||
|
||||
scenario 'is not shown if logged in user is a regular user' do
|
||||
login_as(create(:user))
|
||||
visit user_path(@author)
|
||||
expect(page).to_not have_content('Build a school')
|
||||
end
|
||||
|
||||
scenario 'is not shown if logged in user is moderator' do
|
||||
login_as(create(:moderator).user)
|
||||
visit user_path(@author)
|
||||
expect(page).to_not have_content('Build a school')
|
||||
end
|
||||
|
||||
scenario 'is shown if logged in user is admin' do
|
||||
login_as(create(:administrator).user)
|
||||
visit user_path(@author)
|
||||
expect(page).to have_content('Build a school')
|
||||
end
|
||||
|
||||
scenario 'is shown if logged in user is author' do
|
||||
login_as(@author)
|
||||
visit user_path(@author)
|
||||
expect(page).to have_content('Build a school')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature 'Special comments' do
|
||||
|
||||
Reference in New Issue
Block a user