mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-26 07:22:10 -05:00
Prevent granting permissions you don't have
This commit is contained in:
parent
c02c4a63fa
commit
5be8e60b45
1 changed files with 7 additions and 2 deletions
|
@ -6,7 +6,7 @@ import { Server } from "revolt.js/dist/maps/Servers";
|
||||||
|
|
||||||
import styles from "./Panes.module.scss";
|
import styles from "./Panes.module.scss";
|
||||||
import { Text } from "preact-i18n";
|
import { Text } from "preact-i18n";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
|
import {useCallback, useContext, useEffect, useMemo, useState} from "preact/hooks";
|
||||||
|
|
||||||
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import InputBox from "../../../components/ui/InputBox";
|
||||||
import Overline from "../../../components/ui/Overline";
|
import Overline from "../../../components/ui/Overline";
|
||||||
|
|
||||||
import ButtonItem from "../../../components/navigation/items/ButtonItem";
|
import ButtonItem from "../../../components/navigation/items/ButtonItem";
|
||||||
|
import {AppContext} from "../../../context/revoltjs/RevoltClient";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
server: Server;
|
server: Server;
|
||||||
|
@ -26,6 +27,7 @@ const I32ToU32 = (arr: number[]) => arr.map((x) => x >>> 0);
|
||||||
|
|
||||||
// ! FIXME: bad code :)
|
// ! FIXME: bad code :)
|
||||||
export const Roles = observer(({ server }: Props) => {
|
export const Roles = observer(({ server }: Props) => {
|
||||||
|
const client = useContext(AppContext);
|
||||||
const [role, setRole] = useState("default");
|
const [role, setRole] = useState("default");
|
||||||
const { openScreen } = useIntermediate();
|
const { openScreen } = useIntermediate();
|
||||||
const roles = useMemo(() => server.roles ?? {}, [server]);
|
const roles = useMemo(() => server.roles ?? {}, [server]);
|
||||||
|
@ -35,6 +37,8 @@ export const Roles = observer(({ server }: Props) => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientPermissions = client.servers.get(server._id)!.permission;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
name: roleName,
|
name: roleName,
|
||||||
colour: roleColour,
|
colour: roleColour,
|
||||||
|
@ -207,6 +211,7 @@ export const Roles = observer(({ server }: Props) => {
|
||||||
onChange={() =>
|
onChange={() =>
|
||||||
setPerm([perm[0] ^ value, perm[1]])
|
setPerm([perm[0] ^ value, perm[1]])
|
||||||
}
|
}
|
||||||
|
disabled={!(clientPermissions & value)}
|
||||||
description={
|
description={
|
||||||
<Text id={`permissions.server.${key}.d`} />
|
<Text id={`permissions.server.${key}.d`} />
|
||||||
}>
|
}>
|
||||||
|
@ -233,7 +238,7 @@ export const Roles = observer(({ server }: Props) => {
|
||||||
onChange={() =>
|
onChange={() =>
|
||||||
setPerm([perm[0], perm[1] ^ value])
|
setPerm([perm[0], perm[1] ^ value])
|
||||||
}
|
}
|
||||||
disabled={key === "View"}
|
disabled={key === "View" || (!(clientPermissions & value))}
|
||||||
description={
|
description={
|
||||||
<Text id={`permissions.channel.${key}.d`} />
|
<Text id={`permissions.channel.${key}.d`} />
|
||||||
}>
|
}>
|
||||||
|
|
Loading…
Reference in a new issue