about summary refs log tree commit diff
path: root/lib/mastodon/settings_cli.rb
blob: 488c655deedd7ba94e44eb00dc6822c229787121 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require_relative '../../config/boot'
require_relative '../../config/environment'
require_relative 'cli_helper'

module Mastodon
  class RegistrationsCLI < Thor
    def self.exit_on_failure?
      true
    end

    desc 'open', 'Open registrations'
    def open
      Setting.registrations_mode = 'open'
      say('OK', :green)
    end

    desc 'approved', 'Open approval-based registrations'
    option :require_reason, type: :boolean, aliases: [:require_invite_text]
    long_desc <<~LONG_DESC
      Set registrations to require review from staff.

      With --require-reason, require users to enter a reason when registering,
      otherwise this field is optional.
    LONG_DESC
    def approved
      Setting.registrations_mode = 'approved'
      Setting.require_invite_text = options[:require_reason] unless options[:require_reason].nil?
      say('OK', :green)
    end

    desc 'close', 'Close registrations'
    def close
      Setting.registrations_mode = 'none'
      say('OK', :green)
    end
  end

  class SettingsCLI < Thor
    desc 'registrations SUBCOMMAND ...ARGS', 'Manage state of registrations'
    subcommand 'registrations', RegistrationsCLI
  end
end