about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorpluralcafe-docker <docker@plural.cafe>2018-08-30 05:23:58 +0000
committerpluralcafe-docker <docker@plural.cafe>2018-08-30 05:23:58 +0000
commitcc7437e25597e24b9a5f06f7991861506d9abe5c (patch)
treee627d32df29ef7ae30a67607caf3ecdc1ae333a9 /app/controllers
parent395164add468b1079669699dfe8eeaab73f69c15 (diff)
parent5ce67276691c37baad149f2f89f765543f70e6f9 (diff)
Merge branch 'glitch'
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/settings_controller.rb3
-rw-r--r--app/controllers/admin/suspensions_controller.rb2
-rw-r--r--app/controllers/api/base_controller.rb2
-rw-r--r--app/controllers/api/v1/lists/accounts_controller.rb2
-rw-r--r--app/controllers/api/v1/lists_controller.rb2
-rw-r--r--app/controllers/api/v1/mutes_controller.rb24
-rw-r--r--app/controllers/application_controller.rb10
-rw-r--r--app/controllers/auth/sessions_controller.rb2
-rw-r--r--app/controllers/custom_css_controller.rb10
9 files changed, 35 insertions, 22 deletions
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index 3234b194f..c05c4c841 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -16,6 +16,8 @@ module Admin
       timeline_preview
       show_staff_badge
       bootstrap_timeline_accounts
+      flavour
+      skin
       thumbnail
       hero
       min_invite_role
@@ -23,6 +25,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/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
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/api/v1/lists/accounts_controller.rb b/app/controllers/api/v1/lists/accounts_controller.rb
index 19de56732..ec4477034 100644
--- a/app/controllers/api/v1/lists/accounts_controller.rb
+++ b/app/controllers/api/v1/lists/accounts_controller.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class Api::V1::Lists::AccountsController < Api::BaseController
-  before_action -> { doorkeeper_authorize! :read, :'read:lists' },    only:  [:show]
+  before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:show]
   before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:show]
 
   before_action :require_user!
diff --git a/app/controllers/api/v1/lists_controller.rb b/app/controllers/api/v1/lists_controller.rb
index b42b8b971..054172bee 100644
--- a/app/controllers/api/v1/lists_controller.rb
+++ b/app/controllers/api/v1/lists_controller.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class Api::V1::ListsController < Api::BaseController
-  before_action -> { doorkeeper_authorize! :read, :'read:lists' },    only:  [:index, :show]
+  before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:index, :show]
   before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:index, :show]
 
   before_action :require_user!
diff --git a/app/controllers/api/v1/mutes_controller.rb b/app/controllers/api/v1/mutes_controller.rb
index aea94d553..3b3a39943 100644
--- a/app/controllers/api/v1/mutes_controller.rb
+++ b/app/controllers/api/v1/mutes_controller.rb
@@ -20,11 +20,7 @@ class Api::V1::MutesController < Api::BaseController
   private
 
   def load_accounts
-    default_accounts.merge(paginated_mutes).to_a
-  end
-
-  def default_accounts
-    Account.includes(:muted_by).references(:muted_by)
+    paginated_mutes.map(&:target_account)
   end
 
   def load_mutes
@@ -32,11 +28,13 @@ class Api::V1::MutesController < Api::BaseController
   end
 
   def paginated_mutes
-    Mute.where(account: current_account).paginate_by_max_id(
-      limit_param(DEFAULT_ACCOUNTS_LIMIT),
-      params[:max_id],
-      params[:since_id]
-    )
+    @paginated_mutes ||= Mute.eager_load(:target_account)
+                             .where(account: current_account)
+                             .paginate_by_max_id(
+                               limit_param(DEFAULT_ACCOUNTS_LIMIT),
+                               params[:max_id],
+                               params[:since_id]
+                             )
   end
 
   def insert_pagination_headers
@@ -50,7 +48,7 @@ class Api::V1::MutesController < Api::BaseController
   end
 
   def prev_path
-    unless@data.empty?
+    unless @data.empty?
       url_for pagination_params(since_id: pagination_since_id)
     end
   end
@@ -59,7 +57,7 @@ class Api::V1::MutesController < Api::BaseController
     if params[:action] == "details"
       @mutes.last.id
     else
-      @accounts.last.muted_by_ids.last
+      paginated_mutes.last.id
     end
   end
 
@@ -67,7 +65,7 @@ class Api::V1::MutesController < Api::BaseController
     if params[:action] == "details"
       @mutes.first.id
     else
-      @accounts.first.muted_by_ids.first
+      paginated_mutes.first.id
     end
   end
 
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 27cd0f4f9..8ffc31bb4 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -25,7 +25,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]}"
@@ -49,8 +49,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)
@@ -165,12 +165,12 @@ class ApplicationController < ActionController::Base
   end
 
   def current_flavour
-    return Setting.default_settings['flavour'] unless Themes.instance.flavours.include? current_user&.setting_flavour
+    return Setting.flavour unless Themes.instance.flavours.include? current_user&.setting_flavour
     current_user.setting_flavour
   end
 
   def current_skin
-    return 'default' unless Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin
+    return Setting.skin unless Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin
     current_user.setting_skin
   end
 
diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb
index 4c0d93f5d..7cd46662f 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]
   prepend_before_action :set_pack
   before_action :set_instance_presenter, only: [:new]
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