mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
Add RBAC to org views
This commit is contained in:
@@ -33,13 +33,17 @@ class Organization extends Component {
|
||||
organization: null,
|
||||
error: false,
|
||||
loading: true,
|
||||
isNotifAdmin: false,
|
||||
isAuditorOfThisOrg: false,
|
||||
isAdminOfThisOrg: false
|
||||
};
|
||||
|
||||
this.fetchOrganization = this.fetchOrganization.bind(this);
|
||||
this.fetchOrganizationAndRoles = this.fetchOrganizationAndRoles.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.fetchOrganization();
|
||||
this.fetchOrganizationAndRoles();
|
||||
}
|
||||
|
||||
async componentDidUpdate (prevProps) {
|
||||
@@ -49,6 +53,43 @@ class Organization extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async fetchOrganizationAndRoles () {
|
||||
const {
|
||||
match,
|
||||
setBreadcrumb,
|
||||
api,
|
||||
handleHttpError
|
||||
} = this.props;
|
||||
|
||||
try {
|
||||
const [{ data }, notifAdminRest, auditorRes, adminRes] = await Promise.all([
|
||||
api.getOrganizationDetails(parseInt(match.params.id, 10)),
|
||||
api.getOrganizations({
|
||||
role_level: 'notification_admin_role',
|
||||
page_size: 1
|
||||
}),
|
||||
api.getOrganizations({
|
||||
role_level: 'auditor_role',
|
||||
id: parseInt(match.params.id, 10)
|
||||
}),
|
||||
api.getOrganizations({
|
||||
role_level: 'admin_role',
|
||||
id: parseInt(match.params.id, 10)
|
||||
})
|
||||
]);
|
||||
setBreadcrumb(data);
|
||||
this.setState({
|
||||
organization: data,
|
||||
loading: false,
|
||||
isNotifAdmin: notifAdminRest.data.results.length > 0,
|
||||
isAuditorOfThisOrg: auditorRes.data.results.length > 0,
|
||||
isAdminOfThisOrg: adminRes.data.results.length > 0
|
||||
});
|
||||
} catch (error) {
|
||||
handleHttpError(error) || this.setState({ error: true, loading: false });
|
||||
}
|
||||
}
|
||||
|
||||
async fetchOrganization () {
|
||||
const {
|
||||
match,
|
||||
@@ -70,19 +111,40 @@ class Organization extends Component {
|
||||
const {
|
||||
location,
|
||||
match,
|
||||
me,
|
||||
history
|
||||
} = this.props;
|
||||
|
||||
const {
|
||||
organization,
|
||||
error,
|
||||
loading
|
||||
loading,
|
||||
isNotifAdmin,
|
||||
isAuditorOfThisOrg,
|
||||
isAdminOfThisOrg
|
||||
} = this.state;
|
||||
|
||||
const tabsPaddingOverride = {
|
||||
padding: '0'
|
||||
};
|
||||
|
||||
const canSeeNotificationsTab = me.is_system_auditor || isNotifAdmin || isAuditorOfThisOrg;
|
||||
const canToggleNotifications = isNotifAdmin && (
|
||||
me.is_system_auditor
|
||||
|| isAuditorOfThisOrg
|
||||
|| isAdminOfThisOrg
|
||||
);
|
||||
|
||||
const tabElements = [
|
||||
{ name: i18nMark('Details'), link: `${match.url}/details` },
|
||||
{ name: i18nMark('Access'), link: `${match.url}/access` },
|
||||
{ name: i18nMark('Teams'), link: `${match.url}/teams` }
|
||||
];
|
||||
|
||||
if (canSeeNotificationsTab) {
|
||||
tabElements.push({ name: i18nMark('Notifications'), link: `${match.url}/notifications` });
|
||||
}
|
||||
|
||||
let cardHeader = (
|
||||
loading ? ''
|
||||
: (
|
||||
@@ -174,16 +236,19 @@ class Organization extends Component {
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Route
|
||||
path="/organizations/:id/notifications"
|
||||
render={() => (
|
||||
<OrganizationNotifications
|
||||
match={match}
|
||||
location={location}
|
||||
history={history}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{canSeeNotificationsTab && (
|
||||
<Route
|
||||
path="/organizations/:id/notifications"
|
||||
render={() => (
|
||||
<OrganizationNotifications
|
||||
match={match}
|
||||
location={location}
|
||||
history={history}
|
||||
canToggleNotifications={canToggleNotifications}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{organization && <NotifyAndRedirect to={`/organizations/${match.params.id}/details`} />}
|
||||
</Switch>
|
||||
{error ? 'error!' : ''}
|
||||
|
||||
Reference in New Issue
Block a user