makes public activity toggleable
This commit is contained in:
committed by
Juanjo Bazán
parent
6d26901f9f
commit
f57eef4929
@@ -25,7 +25,7 @@ class AccountController < ApplicationController
|
||||
if @account.organization?
|
||||
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
|
||||
else
|
||||
params.require(:account).permit(:username, :email_on_comment, :email_on_comment_reply)
|
||||
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@ class UsersController < ApplicationController
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_activity_counts, only: :show
|
||||
|
||||
def show
|
||||
load_filtered_activity
|
||||
load_filtered_activity if valid_access?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -18,6 +16,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def load_filtered_activity
|
||||
set_activity_counts
|
||||
case params[:filter]
|
||||
when "proposals" then load_proposals
|
||||
when "debates" then load_debates
|
||||
@@ -51,4 +50,11 @@ class UsersController < ApplicationController
|
||||
@comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def valid_access?
|
||||
@user.public_activity || authorized_current_user?
|
||||
end
|
||||
|
||||
def authorized_current_user?
|
||||
@authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<ul class="right">
|
||||
<% if user_signed_in? %>
|
||||
<li>
|
||||
<%= link_to(t("layouts.header.my_activity_link"), user_path(current_user)) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to(t("layouts.header.my_account_link"), account_path) %>
|
||||
</li>
|
||||
|
||||
@@ -4,21 +4,25 @@
|
||||
|
||||
<h2><%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %></h2>
|
||||
|
||||
<dl class="sub-nav">
|
||||
<% @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 @user.public_activity || @authorized_current_user %>
|
||||
<dl class="sub-nav">
|
||||
<% @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>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %>
|
||||
</dl>
|
||||
<%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %>
|
||||
</dl>
|
||||
|
||||
<%= render "activity_page" %>
|
||||
<%= render "activity_page" %>
|
||||
<% else %>
|
||||
<p><%= t('users.show.private_activity') %></p>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user