diff --git a/docs/getting-started/_quickstart-parts/_quickstart_python_sync.mdx b/docs/getting-started/_quickstart-parts/_quickstart_python_sync.mdx index c8382872..ea846671 100644 --- a/docs/getting-started/_quickstart-parts/_quickstart_python_sync.mdx +++ b/docs/getting-started/_quickstart-parts/_quickstart_python_sync.mdx @@ -128,7 +128,7 @@ user = { "lastName": "Smith", # optional "email": "john@smith.com", # optional } -permit.write(permit.api.sync_user(user)) +permit.api.users.create(user) ``` ### Sync user with initial roles @@ -145,7 +145,7 @@ user = { # John will be assigned the admin role in the default tenant upon creation "roles": [{"role":"admin", "tenant": "default"}] } -permit.write(permit.api.sync_user(user)) +permit.api.users.create(user) ``` :::note @@ -161,7 +161,7 @@ the tenant cannot access the tenant's associated resources. Every one of your customers is typically a tenant that contains only that tenant's users. -To create a tenant, use `permit.api.create_tenant()`: +To create a tenant, use `permit.api.tenants.create()`: ```python cool_company_tenant = { @@ -178,7 +178,7 @@ You can assign a role to a user in a given tenant: ```python permit.write( - permit.api.assign_role("john@smith.com", "viewer", "cool_company_inc") + permit.api.users.assign_role("john@smith.com", "viewer", "cool_company_inc") ) ``` @@ -189,22 +189,20 @@ will run them according to the order you specify. ```python # runs the mutations in order: -permit.write( - # first creates the user "john" - permit.api.sync_user({ +# first creates the user "john" +permit.api.users.create( + { "key": "john@smith.com", - "firstName": "John", - "lastName": "Smith", + "first_name": "John", + "last_name": "Smith", "email": "john@smith.com", - }), - # then, creates the "cool_company_inc" tenant - permit.api.create_tenant({ - "key": "cool_company_inc", - "name": "Cool Company Inc" - }), - # finally, assigns the role "admin" to user "john" on the tenant "cool_company_inc" - permit.api.assign_role("john@smith.com", "admin", "cool_company_inc") -) + } +), +# then, creates the "cool_company_inc" tenant +permit.api.tenants.create({"key": "cool_company_inc", "name": "Cool Company Inc"}), +# finally, assigns the role "admin" to user "john" on the tenant "cool_company_inc" +permit.api.users.assign_role("john@smith.com", "admin", "cool_company_inc") + ``` --> ## Full app example @@ -226,7 +224,7 @@ pyenv virtualenv permissions && pyenv activate permissions Now install the Permit.io SDK. We will also install `flask` package. ``` -pip install permit==1.0.0rc1 flask +pip install permit flask ``` Create a file called `test.py`. @@ -259,31 +257,30 @@ permit = Permit( def sync_objects(): # first let's create a user: user = { - "key": "john@smith.com", - "firstName": "John", - "lastName": "Smith", + "key": "john3@smith.com", + "first_name": "John", + "last_name": "Smith", "email": "john@smith.com", - "roles": [{"role":"admin", "tenant": "default"}] + "role_assignments": [{"role":"admin", "tenant": "default"}] } - permit.write(permit.api.sync_user(user)) - + permit.api.users.create(user) tenant2 = { "key": "tenant2", "name": "Second Tenant" } # create tenant 2 and assign role viewer to user john - permit.write( + permit.api.roles.create( permit.api.create_tenant(tenant2), permit.api.assign_role("john@smith.com", "viewer", "tenant2") ) -sync_objects() +# sync_objects() @app.route("/") def check_permissions(): # After we created this user in the previous step, we also synced the user's identifier - # to permit.io servers with permit.write(permit.api.syncUser(user)). The user identifier + # to permit.io servers with permit.api.users.create(user). The user identifier # can be anything (email, db id, etc.) but must be unique for each user. Now that the # user is synced, we can use its identifier to check permissions with `permit.check()`. permitted = permit.check("john@smith.com", "retrieve", "task") # default tenant is used @@ -299,7 +296,7 @@ def check_permissions(): @app.route("/tenant2") def check_permissions_tenant2(): # After we created this user in the previous step, we also synced the user's identifier - # to permit.io servers with permit.write(permit.api.syncUser(user)). The user identifier + # to permit.io servers with permit.api.users.create(user). The user identifier # can be anything (email, db id, etc.) but must be unique for each user. Now that the # user is synced, we can use its identifier to check permissions with `permit.check()`. permitted = permit.check("john@smith.com", "create", {"type": "task", "tenant": "tenant2"}) # tenant2 is used @@ -312,6 +309,7 @@ def check_permissions_tenant2(): "result": f"John Smith is PERMITTED to create task (tenant 2)!" }), status=200, mimetype='application/json') + ``` Now that your application is ready, let's run it!