diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index c46b6e42f..843d49498 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -25,8 +25,8 @@ class AccountController < ApplicationController if @account.organization? params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name]) else - params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter, :official_position_badge) + params.require(:account).permit(:username, :public_activity, :public_interests, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter, :official_position_badge) end end -end \ No newline at end of file +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e99102396..c5d919b3a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,6 +7,7 @@ class UsersController < ApplicationController def show load_filtered_activity if valid_access? + load_interest if valid_interest_access? end private @@ -62,10 +63,18 @@ class UsersController < ApplicationController @budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page]) end + def load_interest + @interests = Follow.interests_by(@user) + end + def valid_access? @user.public_activity || authorized_current_user? end + def valid_interest_access? + @user.public_interests || authorized_current_user? + end + def author? @author ||= current_user && (current_user == @user) end diff --git a/app/models/follow.rb b/app/models/follow.rb index ee44cac96..a7ca4a76b 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -18,4 +18,14 @@ class Follow < ActiveRecord::Base !! by_user_and_followable(user, followable).try(:first) end + def self.interests_by(user) + interests = [] + user.follows.each do |follow| + follow.followable.tags.each do |tag| + interests << tag.name + end + end + return interests.uniq + end + end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index a0d9f1693..a3407f5a7 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -40,6 +40,16 @@ <% end %> +
+ <%= f.label :public_interests do %> + <%= f.check_box :public_interests, title: t('account.show.public_interests_label'), label: false %> + + <%= t("account.show.public_interests_label") %> + + <% end %> +
+ + <% if @account.email.present? %>

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

diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c00769216..045a5bd63 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -46,6 +46,14 @@

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

<% end %> + <% if @user.public_interests || @authorized_current_user %> +
+ <% @interests.each do |interest| %> + <%= interest %> + <% end %> +
+ <% end %> + diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 408489fa1..b2ec63d06 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -13,6 +13,7 @@ en: personal: Personal details phone_number_label: Phone number public_activity_label: Keep my list of activities public + public_interests_label: Keep my interests public save_changes_submit: Save changes subscription_to_website_newsletter_label: Receive by email website relevant information email_on_direct_message_label: Receive emails about direct messages diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 72bed0a59..e149f1bc4 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -13,6 +13,7 @@ es: personal: Datos personales phone_number_label: Teléfono public_activity_label: Mostrar públicamente mi lista de actividades + public_interests_label: Mostrar públicamente mis intereses save_changes_submit: Guardar cambios subscription_to_website_newsletter_label: Recibir emails con información interesante sobre la web email_on_direct_message_label: Recibir emails con mensajes privados diff --git a/db/migrate/20170630105250_add_public_interests_to_user.rb b/db/migrate/20170630105250_add_public_interests_to_user.rb new file mode 100644 index 000000000..8fec4a748 --- /dev/null +++ b/db/migrate/20170630105250_add_public_interests_to_user.rb @@ -0,0 +1,5 @@ +class AddPublicInterestsToUser < ActiveRecord::Migration + def change + add_column :users, :public_interests, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 0ad6a401f..fc9c3e387 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -955,6 +955,7 @@ ActiveRecord::Schema.define(version: 20170704105112) do t.boolean "created_from_signature", default: false t.integer "failed_email_digests_count", default: 0 t.text "former_users_data_log", default: "" + t.boolean "public_interests", default: false 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 90ee6b94c..b9beef626 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -213,6 +213,88 @@ feature 'Users' do end + feature 'Public interest' do + background do + @user = create(:user) + end + + scenario 'show interests' do + proposal = create(:proposal, tag_list: "Sport") + create(:follow, :followed_proposal, followable: proposal, user: @user) + + login_as(@user) + visit account_path + + check 'account_public_interests' + click_button 'Save changes' + + logout + + visit user_path(@user) + expect(page).to have_content("Sport") + end + + scenario 'no visible by default' do + visit user_path(@user) + + expect(page).to have_content(@user.username) + expect(page).not_to have_css('#public_interests') + end + + scenario 'user can show public page' do + login_as(@user) + visit account_path + + check 'account_public_interests' + click_button 'Save changes' + + logout + + visit user_path(@user) + expect(page).to have_css('#public_interests') + end + + scenario 'is always visible for the owner' do + login_as(@user) + visit account_path + + uncheck 'account_public_interests' + click_button 'Save changes' + + visit user_path(@user) + expect(page).to have_css('#public_interests') + end + + scenario 'is always visible for admins' do + login_as(@user) + visit account_path + + uncheck 'account_public_interests' + click_button 'Save changes' + + logout + + login_as(create(:administrator).user) + visit user_path(@user) + expect(page).to have_css('#public_interests') + end + + scenario 'is always visible for moderators' do + login_as(@user) + visit account_path + + uncheck 'account_public_interests' + click_button 'Save changes' + + logout + + login_as(create(:moderator).user) + visit user_path(@user) + expect(page).to have_css('#public_interests') + end + + end + feature 'Special comments' do scenario 'comments posted as moderator are not visible in user activity' do diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index 4ea0238ec..46fa4653b 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -23,4 +23,17 @@ describe Follow do expect(follow).to_not be_valid end + describe "interests" do + + let(:user) { create(:user) } + + it "interests_by user" do + proposal = create(:proposal, tag_list: "Sport") + create(:follow, :followed_proposal, followable: proposal, user: user) + + expect(Follow.interests_by(user)).to eq ["Sport"] + end + + end + end