Fix claim edit always editing permissions

This commit is contained in:
2025-11-09 17:12:36 +01:00
parent 5a37327e63
commit 8f7f388403
8 changed files with 22 additions and 19 deletions

View File

@@ -276,7 +276,7 @@ set
username = coalesce($2, username), username = coalesce($2, username),
email = coalesce($3, email), email = coalesce($3, email),
password = coalesce($4, password), password = coalesce($4, password),
claims = coalesce($5, claims) claims = claims || coalesce($5, '{}'::jsonb)
where where
id = $1 id = $1
returning returning

View File

@@ -72,7 +72,7 @@ set
username = coalesce(sqlc.narg(username), username), username = coalesce(sqlc.narg(username), username),
email = coalesce(sqlc.narg(email), email), email = coalesce(sqlc.narg(email), email),
password = coalesce(sqlc.narg(password), password), password = coalesce(sqlc.narg(password), password),
claims = coalesce(sqlc.narg(claims), claims) claims = claims || coalesce(sqlc.narg(claims), '{}'::jsonb)
where where
id = $1 id = $1
returning returning

View File

@@ -2,8 +2,8 @@ import { z } from "zod/v4";
export const User = z export const User = z
.object({ .object({
// // keep a default for older versions of the api // // keep a default for older versions of the api
// .default({}), // .default({}),
id: z.string(), id: z.string(),
username: z.string(), username: z.string(),
email: z.string(), email: z.string(),

View File

@@ -68,4 +68,4 @@ export const supportedLanguages = [
"tr", "tr",
"uk", "uk",
"zh", "zh",
]; ];

View File

@@ -275,7 +275,7 @@ export const useMutation = <T = void, QueryRet = void>({
...queryParams ...queryParams
}: MutationParams & { }: MutationParams & {
compute?: (param: T) => MutationParams; compute?: (param: T) => MutationParams;
optimistic?: ((param: T) => QueryRet); optimistic?: (param: T) => QueryRet;
invalidate: string[] | null; invalidate: string[] | null;
}) => { }) => {
const { apiUrl, authToken } = useContext(AccountContext); const { apiUrl, authToken } = useContext(AccountContext);
@@ -299,13 +299,19 @@ export const useMutation = <T = void, QueryRet = void>({
? { ? {
onMutate: async (params) => { onMutate: async (params) => {
const next = optimistic(params); const next = optimistic(params);
await queryClient.cancelQueries({ queryKey: invalidate }); const queryKey = toQueryKey({ apiUrl, path: invalidate });
const previous = queryClient.getQueryData(invalidate); await queryClient.cancelQueries({
queryClient.setQueryData(invalidate, next); queryKey,
});
const previous = queryClient.getQueryData(queryKey);
queryClient.setQueryData(queryKey, next);
return { previous, next }; return { previous, next };
}, },
onError: (_, __, context) => { onError: (_, __, context) => {
queryClient.setQueryData(invalidate, context!.previous); queryClient.setQueryData(
toQueryKey({ apiUrl, path: invalidate }),
context!.previous,
);
}, },
} }
: {}), : {}),

View File

@@ -22,10 +22,10 @@ import {
usePopup, usePopup,
} from "~/primitives"; } from "~/primitives";
import { useAccount } from "~/providers/account-context"; import { useAccount } from "~/providers/account-context";
import { useMutation } from "~/query";
import { deleteAccount, logout } from "../login/logic"; import { deleteAccount, logout } from "../login/logic";
import { PasswordInput } from "../login/password-input"; import { PasswordInput } from "../login/password-input";
import { Preference, SettingsContainer } from "./base"; import { Preference, SettingsContainer } from "./base";
import { useMutation } from "~/query";
// function dataURItoBlob(dataURI: string) { // function dataURItoBlob(dataURI: string) {
// const byteString = atob(dataURI.split(",")[1]); // const byteString = atob(dataURI.split(",")[1]);

View File

@@ -125,18 +125,15 @@ export const useSetting = <Setting extends keyof User["claims"]["settings"]>(
compute: (update: Partial<User["claims"]["settings"]>) => ({ compute: (update: Partial<User["claims"]["settings"]>) => ({
body: { body: {
claims: { claims: {
...account!.claims,
settings: { ...account!.claims.settings, ...update }, settings: { ...account!.claims.settings, ...update },
}, },
}, },
}), }),
optimistic: (update) => ({ optimistic: (update) => ({
body: { ...account,
...account, claims: {
claims: { ...account!.claims,
...account!.claims, settings: { ...account!.claims.settings, ...update },
settings: { ...account!.claims.settings, ...update },
},
}, },
}), }),
invalidate: ["auth", "users", "me"], invalidate: ["auth", "users", "me"],

View File

@@ -1,12 +1,12 @@
import SubtitleLanguage from "@material-symbols/svg-400/rounded/closed_caption-fill.svg"; import SubtitleLanguage from "@material-symbols/svg-400/rounded/closed_caption-fill.svg";
import PlayModeI from "@material-symbols/svg-400/rounded/display_settings-fill.svg"; import PlayModeI from "@material-symbols/svg-400/rounded/display_settings-fill.svg";
import AudioLanguage from "@material-symbols/svg-400/rounded/music_note-fill.svg"; import AudioLanguage from "@material-symbols/svg-400/rounded/music_note-fill.svg";
import langmap from "langmap";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Select } from "~/primitives"; import { Select } from "~/primitives";
import { useLocalSetting } from "~/providers/settings"; import { useLocalSetting } from "~/providers/settings";
import { useLanguageName } from "~/track-utils"; import { useLanguageName } from "~/track-utils";
import { Preference, SettingsContainer, useSetting } from "./base"; import { Preference, SettingsContainer, useSetting } from "./base";
import langmap from "langmap";
const seenNativeNames = new Set(); const seenNativeNames = new Set();
export const languageCodes = Object.keys(langmap) export const languageCodes = Object.keys(langmap)