about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/application_public.js5
-rw-r--r--app/assets/stylesheets/tables.scss4
-rw-r--r--app/controllers/about_controller.rb4
-rw-r--r--app/controllers/admin/settings_controller.rb25
-rw-r--r--app/controllers/settings/preferences_controller.rb20
-rw-r--r--app/helpers/settings_helper.rb4
-rw-r--r--app/lib/hash_object.rb10
-rw-r--r--app/models/setting.rb31
-rw-r--r--app/models/user.rb7
-rw-r--r--app/services/notify_service.rb16
-rw-r--r--app/views/about/index.html.haml5
-rw-r--r--app/views/admin/settings/index.html.haml22
-rw-r--r--app/views/settings/preferences/show.html.haml4
13 files changed, 131 insertions, 26 deletions
diff --git a/app/assets/javascripts/application_public.js b/app/assets/javascripts/application_public.js
index f131a267a..9626c5dae 100644
--- a/app/assets/javascripts/application_public.js
+++ b/app/assets/javascripts/application_public.js
@@ -1,3 +1,8 @@
 //= require jquery
 //= require jquery_ujs
 //= require extras
+//= require best_in_place
+
+$(function () {
+  $(".best_in_place").best_in_place();
+});
diff --git a/app/assets/stylesheets/tables.scss b/app/assets/stylesheets/tables.scss
index a37870786..279cc3069 100644
--- a/app/assets/stylesheets/tables.scss
+++ b/app/assets/stylesheets/tables.scss
@@ -36,6 +36,10 @@
       text-decoration: none;
     }
   }
