makes public activity toggleable

This commit is contained in:
Juanjo Bazán
2015-11-04 13:47:55 +01:00
committed by Juanjo Bazán
parent 6d26901f9f
commit f57eef4929
9 changed files with 105 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ class AccountController < ApplicationController
if @account.organization? if @account.organization?
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name]) params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
else 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
end end

View File

@@ -3,10 +3,8 @@ class UsersController < ApplicationController
load_and_authorize_resource load_and_authorize_resource
before_action :set_activity_counts, only: :show
def show def show
load_filtered_activity load_filtered_activity if valid_access?
end end
private private
@@ -18,6 +16,7 @@ class UsersController < ApplicationController
end end
def load_filtered_activity def load_filtered_activity
set_activity_counts
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
@@ -51,4 +50,11 @@ class UsersController < ApplicationController
@comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page]) @comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
end 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 end

View File

@@ -1,5 +1,8 @@
<ul class="right"> <ul class="right">
<% if user_signed_in? %> <% if user_signed_in? %>
<li>
<%= link_to(t("layouts.header.my_activity_link"), user_path(current_user)) %>
</li>
<li> <li>
<%= link_to(t("layouts.header.my_account_link"), account_path) %> <%= link_to(t("layouts.header.my_account_link"), account_path) %>
</li> </li>

View File

@@ -4,6 +4,7 @@
<h2><%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %></h2> <h2><%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %></h2>
<% if @user.public_activity || @authorized_current_user %>
<dl class="sub-nav"> <dl class="sub-nav">
<% @valid_filters.each do |filter| %> <% @valid_filters.each do |filter| %>
<% if @activity_counts[filter] > 0 %> <% if @activity_counts[filter] > 0 %>
@@ -19,6 +20,9 @@
</dl> </dl>
<%= render "activity_page" %> <%= render "activity_page" %>
<% else %>
<p><%= t('users.show.private_activity') %></p>
<% end %>
</div> </div>
</div> </div>

View File

@@ -283,6 +283,7 @@ en:
title: "My account" title: "My account"
save_changes_submit: "Save changes" save_changes_submit: "Save changes"
change_credentials_link: "Change my credentials" change_credentials_link: "Change my credentials"
public_activity_label: "Keep my list of activities public"
email_on_comment_label: "Notify me by email when someone comments on my proposals or debates" email_on_comment_label: "Notify me by email when someone comments on my proposals or debates"
email_on_comment_reply_label: "Notify me by email when someone replies to my comments" email_on_comment_reply_label: "Notify me by email when someone replies to my comments"
erase_account_link: "Erase my account" erase_account_link: "Erase my account"
@@ -337,6 +338,7 @@ en:
one: "1 Comment" one: "1 Comment"
other: "%{count} Comments" other: "%{count} Comments"
no_activity: "User has no public activity" no_activity: "User has no public activity"
private_activity: "This user decided to keep the activity list private"
comment_to: "Comment in: " comment_to: "Comment in: "
unauthorized: unauthorized:
default: "You do not have permission to access this page." default: "You do not have permission to access this page."

View File

@@ -283,6 +283,7 @@ es:
title: "Mi cuenta" title: "Mi cuenta"
save_changes_submit: "Guardar cambios" save_changes_submit: "Guardar cambios"
change_credentials_link: "Cambiar mis datos de acceso" change_credentials_link: "Cambiar mis datos de acceso"
public_activity_label: "Mostrar públicamente mi lista de actividades"
email_on_comment_label: "Recibir un email cuando alguien comenta en mis propuestas o debates" email_on_comment_label: "Recibir un email cuando alguien comenta en mis propuestas o debates"
email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios"
erase_account_link: "Darme de baja" erase_account_link: "Darme de baja"
@@ -337,6 +338,7 @@ es:
one: "1 Comentario" one: "1 Comentario"
other: "%{count} Comentarios" other: "%{count} Comentarios"
no_activity: "Usuario sin actividad pública" no_activity: "Usuario sin actividad pública"
private_activity: "Este usuario ha decidido mantener en privado su lista de actividades"
comment_to: "Comentario en: " comment_to: "Comentario en: "
unauthorized: unauthorized:
default: "No tienes permiso para acceder a esta página." default: "No tienes permiso para acceder a esta página."

View File

@@ -0,0 +1,5 @@
class AddPublicActivityToUsers < ActiveRecord::Migration
def change
add_column :users, :public_activity, :boolean, default: true
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151103175139) do ActiveRecord::Schema.define(version: 20151103194329) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -306,6 +306,7 @@ ActiveRecord::Schema.define(version: 20151103175139) do
t.datetime "level_two_verified_at" t.datetime "level_two_verified_at"
t.string "erase_reason" t.string "erase_reason"
t.datetime "erased_at" t.datetime "erased_at"
t.boolean "public_activity", default: true
end end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

@@ -65,4 +65,69 @@ feature 'Users' do
end end
feature 'Public activity' do
background do
@user = create(:user)
end
scenario 'visible by default' do
visit user_path(@user)
expect(page).to have_content(@user.username)
expect(page).to_not have_content('activity list private')
end
scenario 'user can hide public page' do
login_as(@user)
visit account_path
uncheck 'account_public_activity'
click_button 'Save changes'
logout
visit user_path(@user)
expect(page).to have_content('activity list private')
end
scenario 'is always visible for the owner' do
login_as(@user)
visit account_path
uncheck 'account_public_activity'
click_button 'Save changes'
visit user_path(@user)
expect(page).to_not have_content('activity list private')
end
scenario 'is always visible for admins' do
login_as(@user)
visit account_path
uncheck 'account_public_activity'
click_button 'Save changes'
logout
login_as(create(:administrator).user)
visit user_path(@user)
expect(page).to_not have_content('activity list private')
end
scenario 'is always visible for moderators' do
login_as(@user)
visit account_path
uncheck 'account_public_activity'
click_button 'Save changes'
logout
login_as(create(:moderator).user)
visit user_path(@user)
expect(page).to_not have_content('activity list private')
end
end
end end