2019-03-15 21:33:31 -06:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-09-03 22:31:29 -06:00
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2019 Travis Ralston
|
2019-03-15 21:33:31 -06:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-03-15 21:33:31 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type Widget, type WidgetKind } from "matrix-widget-api";
|
2021-10-22 17:23:32 -05:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2019-03-15 21:33:31 -06:00
|
|
|
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
2022-10-19 21:00:53 +01:00
|
|
|
import { OIDCState } from "../../../stores/widgets/WidgetPermissionStore";
|
2021-09-05 12:02:43 +02:00
|
|
|
import BaseDialog from "./BaseDialog";
|
2021-09-03 22:31:29 -06:00
|
|
|
import DialogButtons from "../elements/DialogButtons";
|
2022-10-19 21:00:53 +01:00
|
|
|
import { SdkContextClass } from "../../../contexts/SDKContext";
|
2021-09-05 12:02:43 +02:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
interface IProps {
|
2021-09-05 12:02:43 +02:00
|
|
|
widget: Widget;
|
2021-09-03 22:31:29 -06:00
|
|
|
widgetKind: WidgetKind;
|
2021-09-05 12:02:43 +02:00
|
|
|
inRoomId?: string;
|
2023-02-28 10:31:48 +00:00
|
|
|
onFinished(allowed?: boolean): void;
|
2021-09-05 12:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
rememberSelection: boolean;
|
|
|
|
|
}
|
2019-03-15 21:33:31 -06:00
|
|
|
|
2021-09-03 22:31:29 -06:00
|
|
|
export default class WidgetOpenIDPermissionsDialog extends React.PureComponent<IProps, IState> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2021-09-05 12:02:43 +02:00
|
|
|
super(props);
|
2019-03-15 21:33:31 -06:00
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
rememberSelection: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 12:02:43 +02:00
|
|
|
private onAllow = (): void => {
|
|
|
|
|
this.onPermissionSelection(true);
|
2019-03-15 21:33:31 -06:00
|
|
|
};
|
|
|
|
|
|
2021-09-05 12:02:43 +02:00
|
|
|
private onDeny = (): void => {
|
|
|
|
|
this.onPermissionSelection(false);
|
2019-03-15 21:33:31 -06:00
|
|
|
};
|
|
|
|
|
|
2021-09-05 12:02:43 +02:00
|
|
|
private onPermissionSelection(allowed: boolean): void {
|
2019-03-15 21:33:31 -06:00
|
|
|
if (this.state.rememberSelection) {
|
2021-09-21 17:48:09 +02:00
|
|
|
logger.log(`Remembering ${this.props.widget.id} as allowed=${allowed} for OpenID`);
|
2019-03-15 21:33:31 -06:00
|
|
|
|
2022-10-19 21:00:53 +01:00
|
|
|
SdkContextClass.instance.widgetPermissionStore.setOIDCState(
|
2020-11-25 18:39:11 -07:00
|
|
|
this.props.widget,
|
|
|
|
|
this.props.widgetKind,
|
|
|
|
|
this.props.inRoomId,
|
|
|
|
|
allowed ? OIDCState.Allowed : OIDCState.Denied,
|
|
|
|
|
);
|
2019-03-15 21:33:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.onFinished(allowed);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 12:02:43 +02:00
|
|
|
private onRememberSelectionChange = (newVal: boolean): void => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ rememberSelection: newVal });
|
2019-03-15 21:33:31 -06:00
|
|
|
};
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2019-03-15 21:33:31 -06:00
|
|
|
return (
|
2021-04-29 19:57:02 +02:00
|
|
|
<BaseDialog
|
|
|
|
|
className="mx_WidgetOpenIDPermissionsDialog"
|
|
|
|
|
hasCancel={true}
|
2021-04-27 17:23:27 +02:00
|
|
|
onFinished={this.props.onFinished}
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("widget|open_id_permissions_dialog|title")}
|
2021-04-29 19:57:02 +02:00
|
|
|
>
|
2019-03-15 21:33:31 -06:00
|
|
|
<div className="mx_WidgetOpenIDPermissionsDialog_content">
|
2023-10-03 19:17:26 +01:00
|
|
|
<p>{_t("widget|open_id_permissions_dialog|starting_text")}</p>
|
2021-01-27 13:13:44 -07:00
|
|
|
<p className="text-muted">
|
2021-07-19 22:43:11 +01:00
|
|
|
{/* cheap trim to just get the path */}
|
|
|
|
|
{this.props.widget.templateUrl.split("?")[0].split("#")[0]}
|
2019-03-15 21:33:31 -06:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<DialogButtons
|
2023-08-22 20:55:15 +01:00
|
|
|
primaryButton={_t("action|continue")}
|
2021-09-05 12:02:43 +02:00
|
|
|
onPrimaryButtonClick={this.onAllow}
|
|
|
|
|
onCancel={this.onDeny}
|
2021-01-27 13:13:44 -07:00
|
|
|
additive={
|
|
|
|
|
<LabelledToggleSwitch
|
|
|
|
|
value={this.state.rememberSelection}
|
|
|
|
|
toggleInFront={true}
|
2021-09-05 12:02:43 +02:00
|
|
|
onChange={this.onRememberSelectionChange}
|
2023-10-03 19:17:26 +01:00
|
|
|
label={_t("widget|open_id_permissions_dialog|remember_selection")}
|
2021-01-27 13:13:44 -07:00
|
|
|
/>
|
|
|
|
|
}
|
2019-03-15 21:33:31 -06:00
|
|
|
/>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|