diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index dd3e82e02..0816b20a4 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -47,3 +47,11 @@ p.notice:empty { #navbar>ul.navbar-nav>li>a.nav-link { color: var(--bs-navbar-hover-color) !important; } + +span.obfuscated { + -webkit-text-security: disc; +} + +span.deobfuscated { + -webkit-text-security: none; +} diff --git a/app/components/copy_button.rb b/app/components/copy_button.rb index da26980ac..35b69e4bb 100644 --- a/app/components/copy_button.rb +++ b/app/components/copy_button.rb @@ -9,7 +9,7 @@ class Components::CopyButton < Components::Base end def view_template - a href: "#", class: "link-secondary", data: {controller: "copy-text", action: "click->copy-text#copy:prevent", copy_text_text_value: @text} do + button class: "btn btn-secondary", data: {controller: "copy-text", action: "click->copy-text#copy:prevent", copy_text_text_value: @text} do Icon icon: "clipboard-plus", label: @label end end diff --git a/app/components/copyable_text.rb b/app/components/copyable_text.rb new file mode 100644 index 000000000..adc75d5b5 --- /dev/null +++ b/app/components/copyable_text.rb @@ -0,0 +1,27 @@ +class Components::CopyableText < Components::Base + def initialize(text:, label: nil, obfuscated: false) + @text = text + @label = label + @obfuscated = obfuscated + end + + def before_template + @label ||= t("components.copy_button.copy") + end + + def view_template + div(data: {controller: "obfuscated-text"}) do + span(class: @obfuscated ? "obfuscated" : nil) { @text } + whitespace + if @obfuscated + button class: "btn btn-sm btn-outline-secondary", title: t("components.copyable_text.reveal"), data: {action: "click->obfuscated-text#toggle:prevent"} do + Icon icon: "eye" + end + end + whitespace + button class: "btn btn-sm btn-outline-secondary", title: @label, data: {controller: "copy-text", action: "click->copy-text#copy:prevent", copy_text_text_value: @text} do + Icon icon: "clipboard-plus" + end + end + end +end diff --git a/app/javascript/controllers/index.ts b/app/javascript/controllers/index.ts index cf8307575..d710611a7 100644 --- a/app/javascript/controllers/index.ts +++ b/app/javascript/controllers/index.ts @@ -11,6 +11,7 @@ import CocoonedController from './cocooned_controller' import CopyTextController from './copy_text_controller' import EditableController from './editable_controller' import I18nController from './i18n_controller' +import ObfuscatedTextController from './obfuscated_text_controller' import RendererController from './renderer_controller' import SearchableSelectController from './searchable_select_controller' import StorageServiceController from './storage_service_controller' @@ -27,6 +28,7 @@ application.register('cocooned', CocoonedController) application.register('copy-text', CopyTextController) application.register('editable', EditableController) application.register('i18n', I18nController) +application.register('obfuscated-text', ObfuscatedTextController) application.register('renderer', RendererController) application.register('searchable-select', SearchableSelectController) application.register('storage-service', StorageServiceController) diff --git a/app/javascript/controllers/obfuscated_text_controller.ts b/app/javascript/controllers/obfuscated_text_controller.ts new file mode 100644 index 000000000..edb173554 --- /dev/null +++ b/app/javascript/controllers/obfuscated_text_controller.ts @@ -0,0 +1,15 @@ +import { Controller } from '@hotwired/stimulus' + +// Connects to data-controller="obfuscated-text" +export default class extends Controller { + toggle (): void { + const hidden = this.element.querySelectorAll('.obfuscated') + const shown = this.element.querySelectorAll('.deobfuscated') + hidden.forEach((element: HTMLElement) => { + element.classList.replace('obfuscated', 'deobfuscated') + }) + shown.forEach((element: HTMLElement) => { + element.classList.replace('deobfuscated', 'obfuscated') + }) + } +} diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb index 6e822dba7..24f11b827 100644 --- a/app/views/collections/show.html.erb +++ b/app/views/collections/show.html.erb @@ -19,8 +19,7 @@ <%= link_to @collection.federails_actor.at_address, @collection.federails_actor.profile_url, target: "new" %> <% elsif SiteSettings.federation_enabled? %> - <%= @collection.federails_actor.short_at_address %> - <%= CopyButton(text: @collection.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> + <%= CopyableText(text: @collection.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> <% end %>

diff --git a/app/views/creators/show.html.erb b/app/views/creators/show.html.erb index d7563a082..48d8b6976 100644 --- a/app/views/creators/show.html.erb +++ b/app/views/creators/show.html.erb @@ -25,8 +25,7 @@ <%= link_to @creator.federails_actor.at_address, @creator.federails_actor.profile_url, target: "new" %> <% elsif SiteSettings.federation_enabled? %> - <%= @creator.federails_actor.short_at_address %> - <%= CopyButton(text: @creator.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> + <%= CopyableText(text: @creator.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> <% end %>

diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 750f61826..1d5b8b49d 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -15,8 +15,7 @@ <% if SiteSettings.federation_enabled? %>
<%= t("settings.users.index.fediverse_address") %>
- <%= resource.federails_actor.at_address %> - <%= CopyButton(text: resource.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> + <%= CopyableText(text: resource.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %>
<% end %> diff --git a/app/views/doorkeeper_applications/show.html.erb b/app/views/doorkeeper_applications/show.html.erb index aafaed751..a915f926d 100644 --- a/app/views/doorkeeper_applications/show.html.erb +++ b/app/views/doorkeeper_applications/show.html.erb @@ -8,11 +8,11 @@ <%= Doorkeeper::Application.human_attribute_name :uid %> - <%= @application.uid %> + <%= CopyableText text: @application.uid %> <%= Doorkeeper::Application.human_attribute_name :secret %> - <%= @application.secret %> + <%= CopyableText text: @application.secret, obfuscated: true %> <%= Doorkeeper::Application.human_attribute_name :confidential %> diff --git a/app/views/home/_federation.html.erb b/app/views/home/_federation.html.erb index 333d6b14e..d93e51cbb 100644 --- a/app/views/home/_federation.html.erb +++ b/app/views/home/_federation.html.erb @@ -19,8 +19,7 @@
<%= t(".creator_handle") %>
- <%= current_user.creators.local.first.federails_actor.at_address %> - <%= CopyButton text: current_user.creators.local.first.federails_actor.at_address, label: t("general.copy_fediverse_handle") %> + <%= CopyableText text: current_user.creators.local.first.federails_actor.at_address, label: t("general.copy_fediverse_handle") %>
@@ -33,8 +32,7 @@
<%= t(".account_handle") %>
- <%= current_user.federails_actor.at_address %> - <%= CopyButton text: current_user.federails_actor.at_address, label: t("general.copy_fediverse_handle") %> + <%= CopyableText text: current_user.federails_actor.at_address, label: t("general.copy_fediverse_handle") %>
diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb index e9a140cdf..001c0ec61 100644 --- a/app/views/models/show.html.erb +++ b/app/views/models/show.html.erb @@ -91,8 +91,7 @@ <%= link_to @model.federails_actor.at_address, @model.federails_actor.profile_url, target: "new" %> <% else %> - <%= @model.federails_actor.short_at_address %> - <%= CopyButton(text: @model.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> + <%= CopyableText(text: @model.federails_actor.at_address, label: t("general.copy_fediverse_handle")) %> <% end %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index a8a197ac0..f6e578e79 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -359,6 +359,8 @@ cs: help: copy_button: copy: + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/de.yml b/config/locales/de.yml index de9658d39..93fa9aa35 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -359,6 +359,8 @@ de: help: datenschutzfreundlicher Spamschutz durch ALTCHA copy_button: copy: In die Zwischenablage kopieren + copyable_text: + reveal: display_user_quota: request_increase: Um eine Quotenerhöhung zu beantragen, wende dich an deinen Website-Administrator. download_button: diff --git a/config/locales/en.yml b/config/locales/en.yml index 3c195f4b8..113da4988 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -359,6 +359,8 @@ en: help: privacy-friendly spam protection by ALTCHA copy_button: copy: Copy to Clipboard + copyable_text: + reveal: Reveal display_user_quota: request_increase: To request a quota increase, contact your site administrator. download_button: diff --git a/config/locales/es.yml b/config/locales/es.yml index 827b0545c..bf1c84fbb 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -359,6 +359,8 @@ es: help: protección antispam mediante ALTCHA copy_button: copy: Copiar al portapapeles + copyable_text: + reveal: display_user_quota: request_increase: Para solicitar un aumento de cuota, póngase en contacto con el administrador de su sitio. download_button: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 580a204df..851608d2f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -359,6 +359,8 @@ fr: help: copy_button: copy: Copier dans le presse-papiers + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 18449b9e1..667d6313b 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -359,6 +359,8 @@ ja: help: copy_button: copy: + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index dd5a477d1..f0f3619ed 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -359,6 +359,8 @@ nl: help: copy_button: copy: + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 9fe1cb818..51fa7bd7a 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -359,6 +359,8 @@ pl: help: copy_button: copy: Kopiuj do schowka + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 48dc3558c..fa88c2a65 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -359,6 +359,8 @@ pt: help: copy_button: copy: + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 715b948e0..97ab9be78 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -359,6 +359,8 @@ ru: help: copy_button: copy: + copyable_text: + reveal: display_user_quota: request_increase: download_button: diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 78621bf75..7b2129f93 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -359,6 +359,8 @@ zh-CN: help: copy_button: copy: 复制到剪贴板 + copyable_text: + reveal: display_user_quota: request_increase: 如需增加配额,请联系管理员。 download_button: