Skip to content

Commit 3eb28d4

Browse files
authored
New config (#653)
* chore(config,backend): remove useless config params * feat(frontend): respect the `is_demo` field for prefs * build(backend): bump version * chore(config,backend): remove outdated config param * chore(frontend): remove outdated config param * chore(frontend): apply lints * chore(ts-utils): apply lints
1 parent 9136d71 commit 3eb28d4

File tree

13 files changed

+62
-181
lines changed

13 files changed

+62
-181
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ryot"
3-
version = "4.2.9"
3+
version = "4.2.10"
44
edition = "2021"
55
repository = "https://github.com/IgnisDa/ryot"
66
license = "GPL-3.0"

apps/backend/src/miscellaneous/resolver.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,11 @@ struct CoreDetails {
573573
version: String,
574574
author_name: String,
575575
repository_link: String,
576-
default_credentials: bool,
577-
preferences_change_allowed: bool,
578-
credentials_change_allowed: bool,
579576
item_details_height: u32,
580577
reviews_disabled: bool,
581578
videos_disabled: bool,
582579
upgrade: Option<UpgradeType>,
583580
page_limit: i32,
584-
deploy_admin_jobs_allowed: bool,
585581
timezone: String,
586582
}
587583

@@ -1452,11 +1448,7 @@ impl MiscellaneousService {
14521448
page_limit: self.config.frontend.page_size,
14531449
videos_disabled: self.config.server.videos_disabled,
14541450
reviews_disabled: self.config.users.reviews_disabled,
1455-
default_credentials: self.config.server.default_credentials,
14561451
item_details_height: self.config.frontend.item_details_height,
1457-
credentials_change_allowed: self.config.users.allow_changing_credentials,
1458-
preferences_change_allowed: self.config.users.allow_changing_preferences,
1459-
deploy_admin_jobs_allowed: self.config.server.deploy_admin_jobs_allowed,
14601452
})
14611453
}
14621454

