Skip to content

Commit

Permalink
feat: add python to list users snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Jun 10, 2024
1 parent 80b944d commit e1a335d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
9 changes: 5 additions & 4 deletions docs/content/getting-started/perform-list-users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ This section will illustrate how to perform a <ProductConcept section="what-is-a

</TabItem>

{ /* <TabItem value={SupportedLanguage.PYTHON_SDK} label={languageLabelMap.get(SupportedLanguage.PYTHON_SDK)}>
<TabItem value={SupportedLanguage.PYTHON_SDK} label={languageLabelMap.get(SupportedLanguage.PYTHON_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](./install-sdk.mdx).
3. You have [configured the _authorization model_](./configure-model.mdx) and [updated the _relationship tuples_](./update-tuples.mdx).
4. You have loaded `FGA_STORE_ID` and `FGA_API_URL` as environment variables.

</TabItem> */}
</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

Expand Down Expand Up @@ -120,11 +120,11 @@ Before calling the List Users API, you will need to configure the API client.
<SdkSetupHeader lang={SupportedLanguage.DOTNET_SDK} />

</TabItem>
{/* <TabItem value={SupportedLanguage.PYTHON_SDK} label={languageLabelMap.get(SupportedLanguage.PYTHON_SDK)}>
<TabItem value={SupportedLanguage.PYTHON_SDK} label={languageLabelMap.get(SupportedLanguage.PYTHON_SDK)}>

<SdkSetupHeader lang={SupportedLanguage.PYTHON_SDK} />

</TabItem> */}
</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

<SdkSetupHeader lang={SupportedLanguage.JAVA_SDK} />
Expand Down Expand Up @@ -163,6 +163,7 @@ To return all users of type `user` that have have the `reader` relationship with
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
Expand Down
75 changes: 38 additions & 37 deletions src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,46 +227,47 @@ var response = await fgaClient.ListUsers(body, options);
// response.Users = [${expectedResults.users.map((u) => JSON.stringify(u)).join(',')}]
// response.ExcludedUsers = [${expectedResults.excluded_users.map((u) => JSON.stringify(u)).join(',')}]`;
case SupportedLanguage.PYTHON_SDK:
return '';
// return `
// options = {
// "authorization_model_id": "${modelId}"
// }
return `
options = {
"authorization_model_id": "${modelId}"
}
// userFilters=[UserTypeFilter(type="${userFilterType}"${userFilterRelation ? `, relation="${userFilterRelation}"` : ''})]
userFilters = [
UserTypeFilter(type="${userFilterType}"${userFilterRelation ? `, relation="${userFilterRelation}"` : ''})
]
// body = ClientListUsersRequest(
// object=FgaObject(type="${objectId}, id="${objectId}"),
// relation="${relation}",
// userFilters=userFilters,${
// contextualTuples
// ? `
// contextual_tuples=[
// ${contextualTuples
// .map(
// (tuple) => `ClientTupleKey(user="${tuple.user}", relation="${tuple.relation}", object="${tuple.object}")`,
// )
// .join(',\n ')}
// ],`
// : ``
// }${
// context
// ? `
// context=dict(${Object.entries(context)
// .map(
// ([k, v]) => `
// ${k}="${v}"`,
// )
// .join(',')}
// )`
// : ''
// }
// )
body = ClientListUsersRequest(
object="${objectId}:${objectId}",
relation="${relation}",
user_filters=userFilters,${
contextualTuples
? `
contextual_tuples=[
${contextualTuples
.map(
(tuple) => `ClientTupleKey(user="${tuple.user}", relation="${tuple.relation}", object="${tuple.object}")`,
)
.join(',\n ')}
],`
: ``
}${
context
? `
context=dict(${Object.entries(context)
.map(
([k, v]) => `
${k}="${v}"`,
)
.join(',')}
)`
: ''
}
)
// response = await fga_client.list_users(body, options)
response = await fga_client.list_users(body, options)
// # response.users = [${expectedResults.users.map((u) => JSON.stringify(u)).join(',')}]
// # response.excludedUsers = [${expectedResults.excluded_users.map((u) => JSON.stringify(u)).join(',')}]`;
# response.users = [${expectedResults.users.map((u) => JSON.stringify(u)).join(',')}]
# response.excluded_users = [${expectedResults.excluded_users.map((u) => JSON.stringify(u)).join(',')}]`;
case SupportedLanguage.RPC:
return `listUsers(
"${objectId}", // list the objects that the user \`${objectId}\`
Expand Down Expand Up @@ -335,7 +336,7 @@ export function ListUsersRequestViewer(opts: ListUsersRequestViewerOpts): JSX.El
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
// SupportedLanguage.PYTHON_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
Expand Down

0 comments on commit e1a335d

Please sign in to comment.