From 6cb3514d64ec24b164484f4eb84363b96746d5d6 Mon Sep 17 00:00:00 2001 From: Jakub Mendyk Date: Thu, 23 Aug 2018 14:17:35 +0200 Subject: Add ability to change an instance default theme from the administration panel (#7092) (#8381) * Add default_settings class method to ScopedSettings ScopedSettings was extended to use value of unscoped setting instead of only using defaults set in config/settings.yml for selected settings. This adds possibility for admins to set default values of users' settings, for example default theme (as requested in #7092). * Add ability to change an instance default theme Closes #7092 --- app/controllers/admin/settings_controller.rb | 1 + app/controllers/application_controller.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 3234b194f..23e0444d0 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -16,6 +16,7 @@ module Admin timeline_preview show_staff_badge bootstrap_timeline_accounts + theme thumbnail hero min_invite_role diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eafe27047..7ddd26ec0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -95,7 +95,7 @@ class ApplicationController < ActionController::Base end def current_theme - return Setting.default_settings['theme'] unless Themes.instance.names.include? current_user&.setting_theme + return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme current_user.setting_theme end -- cgit From 9d58daac6c860b599f8c266b8bb10c6170220dd3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 23 Aug 2018 21:51:56 +0200 Subject: Fix regression when suspending not from report (#8400) Regression from #8353 --- app/controllers/admin/suspensions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/admin/suspensions_controller.rb b/app/controllers/admin/suspensions_controller.rb index 0c7bdad9e..f9bbf36fb 100644 --- a/app/controllers/admin/suspensions_controller.rb +++ b/app/controllers/admin/suspensions_controller.rb @@ -14,7 +14,7 @@ module Admin @suspension = Form::AdminSuspensionConfirmation.new(suspension_params) if suspension_params[:acct] == @account.acct - resolve_report! if suspension_params[:report_id] + resolve_report! if suspension_params[:report_id].present? perform_suspend! mark_reports_resolved! redirect_to admin_accounts_path -- cgit From 2f34b747b3f765a37d7b23e70de42005c0b62f58 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 23 Aug 2018 23:26:29 +0200 Subject: Allow mods to disable login, improve message when login disabled (#8329) * Allow moderators to disable/enable login * Instead of rejecting login, show forbidden error when login disabled Avoid confusion because when login is rejected, the message is that the account is not activated, which is wrong. * Fix tests --- app/controllers/api/base_controller.rb | 2 ++ app/controllers/application_controller.rb | 6 +++--- app/controllers/auth/sessions_controller.rb | 2 +- app/models/user.rb | 4 ---- app/policies/user_policy.rb | 4 ++-- spec/models/user_spec.rb | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 770a69921..0b3735087 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -7,6 +7,8 @@ class Api::BaseController < ApplicationController include RateLimitHeaders skip_before_action :store_current_location + skip_before_action :check_user_permissions + protect_from_forgery with: :null_session rescue_from ActiveRecord::RecordInvalid, Mastodon::ValidationError do |e| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7ddd26ec0..d266fa1bd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,7 +24,7 @@ class ApplicationController < ActionController::Base rescue_from Mastodon::NotPermittedError, with: :forbidden before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? - before_action :check_suspension, if: :user_signed_in? + before_action :check_user_permissions, if: :user_signed_in? def raise_not_found raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}" @@ -48,8 +48,8 @@ class ApplicationController < ActionController::Base forbidden unless current_user&.staff? end - def check_suspension - forbidden if current_user.account.suspended? + def check_user_permissions + forbidden if current_user.disabled? || current_user.account.suspended? end def after_sign_out_path_for(_resource_or_scope) diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 2e721160b..62b4a6377 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -6,7 +6,7 @@ class Auth::SessionsController < Devise::SessionsController layout 'auth' skip_before_action :require_no_authentication, only: [:create] - skip_before_action :check_suspension, only: [:destroy] + skip_before_action :check_user_permissions, only: [:destroy] prepend_before_action :authenticate_with_two_factor, if: :two_factor_enabled?, only: [:create] before_action :set_instance_presenter, only: [:new] before_action :set_body_classes diff --git a/app/models/user.rb b/app/models/user.rb index a2cf2565f..75b7e9e7c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -216,10 +216,6 @@ class User < ApplicationRecord save! end - def active_for_authentication? - super && !disabled? - end - def setting_default_privacy settings.default_privacy || (account.locked? ? 'private' : 'public') end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index dabdf707a..57af5c61c 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -18,11 +18,11 @@ class UserPolicy < ApplicationPolicy end def enable? - admin? + staff? end def disable? - admin? && !record.admin? + staff? && !record.admin? end def promote? diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 93a6c26fb..015e90edc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -512,7 +512,7 @@ RSpec.describe User, type: :model do context 'when user is confirmed' do let(:confirmed_at) { Time.zone.now } - it { is_expected.to be false } + it { is_expected.to be true } end context 'when user is not confirmed' do -- cgit From a2cabf3f4af9271d8bfdb13c1ae2b7a8b4e6fb88 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 24 Aug 2018 04:33:27 +0200 Subject: Add admin custom CSS setting (#8399) Fix #3894 --- app/controllers/admin/settings_controller.rb | 1 + app/controllers/custom_css_controller.rb | 10 ++++++++++ app/javascript/styles/mastodon/forms.scss | 11 +++++++++++ app/models/form/admin_settings.rb | 2 ++ app/presenters/instance_presenter.rb | 2 +- app/views/admin/settings/edit.html.haml | 2 +- app/views/layouts/application.html.haml | 3 +++ config/routes.rb | 1 + 8 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/controllers/custom_css_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 23e0444d0..7d38f76ae 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -24,6 +24,7 @@ module Admin peers_api_enabled show_known_fediverse_at_about_page preview_sensitive_media + custom_css ).freeze BOOLEAN_SETTINGS = %w( diff --git a/app/controllers/custom_css_controller.rb b/app/controllers/custom_css_controller.rb new file mode 100644 index 000000000..31e501609 --- /dev/null +++ b/app/controllers/custom_css_controller.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class CustomCssController < ApplicationController + before_action :set_cache_headers + + def show + skip_session! + render plain: Setting.custom_css || '', content_type: 'text/css' + end +end diff --git a/app/javascript/styles/mastodon/forms.scss b/app/javascript/styles/mastodon/forms.scss index 020be5ad2..144b4a519 100644 --- a/app/javascript/styles/mastodon/forms.scss +++ b/app/javascript/styles/mastodon/forms.scss @@ -621,3 +621,14 @@ code { .scope-danger { color: $warning-red; } + +.form_admin_settings_site_short_description, +.form_admin_settings_site_description, +.form_admin_settings_site_extended_description, +.form_admin_settings_site_terms, +.form_admin_settings_custom_css, +.form_admin_settings_closed_registrations_message { + textarea { + font-family: 'mastodon-font-monospace', monospace; + } +} diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index db46cda7b..9fef7da97 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -42,6 +42,8 @@ class Form::AdminSettings :show_known_fediverse_at_about_page=, :preview_sensitive_media, :preview_sensitive_media=, + :custom_css, + :custom_css=, to: Setting ) end diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index 31365b646..a4e4af889 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -14,7 +14,7 @@ class InstancePresenter ) def contact_account - Account.find_local(Setting.site_contact_username) + Account.find_local(Setting.site_contact_username.gsub(/\A@/, '')) end def user_count diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index b5aa176a2..f40edc35a 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -49,7 +49,7 @@ .fields-group = f.input :site_extended_description, wrapper: :with_block_label, as: :text, label: t('admin.settings.site_description_extended.title'), hint: t('admin.settings.site_description_extended.desc_html'), input_html: { rows: 8 } = f.input :site_terms, wrapper: :with_block_label, as: :text, label: t('admin.settings.site_terms.title'), hint: t('admin.settings.site_terms.desc_html'), input_html: { rows: 8 } - + = f.input :custom_css, wrapper: :with_block_label, as: :text, input_html: { rows: 8 }, label: t('admin.settings.custom_css.title'), hint: t('admin.settings.custom_css.desc_html') %hr/ .fields-group diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index df898d5a2..68a903197 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -19,6 +19,9 @@ = javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous' = csrf_meta_tags + - if Setting.custom_css.present? + = stylesheet_link_tag custom_css_path, media: 'all' + = yield :header_tags - body_classes ||= @body_classes || '' diff --git a/config/routes.rb b/config/routes.rb index 80a8b7b4c..0e54157dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,6 +23,7 @@ Rails.application.routes.draw do get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger get 'manifest', to: 'manifests#show', defaults: { format: 'json' } get 'intent', to: 'intents#show' + get 'custom.css', to: 'custom_css#show', as: :custom_css devise_scope :user do get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite -- cgit