Some minor permission editor related fixes

This commit is contained in:
WolverinDEV 2020-12-08 12:14:53 +01:00
parent 848de9d4c0
commit 335f527a92
5 changed files with 26 additions and 24 deletions

View file

@ -109,7 +109,7 @@ export class CommandHelper extends AbstractCommandHandler {
for(const clientDatabaseId of uniqueClientDatabaseIds) { for(const clientDatabaseId of uniqueClientDatabaseIds) {
request.push({ cldbid: clientDatabaseId }); request.push({ cldbid: clientDatabaseId });
const requestCallbacks = this.infoByUniqueIdRequest[clientDatabaseId] || (this.infoByUniqueIdRequest[clientDatabaseId] = []); const requestCallbacks = this.infoByDatabaseIdRequest[clientDatabaseId] || (this.infoByDatabaseIdRequest[clientDatabaseId] = []);
requestCallbacks.push(resolvers[clientDatabaseId] = info => response.push(info)); requestCallbacks.push(resolvers[clientDatabaseId] = info => response.push(info));
} }

View file

@ -304,13 +304,13 @@ class PermissionEditorModal extends InternalModal {
} }
protected onInitialize() { protected onInitialize() {
this.modalEvents.fire("query_client_permissions"); this.modalEvents.fire_later("action_activate_tab", {
this.modalEvents.fire("action_activate_tab", {
tab: this.defaultTab, tab: this.defaultTab,
activeChannelId: this.defaultTabValues?.channelId, activeChannelId: this.defaultTabValues?.channelId,
activeGroupId: this.defaultTabValues?.groupId, activeGroupId: this.defaultTabValues?.groupId,
activeClientDatabaseId: this.defaultTabValues?.clientDatabaseId activeClientDatabaseId: this.defaultTabValues?.clientDatabaseId
}); });
this.modalEvents.fire_later("query_client_permissions");
} }
protected onDestroy() { protected onDestroy() {
@ -870,8 +870,9 @@ function initializePermissionEditor(connection: ConnectionHandler, modalEvents:
const failed = failedPermission(); const failed = failedPermission();
events.fire("action_set_mode", {mode: failed ? "no-permissions" : editorMode, failedPermission: failed}); events.fire("action_set_mode", {mode: failed ? "no-permissions" : editorMode, failedPermission: failed});
if (!failed && editorMode === "normal") if (!failed && editorMode === "normal") {
events.fire("query_permission_values"); events.fire("query_permission_values");
}
}); });
events.on("query_permission_list", () => { events.on("query_permission_list", () => {
@ -999,14 +1000,16 @@ function initializePermissionEditor(connection: ConnectionHandler, modalEvents:
} }
let prefix = mode === "groups-server" ? "server" : "channel"; let prefix = mode === "groups-server" ? "server" : "channel";
if (mode === "groups-server") if (mode === "groups-server") {
payload[0].sgid = groupId; payload[0].sgid = groupId;
else } else {
payload[0].cgid = groupId; payload[0].cgid = groupId;
}
promise = connection.serverConnection.send_command(prefix + "groupaddperm", payload); promise = connection.serverConnection.send_command(prefix + "groupaddperm", payload);
break; break;
} }
case "channel": case "channel":
if (!channelId) { if (!channelId) {
promise = Promise.reject(tr("Invalid channel id")); promise = Promise.reject(tr("Invalid channel id"));

View file

@ -894,8 +894,9 @@ class ChannelList extends React.Component<{ connection: ConnectionHandler, event
@EventHandler<PermissionModalEvents>("action_select_channel") @EventHandler<PermissionModalEvents>("action_select_channel")
private handleActionSelectChannel(event: PermissionModalEvents["action_select_channel"]) { private handleActionSelectChannel(event: PermissionModalEvents["action_select_channel"]) {
if (event.target !== this.props.tabTarget) if (event.target !== this.props.tabTarget) {
return; return;
}
this.setState({selectedChanelId: event.id}); this.setState({selectedChanelId: event.id});
if (this.isActiveTab) { if (this.isActiveTab) {
@ -909,13 +910,15 @@ class ChannelList extends React.Component<{ connection: ConnectionHandler, event
@EventHandler<PermissionModalEvents>("action_activate_tab") @EventHandler<PermissionModalEvents>("action_activate_tab")
private handleActionTabSelect(event: PermissionModalEvents["action_activate_tab"]) { private handleActionTabSelect(event: PermissionModalEvents["action_activate_tab"]) {
this.isActiveTab = event.tab === this.props.tabTarget; this.isActiveTab = event.tab === this.props.tabTarget;
if (!this.isActiveTab) if (!this.isActiveTab) {
return; return;
}
if (typeof event.activeChannelId === "number") if (typeof event.activeChannelId === "number") {
this.setState({selectedChanelId: event.activeChannelId}); this.setState({ selectedChanelId: event.activeChannelId });
}
this.props.events.fire("action_set_permission_editor_subject", { this.props.events.fire_later("action_set_permission_editor_subject", {
mode: this.props.tabTarget, mode: this.props.tabTarget,
channelId: typeof event.activeChannelId === "number" ? event.activeChannelId : this.state.selectedChanelId channelId: typeof event.activeChannelId === "number" ? event.activeChannelId : this.state.selectedChanelId
}); });
@ -945,8 +948,9 @@ const ClientSelect = (props: { events: Registry<PermissionModalEvents>, tabTarge
const refDatabaseId = useRef<FlatInputField>(); const refDatabaseId = useRef<FlatInputField>();
props.events.reactUse("action_activate_tab", event => { props.events.reactUse("action_activate_tab", event => {
if (event.tab !== props.tabTarget) if (event.tab !== props.tabTarget) {
return; return;
}
if (typeof event.activeClientDatabaseId !== "undefined") { if (typeof event.activeClientDatabaseId !== "undefined") {
props.events.fire("action_select_client", { props.events.fire("action_select_client", {
@ -954,13 +958,14 @@ const ClientSelect = (props: { events: Registry<PermissionModalEvents>, tabTarge
id: event.activeClientDatabaseId === 0 ? "undefined" : event.activeClientDatabaseId id: event.activeClientDatabaseId === 0 ? "undefined" : event.activeClientDatabaseId
}); });
} else { } else {
if (clientInfo && clientInfo.databaseId) if (clientInfo && clientInfo.databaseId) {
props.events.fire("action_set_permission_editor_subject", { props.events.fire("action_set_permission_editor_subject", {
mode: props.tabTarget, mode: props.tabTarget,
clientDatabaseId: clientInfo.databaseId clientDatabaseId: clientInfo.databaseId
}); });
else } else {
props.events.fire("action_set_permission_editor_subject", {mode: props.tabTarget, clientDatabaseId: 0}); props.events.fire("action_set_permission_editor_subject", {mode: props.tabTarget, clientDatabaseId: 0});
}
} }
}); });
@ -1066,13 +1071,15 @@ const ClientSelect = (props: { events: Registry<PermissionModalEvents>, tabTarge
client = undefined; client = undefined;
} else { } else {
try { try {
if (arrayBufferBase64(value).byteLength !== 20) { if (arrayBufferBase64(value).byteLength !== 20 && value !== "serveradmin") {
refInput.current?.setState({ refInput.current?.setState({
isInvalid: true, isInvalid: true,
invalidMessage: tr("Invalid UUID length") invalidMessage: tr("Invalid UUID length")
}); });
return; return;
} }
client = value;
} catch (e) { } catch (e) {
refInput.current?.setState({isInvalid: true, invalidMessage: tr("Invalid UUID")}); refInput.current?.setState({isInvalid: true, invalidMessage: tr("Invalid UUID")});
return; return;

View file

@ -1,14 +1,6 @@
import * as React from "react"; import * as React from "react";
import * as purify from "dompurify"; import * as purify from "dompurify";
/*
export const HTMLRenderer = (props: { purify: boolean, children: string }) => {
const html = props.purify ? purify.sanitize(props.children) : props.children;
return <span dangerouslySetInnerHTML={{ __html: html }} />
};
*/
export class HTMLRenderer extends React.PureComponent<{ purify: boolean, children: string }, {}> { export class HTMLRenderer extends React.PureComponent<{ purify: boolean, children: string }, {}> {
private readonly reference = React.createRef<HTMLSpanElement>(); private readonly reference = React.createRef<HTMLSpanElement>();
private readonly newNodes: Element[]; private readonly newNodes: Element[];

View file

@ -1,4 +1,4 @@
import {Dispatch, SetStateAction, useEffect, useMemo, useState} from "react"; import {Dispatch, SetStateAction, useMemo, useState} from "react";
export function useDependentState<S>( export function useDependentState<S>(
factory: (prevState?: S) => S, factory: (prevState?: S) => S,