diff --git a/Gemfile b/Gemfile index d84597a787994b45b44daeb2caae5cf9c0568ab3..79e9fb895344e1785a6593e50cf9063cfebe4062 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,6 @@ gem 'hamlit-rails' gem 'pg' gem 'pghero' gem 'dotenv-rails' -gem 'best_in_place', '~> 3.0.1' gem 'aws-sdk', '>= 2.0' gem 'paperclip', '~> 5.1' diff --git a/Gemfile.lock b/Gemfile.lock index 7b687c6bd1a7b69b8618f801628d0f416ce688cb..7db2b61d1d47d6d68248878e39705370ef89329e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,9 +65,6 @@ GEM babel-source (>= 4.0, < 6) execjs (~> 2.0) bcrypt (3.1.11) - best_in_place (3.0.3) - actionpack (>= 3.2) - railties (>= 3.2) better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -478,7 +475,6 @@ DEPENDENCIES addressable annotate aws-sdk (>= 2.0) - best_in_place (~> 3.0.1) better_errors binding_of_caller bullet diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index fc9064068c361238f91279d2eaa6178c75cd145b..fcd42c79c8cd04ef5303f26d3ee9397d376a5933 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -2,38 +2,43 @@ module Admin class SettingsController < BaseController + ADMIN_SETTINGS = %w( + site_contact_username + site_contact_email + site_title + site_description + site_extended_description + open_registrations + closed_registrations_message + ).freeze BOOLEAN_SETTINGS = %w(open_registrations).freeze - def index + def edit @settings = Setting.all_as_records end def update - @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id]) - @setting.update(value: value_for_update) - - respond_to do |format| - format.html { redirect_to admin_settings_path } - format.json { respond_with_bip(@setting) } + settings_params.each do |key, value| + setting = Setting.where(var: key).first_or_initialize(var: key) + setting.update(value: value_for_update(key, value)) end + + flash[:notice] = 'Success!' + redirect_to edit_admin_settings_path end private def settings_params - params.require(:setting).permit(:value) + params.permit(ADMIN_SETTINGS) end - def value_for_update - if updating_boolean_setting? - settings_params[:value] == 'true' + def value_for_update(key, value) + if BOOLEAN_SETTINGS.include?(key) + value == 'true' else - settings_params[:value] + value end end - - def updating_boolean_setting? - BOOLEAN_SETTINGS.include?(params[:id]) - end end end diff --git a/app/javascript/styles/forms.scss b/app/javascript/styles/forms.scss index 18258099b8f700cf5f72ae2d52ee30f612888712..18e8657cdb16c895ec80d85f066d89a821144e56 100644 --- a/app/javascript/styles/forms.scss +++ b/app/javascript/styles/forms.scss @@ -9,6 +9,12 @@ code { margin: 0 auto; } +.admin { + input, textarea { + width: 100%; + } +} + .simple_form { .input { margin-bottom: 15px; diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..0808f467cdb3f4f2b87c37257d71cd647096a703 --- /dev/null +++ b/app/views/admin/settings/edit.html.haml @@ -0,0 +1,58 @@ +- content_for :page_title do + = t('admin.settings.title') + += form_tag(admin_settings_path, method: :put) do + %table.table + %thead + %tr + %th{width: '40%'} + = t('admin.settings.setting') + %th + %tbody + %tr + %td + %strong= t('admin.settings.contact_information.label') + %td= text_field_tag :site_contact_username, + @settings['site_contact_username'].value, + place_holder: t('admin.settings.contact_information.username') + %tr + %td + %strong= t('admin.accounts.email') + %td= text_field_tag :site_contact_email, + @settings['site_contact_email'].value, + place_holder: t('admin.settings.contact_information.email') + %tr + %td + %strong= t('admin.settings.site_title') + %td= text_field_tag :site_title, + @settings['site_title'].value + %tr + %td + %strong= t('admin.settings.site_description.title') + %p= t('admin.settings.site_description.desc_html') + %td= text_area_tag :site_description, + @settings['site_description'].value, + rows: 8 + %tr + %td + %strong= t('admin.settings.site_description_extended.title') + %p= t('admin.settings.site_description_extended.desc_html') + %td= text_area_tag :site_extended_description, + @settings['site_extended_description'].value, + rows: 8 + %tr + %td + %strong= t('admin.settings.registrations.open.title') + %td + = select_tag :open_registrations, + options_for_select({ t('admin.settings.registrations.open.disabled') => false, t('admin.settings.registrations.open.enabled') => true }, @settings['open_registrations'].value) + %tr + %td + %strong= t('admin.settings.registrations.closed_message.title') + %p= t('admin.settings.registrations.closed_message.desc_html') + %td= text_area_tag :closed_registrations_message, + @settings['closed_registrations_message'].value, + rows: 8 + + .simple_form.actions + = button_tag t('generic.save_changes'), type: :submit, class: :btn diff --git a/app/views/admin/settings/index.html.haml b/app/views/admin/settings/index.html.haml deleted file mode 100644 index b00e75a1666400d2c1d4e8658ec011dd586b80eb..0000000000000000000000000000000000000000 --- a/app/views/admin/settings/index.html.haml +++ /dev/null @@ -1,40 +0,0 @@ -- content_for :page_title do - = t('admin.settings.title') - -%table.table - %colgroup - %col{ width: '35%' }/ - %thead - %tr - %th= t('admin.settings.setting') - %th= t('admin.settings.click_to_edit') - %tbody - %tr - %td{ rowspan: 2 } - %strong= t('admin.settings.contact_information.label') - %td= best_in_place @settings['site_contact_username'], :value, url: admin_setting_path(@settings['site_contact_username']), place_holder: t('admin.settings.contact_information.username') - %tr - %td= best_in_place @settings['site_contact_email'], :value, url: admin_setting_path(@settings['site_contact_email']), place_holder: t('admin.settings.contact_information.email') - %tr - %td - %strong= t('admin.settings.site_title') - %td= best_in_place @settings['site_title'], :value, url: admin_setting_path(@settings['site_title']) - %tr - %td - %strong= t('admin.settings.site_description.title') - %p= t('admin.settings.site_description.desc_html') - %td= best_in_place @settings['site_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_description']) - %tr - %td - %strong= t('admin.settings.site_description_extended.title') - %p= t('admin.settings.site_description_extended.desc_html') - %td= best_in_place @settings['site_extended_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_extended_description']) - %tr - %td - %strong= t('admin.settings.registrations.open.title') - %td= best_in_place @settings['open_registrations'], :value, as: :checkbox, collection: { false: t('admin.settings.registrations.open.disabled'), true: t('admin.settings.registrations.open.enabled')}, url: admin_setting_path(@settings['open_registrations']) - %tr - %td - %strong= t('admin.settings.registrations.closed_message.title') - %p= t('admin.settings.registrations.closed_message.desc_html') - %td= best_in_place @settings['closed_registrations_message'], :value, as: :textarea, url: admin_setting_path(@settings['closed_registrations_message']) diff --git a/config/locales/de.yml b/config/locales/de.yml index 7b8d09d105b699d3d57e1a4b2c75b1237b4a0c51..b98c613f9dc959a3d773d708d0c5d15015d4c71d 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -145,7 +145,6 @@ de: unresolved: Ungelöst view: Ansehen settings: - click_to_edit: Klicken zum Bearbeiten contact_information: email: Eine öffentliche E-Mail-Adresse angeben label: Kontaktinformationen diff --git a/config/locales/en.yml b/config/locales/en.yml index 936aa38d936a498b7c17242de4777f359c35f9c5..2210bd3c5c597e8368a29792dfcd7b273755c717 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -158,7 +158,6 @@ en: unresolved: Unresolved view: View settings: - click_to_edit: Click to edit contact_information: email: Enter a public e-mail address label: Contact information diff --git a/config/locales/fa.yml b/config/locales/fa.yml index d118582a00df9b76e1f2ee1b8ad612961d59c438..97792ede744ef90edb7e5341b5c195f4e6eaa4f9 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -156,7 +156,6 @@ fa: unresolved: Øل‌نشده view: نمایش settings: - click_to_edit: برای ویرایش کلیک کنید contact_information: email: یک نشانی ایمیل عمومی وارد کنید label: اطلاعات تماس @@ -297,7 +296,7 @@ fa: visibilities: private: نمایش تنها به پیگیران public: عمومی - unlisted: عمومی، ولی در Ùهرست نوشته‌ها نمایش نده + unlisted: عمومی، ولی در Ùهرست نوشته‌ها نمایش نده stream_entries: click_to_show: برای نمایش کلیک کنید reblogged: بازبوقیده diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f238d601ae5cdc3957e2ab1d6703a5dee105ae4c..db892619cdaf846e39ef4ffce7d090748479cf76 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -136,7 +136,6 @@ fr: unresolved: Non résolus view: Voir settings: - click_to_edit: Cliquez pour éditer contact_information: email: Entrez une adresse courriel publique label: Informations de contact diff --git a/config/locales/he.yml b/config/locales/he.yml index 0cda09add71535680553ed172c38917c6540000f..282cff21e856a476c4e5669b99413458fc174c6d 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -157,7 +157,6 @@ he: unresolved: ×œ× ×¤×ª×•×¨ view: תצוגה settings: - click_to_edit: לחיצה כדי לערוך contact_information: email: '× × ×œ×”×§×œ×™×“ כתובת דו×"ל פומבית' label: פרטי התקשרות diff --git a/config/locales/id.yml b/config/locales/id.yml index 55c27ca085e8068da91ac6371154998c1919b33d..14c8d0b59d56ac8722af2e474569b5f90f2203e8 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -156,7 +156,6 @@ id: unresolved: Belum Terseleseikan view: Tampilan settings: - click_to_edit: Klik untuk mengubah contact_information: email: Masukkan alamat email label: Informasi kontak diff --git a/config/locales/io.yml b/config/locales/io.yml index 4fad8423cc3c4377c7aaa271eeb60ee939ecb27d..438fc301ff78b69ad28fad6ce9c55aa379ce330e 100644 --- a/config/locales/io.yml +++ b/config/locales/io.yml @@ -144,7 +144,6 @@ io: unresolved: Unresolved view: View settings: - click_to_edit: Click to edit contact_information: email: Enter a public e-mail address label: Contact information diff --git a/config/locales/ja.yml b/config/locales/ja.yml index af5e77d1428c9916b64d071748f45772c2be92f1..3f961bc935f19324b16caddebf1b40286e422cf0 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -157,7 +157,6 @@ ja: unresolved: 未解決 view: 表示 settings: - click_to_edit: クリックã—ã¦ç·¨é›† contact_information: email: 公開ã™ã‚‹ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’入力 label: é€£çµ¡å…ˆæƒ…å ± diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 3fb7c0487e58089d467245cfdeebe4aadf9cf6c6..f5a1068b8232e712c27a17c12f2828ea351af3e6 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -41,7 +41,6 @@ nl: unfollow: Ontvolgen admin: settings: - click_to_edit: Klik om te bewerken contact_information: email: Vul een openbaar gebruikt e-mailadres in label: Contactgegevens diff --git a/config/locales/oc.yml b/config/locales/oc.yml index 237b9c4522d0c23d890b38fabbd6ca62f0b3a75d..da18075825a7414718ac7668480034c6b5bd1b1f 100644 --- a/config/locales/oc.yml +++ b/config/locales/oc.yml @@ -146,7 +146,6 @@ oc: unresolved: Pas resolguts view: Veire settings: - click_to_edit: Clicatz per modificar contact_information: email: Picatz una adreça de corrièl label: Informacions de contacte diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 71877aada9f808dd5f672599fe586b796f138723..8f88db22cee0ca79336c2f4566ad9f6ad1d265ba 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -12,7 +12,7 @@ pl: domain_count_before: Serwer poÅ‚Ä…czony z features: api: Otwarte API dla aplikacji i usÅ‚ug - blocks: Rozbudowane narzÄ™dzia blokowania i ukrywania + blocks: Rozbudowane narzÄ™dzia blokowania i ukrywania characters: 500 znaków na wpis chronology: Chronologiczny porzÄ…dek wyÅ›wietlania ethics: 'Etyczne zaÅ‚ożenia: nie Å›ledzimy, bez reklam' @@ -158,7 +158,6 @@ pl: unresolved: NierozwiÄ…zane view: WyÅ›wietl settings: - click_to_edit: NaciÅ›nij, aby edytować contact_information: email: Wprowadź publiczny adres e-mail label: Informacje kontaktowe diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 067f908ba47226c593402113bc237c9e31380e85..2126a5529a8f512b1f2439fd11d565b8793fdfbf 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -157,7 +157,6 @@ pt-BR: unresolved: Unresolved view: View settings: - click_to_edit: Clique para editar contact_information: email: Entre um endereço de email público label: Informação de contato diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 2fc9f900fecf7293f2b04be3b5c79bb04877a2fc..cd841be5148c7205610665604f9f9730cba286fb 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -152,7 +152,6 @@ pt: unresolved: Por resolver view: Ver settings: - click_to_edit: Clique para editar contact_information: email: Inserir um endereço de email para tornar público label: Informação de contacto diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 918b5a94739ca5acbb42e6b1c1eb108f334dc73c..04e6d15f311c75dc80b88ec298a1d291a4af74fa 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -29,7 +29,7 @@ ru: terms: УÑÐ»Ð¾Ð²Ð¸Ñ user_count_after: пользователей user_count_before: ЗдеÑÑŒ живет - version: ВерÑÐ¸Ñ + version: ВерÑÐ¸Ñ accounts: follow: ПодпиÑатьÑÑ followers: ПодпиÑчики @@ -139,7 +139,6 @@ ru: unresolved: Ðеразрешенные view: ПроÑмотреть settings: - click_to_edit: Ðажмите Ð´Ð»Ñ Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ contact_information: email: Введите публичный e-mail label: ÐšÐ¾Ð½Ñ‚Ð°ÐºÑ‚Ð½Ð°Ñ Ð¸Ð½Ñ„Ð¾Ñ€Ð¼Ð°Ñ†Ð¸Ñ diff --git a/config/locales/th.yml b/config/locales/th.yml index ae5273dd7325c0532db8b37126dd51921b353640..5383b31ab98aa5cae6e8a652410ed973daa1b96c 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -35,7 +35,7 @@ th: followers: ผู้ติดตาม following: à¸à¸³à¸¥à¸±à¸‡à¸•à¸´à¸”ตาม nothing_here: ไม่พบสิ่งใดที่นี่! - people_followed_by: ถูà¸à¸•à¸´à¸”ตามโดย %{name} + people_followed_by: ถูà¸à¸•à¸´à¸”ตามโดย %{name} people_who_follow: คนที่ติดตาม %{name} posts: โพสต์ remote_follow: Remote follow @@ -157,7 +157,6 @@ th: unresolved: Unresolved view: วิว settings: - click_to_edit: คลิ๊à¸à¹€à¸žà¸·à¹ˆà¸à¹à¸à¹‰à¹„ข contact_information: email: à¸à¸£à¸à¸à¸—ี่à¸à¸¢à¸¹à¹ˆà¸à¸µà¹€à¸¡à¸¥à¹Œà¸ªà¸²à¸˜à¸²à¸£à¸“ะ label: ข้à¸à¸¡à¸¹à¸¥à¸—ี่ติดต่ภdiff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index e3c4a41ca1c2fa0f930710f3e31d13a7eecb8286..67cd5b1b818eeaff2e9e268fb23d588f17a25b0c 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -154,7 +154,6 @@ zh-CN: unresolved: æœªå¤„ç† view: 查看 settings: - click_to_edit: 点击编辑 contact_information: email: è¾“å…¥ä¸€ä¸ªå…¬å¼€çš„ç”µé‚®åœ°å€ label: è”ç³»æ•°æ® diff --git a/config/locales/zh-HK.yml b/config/locales/zh-HK.yml index 26fd0855fff4415d2125a2fb98ee3a4174df9a4c..4f7a263b4ccc4da12934f18cf6317458b9cb9175 100644 --- a/config/locales/zh-HK.yml +++ b/config/locales/zh-HK.yml @@ -141,7 +141,6 @@ zh-HK: unresolved: æœªè™•ç† view: 檢視 settings: - click_to_edit: 點擊編輯 contact_information: email: è¼¸å…¥ä¸€å€‹å…¬é–‹çš„é›»éƒµåœ°å€ label: è¯çµ¡è³‡æ–™ diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index b5918e0ef6c026e00e487239c7c3ff1c63ec272d..8f6f008ee35dbc5fa8b3ea789383848eeaec1a85 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -118,7 +118,6 @@ zh-TW: unresolved: 未解決 view: 檢視 settings: - click_to_edit: 點é¸ä»¥ç·¨è¼¯ contact_information: email: 請輸入輸入一個公開電åä¿¡ç®± label: è¯çµ¡è³‡è¨Š diff --git a/config/navigation.rb b/config/navigation.rb index 16bc86696dff39f7edf1abc33717118d8f98a81c..38dee91b244276b84d1a7fd9466494119b0f8027 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -23,7 +23,7 @@ SimpleNavigation::Configuration.run do |navigation| admin.item :domain_blocks, safe_join([fa_icon('lock fw'), t('admin.domain_blocks.title')]), admin_domain_blocks_url, highlights_on: %r{/admin/domain_blocks} admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' } admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' } - admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), admin_settings_url + admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url end primary.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' } diff --git a/config/routes.rb b/config/routes.rb index 1492f99fbdbbb411327f2836b89be8c764e51201..577a66923cb24e1ca7b1bfd84f2a5b67cc3d9855 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,7 +76,7 @@ Rails.application.routes.draw do namespace :admin do resources :pubsubhubbub, only: [:index] resources :domain_blocks, only: [:index, :new, :create, :show, :destroy] - resources :settings, only: [:index, :update] + resource :settings, only: [:edit, :update] resources :instances, only: [:index] resources :reports, only: [:index, :show, :update] do diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 2ddf3c2f0a21a85ed2e5ded213ecffa46f9722d5..2cc1c29eb727daceec076eb02d9a54a75dacdf25 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -22,7 +22,7 @@ namespace :mastodon do user = Account.find_local(ENV.fetch('USERNAME')).user user.update(admin: true) - puts "Congrats! #{user.account.username} is now an admin. \\o/\nNavigate to #{admin_settings_url} to get started" + puts "Congrats! #{user.account.username} is now an admin. \\o/\nNavigate to #{edit_admin_settings_url} to get started" end desc 'Manually confirms a user with associated user email address stored in USER_EMAIL environment variable.' diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index 889f78bc130d0981defebcc069158d13f8992f2f..533ae20459aaacdd3e4716bf7eb9804bfb7eba71 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -1,51 +1,65 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Admin::SettingsController, type: :controller do render_views + before do + Rails.cache.clear + end + describe 'When signed in as an admin' do before do sign_in Fabricate(:user, admin: true), scope: :user end - describe 'GET #index' do + describe 'GET #edit' do it 'returns http success' do - get :index + get :edit expect(response).to have_http_status(:success) end end describe 'PUT #update' do - describe 'for a record that doesnt exist' do after do Setting.new_setting_key = nil end - it 'creates a settings value that didnt exist before' do + it 'cannot create a setting value for a non-admin key' do expect(Setting.new_setting_key).to be_nil - patch :update, params: { id: 'new_setting_key', setting: { value: 'New key value' } } + patch :update, params: { new_setting_key: 'New key value' } + + expect(response).to redirect_to(edit_admin_settings_path) + expect(Setting.new_setting_key).to be_nil + end + + it 'creates a settings value that didnt exist before for eligible key' do + expect(Setting.site_extended_description).to be_blank + + patch :update, params: { site_extended_description: 'New key value' } - expect(response).to redirect_to(admin_settings_path) - expect(Setting.new_setting_key).to eq 'New key value' + expect(response).to redirect_to(edit_admin_settings_path) + expect(Setting.site_extended_description).to eq 'New key value' end end it 'updates a settings value' do Setting.site_title = 'Original' - patch :update, params: { id: 'site_title', setting: { value: 'New title' } } + patch :update, params: { site_title: 'New title' } - expect(response).to redirect_to(admin_settings_path) + expect(response).to redirect_to(edit_admin_settings_path) expect(Setting.site_title).to eq 'New title' end it 'typecasts open_registrations to boolean' do Setting.open_registrations = false - patch :update, params: { id: 'open_registrations', setting: { value: 'true' } } + patch :update, params: { open_registrations: 'true' } - expect(response).to redirect_to(admin_settings_path) + expect(response).to redirect_to(edit_admin_settings_path) expect(Setting.open_registrations).to eq true end end