Skip to content

Commit bd72dba

Browse files
pavoktanick-gagliardirhamzeh
authored
chore(docs): refine the roles-and-permissions document (#675)
Co-authored-by: Nick Gagliardi <[email protected]> Co-authored-by: Raghd Hamzeh <[email protected]>
1 parent 5c837fa commit bd72dba

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

docs/content/modeling/roles-and-permissions.mdx

+44-45
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ import {
2121

2222
<DocumentationNotice />
2323

24-
In this guide you will learn how to model roles and permissions model within <ProductName format={ProductNameFormat.ProductLink}/> using the _<ProductConcept section="what-is-an-authorization-model" linkName="authorization model" />_ and _<ProductConcept section="what-is-a-relationship-tuple" linkName="relationship tuple" />_.
24+
To model roles and permissions in <ProductName format={ProductNameFormat.ProductLink}/> using <ProductConcept section="what-is-an-authorization-model" linkName="authorization models" /> and <ProductConcept section="what-is-a-relationship-tuple" linkName="relationship tuples" />. For the purpose of this guide:
2525

26-
- **Roles** are assigned to <ProductConcept section="what-is-a-user" linkName="users" /> or a group of users, where any user can have more than one role (`editor`, `owner`, etc..).
27-
- **Permissions** are what allows users to access certain <ProductConcept section="what-is-an-object" linkName="objects" /> based on their specific roles (`device_renamer`, `channel_archiver`, etc..).
26+
- **Roles** are assigned to <ProductConcept section="what-is-a-user" linkName="users" /> or groups of users, where any user can have more than one role, like `editor` or `owner`.
27+
- **Permissions** allow users to access certain <ProductConcept section="what-is-an-object" linkName="objects" /> based on their specific roles, like `device_renamer` or `channel_archiver`.
2828

29-
For example, the role `viewer` of a `trip` can have **permissions to view bookings** or the role `owners` can have **permissions to add/view bookings to a trip.**
29+
For example, the role `viewer` of a `trip` can have permissions to view bookings, while the role `owners` has permissions to add or view bookings to a trip.
3030

3131
<CardBox title="When to use" appearance="filled">
3232

33-
When trying to create a role and permissions model within <ProductName format={ProductNameFormat.ShortForm}/>.:
33+
When creating a role and permissions model within <ProductName format={ProductNameFormat.ShortForm}/>, you should:
3434

35-
- Create roles by creating relations that can be directly assigned to users
36-
- Assign permissions by creating relations that users get through other relations
35+
- Create roles by creating relations that can be directly assigned to users.
36+
- Assign permissions by creating relations that users get through other relations.
3737

3838
For example:
3939

@@ -43,20 +43,19 @@ For example:
4343

4444
There are advantages to implementing roles and permissions within <ProductName format={ProductNameFormat.ShortForm}/>, such as:
4545

46-
- Breaking down existing roles to have more fine grained permissions. This allows your application to check whether a _user_ has access to a certain object without having to explicitly check that specific _users_ role.
47-
- Introduce new roles/permissions or consolidate roles without affecting your application behavior. For example: if in your app all the checks are for the fine permissions `check('bob', 'booking_adder', 'trip:Europe')` instead of `check('bob', 'owner', 'trip:Europe')`, and then you later decide `owners` can no longer add bookings to a `trip`, you can remove the relation within the `trip` type with no code changes in your application, and all the permissions will automatically honor the change.
46+
- Breaking down existing roles to have more fine grained permission, which enables your application to check whether a user has access to a certain object without having to explicitly check that specific user's role.
47+
- Introduce new roles/permissions or consolidate roles without affecting your application behavior. For example: if your app's checks are for the fine permissions `check('bob', 'booking_adder', 'trip:Europe')` instead of `check('bob', 'owner', 'trip:Europe')`, and you later decide `owners` can no longer add bookings to a `trip`, you can remove the relation within the `trip` type with no code changes in your application, and all the permissions will automatically honor the change.
4848

4949
</CardBox>
5050

5151
## Before you start
5252

53-
In order to understand this guide correctly you must be familiar with some <ProductConcept /> and know how to develop the things that we will list below.
53+
Familiarize yourself with the <ProductConcept />.
5454

5555
<details>
5656
<summary>
5757

58-
Assume that you have the following <ProductConcept section="what-is-an-authorization-model" linkName="authorization model" />.<br />
59-
You have a <ProductConcept section="what-is-a-type" linkName="type" /> called `trip` that _users_ can be related to as `viewer` and/or an `owner`.
58+
Assume you have the following <ProductConcept section="what-is-an-authorization-model" linkName="authorization model" /><br /> and that you have a <ProductConcept section="what-is-a-type" linkName="type" /> called `trip` that users can be related to as `viewer` and/or as an `owner`.
6059

6160
</summary>
6261

@@ -90,41 +89,41 @@ You have a <ProductConcept section="what-is-a-type" linkName="type" /> called `t
9089

9190
<hr />
9291

93-
In addition, you will need to know the following:
92+
In addition, you need to know the following:
9493

9594
### Direct Access
9695

97-
You need to know how to create an authorization model and create a relationship tuple to grant a user access to an object. [Learn more ](./direct-access.mdx)
96+
Learn how to create an authorization model and create a relationship tuple to grant a user access to an object. For more information, see [Direct Access.](./direct-access.mdx)
9897

9998
### <ProductName format={ProductNameFormat.ShortForm}/> Concepts
10099

101100
- A <ProductConcept section="what-is-a-type" linkName="Type" />: a class of objects that have similar characteristics
102101
- A <ProductConcept section="what-is-a-user" linkName="User" />: an entity in the system that can be related to an object
103-
- A <ProductConcept section="what-is-a-relation" linkName="Relation" />: is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
102+
- A <ProductConcept section="what-is-a-relation" linkName="Relation" />: a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
104103
- An <ProductConcept section="what-is-an-object" linkName="Object" />: represents an entity in the system. Users' relationships to it can be define through relationship tuples and the authorization model
105-
- A <ProductConcept section="what-is-a-relationship-tuple" linkName="Relationship Tuple" />: a grouping consisting of a user, a relation and an object stored in Auth <ProductName format={ProductNameFormat.ShortForm}/>
104+
- A <ProductConcept section="what-is-a-relationship-tuple" linkName="Relationship Tuple" />: a group consisting of a user, a relation, and an object stored in Auth <ProductName format={ProductNameFormat.ShortForm}/>
106105
- A <ProductConcept section="what-is-a-relationship" linkName="Relationship" />: <ProductName format={ProductNameFormat.ShortForm}/> will be called to check if there is a relationship between a user and an object, indicating that the access is allowed
107106
- [Direct Relationship Type Restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions): can be used to indicate direct relationships between users and objects
108-
- A <ProductConcept section="what-is-a-check-request" linkName="Check API Request" /> the Check API Request is used to check for relationships between users and objects
107+
- A <ProductConcept section="what-is-a-check-request" linkName="Check API Request" />: used to check for relationships between users and objects
109108

110109
</details>
111110

112111
<Playground />
113112

114113
## Step By Step
115114

116-
To illustrate modeling Roles and Permissions in <ProductName format={ProductNameFormat.ShortForm}/>, we will use a trip booking system where you can have `owners` and/or `viewers` that can have more granular permissions such as adding bookings to a trip or viewing bookings on it.
115+
To illustrate modeling Roles and Permissions in <ProductName format={ProductNameFormat.ShortForm}/>, imagine a trip booking system that has `owners` and/or `viewers`. It can also have granular permissions like adding bookings or viewing bookings on a trip.
117116

118-
In order to represent this, we need to:
117+
To represent this, you need to:
119118

120-
1. Understand how roles are related to direct relations for our trip booking system
121-
2. Adding implied relations to existing authorization model to define permissions for bookings
122-
3. <ProductConcept section="what-is-a-check-request" linkName="Checking" /> user roles and their permissions based on *relationship
123-
tuples* for direct and implied relations
119+
1. Understand how roles are related to direct relations for the trip booking system
120+
2. Add implied relations to the existing authorization model to define permissions for bookings
121+
3. <ProductConcept section="what-is-a-check-request" linkName="Check" /> user roles and their permissions based on relationship
122+
tuples for direct and implied relations
124123

125124
### 01. Understand How Roles Work Within Our Trip Booking System
126125

127-
Relating roles within <ProductName format={ProductNameFormat.ShortForm}/> can be best described as the following: **Roles are relations that can be directly assigned to users.** Looking at our authorization model, our roles would then be `owner` and `viewer`. Meaning that a specific _user_ can be an `owner` and/or a `viewer`.
126+
In <ProductName format={ProductNameFormat.ShortForm}/>, roles are relations that can be directly assigned to users. In this authorization model, your roles are `owner` and `viewer`, so a specific user can be an `owner` and/or a `viewer`.
128127

129128
<AuthzModelSnippetViewer
130129
configuration={{
@@ -156,13 +155,13 @@ Relating roles within <ProductName format={ProductNameFormat.ShortForm}/> can be
156155
}}
157156
/>
158157

159-
### 02. Adding Permissions For Bookings
158+
### 02. Add Permissions For Bookings
160159

161-
Permissions within <ProductName format={ProductNameFormat.LongForm}/> can be best described as the following: **Permissions are relations that users get only through other relations.** To represent permissions, we avoid adding a [**direct relationship type restriction**](../configuration-language.mdx#the-direct-relationship-type-restrictions) to the relation in the authorization model. Instead, we define the relation from other relations to indicate that it is a permission granted to and implied from a different relation.
160+
In <ProductName format={ProductNameFormat.LongForm}/>, permissions are relations that users get only through other relations. To represent permissions, define the relation by other relations to indicate that it is a permission both granted to and implied from a different relation. Doing so avoids adding a [direct relationship type restriction](../configuration-language.mdx#the-direct-relationship-type-restrictions) to the relation in the authorization model.
162161

163-
To add permissions related to bookings, we can add new relations to the `trip` _object_ type denoting the various actions a user can take on `trips` (view, edit, delete, rename, etc...)
162+
To add permissions related to bookings, add new relations to the `trip` object type denoting the various actions a user can take on `trips`, like view, edit, or delete.
164163

165-
To allow `viewers` of a `trip` to have **permissions to view bookings** and `owners` to have **permissions to add/view bookings,** we would modify the type as the following:
164+
To allow `viewers` of a `trip` to view bookings and `owners` to add/view bookings, modify the type as seen below:
166165

167166
<AuthzModelSnippetViewer
168167
configuration={{
@@ -219,16 +218,16 @@ To allow `viewers` of a `trip` to have **permissions to view bookings** and `own
219218
}}
220219
/>
221220

