Only allow specific server features to be edited
This commit is contained in:
parent
fbde8f978b
commit
d8b3e95942
@ -9,6 +9,7 @@ import {
|
|||||||
handleFile,
|
handleFile,
|
||||||
Member,
|
Member,
|
||||||
GuildUpdateSchema,
|
GuildUpdateSchema,
|
||||||
|
FosscordApiErrors,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
@ -74,6 +75,27 @@ router.patch(
|
|||||||
body.discovery_splash,
|
body.discovery_splash,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (body.features) {
|
||||||
|
const diff = guild.features.filter(x => !body.features?.includes(x))
|
||||||
|
.concat(body.features.filter(x => !guild.features.includes(x)));
|
||||||
|
|
||||||
|
// TODO move these
|
||||||
|
const MUTABLE_FEATURES = [
|
||||||
|
"COMMUNITY",
|
||||||
|
"INVITES_DISABLED",
|
||||||
|
"DISCOVERABLE",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var feature of diff) {
|
||||||
|
if (MUTABLE_FEATURES.includes(feature)) continue;
|
||||||
|
|
||||||
|
throw FosscordApiErrors.FEATURE_IS_IMMUTABLE.withParams(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for some reason, they don't update in the assign.
|
||||||
|
guild.features = body.features;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: check if body ids are valid
|
// TODO: check if body ids are valid
|
||||||
guild.assign(body);
|
guild.assign(body);
|
||||||
|
|
||||||
|
@ -1043,6 +1043,11 @@ export const FosscordApiErrors = {
|
|||||||
45006,
|
45006,
|
||||||
501,
|
501,
|
||||||
),
|
),
|
||||||
|
FEATURE_IS_IMMUTABLE : new ApiError(
|
||||||
|
"The feature ({}) cannot be edited.",
|
||||||
|
45007,
|
||||||
|
403,
|
||||||
|
),
|
||||||
MISSING_RIGHTS: new ApiError(
|
MISSING_RIGHTS: new ApiError(
|
||||||
"You lack rights to perform that action ({})",
|
"You lack rights to perform that action ({})",
|
||||||
50013,
|
50013,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user