great-crayon-86888
11/07/2023, 12:38 PMcommunity
, marketing
, finance
and `admin`:
The role admin
inherits all privileges from finance
, marketing
and community
.chilly-king-10285
11/07/2023, 12:38 PMchilly-king-10285
11/07/2023, 12:39 PMyaml # ... namespaces: - id: 0 name: groups - id: 1 name: reports #...
Then, you can define the permissions for each group and the admin role: plaintext // View only access for finance department reports:finance#view@(groups:finance#member) // View only access for community department reports:community#view@(groups:community#member) // View only access for marketing department reports:marketing#view@(groups:marketing#member) // Edit access for admin group reports:finance#edit@(groups:admin#member) reports:community#edit@(groups:admin#member) reports:marketing#edit@(groups:admin#member) reports:finance#view@(groups:admin#member) reports:community#view@(groups:admin#member) reports:marketing#view@(groups:admin#member)
This OPL code defines that members of the finance
, community
, and marketing
groups have view access to their respective reports. The admin
group has both view and edit access to all reports. Please note that you need to add users to these groups in your application. For example: plaintext groups:finance#member@User1 groups:community#member@User2 groups:marketing#member@User3 groups:admin#member@AdminUser
This code adds User1
to the finance
group, User2
to the community
group, User3
to the marketing
group, and AdminUser
to the admin
group. For more information, please refer to the [Ory documentation](https://www.ory.sh/docs/keto/guides/rbac).great-crayon-86888
11/07/2023, 12:39 PMchilly-king-10285
11/07/2023, 12:40 PMchilly-king-10285
11/07/2023, 12:40 PMtypescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {} class Report implements Namespace { related: { finance: User[] marketing: User[] community: User[] admin: User[] } permits = { view: (ctx: Context): boolean => this.related.finance.includes(ctx.subject) || this.related.marketing.includes(ctx.subject) || this.related.community.includes(ctx.subject) || this.related.admin.includes(ctx.subject), edit: (ctx: Context): boolean => this.related.admin.includes(ctx.subject) } }
In this OPL code, we define a Report
class that has relationships with four types of users: finance
, marketing
, community
, and admin
. The permits
object within the Report
class defines two permissions: view
and edit
. The view
permission is granted if the subject is included in any of the user groups, while the edit
permission is only granted if the subject is an admin
. Please note that this is a simplified example and might need to be adjusted based on your specific requirements and the structure of your application. For more information on how to use OPL, you can refer to the [Ory documentation](https://www.ory.sh/docs/keto/reference/ory-permission-language).