summaryrefslogtreecommitdiffstats
path: root/users/views/admin/settings.py
blob: d87fb7ee9f73724ea2c79cda7b3da8e87ed88b7a (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from django.utils.decorators import method_decorator
from django.utils.safestring import mark_safe

from core.models import Config
from users.decorators import admin_required
from users.views.settings import SettingsPage


@method_decorator(admin_required, name="dispatch")
class AdminSettingsPage(SettingsPage):
    """
    Shows a settings page dynamically created from our settings layout
    at the bottom of the page. Don't add this to a URL directly - subclass!
    """

    options_class = Config.SystemOptions

    def load_config(self):
        return Config.load_system()

    def save_config(self, key, value):
        Config.set_system(key, value)


class BasicSettings(AdminSettingsPage):

    section = "basic"

    options = {
        "site_name": {
            "title": "Site Name",
        },
        "highlight_color": {
            "title": "Highlight Color",
            "help_text": "Used for logo background and other highlights",
        },
        "post_length": {
            "title": "Maximum Post Length",
            "help_text": "The maximum number of characters allowed per post",
        },
        "post_minimum_interval": {
            "title": "Minimum Posting Interval",
            "help_text": "The minimum number of seconds a user must wait between posts",
        },
        "content_warning_text": {
            "title": "Content Warning Feature Name",
            "help_text": "What the feature that lets users provide post summaries is called",
        },
        "site_about": {
            "title": "About This Site",
            "help_text": "Displayed on the homepage and the about page.\nUse Markdown for formatting.",
            "display": "textarea",
        },
        "site_icon": {
            "title": "Site Icon",
            "help_text": "Minimum size 64x64px. Should be square.",
        },
        "site_banner": {
            "title": "Site Banner",
            "help_text": "Must be at least 650px wide. 3:1 ratio of width:height recommended.",
        },
        "identity_max_per_user": {
            "title": "Maximum Identities Per User",
            "help_text": "Non-admins will be blocked from creating more than this",
        },
        "identity_min_length": {
            "title": "Minimum Length For User Identities",
            "help_text": "Non-admins will be blocked from creating identities shorter than this",
        },
        "signup_allowed": {
            "title": "Signups Allowed",
            "help_text": "If signups are allowed at all",
        },
        "signup_invite_only": {
            "title": "Invite-Only",
            "help_text": "If signups require an invite code",
        },
        "signup_text": {
            "title": "Signup Page Text",
            "help_text": "Shown above the signup form.\nUse Markdown for formatting.",
            "display": "textarea",
        },
        "restricted_usernames": {
            "title": "Restricted Usernames",
            "help_text": "Usernames that only admins can register for identities. One per line.",
            "display": "textarea",
        },
        "hashtag_unreviewed_are_public": {
            "title": "Unreviewed Hashtags Are Public",
            "help_text": "Public Hashtags may appear in Trending and have a Tags timeline",
        },
        "emoji_unreviewed_are_public": {
            "title": "Unreviewed Emoji Are Public",
            "help_text": "Public Emoji may appear as images, instead of shortcodes",
        },
    }

    layout = {
        "Branding": [
            "site_name",
            "site_about",
            "site_icon",
            "site_banner",
            "highlight_color",
        ],
        "Signups": ["signup_allowed", "signup_invite_only", "signup_text"],
        "Posts": [
            "post_length",
            "post_minimum_interval",
            "content_warning_text",
            "hashtag_unreviewed_are_public",
            "emoji_unreviewed_are_public",
        ],
        "Identities": [
            "identity_max_per_user",
            "identity_min_length",
            "restricted_usernames",
        ],
    }


cache_field_defaults = {
    "min_value": 0,
    "max_value": 900,
    "step_size": 15,
}


class TuningSettings(AdminSettingsPage):

    section = "tuning"

    options = {
        "cache_timeout_page_default": {
            **cache_field_defaults,
            "title": "Default Timeout",
            "help_text": "The number of seconds to cache a rendered page",
        },
        "cache_timeout_page_timeline": {
            **cache_field_defaults,
            "title": "Timeline Timeout",
            "help_text": "The number of seconds to cache a rendered timeline page",
        },
        "cache_timeout_page_post": {
            **cache_field_defaults,
            "title": "Individual Post Timeout",
            "help_text": mark_safe(
                "The number of seconds to cache a rendered individual Post page<br>Note: This includes the JSON responses to other servers"
            ),
        },
        "cache_timeout_identity_feed": {
            **cache_field_defaults,
            "title": "Identity Feed Timeout",
            "help_text": "The number of seconds to cache a rendered Identity RSS feed",
        },
    }

    layout = {
        "Rendered Page Cache": [
            "cache_timeout_page_default",
            "cache_timeout_page_timeline",
            "cache_timeout_page_post",
        ],
        "RSS Feeds": [
            "cache_timeout_identity_feed",
        ],
    }


class PoliciesSettings(AdminSettingsPage):

    section = "policies"

    options = {
        "policy_terms": {
            "title": "Terms of Service Page",
            "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
            "display": "textarea",
        },
        "policy_privacy": {
            "title": "Privacy Policy Page",
            "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
            "display": "textarea",
        },
        "policy_rules": {
            "title": "Server Rules Page",
            "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
            "display": "textarea",
        },
    }

    layout = {
        "Policies": [
            "policy_rules",
            "policy_terms",
            "policy_privacy",
        ],
    }