1

我正在使用 Marmelab Admin-On-Rest 创建一个应用程序,以创建一个应用程序,让一组用户编辑、绘制图表、安排、发布并最终跟踪一组博客文章。

希望根据每个团队的角色向每个团队显示自定义视图。

有什么方法可以使用 Admin-On-Rest 实现这一目标?理想情况下,希望使用默认的 Admin-On-Rest,而不是从头开始创建我自己的 Redux 和 React 应用程序。

4

2 回答 2

1

我认为这是一个相当普遍的情况。我正在考虑以下解决方案:

使用方法扩展 authClient hasRole

提供一个withRoles高阶函数,authClient将角色和对象映射到视图组件。

用法是:

import React from 'react';

import { simpleRestClient, Admin, Resource } from 'admin-on-rest';
import withRoles from 'aor-roles';

import { PostCreateForTeam1, PostCreateForTeam2 } from './posts';

const App = () => (
    <Admin restClient={simpleRestClient('http://path.to.my.api')}>
        <Resource name="posts" list={PostList} create={
            withRoles(authClient, {
                team1: PostCreateForTeam1,
                team2: PostCreateForTeam2,
            })
        } />
    </Admin>
);

export default App;

在哪里team1以及team2将是角色。可能很有趣,它authClient.hasRole可以是异步的,以便它可以使用 API 检查角色(我正在考虑用于身份验证和角色检查的 SASS 服务)。正确处理这个问题可能很棘手。

给我几天时间考虑:)

编辑:找到一个我很满意的 API。

authClient 必须管理一个新类型:AUTH_GET_ROLE它将返回一个解析到用户角色的承诺。

export const ProductEdit = props => (
    <SwitchRoles authClient={authClient} {...props}>
        <ForRole role="role1">
            <ProductEditRole1 />
        </ForRole>
        <ForRole role="role2">
            <ProductEditRole2 />
        </ForRole>
    </SwitchRoles>
);

组件的rolepropForRole也接受更复杂检查的功能。

我们刚刚发布了aor-permissions

于 2017-05-13T17:29:28.320 回答
0

除了您的 authClient 之外,您可能还必须至少制作一个自定义减速器。然后制作一个与redux连接的ForRole组件,类似于Admin-on-rest中的Responsive组件。

检查其中的角色并使其显示每个角色所需的内容

于 2017-05-13T07:53:03.137 回答