@@ -2658,9 +2650,6 @@ impl MiscellaneousService {
26582650
.await?;
26592651
}
26602652
BackgroundJob::UpdateAllMetadata => {
2661-
if !self.config.server.deploy_admin_jobs_allowed {
2662-
return Ok(false);
2663-
}
26642653
self.admin_account_guard(user_id).await?;
26652654
let many_metadata = Metadata::find()
26662655
.select_only()
@@ -4870,17 +4859,13 @@ impl MiscellaneousService {
48704859
.unwrap()
48714860
.into();
48724861
if let Some(n) = input.username {
4873-
if self.config.users.allow_changing_credentials {
4874-
user_obj.name = ActiveValue::Set(n);
4875-
}
4862+
user_obj.name = ActiveValue::Set(n);
48764863
}
48774864
if let Some(e) = input.email {
48784865
user_obj.email = ActiveValue::Set(Some(e));
48794866
}
48804867
if let Some(p) = input.password {
4881-
if self.config.users.allow_changing_credentials {
4882-
user_obj.password = ActiveValue::Set(p);
4883-
}
4868+
user_obj.password = ActiveValue::Set(p);
48844869
}
48854870
let user_obj = user_obj.update(&self.db).await.unwrap();
48864871
Ok(IdObject { id: user_obj.id })
@@ -4992,9 +4977,6 @@ impl MiscellaneousService {
49924977
input: UpdateUserPreferenceInput,
49934978
user_id: i32,
49944979
) -> Result<bool> {
4995-
if !self.config.users.allow_changing_preferences {
4996-
return Ok(false);
4997-
}
49984980
let err = || Error::new("Incorrect property value encountered");
49994981
let user_model = user_by_id(&self.db, user_id).await?;
50004982
let mut preferences = user_model.preferences.clone();

apps/frontend/app/routes/_dashboard.settings.miscellaneous.tsx

+21-56
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Stack,
77
Text,
88
Title,
9-
Tooltip,
109
} from "@mantine/core";
1110
import {
1211
ActionFunctionArgs,
@@ -20,22 +19,15 @@ import {
2019
DeployBackgroundJobDocument,
2120
UserLot,
2221
} from "@ryot/generated/graphql/backend/graphql";
23-
import { ReactNode } from "react";
2422
import { z } from "zod";
2523
import { getAuthorizationHeader, gqlClient } from "~/lib/api.server";
26-
import { getCoreDetails, getUserDetails } from "~/lib/graphql.server";
24+
import { getUserDetails } from "~/lib/graphql.server";
2725
import { createToastHeaders } from "~/lib/toast.server";
2826
import { processSubmission } from "~/lib/utilities.server";
2927

3028
export const loader = async ({ request }: LoaderFunctionArgs) => {
31-
const [coreDetails, userDetails] = await Promise.all([
32-
getCoreDetails(),
33-
getUserDetails(request),
34-
]);
35-
return json({
36-
coreDetails: { deployAdminJobsAllowed: coreDetails.deployAdminJobsAllowed },
37-
userDetails,
38-
});
29+
const [userDetails] = await Promise.all([getUserDetails(request)]);
30+
return json({ userDetails });
3931
};
4032

4133
export const meta: MetaFunction = () => {
@@ -86,18 +78,13 @@ export default function Page() {
8678
providers.
8779
</Text>
8880
</Box>
89-
<DisabledNotice
90-
enabled={!loaderData.coreDetails.deployAdminJobsAllowed}
81+
<Button
82+
{...buttonProps}
83+
name="jobName"
84+
value={BackgroundJob.UpdateAllMetadata}
9185
>
92-
<Button
93-
disabled={!loaderData.coreDetails.deployAdminJobsAllowed}
94-
{...buttonProps}
95-
name="jobName"
96-
value={BackgroundJob.UpdateAllMetadata}
97-
>
98-
Update metadata
99-
</Button>
100-
</DisabledNotice>
86+
Update metadata
87+
</Button>
10188
</Stack>
10289
<Stack>
10390
<Box>
@@ -109,18 +96,13 @@ export default function Page() {
10996
automatically.
11097
</Text>
11198
</Box>
112-
<DisabledNotice
113-
enabled={!loaderData.coreDetails.deployAdminJobsAllowed}
99+
<Button
100+
{...buttonProps}
101+
name="jobName"
102+
value={BackgroundJob.RecalculateCalendarEvents}
114103
>
115-
<Button
116-
disabled={!loaderData.coreDetails.deployAdminJobsAllowed}
117-
{...buttonProps}
118-
name="jobName"
119-
value={BackgroundJob.RecalculateCalendarEvents}
120-
>
121-
Update calendar events
122-
</Button>
123-
</DisabledNotice>
104+
Update calendar events
105+
</Button>
124106
</Stack>
125107
<Stack>
126108
<Box>
@@ -131,18 +113,13 @@ export default function Page() {
131113
job when there are new exercises available.
132114
</Text>
133115
</Box>
134-
<DisabledNotice
135-
enabled={!loaderData.coreDetails.deployAdminJobsAllowed}
116+
<Button
117+
{...buttonProps}
118+
name="jobName"
119+
value={BackgroundJob.UpdateAllExercises}
136120
>
137-
<Button
138-
disabled={!loaderData.coreDetails.deployAdminJobsAllowed}
139-
{...buttonProps}
140-
name="jobName"
141-
value={BackgroundJob.UpdateAllExercises}
142-
>
143-
Update exercises
144-
</Button>
145-
</DisabledNotice>
121+
Update exercises
122+
</Button>
146123
</Stack>
147124
</>
148125
) : null}
@@ -205,15 +182,3 @@ export default function Page() {
205182
}
206183

207184
const buttonProps = { variant: "light", type: "submit" as const };
208-
209-
const DisabledNotice = (props: {
210-
children: ReactNode;
211-
enabled: boolean;
212-
}) => (
213-
<Tooltip
214-
label="Deploying this job is disabled on this instance"
215-
disabled={!props.enabled}
216-
>
217-
{props.children}
218-
</Tooltip>
219-
);

apps/frontend/app/routes/_dashboard.settings.preferences.tsx

+21-26
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { match } from "ts-pattern";
5050
import { z } from "zod";
5151
import { zx } from "zodix";
5252
import { getAuthorizationHeader, gqlClient } from "~/lib/api.server";
53-
import { getCoreDetails, getUserPreferences } from "~/lib/graphql.server";
53+
import { getUserDetails, getUserPreferences } from "~/lib/graphql.server";
5454
import classes from "~/styles/preferences.module.css";
5555

5656
const searchSchema = z.object({
@@ -59,15 +59,13 @@ const searchSchema = z.object({
5959

6060
export const loader = async ({ request }: LoaderFunctionArgs) => {
6161
const query = zx.parseQuery(request, searchSchema);
62-
const [coreDetails, userPreferences] = await Promise.all([
63-
getCoreDetails(),
62+
const [userPreferences, userDetails] = await Promise.all([
6463
getUserPreferences(request),
64+
getUserDetails(request),
6565
]);
6666
return json({
6767
query,
68-
coreDetails: {
69-
preferencesChangeAllowed: coreDetails.preferencesChangeAllowed,
70-
},
68+
userDetails: { isDemo: userDetails.isDemo },
7169
userPreferences,
7270
});
7371
};
@@ -79,7 +77,8 @@ export const meta: MetaFunction = () => {
7977
const notificationContent = {
8078
title: "Invalid action",
8179
color: "red",
82-
message: "Changing preferences is disabled on this instance.",
80+
message:
81+
"Changing preferences is disabled for demo users. Please create an account to save your preferences.",
8382
};
8483

8584
export const action = async ({ request }: ActionFunctionArgs) => {
@@ -159,7 +158,7 @@ export default function Page() {
159158
color="red"
160159
variant="outline"
161160
onClick={async (e) => {
162-
if (loaderData.coreDetails.preferencesChangeAllowed) {
161+
if (!loaderData.userDetails.isDemo) {
163162
if (
164163
!confirm(
165164
"This will reset all your preferences to default. Are you sure you want to continue?",
@@ -182,7 +181,7 @@ export default function Page() {
182181
</ActionIcon>
183182
</Form>
184183
</Group>
185-
{!loaderData.coreDetails.preferencesChangeAllowed ? (
184+
{loaderData.userDetails.isDemo ? (
186185
<Alert icon={<IconAlertCircle />} variant="outline" color="violet">
187186
{notificationContent.message}
188187
</Alert>
@@ -203,7 +202,7 @@ export default function Page() {
203202
<Text mb="md">The different sections on the dashboard.</Text>
204203
<DragDropContext
205204
onDragEnd={({ destination, source }) => {
206-
if (loaderData.coreDetails.preferencesChangeAllowed) {
205+
if (!loaderData.userDetails.isDemo) {
207206
flushSync(() => {
208207
dashboardElementsHandlers.reorder({
209208
from: source.index,
@@ -254,9 +253,7 @@ export default function Page() {
254253
label={changeCase(snakeCase(name))}
255254
// biome-ignore lint/suspicious/noExplicitAny: required here
256255
defaultChecked={isEnabled as any}
257-
disabled={
258-
!loaderData.coreDetails.preferencesChangeAllowed
259-
}
256+
disabled={!!loaderData.userDetails.isDemo}
260257
onChange={(ev) => {
261258
const lot = snakeCase(name);
262259
appendPref(
@@ -282,7 +279,7 @@ export default function Page() {
282279
value: c,
283280
}))}
284281
defaultValue={loaderData.userPreferences.general.reviewScale}
285-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
282+
disabled={!!loaderData.userDetails.isDemo}
286283
onChange={(val) => {
287284
if (val) appendPref("general.review_scale", val);
288285
}}
@@ -294,7 +291,7 @@ export default function Page() {
294291
defaultChecked={
295292
loaderData.userPreferences.general.displayNsfw
296293
}
297-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
294+
disabled={!!loaderData.userDetails.isDemo}
298295
onChange={(ev) => {
299296
appendPref(
300297
"general.display_nsfw",
@@ -309,7 +306,7 @@ export default function Page() {
309306
defaultChecked={
310307
loaderData.userPreferences.general.disableYankIntegrations
311308
}
312-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
309+
disabled={!!loaderData.userDetails.isDemo}
313310
onChange={(ev) => {
314311
appendPref(
315312
"general.disable_yank_integrations",
@@ -366,9 +363,7 @@ export default function Page() {
366363
)
367364
.otherwise(() => undefined)}
368365
defaultChecked={isEnabled}
369-
disabled={
370-
!loaderData.coreDetails.preferencesChangeAllowed
371-
}
366+
disabled={!!loaderData.userDetails.isDemo}
372367
onChange={(ev) => {
373368
appendPref(
374369
`notifications.${snakeCase(name)}`,
@@ -394,7 +389,7 @@ export default function Page() {
394389
loaderData.userPreferences.fitness.exercises.defaultTimer ||
395390
undefined
396391
}
397-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
392+
disabled={!!loaderData.userDetails.isDemo}
398393
onChange={(num) => {
399394
appendPref("fitness.exercises.default_timer", String(num));
400395
}}
@@ -405,7 +400,7 @@ export default function Page() {
405400
defaultValue={
406401
loaderData.userPreferences.fitness.exercises.saveHistory
407402
}
408-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
403+
disabled={!!loaderData.userDetails.isDemo}
409404
onChange={(num) => {
410405
if (num)
411406
appendPref("fitness.exercises.save_history", String(num));
@@ -438,7 +433,7 @@ export default function Page() {
438433
label: startCase(c.toLowerCase()),
439434
}))}
440435
defaultValue={loaderData.userPreferences.fitness.exercises.unitSystem.toLowerCase()}
441-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
436+
disabled={!!loaderData.userDetails.isDemo}
442437
onChange={(val) => {
443438
if (val) appendPref("fitness.exercises.unit_system", val);
444439
}}
@@ -454,7 +449,7 @@ export default function Page() {
454449
key={name}
455450
label={changeCase(snakeCase(name))}
456451
defaultChecked={isEnabled}
457-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
452+
disabled={!!loaderData.userDetails.isDemo}
458453
onChange={(ev) => {
459454
appendPref(
460455
`fitness.measurements.inbuilt.${snakeCase(name)}`,
@@ -472,7 +467,7 @@ export default function Page() {
472467
null,
473468
4,
474469
)}
475-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
470+
disabled={!!loaderData.userDetails.isDemo}
476471
autosize
477472
formatOnBlur
478473
onChange={(v) => {
@@ -532,7 +527,7 @@ const EditDashboardElement = (props: {
532527
label="Hidden"
533528
labelPosition="left"
534529
defaultChecked={focusedElement.hidden}
535-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
530+
disabled={!!loaderData.userDetails.isDemo}
536531
onChange={(ev) => {
537532
const newValue = ev.currentTarget.checked;
538533
const newDashboardData = Array.from(
@@ -552,7 +547,7 @@ const EditDashboardElement = (props: {
552547
label="Number of elements"
553548
size="xs"
554549
defaultValue={focusedElement.numElements}
555-
disabled={!loaderData.coreDetails.preferencesChangeAllowed}
550+
disabled={!!loaderData.userDetails.isDemo}
556551
onChange={(num) => {
557552
if (typeof num === "number") {
558553
const newDashboardData = Array.from(

0 commit comments

Comments
 (0)