1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import {Component, Fragment} from 'react';
- import Panel from 'sentry/components/panels/panel';
- import PanelBody from 'sentry/components/panels/panelBody';
- import PanelHeader from 'sentry/components/panels/panelHeader';
- import {t} from 'sentry/locale';
- import {Permissions, Scope, WebhookEvent} from 'sentry/types';
- import {toResourcePermissions} from 'sentry/utils/consolidatedScopes';
- import PermissionSelection from 'sentry/views/settings/organizationDeveloperSettings/permissionSelection';
- import Subscriptions from 'sentry/views/settings/organizationDeveloperSettings/resourceSubscriptions';
- type DefaultProps = {
- appPublished: boolean;
- webhookDisabled: boolean;
- };
- type Props = DefaultProps & {
- events: WebhookEvent[];
- scopes: Scope[];
- };
- type State = {
- events: WebhookEvent[];
- permissions: Permissions;
- };
- export default class PermissionsObserver extends Component<Props, State> {
- static defaultProps: DefaultProps = {
- webhookDisabled: false,
- appPublished: false,
- };
- constructor(props: Props) {
- super(props);
- this.state = {
- permissions: this.scopeListToPermissionState(),
- events: this.props.events,
- };
- }
- /**
- * Converts the list of raw API scopes passed in to an object that can
- * before stored and used via `state`. This object is structured by
- * resource and holds "Permission" values. For example:
- *
- * {
- * 'Project': 'read',
- * ...,
- * }
- *
- */
- scopeListToPermissionState() {
- return toResourcePermissions(this.props.scopes);
- }
- onPermissionChange = (permissions: Permissions) => {
- this.setState({permissions});
- };
- onEventChange = (events: WebhookEvent[]) => {
- this.setState({events});
- };
- render() {
- const {permissions, events} = this.state;
- return (
- <Fragment>
- <Panel>
- <PanelHeader>{t('Permissions')}</PanelHeader>
- <PanelBody>
- <PermissionSelection
- permissions={permissions}
- onChange={this.onPermissionChange}
- appPublished={this.props.appPublished}
- />
- </PanelBody>
- </Panel>
- <Panel>
- <PanelHeader>{t('Webhooks')}</PanelHeader>
- <PanelBody>
- <Subscriptions
- permissions={permissions}
- events={events}
- onChange={this.onEventChange}
- webhookDisabled={this.props.webhookDisabled}
- />
- </PanelBody>
- </Panel>
- </Fragment>
- );
- }
- }
|