Schema | Open in playground
Brief Examination of the Model
The Instagram Authorization Schema models the relationships between users, accounts, and posts in the Instagram platform. Users can own accounts, follow other accounts, and be followed by other users. Accounts can have public or private settings, and access to view an account is determined by ownership, followers, and privacy settings. Posts are associated with accounts and can have restricted comments and likes based on account privacy.Entities & Relations
-
User
: Represents a user on the Instagram platform. -
Account
: Represents a user account on Instagram. Accounts have owners, followers, and can follow other accounts. -
Post
: Represents a post on Instagram. Posts are linked to accounts and can have restricted comments and likes.
Permissions
Users can view an account if they are the owner, a follower, or if the account is public. Users can comment and like posts if they have access to view the linked account and the post is unrestricted.Relationships and Attributes
Based on our schema, let’s create some sample relationships to test both our schema and our authorization logic.Test & Validation
To validate our authorization logic, let’s run some tests on different scenarios using the Instagram Authorization Schema.Test 1: Checking Account Viewing Permissions
Can user:kevin view account:1?
Can user:kevin view account:1?
user:kevin
is the owner of account:1
. Hence, user:kevin
should be able to view account:1
. The expected result is 'true'
.Can user:kevin view account:2 ?
Can user:kevin view account:2 ?
user:kevin
follows account:2
. Hence, user:kevin
should be able to view account:2
because he is a follower. The expected result is 'true'
.Can user:george view account:1 ?
Can user:george view account:1 ?
user:george
can view account:1
, because the account is public. Hence, user:george
should be able to view account:1
. The expected result is 'true'
.Can user:george view account:2 ?
Can user:george view account:2 ?
user:george
is the owner of account:2
. Hence, user:george
should be able to view account:2
. The expected result is 'true'
.Test 2: Checking Post Viewing Permissions
Can user:george view post:1 ?
Can user:george view post:1 ?
post:1
is linked with account:1
, and it does not have restricted access. Also, user:george
is following account:1
. Hence, user:george
should be able to view post:1
. The expected result is 'true'
.Can user:kevin view post:2 ?
Can user:kevin view post:2 ?
post:2
is linked with account:2
, and it has restricted access. Also, user:george
is not following account:1
. Hence, user:kevin
should not be able to view post:2
. The expected result is 'false'
.Can user:george view post:2 ?
Can user:george view post:2 ?
post:2
is linked with account:2
, and it is restricted access. Also, user:george
can view his own post:2
. The expected result is 'true'
.Test 3: Checking Post Commenting Permissions
Can user:george comment post:1 ?
Can user:george comment post:1 ?
post:1
is linked with account:1
, and it is not restricted. Also, user:george
can comment on post:1
. The expected result is 'true'
.Can user:kevin comment post:2 ?
Can user:kevin comment post:2 ?
post:2
is linked with account:2
, and it is restricted. user:kevin
cannot comment on post:2
. The expected result is 'false'
.Using Schema Validator in Local
After cloning Permify, open up a new file and copy the schema yaml file content inside. Then, build and run Permify instance using the commandmake serve
permify validate {path of your schema validation file}
to start the test process.
The validation result according to our example schema validation file: