Replaces spending proposals by budget investments in user/show
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
has_filters %w{proposals debates comments spending_proposals}, only: :show
|
has_filters %w{proposals debates budget_investments comments}, only: :show
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
helper_method :authorized_for_filter?
|
|
||||||
helper_method :author?
|
helper_method :author?
|
||||||
helper_method :author_or_admin?
|
helper_method :author_or_admin?
|
||||||
|
|
||||||
@@ -15,8 +14,8 @@ class UsersController < ApplicationController
|
|||||||
@activity_counts = HashWithIndifferentAccess.new(
|
@activity_counts = HashWithIndifferentAccess.new(
|
||||||
proposals: Proposal.where(author_id: @user.id).count,
|
proposals: Proposal.where(author_id: @user.id).count,
|
||||||
debates: Debate.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,
|
budget_investments: Budget::Investment.where(author_id: @user.id).count,
|
||||||
spending_proposals: SpendingProposal.where(author_id: @user.id).count)
|
comments: Comment.not_as_admin_or_moderator.where(user_id: @user.id).count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_filtered_activity
|
def load_filtered_activity
|
||||||
@@ -24,8 +23,8 @@ class UsersController < ApplicationController
|
|||||||
case params[:filter]
|
case params[:filter]
|
||||||
when "proposals" then load_proposals
|
when "proposals" then load_proposals
|
||||||
when "debates" then load_debates
|
when "debates" then load_debates
|
||||||
|
when "budget_investments" then load_budget_investments
|
||||||
when "comments" then load_comments
|
when "comments" then load_comments
|
||||||
when "spending_proposals" then load_spending_proposals if author_or_admin?
|
|
||||||
else load_available_activity
|
else load_available_activity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -37,12 +36,12 @@ class UsersController < ApplicationController
|
|||||||
elsif @activity_counts[:debates] > 0
|
elsif @activity_counts[:debates] > 0
|
||||||
load_debates
|
load_debates
|
||||||
@current_filter = "debates"
|
@current_filter = "debates"
|
||||||
|
elsif @activity_counts[:budget_investments] > 0
|
||||||
|
load_budget_investments
|
||||||
|
@current_filter = "budget_investments"
|
||||||
elsif @activity_counts[:comments] > 0
|
elsif @activity_counts[:comments] > 0
|
||||||
load_comments
|
load_comments
|
||||||
@current_filter = "comments"
|
@current_filter = "comments"
|
||||||
elsif @activity_counts[:spending_proposals] > 0 && author_or_admin?
|
|
||||||
load_spending_proposals
|
|
||||||
@current_filter = "spending_proposals"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -58,8 +57,8 @@ class UsersController < ApplicationController
|
|||||||
@comments = Comment.not_as_admin_or_moderator.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
|
@comments = Comment.not_as_admin_or_moderator.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_spending_proposals
|
def load_budget_investments
|
||||||
@spending_proposals = SpendingProposal.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
|
@budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_access?
|
def valid_access?
|
||||||
@@ -78,7 +77,4 @@ class UsersController < ApplicationController
|
|||||||
@authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?)
|
@authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized_for_filter?(filter)
|
|
||||||
filter == "spending_proposals" ? author_or_admin? : true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<%= render "proposals" if @proposals.present? %>
|
<%= render "proposals" if @proposals.present? %>
|
||||||
<%= render "debates" if @debates.present? && feature?(:debates) %>
|
<%= render "debates" if @debates.present? && feature?(:debates) %>
|
||||||
|
<%= render "investments" if @investments.present? %>
|
||||||
|
<%= render "budget_investments" if @budget_investments.present? %>
|
||||||
<%= render "comments" if @comments.present? %>
|
<%= render "comments" if @comments.present? %>
|
||||||
<%= render "spending_proposals" if @spending_proposals.present? %>
|
|
||||||
|
|||||||
11
app/views/users/_budget_investments.html.erb
Normal file
11
app/views/users/_budget_investments.html.erb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<table id="budget_investments_list" class="clear activity-investment-projects">
|
||||||
|
<% @budget_investments.each do |budget_investment| %>
|
||||||
|
<tr id="budget_investment_<%= budget_investment.id %>">
|
||||||
|
<td>
|
||||||
|
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @budget_investments %>
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<table id="spending_proposals_list" class="clear activity-investment-projects">
|
|
||||||
<% @spending_proposals.each do |spending_proposal| %>
|
|
||||||
<tr id="spending_proposal_<%= spending_proposal.id %>">
|
|
||||||
<td>
|
|
||||||
<%= link_to spending_proposal.title, spending_proposal %>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<% if can?(:destroy, spending_proposal) %>
|
|
||||||
<%= link_to t("users.show.delete_spending_proposal"),
|
|
||||||
spending_proposal,
|
|
||||||
method: :delete,
|
|
||||||
data: { confirm: t("users.show.confirm_deletion_spending_proposal") },
|
|
||||||
class: 'delete' %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<%= paginate @spending_proposals %>
|
|
||||||
@@ -26,17 +26,15 @@
|
|||||||
<ul class="menu simple margin-top">
|
<ul class="menu simple margin-top">
|
||||||
<% @valid_filters.each do |filter| %>
|
<% @valid_filters.each do |filter| %>
|
||||||
<% if @activity_counts[filter] > 0 %>
|
<% if @activity_counts[filter] > 0 %>
|
||||||
<% if authorized_for_filter?(filter) %>
|
<% if @current_filter == filter %>
|
||||||
<% if @current_filter == filter %>
|
<li class="active">
|
||||||
<li class="active">
|
<%= t("users.show.filters.#{filter}", count: @activity_counts[filter]) %>
|
||||||
<%= t("users.show.filters.#{filter}", count: @activity_counts[filter]) %>
|
</li>
|
||||||
</li>
|
<% else %>
|
||||||
<% else %>
|
<li>
|
||||||
<li>
|
<%= link_to t("users.show.filters.#{filter}", count: @activity_counts[filter]),
|
||||||
<%= link_to t("users.show.filters.#{filter}", count: @activity_counts[filter]),
|
current_path_with_query_params(filter: filter, page: 1) %>
|
||||||
current_path_with_query_params(filter: filter, page: 1) %>
|
</li>
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ feature 'Users' do
|
|||||||
@user = create(:user)
|
@user = create(:user)
|
||||||
1.times {create(:debate, author: @user)}
|
1.times {create(:debate, author: @user)}
|
||||||
2.times {create(:proposal, author: @user)}
|
2.times {create(:proposal, author: @user)}
|
||||||
3.times {create(:comment, user: @user)}
|
3.times {create(:budget_investment, author: @user)}
|
||||||
|
4.times {create(:comment, user: @user)}
|
||||||
|
|
||||||
visit user_path(@user)
|
visit user_path(@user)
|
||||||
end
|
end
|
||||||
@@ -16,7 +17,8 @@ feature 'Users' do
|
|||||||
scenario 'shows user public activity' do
|
scenario 'shows user public activity' do
|
||||||
expect(page).to have_content('1 Debate')
|
expect(page).to have_content('1 Debate')
|
||||||
expect(page).to have_content('2 Proposals')
|
expect(page).to have_content('2 Proposals')
|
||||||
expect(page).to have_content('3 Comments')
|
expect(page).to have_content('3 Investments')
|
||||||
|
expect(page).to have_content('4 Comments')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'shows only items where user has activity' do
|
scenario 'shows only items where user has activity' do
|
||||||
@@ -24,7 +26,8 @@ feature 'Users' do
|
|||||||
|
|
||||||
expect(page).to_not have_content('0 Proposals')
|
expect(page).to_not have_content('0 Proposals')
|
||||||
expect(page).to have_content('1 Debate')
|
expect(page).to have_content('1 Debate')
|
||||||
expect(page).to have_content('3 Comments')
|
expect(page).to have_content('3 Investments')
|
||||||
|
expect(page).to have_content('4 Comments')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'default filter is proposals' do
|
scenario 'default filter is proposals' do
|
||||||
@@ -48,11 +51,20 @@ feature 'Users' do
|
|||||||
expect(page).to have_content(@user.debates.first.title)
|
expect(page).to have_content(@user.debates.first.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'shows comments by default if user has no proposals nor debates' do
|
scenario 'shows investments by default if user has no proposals nor debates' do
|
||||||
@user.proposals.destroy_all
|
@user.proposals.destroy_all
|
||||||
@user.debates.destroy_all
|
@user.debates.destroy_all
|
||||||
visit user_path(@user)
|
visit user_path(@user)
|
||||||
|
|
||||||
|
expect(page).to have_content(@user.budget_investments.first.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'shows comments by default if user has no proposals nor debates nor investments' do
|
||||||
|
@user.proposals.destroy_all
|
||||||
|
@user.debates.destroy_all
|
||||||
|
@user.budget_investments.destroy_all
|
||||||
|
visit user_path(@user)
|
||||||
|
|
||||||
@user.comments.each do |comment|
|
@user.comments.each do |comment|
|
||||||
expect(page).to have_content(comment.body)
|
expect(page).to have_content(comment.body)
|
||||||
end
|
end
|
||||||
@@ -73,7 +85,7 @@ feature 'Users' do
|
|||||||
expect(page).to_not have_content(comment.body)
|
expect(page).to_not have_content(comment.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
click_link '3 Comments'
|
click_link '4 Comments'
|
||||||
|
|
||||||
@user.comments.each do |comment|
|
@user.comments.each do |comment|
|
||||||
expect(page).to have_content(comment.body)
|
expect(page).to have_content(comment.body)
|
||||||
@@ -199,64 +211,6 @@ feature 'Users' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature 'Spending proposals' do
|
|
||||||
|
|
||||||
background do
|
|
||||||
@author = create(:user, :level_two)
|
|
||||||
@spending_proposal = create(:spending_proposal, author: @author, title: 'Build a school')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'is not shown if no user logged in' do
|
|
||||||
visit user_path(@author)
|
|
||||||
expect(page).to_not have_content('Build a school')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'is not shown if no user logged in (filtered url)' do
|
|
||||||
visit user_path(@author, filter: 'spending_proposals')
|
|
||||||
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
|
|
||||||
|
|
||||||
scenario 'delete button is not shown if logged in user is author' do
|
|
||||||
login_as(@author)
|
|
||||||
visit user_path(@author)
|
|
||||||
within("#spending_proposal_#{@spending_proposal.id}") do
|
|
||||||
expect(page).to_not have_content('Delete')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'delete button is shown if logged in user is admin' do
|
|
||||||
login_as(create(:administrator).user)
|
|
||||||
visit user_path(@author)
|
|
||||||
within("#spending_proposal_#{@spending_proposal.id}") do
|
|
||||||
expect(page).to have_content('Delete')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature 'Special comments' do
|
feature 'Special comments' do
|
||||||
@@ -283,4 +237,4 @@ feature 'Users' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user