+
+  strong {
+    font-weight: 500;
+  }
 }
 
 samp {
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb
index 7df58444f..84e5fbbd9 100644
--- a/app/controllers/about_controller.rb
+++ b/app/controllers/about_controller.rb
@@ -4,10 +4,10 @@ class AboutController < ApplicationController
   before_action :set_body_classes
 
   def index
+    @description = Setting.site_description
   end
 
-  def terms
-  end
+  def terms; end
 
   private
 
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
new file mode 100644
index 000000000..af0be8823
--- /dev/null
+++ b/app/controllers/admin/settings_controller.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class Admin::SettingsController < ApplicationController
+  before_action :require_admin!
+
+  layout 'admin'
+
+  def index
+    @settings = Setting.all_as_records
+  end
+
+  def update
+    @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
+
+    if @setting.value != params[:setting][:value]
+      @setting.value = params[:setting][:value]
+      @setting.save
+    end
+
+    respond_to do |format|
+      format.html { redirect_to admin_settings_path }
+      format.json { respond_with_bip(@setting) }
+    end
+  end
+end
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 3b6d109a6..f273b5f21 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -8,14 +8,18 @@ class Settings::PreferencesController < ApplicationController
   def show; end
 
   def update
-    current_user.settings(:notification_emails).follow         = user_params[:notification_emails][:follow]         == '1'
-    current_user.settings(:notification_emails).follow_request = user_params[:notification_emails][:follow_request] == '1'
-    current_user.settings(:notification_emails).reblog         = user_params[:notification_emails][:reblog]         == '1'
-    current_user.settings(:notification_emails).favourite      = user_params[:notification_emails][:favourite]      == '1'
-    current_user.settings(:notification_emails).mention        = user_params[:notification_emails][:mention]        == '1'
-
-    current_user.settings(:interactions).must_be_follower  = user_params[:interactions][:must_be_follower]  == '1'
-    current_user.settings(:interactions).must_be_following = user_params[:interactions][:must_be_following] == '1'
+    current_user.settings['notification_emails'] = {
+      follow:         user_params[:notification_emails][:follow]         == '1',
+      follow_request: user_params[:notification_emails][:follow_request] == '1',
+      reblog:         user_params[:notification_emails][:reblog]         == '1',
+      favourite:      user_params[:notification_emails][:favourite]      == '1',
+      mention:        user_params[:notification_emails][:mention]        == '1',
+    }
+
+    current_user.settings['interactions'] = {
+      must_be_follower:  user_params[:interactions][:must_be_follower]  == '1',
+      must_be_following: user_params[:interactions][:must_be_following] == '1',
+    }
 
     if current_user.update(user_params.except(:notification_emails, :interactions))
       redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index fa569e73a..aed8770c8 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -14,4 +14,8 @@ module SettingsHelper
   def human_locale(locale)
     HUMAN_LOCALES[locale]
   end
+
+  def hash_to_object(hash)
+    HashObject.new(hash)
+  end
 end
diff --git a/app/lib/hash_object.rb b/app/lib/hash_object.rb
new file mode 100644
index 000000000..274c020ad
--- /dev/null
+++ b/app/lib/hash_object.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class HashObject
+  def initialize(hash)
+    hash.each do |k, v|
+      instance_variable_set("@#{k}", v)
+      self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") })
+    end
+  end
+end
diff --git a/app/models/setting.rb b/app/models/setting.rb
new file mode 100644
index 000000000..0a429a62b
--- /dev/null
+++ b/app/models/setting.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class Setting < RailsSettings::Base
+  source Rails.root.join('config/settings.yml')
+  namespace Rails.env
+
+  def to_param
+    var
+  end
+
+  class << self
+    def all_as_records
+      vars    = thing_scoped
+      records = vars.map { |r| [r.var, r] }.to_h
+
+      default_settings.each do |key, default_value|
+        next if records.key?(key) || default_value.is_a?(Hash)
+        records[key] = Setting.new(var: key, value: default_value)
+      end
+
+      records
+    end
+
+    private
+
+    def default_settings
+      return {} unless RailsSettings::Default.enabled?
+      RailsSettings::Default.instance
+    end
+  end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index d5a52da06..bf7d04d7c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 class User < ApplicationRecord
+  include RailsSettings::Extend
+
   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
 
   belongs_to :account, inverse_of: :user
@@ -14,11 +16,6 @@ class User < ApplicationRecord
   scope :recent,   -> { order('id desc') }
   scope :admins,   -> { where(admin: true) }
 
-  has_settings do |s|
-    s.key :notification_emails, defaults: { follow: false, reblog: false, favourite: false, mention: false, follow_request: true }
-    s.key :interactions, defaults: { must_be_follower: false, must_be_following: false }
-  end
-
   def send_devise_notification(notification, *args)
     devise_mailer.send(notification, self, *args).deliver_later
   end
diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb
index 2fb1d3919..2eb0f417d 100644
--- a/app/services/notify_service.rb
+++ b/app/services/notify_service.rb
@@ -37,13 +37,13 @@ class NotifyService < BaseService
   end
 
   def blocked?
-    blocked   = @recipient.suspended?                                                                                             # Skip if the recipient account is suspended anyway
-    blocked ||= @recipient.id == @notification.from_account.id                                                                    # Skip for interactions with self
-    blocked ||= @recipient.blocking?(@notification.from_account)                                                                  # Skip for blocked accounts
-    blocked ||= (@notification.from_account.silenced? && !@recipient.following?(@notification.from_account))                      # Hellban
-    blocked ||= (@recipient.user.settings(:interactions).must_be_follower  && !@notification.from_account.following?(@recipient)) # Options
-    blocked ||= (@recipient.user.settings(:interactions).must_be_following && !@recipient.following?(@notification.from_account)) # Options
-    blocked ||= send("blocked_#{@notification.type}?")                                                                            # Type-dependent filters
+    blocked   = @recipient.suspended?                                                                                              # Skip if the recipient account is suspended anyway
+    blocked ||= @recipient.id == @notification.from_account.id                                                                     # Skip for interactions with self
+    blocked ||= @recipient.blocking?(@notification.from_account)                                                                   # Skip for blocked accounts
+    blocked ||= (@notification.from_account.silenced? && !@recipient.following?(@notification.from_account))                       # Hellban
+    blocked ||= (@recipient.user.settings.interactions['must_be_follower']  && !@notification.from_account.following?(@recipient)) # Options
+    blocked ||= (@recipient.user.settings.interactions['must_be_following'] && !@recipient.following?(@notification.from_account)) # Options
+    blocked ||= send("blocked_#{@notification.type}?")                                                                             # Type-dependent filters
     blocked
   end
 
@@ -58,6 +58,6 @@ class NotifyService < BaseService
   end
 
   def email_enabled?
-    @recipient.user.settings(:notification_emails).send(@notification.type)
+    @recipient.user.settings.notification_emails[@notification.type]
   end
 end
diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml
index 0c6516036..a593ff578 100644
--- a/app/views/about/index.html.haml
+++ b/app/views/about/index.html.haml
@@ -8,7 +8,7 @@
   %meta{ property: 'og:site_name', content: 'Mastodon' }/
   %meta{ property: 'og:type', content: 'website' }/
   %meta{ property: 'og:title', content: Rails.configuration.x.local_domain }/
-  %meta{ property: 'og:description', content: "Mastodon is a free, open-source social network server. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. Anyone can run Mastodon and participate in the social network seamlessly" }/
+  %meta{ property: 'og:description', content: @description.blank? ? "Mastodon is a free, open-source social network server. A decentralized alternative to commercial platforms, it avoids the risks of a single company monopolizing your communication. Anyone can run Mastodon and participate in the social network seamlessly" : strip_tags(@description) }/
   %meta{ property: 'og:image', content: asset_url('mastodon_small.jpg') }/
   %meta{ property: 'og:image:width', content: '400' }/
   %meta{ property: 'og:image:height', content: '400' }/
@@ -24,6 +24,9 @@
 
   .screenshot= image_tag 'screenshot.png'
 
+  - unless @description.blank?
+    %p= @description.html_safe
+
   .actions
     .info
       = link_to t('about.terms'), terms_path
diff --git a/app/views/admin/settings/index.html.haml b/app/views/admin/settings/index.html.haml
new file mode 100644
index 000000000..b8ca3a7a4
--- /dev/null
+++ b/app/views/admin/settings/index.html.haml
@@ -0,0 +1,22 @@
+- content_for :page_title do
+  Site Settings
+
+%table.table
+  %colgroup
+    %col{ width: '35%' }/
+  %thead
+    %tr
+      %th Setting
+      %th Click to edit
+  %tbody
+    %tr
+      %td
+        %strong Site description
+        %br/
+        Displayed as a paragraph on the frontpage and used as a meta tag.
+        %br/
+        You can use HTML tags, in particular
+        %code= '<a>'
+        and
+        %code= '<em>'
+      %td= best_in_place @settings['site_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_description'])
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index a0860c94b..a9a1d21ac 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -6,14 +6,14 @@
 
   = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }
 
-  = f.simple_fields_for :notification_emails, current_user.settings(:notification_emails) do |ff|
+  = f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
     = ff.input :follow, as: :boolean, wrapper: :with_label
     = ff.input :follow_request, as: :boolean, wrapper: :with_label
     = ff.input :reblog, as: :boolean, wrapper: :with_label
     = ff.input :favourite, as: :boolean, wrapper: :with_label
     = ff.input :mention, as: :boolean, wrapper: :with_label
 
-  = f.simple_fields_for :interactions, current_user.settings(:interactions) do |ff|
+  = f.simple_fields_for :interactions, hash_to_object(current_user.settings.interactions) do |ff|
     = ff.input :must_be_follower, as: :boolean, wrapper: :with_label
     = ff.input :must_be_following, as: :boolean, wrapper: :with_label