Files
grafana/public/app/features/org/OrgDetailsPage.tsx

89 lines
2.9 KiB
TypeScript
Raw Normal View History

2018-10-25 07:45:22 +02:00
import React, { PureComponent } from 'react';
import { ConnectedProps, connect } from 'react-redux';
import { VerticalGroup } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
import { appEvents, contextSrv } from 'app/core/core';
import { getNavModel } from 'app/core/selectors/navModel';
import { AccessControlAction, StoreState } from 'app/types';
import { ShowConfirmModalEvent } from 'app/types/events';
import OrgProfile from './OrgProfile';
import { loadOrganization, updateOrganization } from './state/actions';
import { setOrganizationName } from './state/reducers';
2018-10-25 07:45:22 +02:00
interface OwnProps {}
2018-10-25 07:45:22 +02:00
2018-10-26 14:15:37 +02:00
export class OrgDetailsPage extends PureComponent<Props> {
2018-10-25 07:45:22 +02:00
async componentDidMount() {
2018-10-26 14:15:37 +02:00
await this.props.loadOrganization();
2018-10-25 07:45:22 +02:00
}
onUpdateOrganization = (orgName: string) => {
this.props.setOrganizationName(orgName);
this.props.updateOrganization();
};
2018-10-25 07:45:22 +02:00
handleConfirm = () => {
return new Promise<boolean>((resolve) => {
appEvents.publish(
new ShowConfirmModalEvent({
title: 'Confirm preferences update',
text: 'This will update the preferences for the whole organization. Are you sure you want to update the preferences?',
yesText: 'Save',
yesButtonVariant: 'primary',
onConfirm: async () => resolve(true),
onDismiss: async () => resolve(false),
})
);
});
};
2018-10-25 16:56:49 +02:00
render() {
const { navModel, organization } = this.props;
const isLoading = Object.keys(organization).length === 0;
AccessControl: FGAC permissions for orgs endpoint on frontend (#41050) * AccessControl: FGAC permissions for orgs endpoint on frontend Protect org update endpoints add or refactor missing right messages cover org page * removing scopes from orgs * Perform permission control with global org * Perform the error handling in case of 403 * Simplify frontend code by requiring read access for sure * Remove roles I added to decrease the number of changes * Remove the check for server admin to reduce the number of changes * change error message * Cleaning todos * Remove unecessary changes * Fix tests * Update test snapshot * Update pkg/api/roles.go Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Format AdminEditOrgPage for linting * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Vardan Torosyan <vardants@gmail.com> * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Update public/app/features/admin/AdminListOrgsPage.tsx Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Commit suggestions * Commit suggestion canRead canWrite * fix typo Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Vardan Torosyan <vardants@gmail.com> Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
2021-11-18 14:10:38 +01:00
const canReadOrg = contextSrv.hasPermission(AccessControlAction.OrgsRead);
const canReadPreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesRead);
const canWritePreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesWrite);
2018-10-25 07:45:22 +02:00
return (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
{!isLoading && (
<VerticalGroup spacing="lg">
AccessControl: FGAC permissions for orgs endpoint on frontend (#41050) * AccessControl: FGAC permissions for orgs endpoint on frontend Protect org update endpoints add or refactor missing right messages cover org page * removing scopes from orgs * Perform permission control with global org * Perform the error handling in case of 403 * Simplify frontend code by requiring read access for sure * Remove roles I added to decrease the number of changes * Remove the check for server admin to reduce the number of changes * change error message * Cleaning todos * Remove unecessary changes * Fix tests * Update test snapshot * Update pkg/api/roles.go Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Format AdminEditOrgPage for linting * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Vardan Torosyan <vardants@gmail.com> * Update public/app/features/admin/AdminEditOrgPage.tsx Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Update public/app/features/admin/AdminListOrgsPage.tsx Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Commit suggestions * Commit suggestion canRead canWrite * fix typo Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Vardan Torosyan <vardants@gmail.com> Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
2021-11-18 14:10:38 +01:00
{canReadOrg && <OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />}
{canReadPreferences && (
<SharedPreferences
resourceUri="org"
disabled={!canWritePreferences}
preferenceType="org"
onConfirm={this.handleConfirm}
/>
)}
</VerticalGroup>
)}
</Page.Contents>
</Page>
2018-10-25 07:45:22 +02:00
);
}
}
function mapStateToProps(state: StoreState) {
return {
navModel: getNavModel(state.navIndex, 'org-settings'),
2018-10-26 14:15:37 +02:00
organization: state.organization.organization,
2018-10-25 07:45:22 +02:00
};
}
const mapDispatchToProps = {
2018-10-25 16:56:49 +02:00
loadOrganization,
2018-10-26 14:15:37 +02:00
setOrganizationName,
updateOrganization,
2018-10-25 07:45:22 +02:00
};
const connector = connect(mapStateToProps, mapDispatchToProps);
export type Props = OwnProps & ConnectedProps<typeof connector>;
export default connector(OrgDetailsPage);