222-
> Note: notice how both `booking_viewer` and `booking_adder` don't have [direct relationship type restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions). This is to ensure that the relation can only be assigned through the **role** and not directly.
221+
> Note: Both `booking_viewer` and `booking_adder` don't have [direct relationship type restrictions](../configuration-language.mdx#the-direct-relationship-type-restrictions). This ensures that the relation can only be assigned through the role and not directly.
223222
224223
### 03. Checking User Roles And Their Permissions
225224

226-
Now that our type definitions reflects the roles and permissions on how bookings can be viewed/added. Let's create _<ProductConcept section="what-is-a-relationship-tuple" linkName="relationship tuples" />_ to assign roles to _users_ and then *<ProductConcept section="what-is-a-check-request" linkName="check" />* if _users_ have the proper permissions.
225+
Now that your type definitions reflect the roles and permissions governing how bookings can be viewed and added, create <ProductConcept section="what-is-a-relationship-tuple" linkName="relationship tuples" /> to assign roles to users, then *<ProductConcept section="what-is-a-check-request" linkName="check" />* if users have the proper permissions.
227226

228-
Let us create two relationship tuples:
227+
Create two relationship tuples:
229228

230-
1. that gives **bob** the role of `viewer` on `trip`: **Europe**.
231-
2. that gives **alice** the role of `owner` on `trip`: **Europe**.
229+
1. gives `bob` the role of `viewer` on `trip:Europe`.
230+
2. gives `alice` the role of `owner` on `trip:Europe`.
232231

233232
<WriteRequestViewer
234233
relationshipTuples={[
@@ -247,40 +246,40 @@ Let us create two relationship tuples:
247246
]}
248247
/>
249248

250-
Now we can check: **is bob allowed to view bookings on trip Europe?**
249+
Now check: `is bob allowed to view bookings on trip Europe?`
251250

252251
<CheckRequestViewer user={'user:bob'} relation={'booking_viewer'} object={'trip:Europe'} allowed={true} />
253252

254-
**bob** is a `booking_viewer` because of the following chain of resolution:
253+
`bob` is a `booking_viewer` because of the following chain of resolution:
255254

256-
1. **bob** is a `viewer` on `trip`: **Europe**
257-
2. Any user related to the _object_ `trip:`**Europe** as `viewer` is also related as a `booking_viewer` (i.e `usersRelatedToObjectAs: viewer`)
255+
1. `bob` is a `viewer` on `trip:Europe`
256+
2. Any user related to the object `trip:Europe` as `viewer` is also related as a `booking_viewer` (i.e `usersRelatedToObjectAs: viewer`)
258257
3. Therefore, all `viewers` on a given `trip` are `booking_viewers`
259258

260-
To confirm that **bob is not allowed to add bookings on trip Europe**, we can do the following check:
259+
To confirm that `bob` is not allowed to add bookings on trip `Europe`, perform the following check:
261260

