-
-
Notifications
You must be signed in to change notification settings - Fork 822
Widget OpenID reauth implementation #2781
Changes from 4 commits
d63c5e7
44d8f9e
f045bea
b48842e
1ed2e6d
d326880
21d52a8
2dcb40f
3654c89
69fcebf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2019 Travis Ralston | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_WidgetOpenIDPermissionsDialog .mx_SettingsFlag { | ||
.mx_ToggleSwitch { | ||
display: inline-block; | ||
vertical-align: middle; | ||
margin-right: 8px; | ||
} | ||
|
||
.mx_SettingsFlag_label { | ||
display: inline-block; | ||
vertical-align: middle; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
Copyright 2019 Travis Ralston | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {_t} from "../../../languageHandler"; | ||
import SettingsStore, {SettingLevel} from "../../../settings/SettingsStore"; | ||
import sdk from "../../../index"; | ||
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch"; | ||
|
||
export default class WidgetOpenIDPermissionsDialog extends React.Component { | ||
static propTypes = { | ||
onFinished: PropTypes.func.isRequired, | ||
widgetUrl: PropTypes.string.isRequired, | ||
widgetId: PropTypes.string.isRequired, | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
rememberSelection: false, | ||
}; | ||
} | ||
|
||
_onAllow = () => { | ||
this._onPermissionSelection(true); | ||
}; | ||
|
||
_onDeny = () => { | ||
this._onPermissionSelection(false); | ||
}; | ||
|
||
_onPermissionSelection(allowed) { | ||
if (this.state.rememberSelection) { | ||
console.log(`Remembering ${this.props.widgetId} as allowed=${allowed} for OpenID`); | ||
|
||
const currentValues = SettingsStore.getValue("widgetOpenIDPermissions"); | ||
if (!currentValues.whitelist) currentValues.whitelist = []; | ||
if (!currentValues.blacklist) currentValues.blacklist = []; | ||
|
||
(allowed ? currentValues.whitelist : currentValues.blacklist).push(this.props.widgetId); | ||
SettingsStore.setValue("widgetOpenIDPermissions", null, SettingLevel.DEVICE, currentValues); | ||
} | ||
|
||
this.props.onFinished(allowed); | ||
} | ||
|
||
_onRememberSelectionChange = (newVal) => { | ||
this.setState({rememberSelection: newVal}); | ||
}; | ||
|
||
render() { | ||
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); | ||
const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); | ||
|
||
return ( | ||
<BaseDialog className='mx_WidgetOpenIDPermissionsDialog' hasCancel={true} | ||
onFinished={this.props.onFinished} | ||
title={_t("A widget would like to verify your identity")}> | ||
<div className='mx_WidgetOpenIDPermissionsDialog_content'> | ||
<p> | ||
{_t( | ||
"A widget located at %(widgetUrl)s would like to verify your identity. " + | ||
"By allowing this, the widget will be able to verify your user ID, but not " + | ||
"perform actions as you.", { | ||
widgetUrl: this.props.widgetUrl, | ||
}, | ||
)} | ||
</p> | ||
<LabelledToggleSwitch value={this.state.rememberSelection} toggleInFront={true} | ||
onChange={this._onRememberSelectionChange} | ||
label={_t("Remember my selection for this widget")} /> | ||
</div> | ||
<DialogButtons | ||
primaryButton={_t("Allow")} | ||
onPrimaryButtonClick={this._onAllow} | ||
cancelButton={_t("Deny")} | ||
onCancel={this._onDeny} | ||
/> | ||
</BaseDialog> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,29 @@ export default class LabelledToggleSwitch extends React.Component { | |
|
||
// Whether or not to disable the toggle switch | ||
disabled: PropTypes.bool, | ||
|
||
// True to put the toggle in front of the label | ||
// Default false. | ||
toggleInFront: PropTypes.bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we sometimes want the opposite order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, well, technically it's fine. I'd suggest asking Nad if he would prefer only having one layout of toggles or if he agrees it seems better reversed as you've done it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summarizing the discussion from earlier today: We'll take care of this in element-hq/element-web#7566 |
||
}; | ||
|
||
render() { | ||
// This is a minimal version of a SettingsFlag | ||
|
||
let firstPart = <span className="mx_SettingsFlag_label">{this.props.label}</span>; | ||
let secondPart = <ToggleSwitch checked={this.props.value} disabled={this.props.disabled} | ||
onChange={this.props.onChange} />; | ||
|
||
if (this.props.toggleInFront) { | ||
const temp = firstPart; | ||
firstPart = secondPart; | ||
secondPart = temp; | ||
} | ||
|
||
return ( | ||
<div className="mx_SettingsFlag"> | ||
<span className="mx_SettingsFlag_label">{this.props.label}</span> | ||
<ToggleSwitch checked={this.props.value} disabled={this.props.disabled} | ||
onChange={this.props.onChange} /> | ||
{firstPart} | ||
{secondPart} | ||
</div> | ||
); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.