refactor: Policies Architecture (#1016)
* add policy serialize method * Add policies to collection responses * wip * test: remove .only * refactor: Return policies with team and document requests * store policies on the client * refactor: drive admin UI from policies
This commit is contained in:
@@ -25,12 +25,14 @@ import Bubble from './components/Bubble';
|
||||
|
||||
import AuthStore from 'stores/AuthStore';
|
||||
import DocumentsStore from 'stores/DocumentsStore';
|
||||
import PoliciesStore from 'stores/PoliciesStore';
|
||||
import UiStore from 'stores/UiStore';
|
||||
import { observable } from 'mobx';
|
||||
|
||||
type Props = {
|
||||
auth: AuthStore,
|
||||
documents: DocumentsStore,
|
||||
policies: PoliciesStore,
|
||||
ui: UiStore,
|
||||
};
|
||||
|
||||
@@ -55,11 +57,12 @@ class MainSidebar extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { auth, documents } = this.props;
|
||||
const { auth, documents, policies } = this.props;
|
||||
const { user, team } = auth;
|
||||
if (!user || !team) return null;
|
||||
|
||||
const draftDocumentsCount = documents.drafts.length;
|
||||
const can = policies.abilties(team.id);
|
||||
|
||||
return (
|
||||
<Sidebar>
|
||||
@@ -125,7 +128,7 @@ class MainSidebar extends React.Component<Props> {
|
||||
documents.active ? documents.active.isArchived : undefined
|
||||
}
|
||||
/>
|
||||
{user.isAdmin && (
|
||||
{can.invite && (
|
||||
<SidebarLink
|
||||
onClick={this.handleInviteModalOpen}
|
||||
icon={<PlusIcon />}
|
||||
@@ -151,4 +154,4 @@ const Drafts = styled(Flex)`
|
||||
height: 24px;
|
||||
`;
|
||||
|
||||
export default inject('documents', 'auth', 'ui')(MainSidebar);
|
||||
export default inject('documents', 'policies', 'auth', 'ui')(MainSidebar);
|
||||
|
||||
@@ -23,10 +23,12 @@ import Section from './components/Section';
|
||||
import Header from './components/Header';
|
||||
import SidebarLink from './components/SidebarLink';
|
||||
import HeaderBlock from './components/HeaderBlock';
|
||||
import PoliciesStore from 'stores/PoliciesStore';
|
||||
import AuthStore from 'stores/AuthStore';
|
||||
|
||||
type Props = {
|
||||
history: RouterHistory,
|
||||
policies: PoliciesStore,
|
||||
auth: AuthStore,
|
||||
};
|
||||
|
||||
@@ -37,8 +39,11 @@ class SettingsSidebar extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { team, user } = this.props.auth;
|
||||
if (!team || !user) return null;
|
||||
const { policies, auth } = this.props;
|
||||
const { team } = auth;
|
||||
if (!team) return null;
|
||||
|
||||
const can = policies.abilties(team.id);
|
||||
|
||||
return (
|
||||
<Sidebar>
|
||||
@@ -71,14 +76,14 @@ class SettingsSidebar extends React.Component<Props> {
|
||||
</Section>
|
||||
<Section>
|
||||
<Header>Team</Header>
|
||||
{user.isAdmin && (
|
||||
{can.update && (
|
||||
<SidebarLink
|
||||
to="/settings/details"
|
||||
icon={<TeamIcon />}
|
||||
label="Details"
|
||||
/>
|
||||
)}
|
||||
{user.isAdmin && (
|
||||
{can.update && (
|
||||
<SidebarLink
|
||||
to="/settings/security"
|
||||
icon={<PadlockIcon />}
|
||||
@@ -96,14 +101,14 @@ class SettingsSidebar extends React.Component<Props> {
|
||||
icon={<LinkIcon />}
|
||||
label="Share Links"
|
||||
/>
|
||||
{user.isAdmin && (
|
||||
{can.auditLog && (
|
||||
<SidebarLink
|
||||
to="/settings/events"
|
||||
icon={<BulletedListIcon />}
|
||||
label="Audit Log"
|
||||
/>
|
||||
)}
|
||||
{user.isAdmin && (
|
||||
{can.export && (
|
||||
<SidebarLink
|
||||
to="/settings/export"
|
||||
icon={<DocumentIcon />}
|
||||
@@ -111,7 +116,7 @@ class SettingsSidebar extends React.Component<Props> {
|
||||
/>
|
||||
)}
|
||||
</Section>
|
||||
{user.isAdmin && (
|
||||
{can.update && (
|
||||
<Section>
|
||||
<Header>Integrations</Header>
|
||||
<SidebarLink
|
||||
@@ -133,4 +138,4 @@ class SettingsSidebar extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default inject('auth')(SettingsSidebar);
|
||||
export default inject('auth', 'policies')(SettingsSidebar);
|
||||
|
||||
Reference in New Issue
Block a user