diff --git a/app/controllers/settings/sharing_controller.rb b/app/controllers/settings/sharing_controller.rb new file mode 100644 index 00000000..a92bd364 --- /dev/null +++ b/app/controllers/settings/sharing_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class Settings::SharingController < ApplicationController + before_action :authenticate_user! + + def edit; end + + def update + user_attributes = params.require(:user).permit(:sharing_enabled, + :sharing_autoclose, + :sharing_custom_url) + if current_user.update(user_attributes) + flash[:success] = t(".success") + else + flash[:error] = t(".error") + end + redirect_to settings_sharing_path + end +end diff --git a/app/views/settings/sharing/edit.html.haml b/app/views/settings/sharing/edit.html.haml new file mode 100644 index 00000000..002fc279 --- /dev/null +++ b/app/views/settings/sharing/edit.html.haml @@ -0,0 +1,20 @@ += bootstrap_form_for(current_user, url: settings_sharing_path, method: :patch, data: { turbo: false }) do |f| + .card + .card-body + = f.form_group :sharing, help: t("activerecord.help.user.sharing_enabled") do + = f.check_box :sharing_enabled + = f.form_group :sharing, help: t("activerecord.help.user.sharing_autoclose"), class: false do + = f.check_box :sharing_autoclose + + .card + .card-body + %h3= t(".advanced.title") + = t(".advanced.body_html") + = f.url_field :sharing_custom_url + + .card + .card-body + = f.primary + +- provide(:title, generate_title(t(".title"))) +- parent_layout "user/settings" diff --git a/app/views/tabs/_settings.html.haml b/app/views/tabs/_settings.html.haml index 366aafc1..f54ba115 100644 --- a/app/views/tabs/_settings.html.haml +++ b/app/views/tabs/_settings.html.haml @@ -4,7 +4,7 @@ = list_group_item t(".profile"), edit_settings_profile_path = list_group_item t(".privacy"), edit_settings_privacy_path = list_group_item t(".security"), settings_two_factor_authentication_otp_authentication_path - = list_group_item t(".sharing"), services_path + = list_group_item t(".sharing"), settings_sharing_path = list_group_item t(".mutes"), settings_muted_path = list_group_item t(".blocks"), settings_blocks_path = list_group_item t(".theme"), edit_settings_theme_path diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 3a0a0742..779d1227 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -74,6 +74,9 @@ en: privacy_allow_stranger_answers: "Allow other people to answer your questions" privacy_noindex: "Prevent search engines from indexing your profile" privacy_hide_social_graph: "Hide your social graph from others" + sharing_enabled: "Enable sharing" + sharing_autoclose: "Automatically close inbox entry after sharing once" + sharing_custom_url: "Custom Share Link" profile_picture: "Profile picture" profile_header: "Profile header" sign_in_count: "Sign in count" @@ -85,6 +88,9 @@ en: screen_name: "Alphanumerical and underscores allowed, max. 16 characters" email: "Don't forget to check your spam folder in case our email might have landed there!" current_password: "We need your current password to confirm your changes" + sharing_enabled: "Shows a sharing dialog after answering a question from your inbox" + sharing_autoclose: "Use this if you mainly post to a single service" + sharing_custom_url: "Example: https://mastodon.social/share?text=" profile: anon_display_name: "This name will be used for questions asked to you by anonymous users." motivation_header: "Shown in the header of the question box on your profile. Motivate users to ask you questions!" diff --git a/config/locales/controllers.en.yml b/config/locales/controllers.en.yml index 7c047680..4b5f49af 100644 --- a/config/locales/controllers.en.yml +++ b/config/locales/controllers.en.yml @@ -170,6 +170,10 @@ en: notice: profile_picture: " It might take a few minutes until your new profile picture is shown everywhere." profile_header: " It might take a few minutes until your new profile header is shown everywhere." + sharing: + update: + success: "Sharing settings updated successfully." + error: "Unable to update sharing settings." theme: update: success: "Theme saved successfully." diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml index 295f8aab..29b241e8 100644 --- a/config/locales/views.en.yml +++ b/config/locales/views.en.yml @@ -363,9 +363,6 @@ en: heading: "Twitter connection expired" text_html: "If you would like to continue automatically sharing your answers to Twitter, head to %{settings_sharing} and re-connect your account." settings_services: "Sharing Settings" - services: - index: - title: "Service Settings" settings: account: email_confirm: "Currently awaiting confirmation for %{resource}" @@ -453,6 +450,14 @@ en: profile_picture: "Adjust your new profile picture" profile_header: "Adjust your new profile header" submit_picture: "Save pictures" + sharing: + edit: + title: "Sharing Settings" + advanced: + title: "Advanced options" + body_html: | +

If you use a service other than Twitter or Tumblr, which has support for sharing from external services, you can enter their sharing URL here so it will be listed as an option for sharing after an answer has been sent.

+

We will prepend a URL-encoded version of the answer to the end of the given link.

two_factor_authentication: otp_authentication: index: diff --git a/config/routes.rb b/config/routes.rb index fbc7aa0a..74ebc5b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,9 @@ Rails.application.routes.draw do get :privacy, to: redirect("/settings/privacy/edit") resource :privacy, controller: :privacy, only: %i[edit update] + get :sharing, to: redirect("/settings/sharing/edit") + resource :sharing, controller: :sharing, only: %i[edit update] + get :export, to: "export#index" post :export, to: "export#create"