]> cat aescling's git repositories - mastodon.git/commitdiff
New admin setting: open/close registrations, with custom message, from the admin UI
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 4 Apr 2017 13:26:57 +0000 (15:26 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 4 Apr 2017 13:28:12 +0000 (15:28 +0200)
app/assets/stylesheets/about.scss
app/controllers/about_controller.rb
app/controllers/admin/settings_controller.rb
app/controllers/auth/registrations_controller.rb
app/views/about/index.html.haml
app/views/admin/settings/index.html.haml
config/locales/en.yml
config/settings.yml

index 2ff1d14537180de1e7db628ad19cadf1b98a4ee2..c9d9dc5d5984e0adc6783f2c4ce4614d072c7542 100644 (file)
     }
   }
 
-  .simple_form {
+  .simple_form, .closed-registrations-message {
     width: 300px;
     flex: 0 0 auto;
     background: rgba(darken($color1, 7%), 0.5);
     }
   }
 }
+
+.closed-registrations-message {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  text-align: center;
+}
index abf4b7df4ca1b4a36a71de499b47164b3032d35e..7fd43489f2398a96e9313196a9073831e23c7d62 100644 (file)
@@ -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
index af0be88230766daff185935e8bab6fdc59d136af..7615c781d5fee0bc19b1e1f5c3f4188003a5061c 100644 (file)
@@ -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
index 501e66807609397629ac9f5578a3a1fab566734f..4881c074aa0eb6426ca8022efdb4133a8a68fbb4 100644 (file)
@@ -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
index fdfb2b916f1b56362dd13d4c2c5034b5d73567ec..ebca4213a77f1336599fa68d8123ebda78a37dfa 100644 (file)
   .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')
 
index 1429dbd9ee2301cbc81e14df3eda45ddbb64bd20..02faac8c26a7193b1672605108e35c3340a1b85e 100644 (file)
         %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'])
index 157f107a59ae00da293ede5e0979062f1d949c66..750af0b7a2c20d45a9e16d6a6e91eb8007f845b7 100644 (file)
@@ -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
index 6ae9217a4a68339ddbbd7ef7b45c6db4375feff9..ffcc1eaa74844bb52f8712dc4315217a7c85a259 100644 (file)
@@ -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