Skip to content

Commit

Permalink
chore: allow showing just types, error out when parsing not possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Nov 8, 2023
1 parent 7dd1875 commit 42205e0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 79 deletions.
30 changes: 10 additions & 20 deletions docs/content/modeling/advanced/entitlements.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ Add it now. Like so:

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type: 'feature',
relations: {
associated_plan: {
Expand Down Expand Up @@ -433,24 +432,19 @@ If you have already completed some of the other tutorials you might have encount

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type_definitions: [
{
type: 'object',
relations: {
viewer: {
tupleToUserset: {
tupleset: {
relation: 'parent',
},
computedUserset: {
relation: 'all_objects_viewer',
},
},
type: 'resource',
relations: {
viewer: {
tupleToUserset: {
tupleset: {
relation: 'parent',
},
computedUserset: {
relation: 'all_objects_viewer',
},
},
},
],
},
}}
skipVersion={true}
/>
Expand All @@ -469,7 +463,6 @@ If you want to give all subscribers on a plan access to a feature, you can do it

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type: 'feature',
relations: {
associated_plan: {
Expand Down Expand Up @@ -728,7 +721,6 @@ To disallow a direct relationship, you need to remove the direct relationship ty

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type: 'feature',
relations: {
associated_plan: {
Expand Down Expand Up @@ -770,7 +762,6 @@ becomes

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type: 'feature',
relations: {
associated_plan: {
Expand Down Expand Up @@ -812,7 +803,6 @@ Ensure that your authorization model matches the one below

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type_definitions: [
{
type: 'user',
Expand Down
73 changes: 34 additions & 39 deletions docs/content/modeling/advanced/gdrive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -582,48 +582,43 @@ We express it like this:

<AuthzModelSnippetViewer
configuration={{
schema_version: '1.1',
type_definitions: [
{
type: 'document',
relations: {
viewer: {
union: {
child: [
{
this: {},
},
{
computedUserset: {
relation: 'commenter',
},
},
{
tupleToUserset: {
tupleset: {
// read all relationship tuples related to document:2021-budget as parent
// which returns [{ "object": "document:2021-budget", "relation": "parent", "user": "document:2021-planning"}]
relation: 'parent',
},
computedUserset: {
// and for each relationship tuple return all usersets that match the following, replacing $TUPLE_USERSET_OBJECT with document:2021-planning
// this will return relationship tuples of shape { "object": "document:2021-planning", "viewer", "user": ??? }
// including { "object": "document:2021-planning", "viewer", "user": "user:diane" }
relation: 'viewer',
},
},
},
],
type: 'document',
relations: {
viewer: {
union: {
child: [
{
this: {},
},
},
},
metadata: {
relations: {
viewer: { directly_related_user_types: [{ type: 'user' }, { type: 'domain', relation: 'member' }] },
},
{
computedUserset: {
relation: 'commenter',
},
},
{
tupleToUserset: {
tupleset: {
// read all relationship tuples related to document:2021-budget as parent
// which returns [{ "object": "document:2021-budget", "relation": "parent", "user": "document:2021-planning"}]
relation: 'parent',
},
computedUserset: {
// and for each relationship tuple return all usersets that match the following, replacing $TUPLE_USERSET_OBJECT with document:2021-planning
// this will return relationship tuples of shape { "object": "document:2021-planning", "viewer", "user": ??? }
// including { "object": "document:2021-planning", "viewer", "user": "user:diane" }
relation: 'viewer',
},
},
},
],
},
},
],
},
metadata: {
relations: {
viewer: { directly_related_user_types: [{ type: 'user' }, { type: 'domain', relation: 'member' }] },
},
},
}}
skipVersion={true}
/>
Expand Down
32 changes: 12 additions & 20 deletions docs/content/modeling/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,7 @@ When a document is created a relationship tuple will be stored in <ProductName f

<AuthzModelSnippetViewer
onlyShow={SyntaxFormat.Friendly2}
configuration={{
schema_version: '1.1',
type_definitions: [
configuration={
{
type: 'document',
relations: {
Expand All @@ -808,8 +806,6 @@ When a document is created a relationship tuple will be stored in <ProductName f
parent: { directly_related_user_types: [{ type: 'folder' }, { type: 'drive' }] },
},
},
},
],
}}
skipVersion={true}
/>
Expand Down Expand Up @@ -839,10 +835,10 @@ We can achieve that with the following definition using <UpdateProductNameInLink
<AuthzModelSnippetViewer
onlyShow={SyntaxFormat.Friendly2}
skipVersion={true}
configuration={{
schema_version: '1.1',
type_definitions: [
{
configuration={
{
type: 'document',
relations: {
can_share: {
union: {
child: [
Expand Down Expand Up @@ -873,8 +869,7 @@ We can achieve that with the following definition using <UpdateProductNameInLink
],
},
},
},
],
}
}}
/>

Expand All @@ -900,8 +895,8 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
onlyShow={SyntaxFormat.Friendly2}
skipVersion={true}
configuration={{
schema_version: '1.1',
type_definitions: [
type: 'document',
relations:
{
can_view: {
union: {
Expand Down Expand Up @@ -952,7 +947,6 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
},
},
},
],
}}
/>

Expand All @@ -968,8 +962,8 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
onlyShow={SyntaxFormat.Friendly2}
skipVersion={true}
configuration={{
schema_version: '1.1',
type_definitions: [
type: 'document',
relations:
{
can_write: {
union: {
Expand Down Expand Up @@ -1002,7 +996,6 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
},
},
},
],
}}
/>

Expand All @@ -1018,8 +1011,8 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
onlyShow={SyntaxFormat.Friendly2}
skipVersion={true}
configuration={{
schema_version: '1.1',
type_definitions: [
type: 'document',
relations:
{
can_change_owner: {
computedUserset: {
Expand All @@ -1028,7 +1021,6 @@ Similar to the [can_share relation](#relation-can_share), we can achieve that wi
},
},
},
],
}}
/>

Expand Down
2 changes: 2 additions & 0 deletions src/components/Docs/AuthorizationModel/SyntaxTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const loadSyntax = (
type_definitions: [config as unknown as TypeDefinition],
};
skipVersion = true;
} else if (!config.type_definitions) {
throw new Error("invalid partial model")
}
return skipVersion
? transformer.transformJSONToDSL(config).replace('model\n schema 1.1\n', '')
Expand Down

0 comments on commit 42205e0

Please sign in to comment.