forked from sct/overseerr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
366 lines (359 loc) · 14.3 KB
/
index.tsx
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import Button from '@app/components/Common/Button';
import LoadingSpinner from '@app/components/Common/LoadingSpinner';
import PageTitle from '@app/components/Common/PageTitle';
import SensitiveInput from '@app/components/Common/SensitiveInput';
import PermissionEdit from '@app/components/PermissionEdit';
import QuotaSelector from '@app/components/QuotaSelector';
import globalMessages from '@app/i18n/globalMessages';
import { ArrowDownOnSquareIcon } from '@heroicons/react/24/outline';
import type { MainSettings } from '@server/lib/settings';
import axios from 'axios';
import { Field, Form, Formik } from 'formik';
import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications';
import useSWR, { mutate } from 'swr';
import * as yup from 'yup';
const messages = defineMessages({
users: 'Users',
userSettings: 'User Settings',
userSettingsDescription: 'Configure global and default user settings.',
toastSettingsSuccess: 'User settings saved successfully!',
toastSettingsFailure: 'Something went wrong while saving settings.',
localLogin: 'Enable Local Sign-In',
localLoginTip:
'Allow users to sign in using their email address and password, instead of Plex OAuth',
newPlexLogin: 'Enable New Plex Sign-In',
newPlexLoginTip: 'Allow Plex users to sign in without first being imported',
movieRequestLimitLabel: 'Global Movie Request Limit',
tvRequestLimitLabel: 'Global Series Request Limit',
defaultPermissions: 'Default Permissions',
defaultPermissionsTip: 'Initial permissions assigned to new users',
oidcLogin: 'Enable OIDC Sign-In',
oidcLoginTip: 'Allow users to sign in using an OIDC provider',
oidcName: 'OIDC Provider Name',
oidcNameTip: 'The string used as name on the login page',
oidcClientId: 'OIDC Client ID',
oidcClientSecret: 'OIDC Client Secret',
oidcDomain: 'OIDC Domain',
});
const validationSchema = yup.object().shape({
oidcLogin: yup.boolean(),
oidcClientId: yup.string().when('oidcLogin', {
is: true,
then: yup.string().required(),
}),
oidcClientSecret: yup.string().when('oidcLogin', {
is: true,
then: yup.string().required(),
}),
oidcDomain: yup.string().when('oidcLogin', {
is: true,
then: yup
.string()
.required()
.test({
message: 'Must be a valid domain',
test: (val) => {
return (
!!val &&
// Any HTTPS domain without query string
/^([a-zA-Z0-9-_]+\.)[^?]+$/i.test(val)
);
},
}),
}),
});
const SettingsUsers: React.FC = () => {
const { addToast } = useToasts();
const intl = useIntl();
const {
data,
error,
mutate: revalidate,
} = useSWR<MainSettings>('/api/v1/settings/main');
if (!data && !error) {
return <LoadingSpinner />;
}
return (
<>
<PageTitle
title={[
intl.formatMessage(messages.users),
intl.formatMessage(globalMessages.settings),
]}
/>
<div className="mb-6">
<h3 className="heading">{intl.formatMessage(messages.userSettings)}</h3>
<p className="description">
{intl.formatMessage(messages.userSettingsDescription)}
</p>
</div>
<div className="section">
<Formik
initialValues={{
localLogin: data?.localLogin,
newPlexLogin: data?.newPlexLogin,
oidcName: data?.oidcName,
oidcLogin: data?.oidcLogin,
oidcClientId: data?.oidcClientId,
oidcClientSecret: data?.oidcClientSecret,
oidcDomain: data?.oidcDomain,
movieQuotaLimit: data?.defaultQuotas.movie.quotaLimit ?? 0,
movieQuotaDays: data?.defaultQuotas.movie.quotaDays ?? 7,
tvQuotaLimit: data?.defaultQuotas.tv.quotaLimit ?? 0,
tvQuotaDays: data?.defaultQuotas.tv.quotaDays ?? 7,
defaultPermissions: data?.defaultPermissions ?? 0,
}}
validationSchema={validationSchema}
enableReinitialize
onSubmit={async (values) => {
try {
await axios.post('/api/v1/settings/main', {
localLogin: values.localLogin,
newPlexLogin: values.newPlexLogin,
oidcLogin: values.oidcLogin,
oidcClientId: values.oidcClientId,
oidcClientSecret: values.oidcClientSecret,
oidcDomain: values.oidcDomain,
oidcName: values.oidcName,
defaultQuotas: {
movie: {
quotaLimit: values.movieQuotaLimit,
quotaDays: values.movieQuotaDays,
},
tv: {
quotaLimit: values.tvQuotaLimit,
quotaDays: values.tvQuotaDays,
},
},
defaultPermissions: values.defaultPermissions,
});
mutate('/api/v1/settings/public');
addToast(intl.formatMessage(messages.toastSettingsSuccess), {
autoDismiss: true,
appearance: 'success',
});
} catch (e) {
addToast(intl.formatMessage(messages.toastSettingsFailure), {
autoDismiss: true,
appearance: 'error',
});
} finally {
revalidate();
}
}}
>
{({ isSubmitting, values, setFieldValue, errors, touched }) => {
return (
<Form className="section">
<div className="form-row">
<label htmlFor="localLogin" className="checkbox-label">
{intl.formatMessage(messages.localLogin)}
<span className="label-tip">
{intl.formatMessage(messages.localLoginTip)}
</span>
</label>
<div className="form-input-area">
<Field
type="checkbox"
id="localLogin"
name="localLogin"
onChange={() => {
setFieldValue('localLogin', !values.localLogin);
}}
/>
</div>
</div>
<div className="form-row">
<label htmlFor="newPlexLogin" className="checkbox-label">
{intl.formatMessage(messages.newPlexLogin)}
<span className="label-tip">
{intl.formatMessage(messages.newPlexLoginTip)}
</span>
</label>
<div className="form-input-area">
<Field
type="checkbox"
id="newPlexLogin"
name="newPlexLogin"
onChange={() => {
setFieldValue('newPlexLogin', !values.newPlexLogin);
}}
/>
</div>
</div>
<div className="form-row">
<label htmlFor="oidcLogin" className="checkbox-label">
{intl.formatMessage(messages.oidcLogin)}
<span className="label-tip">
{intl.formatMessage(messages.oidcLoginTip)}
</span>
</label>
<div className="form-input-area">
<Field
type="checkbox"
id="oidcLogin"
name="oidcLogin"
onChange={() => {
setFieldValue('oidcLogin', !values.oidcLogin);
}}
/>
</div>
</div>
{values.oidcLogin ? (
<>
<div className="form-row">
<label htmlFor="oidcName" className="group-label">
{intl.formatMessage(messages.oidcName)}
<span className="label-tip">
{intl.formatMessage(messages.oidcNameTip)}
</span>
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field id="oidcName" name="oidcName" type="text" />
</div>
</div>
</div>
<div className="form-row">
<label htmlFor="oidcDomain" className="text-label">
{intl.formatMessage(messages.oidcDomain)}
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field
id="oidcDomain"
name="oidcDomain"
type="text"
/>
</div>
{errors.oidcDomain && touched.oidcDomain && (
<div className="error">{errors.oidcDomain}</div>
)}
</div>
</div>
<div className="form-row">
<label htmlFor="oidcClientId" className="text-label">
{intl.formatMessage(messages.oidcClientId)}
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field
id="oidcClientId"
name="oidcClientId"
type="text"
/>
</div>
{errors.oidcClientId && touched.oidcDomain && (
<div className="error">{errors.oidcClientId}</div>
)}
</div>
</div>
<div className="form-row">
<label htmlFor="oidcClientSecret" className="text-label">
{intl.formatMessage(messages.oidcClientSecret)}
</label>
<div className="form-input-area">
<div className="form-input-field">
<SensitiveInput
type="password"
id="oidcClientSecret"
className="rounded-l-only"
defaultValue={data?.oidcClientSecret}
onChange={(e) => {
setFieldValue('oidcClientSecret', e.target.value);
}}
autoComplete="off"
/>
</div>
{errors.oidcClientSecret &&
touched.oidcClientSecret && (
<div className="error">
{errors.oidcClientSecret}
</div>
)}
</div>
</div>
</>
) : null}
<div className="form-row">
<label htmlFor="applicationTitle" className="text-label">
{intl.formatMessage(messages.movieRequestLimitLabel)}
</label>
<div className="form-input-area">
<QuotaSelector
onChange={setFieldValue}
dayFieldName="movieQuotaDays"
limitFieldName="movieQuotaLimit"
mediaType="movie"
defaultDays={values.movieQuotaDays}
defaultLimit={values.movieQuotaLimit}
/>
</div>
</div>
<div className="form-row">
<label htmlFor="applicationTitle" className="text-label">
{intl.formatMessage(messages.tvRequestLimitLabel)}
</label>
<div className="form-input-area">
<QuotaSelector
onChange={setFieldValue}
dayFieldName="tvQuotaDays"
limitFieldName="tvQuotaLimit"
mediaType="tv"
defaultDays={values.tvQuotaDays}
defaultLimit={values.tvQuotaLimit}
/>
</div>
</div>
<div
role="group"
aria-labelledby="group-label"
className="form-group"
>
<div className="form-row">
<span id="group-label" className="group-label">
{intl.formatMessage(messages.defaultPermissions)}
<span className="label-tip">
{intl.formatMessage(messages.defaultPermissionsTip)}
</span>
</span>
<div className="form-input-area">
<div className="max-w-lg">
<PermissionEdit
currentPermission={values.defaultPermissions}
onUpdate={(newPermissions) =>
setFieldValue('defaultPermissions', newPermissions)
}
/>
</div>
</div>
</div>
</div>
<div className="actions">
<div className="flex justify-end">
<span className="ml-3 inline-flex rounded-md shadow-sm">
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting}
>
<ArrowDownOnSquareIcon />
<span>
{isSubmitting
? intl.formatMessage(globalMessages.saving)
: intl.formatMessage(globalMessages.save)}
</span>
</Button>
</span>
</div>
</div>
</Form>
);
}}
</Formik>
</div>
</>
);
};
export default SettingsUsers;