From 7f1fe034a30993cf171615e16e5afabcc2ca8043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Thu, 29 Oct 2015 18:26:33 +0100 Subject: [PATCH 01/12] adds user's public show page --- app/controllers/users_controller.rb | 54 +++++++++++++++++++++++++++++ app/models/abilities/everyone.rb | 1 + app/views/users/show.html.erb | 15 ++++++++ config/locales/en.yml | 13 +++++++ config/locales/es.yml | 13 +++++++ config/routes.rb | 2 ++ 6 files changed, 98 insertions(+) create mode 100644 app/controllers/users_controller.rb create mode 100644 app/views/users/show.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..38c36b7cc --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,54 @@ +class UsersController < ApplicationController + has_filters %w{proposals debates comments}, only: :show + + load_and_authorize_resource + + before_action :set_activity_counts, only: :show + + def show + load_filtered_activity + end + + private + def set_activity_counts + @activity_counts = HashWithIndifferentAccess.new( + proposals: Proposal.where(author_id: @user.id).count, + debates: Debate.where(author_id: @user.id).count, + comments: Comment.where(user_id: @user.id).count) + end + + def load_filtered_activity + case params[:filter] + when "proposals" then load_proposals + when "debates" then load_debates + when "comments" then load_comments + else load_available_activity + end + end + + def load_available_activity + if @activity_counts[:proposals] > 0 + load_proposals + @current_filter = "proposals" + elsif @activity_counts[:debates] > 0 + load_debates + @current_filter = "debates" + elsif @activity_counts[:comments] > 0 + load_comments + @current_filter = "comments" + end + end + + def load_proposals + @proposals = Proposal.where(author_id: @user.id).order(created_at: :desc).page(params[:page]) + end + + def load_debates + @debates = Debate.where(author_id: @user.id).order(created_at: :desc).page(params[:page]) + end + + def load_comments + @comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page]) + end + +end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 5f5de51b7..691735b10 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -5,6 +5,7 @@ module Abilities def initialize(user) can :read, Debate can :read, Proposal + can :read, User end end end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 000000000..8850a3586 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,15 @@ +

<%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %>

+ + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2d963f3be..d4e838961 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -324,6 +324,19 @@ en: check: "Select" check_all: "All" check_none: "None" + users: + show: + filters: + proposals: + one: "1 Proposal" + other: "%{count} Proposals" + debates: + one: "1 Debate" + other: "%{count} Debates" + comments: + one: "1 Comment" + other: "%{count} Comments" + no_activity: "Usuario sin actividad pública" unauthorized: default: "You do not have permission to access this page." manage: diff --git a/config/locales/es.yml b/config/locales/es.yml index 34871cce8..90c80f8b5 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -324,6 +324,19 @@ es: check: "Seleccionar" check_all: "Todos" check_none: "Ninguno" + users: + show: + filters: + proposals: + one: "1 Propuesta" + other: "%{count} Propuestas" + debates: + one: "1 Debate" + other: "%{count} Debates" + comments: + one: "1 Comentario" + other: "%{count} Comentarios" + no_activity: "Usuario sin actividad pública" unauthorized: default: "No tienes permiso para acceder a esta página." manage: diff --git a/config/routes.rb b/config/routes.rb index 3a63fa3b1..cb42ef6da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,6 +61,8 @@ Rails.application.routes.draw do end end + resources :users, only: [:show] + resource :account, controller: "account", only: [:show, :update, :delete] do collection { get :erase } end From 15e2ca815de0c719700d3dff1b90e3c96d71ed57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 3 Nov 2015 14:34:04 +0100 Subject: [PATCH 02/12] adds activity page with user's proposals --- app/views/users/_activity_page.html.erb | 4 ++++ app/views/users/_comments.html.erb | 0 app/views/users/_debates.html.erb | 0 app/views/users/_proposals.html.erb | 13 +++++++++++++ app/views/users/show.html.erb | 4 +++- 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_activity_page.html.erb create mode 100644 app/views/users/_comments.html.erb create mode 100644 app/views/users/_debates.html.erb create mode 100644 app/views/users/_proposals.html.erb diff --git a/app/views/users/_activity_page.html.erb b/app/views/users/_activity_page.html.erb new file mode 100644 index 000000000..0b39ad241 --- /dev/null +++ b/app/views/users/_activity_page.html.erb @@ -0,0 +1,4 @@ +<%= render "proposals" if @proposals.present? %> +<%= render "debates" if @debates.present? %> +<%= render "comments" if @comments.present? %> + diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/users/_debates.html.erb b/app/views/users/_debates.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb new file mode 100644 index 000000000..d2adebed0 --- /dev/null +++ b/app/views/users/_proposals.html.erb @@ -0,0 +1,13 @@ + + <% @proposals.each do |proposal| %> + + + + <% end %> +
+ <%= link_to proposal.title, proposal %> +
+ <%= proposal.summary %> +
+ +<%= paginate @proposals %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8850a3586..133592150 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -12,4 +12,6 @@ <% end %> <% end %> <%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %> - \ No newline at end of file + + +<%= render "activity_page" %> \ No newline at end of file From 7b2e09d54d0194f37d090695e4a61afbba7c4624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 3 Nov 2015 14:39:33 +0100 Subject: [PATCH 03/12] adds debates to user's page --- app/views/users/_debates.html.erb | 11 +++++++++++ app/views/users/_proposals.html.erb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/views/users/_debates.html.erb b/app/views/users/_debates.html.erb index e69de29bb..bc1be352f 100644 --- a/app/views/users/_debates.html.erb +++ b/app/views/users/_debates.html.erb @@ -0,0 +1,11 @@ + + <% @debates.each do |debate| %> + + + + <% end %> +
+ <%= link_to debate.title, debate %> +
+ +<%= paginate @debates %> \ No newline at end of file diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index d2adebed0..f41c6d49d 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -3,7 +3,7 @@ <%= link_to proposal.title, proposal %> -
+
<%= proposal.summary %> From e8232f296e4f484e4447b9bf0bf26dc351830a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 3 Nov 2015 19:00:49 +0100 Subject: [PATCH 04/12] adds comments to user's page --- app/views/users/_comments.html.erb | 13 +++++++++++++ config/locales/en.yml | 3 ++- config/locales/es.yml | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index e69de29bb..62be0edc2 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -0,0 +1,13 @@ + + <% @comments.each do |comment| %> + + + + <% end %> +
+ <%= t("users.show.comment_to") %> <%= link_to comment.commentable.title, comment.commentable %> +
+ <%= comment.body %> +
+ +<%= paginate @comments %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d4e838961..cb3c53059 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -336,7 +336,8 @@ en: comments: one: "1 Comment" other: "%{count} Comments" - no_activity: "Usuario sin actividad pública" + no_activity: "User has no public activity" + comment_to: "Comment in " unauthorized: default: "You do not have permission to access this page." manage: diff --git a/config/locales/es.yml b/config/locales/es.yml index 90c80f8b5..89eed3583 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -337,6 +337,7 @@ es: one: "1 Comentario" other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" + comment_to: "Comentario en " unauthorized: default: "No tienes permiso para acceder a esta página." manage: From fe0618e2c1e0ae6c3433226f8b54b4eb39e4bd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 3 Nov 2015 19:52:06 +0100 Subject: [PATCH 05/12] restyling user's page --- app/views/users/_comments.html.erb | 5 +++- app/views/users/show.html.erb | 38 ++++++++++++++++++------------ config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index 62be0edc2..1340fdb7e 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -2,7 +2,10 @@ <% @comments.each do |comment| %> - <%= t("users.show.comment_to") %> <%= link_to comment.commentable.title, comment.commentable %> + + <%= t("users.show.comment_to") %> + <%= comment.commentable.hidden? ? comment.commentable.title : link_to(comment.commentable.title, comment.commentable) %> +
<%= comment.body %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 133592150..4f5bc3e20 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,17 +1,25 @@ -

<%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %>

+
+
+
- +

<%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %>

