From d7911e9486aa6dc0196c1be2b68882f7a0366a32 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 14 Nov 2022 23:11:09 +0100 Subject: [PATCH 01/14] Add input placeholder field to theme --- .../20221114214508_add_input_placeholder_to_themes.rb | 11 +++++++++++ db/schema.rb | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20221114214508_add_input_placeholder_to_themes.rb diff --git a/db/migrate/20221114214508_add_input_placeholder_to_themes.rb b/db/migrate/20221114214508_add_input_placeholder_to_themes.rb new file mode 100644 index 00000000..ca3d5687 --- /dev/null +++ b/db/migrate/20221114214508_add_input_placeholder_to_themes.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddInputPlaceholderToThemes < ActiveRecord::Migration[6.1] + def up + add_column :themes, :input_placeholder, :integer, default: 0x6C757D, null: false + end + + def down + remove_column :themes, :input_placeholder + end +end diff --git a/db/schema.rb b/db/schema.rb index ebffd650..1ba38cf6 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_14_214508) 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,8 @@ 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.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 752d6cb987aeaf9465a58e5aed9b31476486cd1f Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 14 Nov 2022 23:11:23 +0100 Subject: [PATCH 02/14] Make input placeholder themable --- app/javascript/styles/_variables.scss | 1 + app/javascript/styles/overrides/_inputs.scss | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/javascript/styles/_variables.scss b/app/javascript/styles/_variables.scss index afc864c4..9810883c 100644 --- a/app/javascript/styles/_variables.scss +++ b/app/javascript/styles/_variables.scss @@ -97,6 +97,7 @@ $spacers: ( --body-text: 0, 0, 0; --muted-text: 108, 117, 125; --input-text: 0, 0, 0; + --input-placeholder: 108, 117, 125; --turbolinks-progress-color: #a58adc; // --primary lightened by 25% } diff --git a/app/javascript/styles/overrides/_inputs.scss b/app/javascript/styles/overrides/_inputs.scss index bb2c75ce..a1ef2007 100644 --- a/app/javascript/styles/overrides/_inputs.scss +++ b/app/javascript/styles/overrides/_inputs.scss @@ -9,10 +9,14 @@ border-color: var(--primary); box-shadow: .5px 0 0 0.1rem var(--primary); } + + &::placeholder { + color: RGB(var(--input-placeholder)); + } } .input-group-text { color: RGB(var(--body-text)); background-color: var(--raised-accent); border: 0; -} \ No newline at end of file +} From 420a25872e0453a5f2787e8146ebfe5967821d5a Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 14 Nov 2022 23:12:39 +0100 Subject: [PATCH 03/14] Allow input placeholder in theme settings --- app/controllers/settings/theme_controller.rb | 2 +- app/views/settings/theme/edit.html.haml | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/settings/theme_controller.rb b/app/controllers/settings/theme_controller.rb index 22b702a2..14d6457b 100644 --- a/app/controllers/settings/theme_controller.rb +++ b/app/controllers/settings/theme_controller.rb @@ -19,7 +19,7 @@ class Settings::ThemeController < ApplicationController raised_background raised_accent background_color body_text muted_text input_color - input_text + input_text input_placeholder ]) if current_user.theme.nil? diff --git a/app/views/settings/theme/edit.html.haml b/app/views/settings/theme/edit.html.haml index 03623b73..51caa6fe 100644 --- a/app/views/settings/theme/edit.html.haml +++ b/app/views/settings/theme/edit.html.haml @@ -87,6 +87,14 @@ = f.text_field :input_color, class: "color", data: { default: 0xFFFFFF } .col-sm-6 = f.text_field :input_text, class: "color", data: { default: 0x000000 } + + .row + .col-sm-6 + = f.text_field :input_placeholder, class: "color", data: { default: 0x6C757D } + .col-sm-6 + .form-group + %label Example Input + %input.form-control{ placeholder: "A test placeholder" } .card .card-body %h2= t(".raised.heading") @@ -105,4 +113,4 @@ = f.primary - provide(:title, generate_title(t(".title"))) -- parent_layout "user/settings" \ No newline at end of file +- parent_layout "user/settings" From f35d49e5753ed9c42d99707f8e79739f05c27ab0 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 14 Nov 2022 23:13:22 +0100 Subject: [PATCH 04/14] Properly handle placeholder fields in theme application --- app/helpers/theme_helper.rb | 3 ++- app/javascript/retrospring/features/settings/theme.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/helpers/theme_helper.rb b/app/helpers/theme_helper.rb index 5ccb139a..4e99b6e7 100644 --- a/app/helpers/theme_helper.rb +++ b/app/helpers/theme_helper.rb @@ -20,6 +20,7 @@ module ThemeHelper 'body_text' => 'body-text', 'input_color' => 'input-bg', 'input_text' => 'input-text', + 'input_placeholder' => 'input-placeholder', 'muted_text' => 'muted-text' }.freeze @@ -33,7 +34,7 @@ module ThemeHelper theme.attributes.each do |k, v| next unless ATTRIBUTE_MAP.key?(k) - if k.include? 'text' + if k.include? 'text' or k.include? 'placeholder' hex = get_hex_color_from_theme_value(v) body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n" else diff --git a/app/javascript/retrospring/features/settings/theme.ts b/app/javascript/retrospring/features/settings/theme.ts index 541e5ea6..d2c4602b 100644 --- a/app/javascript/retrospring/features/settings/theme.ts +++ b/app/javascript/retrospring/features/settings/theme.ts @@ -36,6 +36,7 @@ const generateTheme = (payload: Record): void => { 'body_text': 'body-text', 'input_color': 'input-bg', 'input_text': 'input-text', + 'input_placeholder': 'input-placeholder', 'muted_text': 'muted-text' }; @@ -43,7 +44,7 @@ const generateTheme = (payload: Record): void => { (Object.keys(payload)).forEach((payloadKey) => { if (themeAttributeMap[payloadKey]) { - if (themeAttributeMap[payloadKey].includes('text')) { + if (themeAttributeMap[payloadKey].includes('text') || themeAttributeMap[payloadKey].includes('placeholder')) { const hex = getHexColorFromThemeValue(payload[payloadKey]); body += `--${themeAttributeMap[payloadKey]}: ${getDecimalTripletsFromHex(hex)};\n`; } @@ -111,4 +112,4 @@ export function themeSubmitHandler(): void { Array.from(document.querySelectorAll('#update .color')).forEach((color: HTMLInputElement) => { color.value = String(parseInt(color.value.substr(1, 6), 16)); }); -} \ No newline at end of file +} From 921f02c4c989c79a29e8421de6029b34b55086e4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 15 Nov 2022 00:32:54 +0100 Subject: [PATCH 05/14] Fix lints in ThemeHelper --- app/helpers/theme_helper.rb | 64 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/app/helpers/theme_helper.rb b/app/helpers/theme_helper.rb index 4e99b6e7..d1956600 100644 --- a/app/helpers/theme_helper.rb +++ b/app/helpers/theme_helper.rb @@ -1,27 +1,29 @@ +# frozen_string_literal: true + module ThemeHelper ATTRIBUTE_MAP = { - 'primary_color' => 'primary', - 'primary_text' => 'primary-text', - 'danger_color' => 'danger', - 'danger_text' => 'danger-text', - 'warning_color' => 'warning', - 'warning_text' => 'warning-text', - 'info_color' => 'info', - 'info_text' => 'info-text', - 'success_color' => 'success', - 'success_text' => 'success-text', - 'dark_color' => 'dark', - 'dark_text' => 'dark-text', - 'light_color' => 'light', - 'light_text' => 'light-text', - 'raised_background' => 'raised-bg', - 'raised_accent' => 'raised-accent', - 'background_color' => 'background', - 'body_text' => 'body-text', - 'input_color' => 'input-bg', - 'input_text' => 'input-text', - 'input_placeholder' => 'input-placeholder', - 'muted_text' => 'muted-text' + "primary_color" => "primary", + "primary_text" => "primary-text", + "danger_color" => "danger", + "danger_text" => "danger-text", + "warning_color" => "warning", + "warning_text" => "warning-text", + "info_color" => "info", + "info_text" => "info-text", + "success_color" => "success", + "success_text" => "success-text", + "dark_color" => "dark", + "dark_text" => "dark-text", + "light_color" => "light", + "light_text" => "light-text", + "raised_background" => "raised-bg", + "raised_accent" => "raised-accent", + "background_color" => "background", + "body_text" => "body-text", + "input_color" => "input-bg", + "input_text" => "input-text", + "input_placeholder" => "input-placeholder", + "muted_text" => "muted-text" }.freeze def render_theme @@ -34,7 +36,7 @@ module ThemeHelper theme.attributes.each do |k, v| next unless ATTRIBUTE_MAP.key?(k) - if k.include? 'text' or k.include? 'placeholder' + if k.include?("text") || k.include?("placeholder") hex = get_hex_color_from_theme_value(v) body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n" else @@ -43,7 +45,7 @@ module ThemeHelper end body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n" - body += '}' + body += "}" content_tag(:style, body) end @@ -53,7 +55,7 @@ module ThemeHelper if theme theme.theme_color else - '#5e35b1' + "#5e35b1" end end @@ -62,7 +64,7 @@ module ThemeHelper if theme theme.mobile_theme_color else - '#f0edf4' + "#f0edf4" end end @@ -93,12 +95,12 @@ module ThemeHelper end def get_hex_color_from_theme_value(value) - ("0000000#{value.to_s(16)}")[-6, 6] + "0000000#{value.to_s(16)}"[-6, 6] end def get_decimal_triplet_from_hex(value) - hexes = value.split(/(.{2})/).reject { |c| c.empty? } - hexes.map(&:hex).join(', ') + hexes = value.split(/(.{2})/).reject(&:empty?) + hexes.map(&:hex).join(", ") end def rgb_values_from_hex(value) @@ -110,10 +112,10 @@ module ThemeHelper end def rgb_to_hex(rgb_values) - rgb_values.map.with_index { |v, i| v << (2 - i) * 8 }.reduce(&:+).to_s(16) + rgb_values.map.with_index { |v, i| v << ((2 - i) * 8) }.reduce(&:+).to_s(16) end def lighten(value, amount = 0.25) - rgb_to_hex(rgb_values_from_hex(value).map { |v| [(v + 255 * amount).round, 255].min }) + rgb_to_hex(rgb_values_from_hex(value).map { |v| [(v + (255 * amount)).round, 255].min }) end end 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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 10/14] 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 11/14] 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 12/14] 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 13/14] 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 14/14] 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