Merge branch 'main' into feature/privacy-noindex

This commit is contained in:
Andreas Nedbal 2022-11-18 23:23:01 +01:00 committed by GitHub
commit 23dafb5bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 133 additions and 50 deletions

View File

@ -12,7 +12,8 @@ class Settings::PrivacyController < ApplicationController
:privacy_allow_stranger_answers, :privacy_allow_stranger_answers,
:privacy_show_in_search, :privacy_show_in_search,
:privacy_require_user, :privacy_require_user,
:privacy_noindex) :privacy_noindex,
:privacy_hide_social_graph)
if current_user.update(user_attributes) if current_user.update(user_attributes)
flash[:success] = t(".success") flash[:success] = t(".success")
else else

View File

@ -19,7 +19,7 @@ class Settings::ThemeController < ApplicationController
raised_background raised_accent raised_background raised_accent
background_color body_text background_color body_text
muted_text input_color muted_text input_color
input_text input_text input_placeholder
]) ])
if current_user.theme.nil? if current_user.theme.nil?

View File

@ -1,6 +1,10 @@
# frozen_string_literal: true
class UserController < ApplicationController class UserController < ApplicationController
before_action :set_user
before_action :hidden_social_graph_redirect, only: %i[followers followings]
def show def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@answers = @user.cursored_answers(last_id: params[:last_id]) @answers = @user.cursored_answers(last_id: params[:last_id])
@answers_last_id = @answers.map(&:id).min @answers_last_id = @answers.map(&:id).min
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero?
@ -20,8 +24,7 @@ class UserController < ApplicationController
end end
def followers def followers
@title = '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 = @user.cursored_follower_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min @relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@ -34,10 +37,8 @@ class UserController < ApplicationController
end end
end end
# rubocop:disable Metrics/AbcSize
def followings def followings
@title = 'Following' @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 = @user.cursored_following_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min @relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@ -49,11 +50,9 @@ class UserController < ApplicationController
format.turbo_stream { render "show_follow" } format.turbo_stream { render "show_follow" }
end end
end end
# rubocop:enable Metrics/AbcSize
def questions def questions
@title = '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 = @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 @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? @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 private
def set_user
@user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first!
end
def hidden_social_graph_redirect
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 def belongs_to_current_user? = @user == current_user
end end

View File

@ -1,26 +1,29 @@
# frozen_string_literal: true
module ThemeHelper module ThemeHelper
ATTRIBUTE_MAP = { ATTRIBUTE_MAP = {
'primary_color' => 'primary', "primary_color" => "primary",
'primary_text' => 'primary-text', "primary_text" => "primary-text",
'danger_color' => 'danger', "danger_color" => "danger",
'danger_text' => 'danger-text', "danger_text" => "danger-text",
'warning_color' => 'warning', "warning_color" => "warning",
'warning_text' => 'warning-text', "warning_text" => "warning-text",
'info_color' => 'info', "info_color" => "info",
'info_text' => 'info-text', "info_text" => "info-text",
'success_color' => 'success', "success_color" => "success",
'success_text' => 'success-text', "success_text" => "success-text",
'dark_color' => 'dark', "dark_color" => "dark",
'dark_text' => 'dark-text', "dark_text" => "dark-text",
'light_color' => 'light', "light_color" => "light",
'light_text' => 'light-text', "light_text" => "light-text",
'raised_background' => 'raised-bg', "raised_background" => "raised-bg",
'raised_accent' => 'raised-accent', "raised_accent" => "raised-accent",
'background_color' => 'background', "background_color" => "background",
'body_text' => 'body-text', "body_text" => "body-text",
'input_color' => 'input-bg', "input_color" => "input-bg",
'input_text' => 'input-text', "input_text" => "input-text",
'muted_text' => 'muted-text' "input_placeholder" => "input-placeholder",
"muted_text" => "muted-text"
}.freeze }.freeze
def render_theme def render_theme
@ -33,7 +36,7 @@ module ThemeHelper
theme.attributes.each do |k, v| theme.attributes.each do |k, v|
next unless ATTRIBUTE_MAP.key?(k) next unless ATTRIBUTE_MAP.key?(k)
if k.include? 'text' if k.include?("text") || k.include?("placeholder")
hex = get_hex_color_from_theme_value(v) hex = get_hex_color_from_theme_value(v)
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n" body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
else else
@ -42,7 +45,7 @@ module ThemeHelper
end end
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n" body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
body += '}' body += "}"
content_tag(:style, body) content_tag(:style, body)
end end
@ -52,7 +55,7 @@ module ThemeHelper
if theme if theme
theme.theme_color theme.theme_color
else else
'#5e35b1' "#5e35b1"
end end
end end
@ -61,7 +64,7 @@ module ThemeHelper
if theme if theme
theme.mobile_theme_color theme.mobile_theme_color
else else
'#f0edf4' "#f0edf4"
end end
end end
@ -92,12 +95,12 @@ module ThemeHelper
end end
def get_hex_color_from_theme_value(value) def get_hex_color_from_theme_value(value)
("0000000#{value.to_s(16)}")[-6, 6] "0000000#{value.to_s(16)}"[-6, 6]
end end
def get_decimal_triplet_from_hex(value) def get_decimal_triplet_from_hex(value)
hexes = value.split(/(.{2})/).reject { |c| c.empty? } hexes = value.split(/(.{2})/).reject(&:empty?)
hexes.map(&:hex).join(', ') hexes.map(&:hex).join(", ")
end end
def rgb_values_from_hex(value) def rgb_values_from_hex(value)
@ -109,10 +112,10 @@ module ThemeHelper
end end
def rgb_to_hex(rgb_values) 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 end
def lighten(value, amount = 0.25) 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
end end