-<%= render "activity_page" %> \ No newline at end of file + + + <%= render "activity_page" %> + +
+
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index cb3c53059..db8505853 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -337,7 +337,7 @@ en: one: "1 Comment" other: "%{count} Comments" no_activity: "User has no public activity" - comment_to: "Comment in " + comment_to: "Comment in: " unauthorized: default: "You do not have permission to access this page." manage: diff --git a/config/locales/es.yml b/config/locales/es.yml index 89eed3583..b9b6b8a9c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -337,7 +337,7 @@ es: one: "1 Comentario" other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" - comment_to: "Comentario en " + comment_to: "Comentario en: " unauthorized: default: "No tienes permiso para acceder a esta página." manage: From 8c4444985f0c32f5c5ffa1a08b8beefd58321c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 3 Nov 2015 20:18:00 +0100 Subject: [PATCH 06/12] renames spec --- spec/features/{users_spec.rb => users_auth_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/features/{users_spec.rb => users_auth_spec.rb} (100%) diff --git a/spec/features/users_spec.rb b/spec/features/users_auth_spec.rb similarity index 100% rename from spec/features/users_spec.rb rename to spec/features/users_auth_spec.rb From 6d26901f9f579881eb9dd1c7c89d18b5cd8e0d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Tue, 3 Nov 2015 20:26:13 +0100 Subject: [PATCH 07/12] adds specs for user's page --- config/i18n-tasks.yml | 1 + spec/features/users_spec.rb | 68 ++++++++++++++++++++++++++++ spec/models/abilities/common_spec.rb | 2 +- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 spec/features/users_spec.rb diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index d725a77d8..c6393c23a 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -120,6 +120,7 @@ ignore_unused: - 'moderation.proposals.index.order*' - 'moderation.debates.index.filter*' - 'moderation.debates.index.order*' + - 'users.show.filters.*' - 'debates.index.orders.*' - 'debates.index.search_form.*' - 'proposals.index.orders.*' diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb new file mode 100644 index 000000000..8d203ffec --- /dev/null +++ b/spec/features/users_spec.rb @@ -0,0 +1,68 @@ +require 'rails_helper' + +feature 'Users' do + + feature 'Show (public page)' do + + background do + @user = create(:user) + 1.times {create(:debate, author: @user)} + 2.times {create(:proposal, author: @user)} + 3.times {create(:comment, user: @user)} + + visit user_path(@user) + end + + scenario 'shows user public activity' do + expect(page).to have_content('1 Debate') + expect(page).to have_content('2 Proposals') + expect(page).to have_content('3 Comments') + end + + scenario 'default filter is proposals' do + @user.proposals.each do |proposal| + expect(page).to have_content(proposal.title) + end + + @user.debates.each do |debate| + expect(page).to_not have_content(debate.title) + end + + @user.comments.each do |comment| + expect(page).to_not have_content(comment.body) + end + end + + scenario 'filters' do + click_link '1 Debate' + + @user.debates.each do |debate| + expect(page).to have_content(debate.title) + end + + @user.proposals.each do |proposal| + expect(page).to_not have_content(proposal.title) + end + + @user.comments.each do |comment| + expect(page).to_not have_content(comment.body) + end + + click_link '3 Comments' + + @user.comments.each do |comment| + expect(page).to have_content(comment.body) + end + + @user.proposals.each do |proposal| + expect(page).to_not have_content(proposal.title) + end + + @user.debates.each do |debate| + expect(page).to_not have_content(debate.title) + end + end + + end + +end \ No newline at end of file diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 8e93f5bca..4775cd1ee 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -57,7 +57,7 @@ describe "Abilities::Common" do describe "other users" do let(:other_user) { create(:user) } - it { should_not be_able_to(:show, other_user) } + it { should be_able_to(:show, other_user) } it { should_not be_able_to(:edit, other_user) } end From f57eef4929a21ccf81c7816fded8ef0923c04622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 4 Nov 2015 13:47:55 +0100 Subject: [PATCH 08/12] makes public activity toggleable --- app/controllers/account_controller.rb | 2 +- app/controllers/users_controller.rb | 12 +++- app/views/devise/menu/_login_items.html.erb | 3 + app/views/users/show.html.erb | 28 ++++---- config/locales/en.yml | 2 + config/locales/es.yml | 2 + ...1103194329_add_public_activity_to_users.rb | 5 ++ db/schema.rb | 3 +- spec/features/users_spec.rb | 65 +++++++++++++++++++ 9 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20151103194329_add_public_activity_to_users.rb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 38bd4bfe5..f2a553c38 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38c36b7cc..a978cd1ce 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/devise/menu/_login_items.html.erb b/app/views/devise/menu/_login_items.html.erb index 6cd27160d..b0998949f 100644 --- a/app/views/devise/menu/_login_items.html.erb +++ b/app/views/devise/menu/_login_items.html.erb @@ -1,5 +1,8 @@
    <% if user_signed_in? %> +
  • + <%= link_to(t("layouts.header.my_activity_link"), user_path(current_user)) %> +
  • <%= link_to(t("layouts.header.my_account_link"), account_path) %>
  • diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 4f5bc3e20..51bfee34c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,21 +4,25 @@

    <%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %>

    - - <%= render "activity_page" %> + <%= render "activity_page" %> + <% else %> +

    <%= t('users.show.private_activity') %>

    + <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index db8505853..506a13763 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -283,6 +283,7 @@ en: title: "My account" save_changes_submit: "Save changes" 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_reply_label: "Notify me by email when someone replies to my comments" erase_account_link: "Erase my account" @@ -337,6 +338,7 @@ en: one: "1 Comment" other: "%{count} Comments" no_activity: "User has no public activity" + private_activity: "This user decided to keep the activity list private" comment_to: "Comment in: " unauthorized: default: "You do not have permission to access this page." diff --git a/config/locales/es.yml b/config/locales/es.yml index b9b6b8a9c..2fb7b5ccf 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -283,6 +283,7 @@ es: title: "Mi cuenta" save_changes_submit: "Guardar cambios" 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_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" erase_account_link: "Darme de baja" @@ -337,6 +338,7 @@ es: one: "1 Comentario" other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" + private_activity: "Este usuario ha decidido mantener en privado su lista de actividades" comment_to: "Comentario en: " unauthorized: default: "No tienes permiso para acceder a esta página." diff --git a/db/migrate/20151103194329_add_public_activity_to_users.rb b/db/migrate/20151103194329_add_public_activity_to_users.rb new file mode 100644 index 000000000..8feebdff7 --- /dev/null +++ b/db/migrate/20151103194329_add_public_activity_to_users.rb @@ -0,0 +1,5 @@ +class AddPublicActivityToUsers < ActiveRecord::Migration + def change + add_column :users, :public_activity, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 320bfffc1..fe174eb0c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -306,6 +306,7 @@ ActiveRecord::Schema.define(version: 20151103175139) do t.datetime "level_two_verified_at" t.string "erase_reason" t.datetime "erased_at" + t.boolean "public_activity", default: true end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 8d203ffec..26500797c 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -65,4 +65,69 @@ feature 'Users' do 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 \ No newline at end of file From 3465b00e89d4c927db9a46e13425baedee1c2f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 4 Nov 2015 13:51:57 +0100 Subject: [PATCH 09/12] adds 'My activity' link --- app/views/account/show.html.erb | 7 +++++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + 3 files changed, 9 insertions(+) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 40cf43a59..5acf6eb62 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -31,6 +31,13 @@ <% end %> +
    + <%= f.label :public_activity do %> + <%= f.check_box :public_activity, label: false %> + <%= t("account.show.public_activity_label") %> + <% end %> +
    +

    <%= t("account.show.notifications")%>

    diff --git a/config/locales/en.yml b/config/locales/en.yml index 506a13763..52f246518 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -22,6 +22,7 @@ en: "There are cities that are governed directly by their inhabitants, who discuss the topics they are concerned about, propose ideas to improve their lives and decide among themselves which ones will be carried out. Madrid is already one of these cities." see_all: "See proposals" + my_activity_link: "My activity" my_account_link: "My account" locale: "Language:" administration: "Administration" diff --git a/config/locales/es.yml b/config/locales/es.yml index 2fb7b5ccf..df76271c1 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -22,6 +22,7 @@ es: "Existen ciudades gobernadas directamente por sus habitantes, que debaten sobre temas que les preocupan, proponen ideas para mejorar sus vidas y deciden entre todas y todos las que se llevan a cabo. Madrid ya es una de ellas." see_all: "Ver propuestas" + my_activity_link: "Mi actividad" my_account_link: "Mi cuenta" locale: "Idioma:" administration: "Administrar" From 2671b25ba6e3b57a9247544d3e8343b357c60ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 4 Nov 2015 14:09:16 +0100 Subject: [PATCH 10/12] makes author name a link to activity page in debates/proposals/comments --- app/views/comments/_comment.html.erb | 2 +- app/views/shared/_author_info.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 1ec571633..dcf02d084 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -36,7 +36,7 @@ <% if comment.user.hidden? || comment.user.erased? %> <%= t("comments.comment.user_deleted") %> <% else %> - <%= comment.user.name %> + <%= link_to comment.user.name, user_path(comment.user) %> <% if comment.user.official? %>  •  diff --git a/app/views/shared/_author_info.html.erb b/app/views/shared/_author_info.html.erb index ee5c1f749..b51d3a261 100644 --- a/app/views/shared/_author_info.html.erb +++ b/app/views/shared/_author_info.html.erb @@ -7,7 +7,7 @@ <% else %> - <%= resource.author.name %> + <%= link_to resource.author.name, user_path(resource.author) %> <% if resource.author.official? %>  •  From b1ea8f79382ed55ced213410b8eedf5badafa7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Thu, 5 Nov 2015 16:39:09 +0100 Subject: [PATCH 11/12] increases coverage of user page --- spec/features/users_spec.rb | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 26500797c..4b90e737b 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -19,6 +19,14 @@ feature 'Users' do expect(page).to have_content('3 Comments') end + scenario 'shows only items where user has activity' do + @user.proposals.destroy_all + + expect(page).to_not have_content('0 Proposals') + expect(page).to have_content('1 Debate') + expect(page).to have_content('3 Comments') + end + scenario 'default filter is proposals' do @user.proposals.each do |proposal| expect(page).to have_content(proposal.title) @@ -33,6 +41,23 @@ feature 'Users' do end end + scenario 'shows debates by default if user has no proposals' do + @user.proposals.destroy_all + visit user_path(@user) + + expect(page).to have_content(@user.debates.first.title) + end + + scenario 'shows comments by default if user has no proposals nor debates' do + @user.proposals.destroy_all + @user.debates.destroy_all + visit user_path(@user) + + @user.comments.each do |comment| + expect(page).to have_content(comment.body) + end + end + scenario 'filters' do click_link '1 Debate' @@ -61,6 +86,20 @@ feature 'Users' do @user.debates.each do |debate| expect(page).to_not have_content(debate.title) end + + click_link '2 Proposals' + + @user.proposals.each do |proposal| + expect(page).to have_content(proposal.title) + end + + @user.comments.each do |comment| + expect(page).to_not have_content(comment.body) + end + + @user.debates.each do |debate| + expect(page).to_not have_content(debate.title) + end end end From ca8f41031918ecfe608761f2c0e53dee3eada0a8 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 6 Nov 2015 12:28:04 +0100 Subject: [PATCH 12/12] Adds styles for user's activity page --- app/assets/stylesheets/layout.scss | 56 +++++++++++++++++++++++ app/assets/stylesheets/participation.scss | 9 +++- app/views/users/_activity_page.html.erb | 1 - app/views/users/_comments.html.erb | 7 +-- app/views/users/_debates.html.erb | 2 +- app/views/users/_proposals.html.erb | 2 +- app/views/users/show.html.erb | 4 +- config/locales/en.yml | 1 - config/locales/es.yml | 1 - db/schema.rb | 4 +- 10 files changed, 73 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 2a78d3cc7..0be3d4eea 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -20,6 +20,7 @@ // 18. Comments // 19. Flags // 20. Accesibility +// 21. Activity // // 01. Variables @@ -2015,3 +2016,58 @@ table { clip: rect(0, 0, 0, 0); border: 0; } + +// 21. Activity +// - - - - - - - - - - - - - - - - - - - - - - - - - + +.activity { + margin-bottom: rem-calc(48); + margin-top: rem-calc(24); + + .sub-nav { + background: none; + border-bottom: 1px solid $border; + border-radius: 0; + padding-bottom: 0; + + dd.active { + background: none; + border-bottom: 2px solid $brand; + border-radius: 0; + color: $brand; + } + } + + table { + border: 0; + + td { + padding-left: rem-calc(36); + position: relative; + + &:before { + color: $brand; + font-family: "icons" !important; + font-size: rem-calc(24); + left: 4px; + position: absolute; + + } + } + + &.activity-comments td:before { + content: "e"; + top: 18px; + } + + &.activity-debates td:before { + content: "i"; + top: 14px; + } + + &.activity-proposals td:before { + content: "h"; + top: 18px; + } + } +} diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 583b614b3..1415ef33d 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -416,8 +416,15 @@ } .author { - color: $text; font-weight: bold; + + a { + color: $link !important; + + &:hover { + color: $link-hover !important; + } + } } aside { diff --git a/app/views/users/_activity_page.html.erb b/app/views/users/_activity_page.html.erb index 0b39ad241..296f7e5c2 100644 --- a/app/views/users/_activity_page.html.erb +++ b/app/views/users/_activity_page.html.erb @@ -1,4 +1,3 @@ <%= render "proposals" if @proposals.present? %> <%= render "debates" if @debates.present? %> <%= render "comments" if @comments.present? %> - diff --git a/app/views/users/_comments.html.erb b/app/views/users/_comments.html.erb index 1340fdb7e..2a8c9d66b 100644 --- a/app/views/users/_comments.html.erb +++ b/app/views/users/_comments.html.erb @@ -1,11 +1,8 @@ - +
    <% @comments.each do |comment| %> diff --git a/app/views/users/_debates.html.erb b/app/views/users/_debates.html.erb index bc1be352f..53fc0d58e 100644 --- a/app/views/users/_debates.html.erb +++ b/app/views/users/_debates.html.erb @@ -1,4 +1,4 @@ -
    - - <%= t("users.show.comment_to") %> - <%= comment.commentable.hidden? ? comment.commentable.title : link_to(comment.commentable.title, comment.commentable) %> - + <%= comment.commentable.hidden? ? comment.commentable.title : link_to(comment.commentable.title, comment.commentable) %>
    <%= comment.body %>
    +
    <% @debates.each do |debate| %>
    diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index f41c6d49d..a8ec5061e 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -1,4 +1,4 @@ - +
    <% @proposals.each do |proposal| %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 51bfee34c..2be31b272 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,6 +1,6 @@
    -
    -
    +
    +

    <%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %>

    diff --git a/config/locales/en.yml b/config/locales/en.yml index 52f246518..2f61df27e 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -340,7 +340,6 @@ en: other: "%{count} Comments" no_activity: "User has no public activity" private_activity: "This user decided to keep the activity list private" - comment_to: "Comment in: " unauthorized: default: "You do not have permission to access this page." manage: diff --git a/config/locales/es.yml b/config/locales/es.yml index df76271c1..aa2036f1d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -340,7 +340,6 @@ es: other: "%{count} Comentarios" no_activity: "Usuario sin actividad pública" private_activity: "Este usuario ha decidido mantener en privado su lista de actividades" - comment_to: "Comentario en: " unauthorized: default: "No tienes permiso para acceder a esta página." manage: diff --git a/db/schema.rb b/db/schema.rb index fe174eb0c..95bd4a36d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -95,10 +95,10 @@ ActiveRecord::Schema.define(version: 20151103194329) do t.string "visit_id" t.datetime "hidden_at" t.integer "flags_count", default: 0 - t.datetime "ignored_flag_at" t.integer "cached_votes_total", default: 0 t.integer "cached_votes_up", default: 0 t.integer "cached_votes_down", default: 0 + t.datetime "ignored_flag_at" t.integer "comments_count", default: 0 t.datetime "confirmed_hide_at" t.integer "cached_anonymous_votes_total", default: 0 @@ -114,6 +114,7 @@ ActiveRecord::Schema.define(version: 20151103194329) do add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree + add_index "debates", ["description"], name: "index_debates_on_description", using: :btree add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree add_index "debates", ["title"], name: "index_debates_on_title", using: :btree @@ -220,6 +221,7 @@ ActiveRecord::Schema.define(version: 20151103194329) do add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree + add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree add_index "proposals", ["question"], name: "index_proposals_on_question", using: :btree