From 4c22d8e4b321fd9474b9183aca782c6047d1b656 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Nov 2022 21:44:14 +0000 Subject: [PATCH 1/9] Bump loader-utils from 1.4.1 to 1.4.2 Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.1 to 1.4.2. - [Release notes](https://github.com/webpack/loader-utils/releases) - [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.2/CHANGELOG.md) - [Commits](https://github.com/webpack/loader-utils/compare/v1.4.1...v1.4.2) --- updated-dependencies: - dependency-name: loader-utils dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index c2e25844..1f13d71d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4784,9 +4784,9 @@ loader-runner@^2.4.0: integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw== loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0: - version "1.4.1" - resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.1.tgz#278ad7006660bccc4d2c0c1578e17c5c78d5c0e0" - integrity sha512-1Qo97Y2oKaU+Ro2xnDMR26g1BwMT29jNbem1EvcujW2jqt+j5COXyscjM7bLQkM9HaxI7pkWeW7gnI072yMI9Q== + version "1.4.2" + resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.2.tgz#29a957f3a63973883eb684f10ffd3d151fec01a3" + integrity sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg== dependencies: big.js "^5.2.2" emojis-list "^3.0.0" From 0b499138e0e9cbfc7305153655cd631140494299 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:34:03 +0100 Subject: [PATCH 2/9] Add social graph hiding field to user --- .../20221115194933_add_privacy_hide_social_graph.rb | 9 +++++++++ db/schema.rb | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20221115194933_add_privacy_hide_social_graph.rb diff --git a/db/migrate/20221115194933_add_privacy_hide_social_graph.rb b/db/migrate/20221115194933_add_privacy_hide_social_graph.rb new file mode 100644 index 00000000..dde49d97 --- /dev/null +++ b/db/migrate/20221115194933_add_privacy_hide_social_graph.rb @@ -0,0 +1,9 @@ +class AddPrivacyHideSocialGraph < ActiveRecord::Migration[6.1] + def up + add_column :users, :privacy_hide_social_graph, :boolean, default: false + end + + def down + remove_column :users, :privacy_hide_social_graph + end +end diff --git a/db/schema.rb b/db/schema.rb index ebffd650..563a2ac3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_11_13_110942) do +ActiveRecord::Schema.define(version: 2022_11_15_194933) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -228,6 +228,7 @@ ActiveRecord::Schema.define(version: 2022_11_13_110942) do t.integer "raised_accent", default: 16250871 t.integer "light_color", default: 16316922 t.integer "light_text", default: 0 + t.integer "input_placeholder", default: 7107965, null: false t.index ["user_id", "created_at"], name: "index_themes_on_user_id_and_created_at" end @@ -292,9 +293,9 @@ ActiveRecord::Schema.define(version: 2022_11_13_110942) do t.datetime "export_created_at" t.string "otp_secret_key" t.integer "otp_module", default: 0, null: false - t.datetime "deleted_at" - t.boolean "privacy_require_user", default: false t.boolean "privacy_lock_inbox", default: false + t.boolean "privacy_require_user", default: false + t.boolean "privacy_hide_social_graph", default: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true From 9249ef976b81fdc4e7e9b312c1aafe28f756bfc3 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:34:45 +0100 Subject: [PATCH 3/9] Add social graph field to privacy settings view --- app/controllers/settings/privacy_controller.rb | 3 ++- app/views/settings/privacy/edit.html.haml | 1 + config/locales/activerecord.en.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/settings/privacy_controller.rb b/app/controllers/settings/privacy_controller.rb index 55d553e8..6deea58a 100644 --- a/app/controllers/settings/privacy_controller.rb +++ b/app/controllers/settings/privacy_controller.rb @@ -11,7 +11,8 @@ class Settings::PrivacyController < ApplicationController :privacy_allow_public_timeline, :privacy_allow_stranger_answers, :privacy_show_in_search, - :privacy_require_user) + :privacy_require_user, + :privacy_hide_social_graph) if current_user.update(user_attributes) flash[:success] = t(".success") else diff --git a/app/views/settings/privacy/edit.html.haml b/app/views/settings/privacy/edit.html.haml index a0f25626..f320c928 100644 --- a/app/views/settings/privacy/edit.html.haml +++ b/app/views/settings/privacy/edit.html.haml @@ -6,6 +6,7 @@ = f.check_box :privacy_require_user = f.check_box :privacy_allow_public_timeline = f.check_box :privacy_allow_stranger_answers + = f.check_box :privacy_hide_social_graph = f.primary diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 956a3d5e..e0992444 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -72,6 +72,7 @@ en: privacy_require_user: "Require users to be logged in to ask you questions" privacy_allow_public_timeline: "Show your answers in the public timeline" privacy_allow_stranger_answers: "Allow other people to answer your questions" + privacy_hide_social_graph: "Hide your social graph" profile_picture: "Profile picture" profile_header: "Profile header" sign_in_count: "Sign in count" From 51a70b67f4c33218bfcb3b3fa64eaea396bfc026 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:35:13 +0100 Subject: [PATCH 4/9] Hide follower/followings tabs if social graph is hidden --- app/views/tabs/_profile.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/tabs/_profile.html.haml b/app/views/tabs/_profile.html.haml index ee490edd..06ceceac 100644 --- a/app/views/tabs/_profile.html.haml +++ b/app/views/tabs/_profile.html.haml @@ -2,5 +2,6 @@ .list-group.list-group-horizontal-sm.text-center = list_group_item t(".answers"), user_path(user), badge: user.answered_count = list_group_item t(".questions"), show_user_questions_path(user.screen_name), badge: user.asked_count - = list_group_item t(".followers"), show_user_followers_path(user.screen_name), badge: user.followers.count - = list_group_item t(".following"), show_user_followings_path(user.screen_name), badge: user.followings.count + - if user == current_user || !user.privacy_hide_social_graph + = list_group_item t(".followers"), show_user_followers_path(user.screen_name), badge: user.followers.count + = list_group_item t(".following"), show_user_followings_path(user.screen_name), badge: user.followings.count From 8699a4ca0869153f5fcac646fe6710d805231501 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:36:06 +0100 Subject: [PATCH 5/9] Redirect from follower/following page if social graph is hidden --- app/controllers/user_controller.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 119bd17a..119b056e 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,6 +1,8 @@ class UserController < ApplicationController + before_action :set_user + before_action :hidden_social_graph_redirect, only: %i[followers followings] + def show - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @answers = @user.cursored_answers(last_id: params[:last_id]) @answers_last_id = @answers.map(&:id).min @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? @@ -21,7 +23,6 @@ class UserController < ApplicationController def followers @title = 'Followers' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? @@ -37,7 +38,6 @@ class UserController < ApplicationController # rubocop:disable Metrics/AbcSize def followings @title = 'Following' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @relationships = @user.cursored_following_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? @@ -53,7 +53,6 @@ class UserController < ApplicationController def questions @title = 'Questions' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @questions = @user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: params[:last_id]) @questions_last_id = @questions.map(&:id).min @more_data_available = !@user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: @questions_last_id, size: 1).count.zero? @@ -66,5 +65,15 @@ class UserController < ApplicationController private + def set_user + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! + end + + def hidden_social_graph_redirect + unless belongs_to_current_user? || !@user.privacy_hide_social_graph + redirect_to user_path(@user) + end + end + def belongs_to_current_user? = @user == current_user end From 92d5918b91ac3254f97c4d93d1ef423d3e9c3b09 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:36:24 +0100 Subject: [PATCH 6/9] Add tests for social graph hiding setting --- spec/controllers/user_controller_spec.rb | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 11599f0a..b66b50b8 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -9,6 +9,32 @@ describe UserController, type: :controller do otp_secret_key: "EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3" end + shared_examples_for "social graph hidden" do + context "user has social graph hidden" do + before(:each) do + user.update(privacy_hide_social_graph: true) + end + + it "shows the followers template to the current user" do + sign_in user + subject + expect(assigns(:user)).to eq(user) + expect(response).to render_template("user/show_follow") + end + + it "redirects to the user profile page if not logged in" do + subject + expect(response).to redirect_to(user_path(user)) + end + + it "redirects to the user profile page if logged in as a different user" do + sign_in FactoryBot.create(:user) + subject + expect(response).to redirect_to(user_path(user)) + end + end + end + describe "#show" do subject { get :show, params: { username: user.screen_name } } @@ -35,6 +61,8 @@ describe UserController, type: :controller do expect(response).to render_template("user/show_follow") end end + + include_examples "social graph hidden" end describe "#followings" do @@ -49,6 +77,8 @@ describe UserController, type: :controller do expect(response).to render_template("user/show_follow") end end + + include_examples "social graph hidden" end describe "#questions" do From fe9a77cd6729d3a5c32fc0a8c7492c9da941cdc7 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 21:41:05 +0100 Subject: [PATCH 7/9] Fix lints --- app/controllers/user_controller.rb | 18 +++++++++--------- ...1115194933_add_privacy_hide_social_graph.rb | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 119b056e..f71e41dc 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UserController < ApplicationController before_action :set_user before_action :hidden_social_graph_redirect, only: %i[followers followings] @@ -22,7 +24,7 @@ class UserController < ApplicationController end def followers - @title = 'Followers' + @title = "Followers" @relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? @@ -35,9 +37,8 @@ class UserController < ApplicationController end end - # rubocop:disable Metrics/AbcSize def followings - @title = 'Following' + @title = "Following" @relationships = @user.cursored_following_relationships(last_id: params[:last_id]) @relationships_last_id = @relationships.map(&:id).min @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? @@ -49,10 +50,9 @@ class UserController < ApplicationController format.turbo_stream { render "show_follow" } end end - # rubocop:enable Metrics/AbcSize def questions - @title = 'Questions' + @title = "Questions" @questions = @user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: params[:last_id]) @questions_last_id = @questions.map(&:id).min @more_data_available = !@user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: @questions_last_id, size: 1).count.zero? @@ -66,13 +66,13 @@ class UserController < ApplicationController private def set_user - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! + @user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first! end def hidden_social_graph_redirect - unless belongs_to_current_user? || !@user.privacy_hide_social_graph - redirect_to user_path(@user) - end + return if belongs_to_current_user? || !@user.privacy_hide_social_graph + + redirect_to user_path(@user) end def belongs_to_current_user? = @user == current_user diff --git a/db/migrate/20221115194933_add_privacy_hide_social_graph.rb b/db/migrate/20221115194933_add_privacy_hide_social_graph.rb index dde49d97..8685dafb 100644 --- a/db/migrate/20221115194933_add_privacy_hide_social_graph.rb +++ b/db/migrate/20221115194933_add_privacy_hide_social_graph.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPrivacyHideSocialGraph < ActiveRecord::Migration[6.1] def up add_column :users, :privacy_hide_social_graph, :boolean, default: false From aced806d02ebc06db81dc1b9276cd23d302a20b4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 23:14:32 +0100 Subject: [PATCH 8/9] Apply review suggestion from @nilsding Co-authored-by: Georg Gadinger --- config/locales/activerecord.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index e0992444..2d619968 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -72,7 +72,7 @@ en: privacy_require_user: "Require users to be logged in to ask you questions" privacy_allow_public_timeline: "Show your answers in the public timeline" privacy_allow_stranger_answers: "Allow other people to answer your questions" - privacy_hide_social_graph: "Hide your social graph" + privacy_hide_social_graph: "Hide your social graph from others" profile_picture: "Profile picture" profile_header: "Profile header" sign_in_count: "Sign in count" From 88375f7d2186d47f94bc9d98a25403dc8ee79b36 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 23:18:20 +0100 Subject: [PATCH 9/9] Cleanup schema --- db/schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 563a2ac3..ea7dc831 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -228,7 +228,6 @@ ActiveRecord::Schema.define(version: 2022_11_15_194933) do t.integer "raised_accent", default: 16250871 t.integer "light_color", default: 16316922 t.integer "light_text", default: 0 - t.integer "input_placeholder", default: 7107965, null: false t.index ["user_id", "created_at"], name: "index_themes_on_user_id_and_created_at" end