262261
<CheckRequestViewer user={'user:bob'} relation={'booking_adder'} object={'trip:Europe'} allowed={false} />
263262

264-
We can also check: **is alice allowed to view and add bookings on trip Europe?**
263+
You can also check: is `alice` allowed to view and add bookings on trip `Europe`?
265264

266265
<CheckRequestViewer user={'user:alice'} relation={'booking_viewer'} object={'trip:Europe'} allowed={true} />
267266
<CheckRequestViewer user={'user:alice'} relation={'booking_adder'} object={'trip:Europe'} allowed={true} />
268267

269-
**alice** is a `booking_viewer` and `booking_adder` because of the following chain of resolution:
268+
`alice` is a `booking_viewer` and `booking_adder` because of the following chain of resolution:
270269

271-
1. **alice** is a `owner` on `trip`: **Europe**
272-
2. Any user related to the _object_ `trip:`**Europe** as `owner` is also related as a `booking_viewer`
273-
3. Any user related to the _object_ `trip:`**Europe** as `owner` is also related as a `booking_adder`
270+
1. `alice` is a `owner` on `trip:Europe`
271+
2. Any user related to the _object_ `trip:` `Europe` as `owner` is also related as a `booking_viewer`
272+
3. Any user related to the _object_ `trip:` `Europe` as `owner` is also related as a `booking_adder`
274273
4. Therefore, all `owners` on a given `trip` are `booking_viewers` and `booking_adders` on that trip
275274

276275
:::caution
277-
**Note:** Make sure to use unique ids for each object and user within your application domain when creating relationship tuples for <ProductName format={ProductNameFormat.LongForm}/>. We are using first names and simple ids to just illustrate an easy-to-follow example.
276+
Note: Use unique IDs for each object and user within your application domain when creating relationship tuples for <ProductName format={ProductNameFormat.LongForm}/>. This guide uses first names and simple IDs as an easy-to-follow example.
278277
:::
279278

280279
## Related Sections
281280

282281
<RelatedSection
283-
description="Check the following sections for more on how to model for roles and permissions."
282+
description="See following sections for more on how to model for roles and permissions."
284283
relatedLinks={[
285284
{
286285
title: 'Modeling Concepts: Concentric Relationships',

0 commit comments

Comments
 (0)