From b7c1b12367b307d07303ce99f2c27bf255ecd56a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 18:55:06 +0200 Subject: Make default admin UI page reports. Add admin UI for creating a domain block --- app/views/admin/domain_blocks/index.html.haml | 1 + app/views/admin/domain_blocks/new.html.haml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 app/views/admin/domain_blocks/new.html.haml (limited to 'app/views') diff --git a/app/views/admin/domain_blocks/index.html.haml b/app/views/admin/domain_blocks/index.html.haml index dbaeb4716..eb7894b86 100644 --- a/app/views/admin/domain_blocks/index.html.haml +++ b/app/views/admin/domain_blocks/index.html.haml @@ -14,3 +14,4 @@ %td= block.severity = will_paginate @blocks, pagination_options += link_to 'Add new', new_admin_domain_block_path, class: 'button' diff --git a/app/views/admin/domain_blocks/new.html.haml b/app/views/admin/domain_blocks/new.html.haml new file mode 100644 index 000000000..fbd39d6cf --- /dev/null +++ b/app/views/admin/domain_blocks/new.html.haml @@ -0,0 +1,18 @@ +- content_for :page_title do + New domain block + += simple_form_for @domain_block, url: admin_domain_blocks_path do |f| + = render 'shared/error_messages', object: @domain_block + + %p.hint The domain block will not prevent creation of account entries in the database, but will retroactively and automatically apply specific moderation methods on those accounts. + + = f.input :domain, placeholder: 'Domain' + = f.input :severity, collection: DomainBlock.severities.keys, wrapper: :with_label, include_blank: false + + %p.hint + %strong Silence + will make the account's posts invisible to anyone who isn't following them. + %strong Suspend + will remove all of the account's content, media, and profile data. + .actions + = f.button :button, 'Create block', type: :submit -- cgit From 71458dc6df368801b32b55bb63baa94375019a83 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 19:17:56 +0200 Subject: When taking action on a report (silence/suspend), it dismisses all other reports for that user automatically --- app/controllers/admin/reports_controller.rb | 4 ++-- app/views/admin/reports/index.html.haml | 35 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'app/views') diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 0117a18ee..bb3f028d9 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -22,13 +22,13 @@ class Admin::ReportsController < ApplicationController def suspend Admin::SuspensionWorker.perform_async(@report.target_account.id) - @report.update(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) redirect_to admin_report_path(@report) end def silence @report.target_account.update(silenced: true) - @report.update(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) redirect_to admin_report_path(@report) end diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index 8a5414cef..839259dc2 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -8,20 +8,25 @@ %li= filter_link_to 'Unresolved', action_taken: nil %li= filter_link_to 'Resolved', action_taken: '1' -%table.table - %thead - %tr - %th ID - %th Target - %th Reported by - %th Comment - %th - %tbody - - @reports.each do |report| += form_tag do + + %table.table + %thead %tr - %td= "##{report.id}" - %td= link_to report.target_account.acct, admin_account_path(report.target_account.id) - %td= link_to report.account.acct, admin_account_path(report.account.id) - %td= truncate(report.comment, length: 30, separator: ' ') - %td= table_link_to 'circle', 'View', admin_report_path(report) + %th + %th ID + %th Target + %th Reported by + %th Comment + %th + %tbody + - @reports.each do |report| + %tr + %td= check_box_tag 'select', report.id + %td= "##{report.id}" + %td= link_to report.target_account.acct, admin_account_path(report.target_account.id) + %td= link_to report.account.acct, admin_account_path(report.account.id) + %td= truncate(report.comment, length: 30, separator: ' ') + %td= table_link_to 'circle', 'View', admin_report_path(report) + = will_paginate @reports, pagination_options -- cgit From 68f829e11c058c55a6695b5812aa0577b5b1eea1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Apr 2017 19:27:30 +0200 Subject: Add basic logging of who resolved report --- app/controllers/admin/reports_controller.rb | 6 +++--- app/models/report.rb | 1 + app/views/admin/reports/show.html.haml | 8 +++++++- ...3172249_add_action_taken_by_account_id_to_reports.rb | 5 +++++ db/schema.rb | 17 +++++++++-------- spec/services/block_domain_service_spec.rb | 2 +- 6 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb (limited to 'app/views') diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index bb3f028d9..2b3b1809f 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -16,19 +16,19 @@ class Admin::ReportsController < ApplicationController end def resolve - @report.update(action_taken: true) + @report.update(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end def suspend Admin::SuspensionWorker.perform_async(@report.target_account.id) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end def silence @report.target_account.update(silenced: true) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) redirect_to admin_report_path(@report) end diff --git a/app/models/report.rb b/app/models/report.rb index 05dc8cff1..fd8e46aac 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -3,6 +3,7 @@ class Report < ApplicationRecord belongs_to :account belongs_to :target_account, class_name: 'Account' + belongs_to :action_taken_by_account, class_name: 'Account' scope :unresolved, -> { where(action_taken: false) } scope :resolved, -> { where(action_taken: true) } diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 74cac016d..caa8415df 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -27,7 +27,7 @@ = link_to remove_admin_report_path(@report, status_id: status.id), method: :post, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: 'Delete' do = fa_icon 'trash' -- unless @report.action_taken? +- if !@report.action_taken? %hr/ %div{ style: 'overflow: hidden' } @@ -36,3 +36,9 @@ = link_to 'Suspend account', suspend_admin_report_path(@report), method: :post, class: 'button' %div{ style: 'float: left' } = link_to 'Mark as resolved', resolve_admin_report_path(@report), method: :post, class: 'button' +- elsif !@report.action_taken_by_account.nil? + %hr/ + + %p + %strong Action taken by: + = @report.action_taken_by_account.acct diff --git a/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb b/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb new file mode 100644 index 000000000..2d4e12198 --- /dev/null +++ b/db/migrate/20170403172249_add_action_taken_by_account_id_to_reports.rb @@ -0,0 +1,5 @@ +class AddActionTakenByAccountIdToReports < ActiveRecord::Migration[5.0] + def change + add_column :reports, :action_taken_by_account_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 5a9ca1426..3aaa3e3ad 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: 20170330164118) do +ActiveRecord::Schema.define(version: 20170403172249) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -201,13 +201,14 @@ ActiveRecord::Schema.define(version: 20170330164118) do end create_table "reports", force: :cascade do |t| - t.integer "account_id", null: false - t.integer "target_account_id", null: false - t.bigint "status_ids", default: [], null: false, array: true - t.text "comment", default: "", null: false - t.boolean "action_taken", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "account_id", null: false + t.integer "target_account_id", null: false + t.bigint "status_ids", default: [], null: false, array: true + t.text "comment", default: "", null: false + t.boolean "action_taken", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "action_taken_by_account_id" end create_table "settings", force: :cascade do |t| diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index d88b3b55c..8e71d4542 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -14,7 +14,7 @@ RSpec.describe BlockDomainService do bad_status2 bad_attachment - subject.call('evil.org', :suspend) + subject.call(DomainBlock.create!(domain: 'evil.org', severity: :suspend)) end it 'creates a domain block' do -- cgit From 5f54981846508daf9558f66ffd70d42d8213bea9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 4 Apr 2017 15:26:57 +0200 Subject: New admin setting: open/close registrations, with custom message, from the admin UI --- app/assets/stylesheets/about.scss | 10 ++++++- app/controllers/about_controller.rb | 4 ++- app/controllers/admin/settings_controller.rb | 14 +++++++-- app/controllers/auth/registrations_controller.rb | 10 +++---- app/views/about/index.html.haml | 37 ++++++++++++++++-------- app/views/admin/settings/index.html.haml | 12 ++++++++ config/locales/en.yml | 1 + config/settings.yml | 3 ++ 8 files changed, 70 insertions(+), 21 deletions(-) (limited to 'app/views') diff --git a/app/assets/stylesheets/about.scss b/app/assets/stylesheets/about.scss index 2ff1d1453..c9d9dc5d5 100644 --- a/app/assets/stylesheets/about.scss +++ b/app/assets/stylesheets/about.scss @@ -319,7 +319,7 @@ } } - .simple_form { + .simple_form, .closed-registrations-message { width: 300px; flex: 0 0 auto; background: rgba(darken($color1, 7%), 0.5); @@ -340,3 +340,11 @@ } } } + +.closed-registrations-message { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + text-align: center; +} diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index abf4b7df4..7fd43489f 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -4,7 +4,9 @@ class AboutController < ApplicationController before_action :set_body_classes def index - @description = Setting.site_description + @description = Setting.site_description + @open_registrations = Setting.open_registrations + @closed_registrations_message = Setting.closed_registrations_message @user = User.new @user.build_account diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index af0be8823..7615c781d 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -11,9 +11,13 @@ class Admin::SettingsController < ApplicationController def update @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id]) + value = settings_params[:value] - if @setting.value != params[:setting][:value] - @setting.value = params[:setting][:value] + # Special cases + value = value == 'true' if @setting.var == 'open_registrations' + + if @setting.value != value + @setting.value = value @setting.save end @@ -22,4 +26,10 @@ class Admin::SettingsController < ApplicationController format.json { respond_with_bip(@setting) } end end + + private + + def settings_params + params.require(:setting).permit(:value) + end end diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 501e66807..4881c074a 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -3,7 +3,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController layout :determine_layout - before_action :check_single_user_mode + before_action :check_enabled_registrations, only: [:new, :create] before_action :configure_sign_up_params, only: [:create] protected @@ -27,12 +27,12 @@ class Auth::RegistrationsController < Devise::RegistrationsController new_user_session_path end - def check_single_user_mode - redirect_to root_path if Rails.configuration.x.single_user_mode + def check_enabled_registrations + redirect_to root_path if Rails.configuration.x.single_user_mode || !Setting.open_registrations end - + private - + def determine_layout %w(edit update).include?(action_name) ? 'admin' : 'auth' end diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml index fdfb2b916..ebca4213a 100644 --- a/app/views/about/index.html.haml +++ b/app/views/about/index.html.haml @@ -24,21 +24,34 @@ .screenshot-with-signup .mascot= image_tag 'fluffy-elephant-friend.png' - = simple_form_for(@user, url: user_registration_path) do |f| - = f.simple_fields_for :account do |ff| - = ff.input :username, autofocus: true, placeholder: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username') } + - if @open_registrations + = simple_form_for(@user, url: user_registration_path) do |f| + = f.simple_fields_for :account do |ff| + = ff.input :username, autofocus: true, placeholder: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username') } - = f.input :email, placeholder: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email') } - = f.input :password, autocomplete: "off", placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password') } - = f.input :password_confirmation, autocomplete: "off", placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') } + = f.input :email, placeholder: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email') } + = f.input :password, autocomplete: "off", placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password') } + = f.input :password_confirmation, autocomplete: "off", placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') } - .actions - = f.button :button, t('about.get_started'), type: :submit + .actions + = f.button :button, t('about.get_started'), type: :submit - .info - = link_to t('auth.login'), new_user_session_path, class: 'webapp-btn' - · - = link_to t('about.about_this'), about_more_path + .info + = link_to t('auth.login'), new_user_session_path, class: 'webapp-btn' + · + = link_to t('about.about_this'), about_more_path + - else + .closed-registrations-message + - if @closed_registrations_message.blank? + %p= t('about.closed_registrations') + - else + = @closed_registrations_message.html_safe + .info + = link_to t('auth.login'), new_user_session_path, class: 'webapp-btn' + · + = link_to t('about.other_instances'), 'https://github.com/tootsuite/mastodon/blob/master/docs/Using-Mastodon/List-of-Mastodon-instances.md' + · + = link_to t('about.about_this'), about_more_path %h3= t('about.features_headline') diff --git a/app/views/admin/settings/index.html.haml b/app/views/admin/settings/index.html.haml index 1429dbd9e..02faac8c2 100644 --- a/app/views/admin/settings/index.html.haml +++ b/app/views/admin/settings/index.html.haml @@ -38,3 +38,15 @@ %br/ You can use HTML tags %td= best_in_place @settings['site_extended_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_extended_description']) + %tr + %td + %strong Open registration + %td= best_in_place @settings['open_registrations'], :value, as: :checkbox, collection: { false: 'Disabled', true: 'Enabled'}, url: admin_setting_path(@settings['open_registrations']) + %tr + %td + %strong Closed registration message + %br/ + Displayed on frontpage when registrations are closed + %br/ + You can use HTML tags + %td= best_in_place @settings['closed_registrations_message'], :value, as: :textarea, url: admin_setting_path(@settings['closed_registrations_message']) diff --git a/config/locales/en.yml b/config/locales/en.yml index 157f107a5..750af0b7a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,6 +6,7 @@ en: apps: Apps business_email: 'Business e-mail:' contact: Contact + closed_registrations: Registrations are currently closed on this instance. description_headline: What is %{domain}? domain_count_after: other instances domain_count_before: Connected to diff --git a/config/settings.yml b/config/settings.yml index 6ae9217a4..ffcc1eaa7 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -5,6 +5,8 @@ defaults: &defaults site_extended_description: '' site_contact_username: '' site_contact_email: '' + open_registrations: true + closed_registrations_message: '' notification_emails: follow: false reblog: false @@ -15,6 +17,7 @@ defaults: &defaults interactions: must_be_follower: false must_be_following: false + development: <<: *defaults -- cgit