View File

@ -36,6 +36,7 @@ const generateTheme = (payload: Record<string, string>): void => {
'body_text': 'body-text', 'body_text': 'body-text',
'input_color': 'input-bg', 'input_color': 'input-bg',
'input_text': 'input-text', 'input_text': 'input-text',
'input_placeholder': 'input-placeholder',
'muted_text': 'muted-text' 'muted_text': 'muted-text'
}; };
@ -43,7 +44,7 @@ const generateTheme = (payload: Record<string, string>): void => {
(Object.keys(payload)).forEach((payloadKey) => { (Object.keys(payload)).forEach((payloadKey) => {
if (themeAttributeMap[payloadKey]) { if (themeAttributeMap[payloadKey]) {
if (themeAttributeMap[payloadKey].includes('text')) { if (themeAttributeMap[payloadKey].includes('text') || themeAttributeMap[payloadKey].includes('placeholder')) {
const hex = getHexColorFromThemeValue(payload[payloadKey]); const hex = getHexColorFromThemeValue(payload[payloadKey]);
body += `--${themeAttributeMap[payloadKey]}: ${getDecimalTripletsFromHex(hex)};\n`; body += `--${themeAttributeMap[payloadKey]}: ${getDecimalTripletsFromHex(hex)};\n`;
} }
@ -111,4 +112,4 @@ export function themeSubmitHandler(): void {
Array.from(document.querySelectorAll('#update .color')).forEach((color: HTMLInputElement) => { Array.from(document.querySelectorAll('#update .color')).forEach((color: HTMLInputElement) => {
color.value = String(parseInt(color.value.substr(1, 6), 16)); color.value = String(parseInt(color.value.substr(1, 6), 16));
}); });
} }

View File

@ -97,6 +97,7 @@ $spacers: (
--body-text: 0, 0, 0; --body-text: 0, 0, 0;
--muted-text: 108, 117, 125; --muted-text: 108, 117, 125;
--input-text: 0, 0, 0; --input-text: 0, 0, 0;
--input-placeholder: 108, 117, 125;
--turbolinks-progress-color: #a58adc; // --primary lightened by 25% --turbolinks-progress-color: #a58adc; // --primary lightened by 25%
} }

View File

@ -9,10 +9,14 @@
border-color: var(--primary); border-color: var(--primary);
box-shadow: .5px 0 0 0.1rem var(--primary); box-shadow: .5px 0 0 0.1rem var(--primary);
} }
&::placeholder {
color: RGB(var(--input-placeholder));
}
} }
.input-group-text { .input-group-text {
color: RGB(var(--body-text)); color: RGB(var(--body-text));
background-color: var(--raised-accent); background-color: var(--raised-accent);
border: 0; border: 0;
} }

View File

@ -7,6 +7,7 @@
= f.check_box :privacy_allow_public_timeline = f.check_box :privacy_allow_public_timeline
= f.check_box :privacy_allow_stranger_answers = f.check_box :privacy_allow_stranger_answers
= f.check_box :privacy_noindex = f.check_box :privacy_noindex
= f.check_box :privacy_hide_social_graph
= f.primary = f.primary

View File

@ -87,6 +87,14 @@
= f.text_field :input_color, class: "color", data: { default: 0xFFFFFF } = f.text_field :input_color, class: "color", data: { default: 0xFFFFFF }
.col-sm-6 .col-sm-6
= f.text_field :input_text, class: "color", data: { default: 0x000000 } = 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
.card-body .card-body
%h2= t(".raised.heading") %h2= t(".raised.heading")
@ -105,4 +113,4 @@
= f.primary = f.primary
- provide(:title, generate_title(t(".title"))) - provide(:title, generate_title(t(".title")))
- parent_layout "user/settings" - parent_layout "user/settings"

View File

@ -2,5 +2,6 @@
.list-group.list-group-horizontal-sm.text-center .list-group.list-group-horizontal-sm.text-center
= list_group_item t(".answers"), user_path(user), badge: user.answered_count = 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(".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 - if user == current_user || !user.privacy_hide_social_graph
= list_group_item t(".following"), show_user_followings_path(user.screen_name), badge: user.followings.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

View File

@ -73,6 +73,7 @@ en:
privacy_allow_public_timeline: "Show your answers in the public timeline" privacy_allow_public_timeline: "Show your answers in the public timeline"
privacy_allow_stranger_answers: "Allow other people to answer your questions" privacy_allow_stranger_answers: "Allow other people to answer your questions"
privacy_noindex: "Prevent search engines from indexing your profile" privacy_noindex: "Prevent search engines from indexing your profile"
privacy_hide_social_graph: "Hide your social graph from others"
profile_picture: "Profile picture" profile_picture: "Profile picture"
profile_header: "Profile header" profile_header: "Profile header"
sign_in_count: "Sign in count" sign_in_count: "Sign in count"

View File

@ -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

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
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

View File

@ -228,6 +228,7 @@ ActiveRecord::Schema.define(version: 2022_11_16_201723) do
t.integer "raised_accent", default: 16250871 t.integer "raised_accent", default: 16250871
t.integer "light_color", default: 16316922 t.integer "light_color", default: 16316922
t.integer "light_text", default: 0 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" t.index ["user_id", "created_at"], name: "index_themes_on_user_id_and_created_at"
end end

View File

@ -9,6 +9,32 @@ describe UserController, type: :controller do
otp_secret_key: "EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3" otp_secret_key: "EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3"
end 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 describe "#show" do
subject { get :show, params: { username: user.screen_name } } subject { get :show, params: { username: user.screen_name } }
@ -51,6 +77,8 @@ describe UserController, type: :controller do
expect(response).to render_template("user/show_follow") expect(response).to render_template("user/show_follow")
end end
end end
include_examples "social graph hidden"
end end
describe "#followings" do describe "#followings" do
@ -65,6 +93,8 @@ describe UserController, type: :controller do
expect(response).to render_template("user/show_follow") expect(response).to render_template("user/show_follow")
end end
end end
include_examples "social graph hidden"
end end
describe "#questions" do describe "#questions" do

View File

@ -4784,9 +4784,9 @@ loader-runner@^2.4.0:
integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw== integrity sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw==
loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0: loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4.0:
version "1.4.1" version "1.4.2"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.1.tgz#278ad7006660bccc4d2c0c1578e17c5c78d5c0e0" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.2.tgz#29a957f3a63973883eb684f10ffd3d151fec01a3"
integrity sha512-1Qo97Y2oKaU+Ro2xnDMR26g1BwMT29jNbem1EvcujW2jqt+j5COXyscjM7bLQkM9HaxI7pkWeW7gnI072yMI9Q== integrity sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg==
dependencies: dependencies:
big.js "^5.2.2" big.js "^5.2.2"
emojis-list "^3.0.0" emojis-list "^3.0.0"