graphql-engine/server/tests-py/queries/graphql_query/permissions/setup.yaml

246 lines
4.5 KiB
YAML

type: bulk
args:
#Author table
- type: run_sql
args:
sql: |
create table author(
id serial primary key,
name text unique,
is_registered boolean not null default false,
remarks_internal text
);
- type: track_table
args:
schema: public
name: author
#Article table
- type: run_sql
args:
sql: |
CREATE TABLE article (
id SERIAL PRIMARY KEY,
title TEXT,
content TEXT,
author_id INTEGER NOT NULL REFERENCES author(id),
is_published BOOLEAN NOT NULL default FALSE,
published_on TIMESTAMP
)
- type: track_table
args:
schema: public
name: article
#Object relationship
- type: create_object_relationship
args:
name: author
table: article
using:
foreign_key_constraint_on: author_id
#Array relationship
- type: create_array_relationship
args:
table: author
name: articles
using:
foreign_key_constraint_on:
table: article
column: author_id
#Article select permission for user
- type: create_select_permission
args:
table: article
role: user
permission:
columns:
- id
- title
- content
- is_published
filter:
$or:
- author_id: X-HASURA-USER-ID
- is_published: true
#Article select permission for anonymous (only published articles)
- type: create_select_permission
args:
table: article
role: anonymous
permission:
columns:
- id
- title
- content
- is_published
filter:
is_published: true
#Article insert permission for user
- type: create_insert_permission
args:
table: article
role: user
permission:
check:
author_id: X-Hasura-User-Id
#Author select permission for user
- type: create_select_permission
args:
table: author
role: user
permission:
columns:
- id
- name
- is_registered
filter:
_or:
- id: X-HASURA-USER-ID
- articles:
is_published:
_eq: true
#Author select permission for anonymous users
#Only authors with atleast one article will be shown
- type: create_select_permission
args:
table: author
role: anonymous
permission:
columns:
- id
- name
filter:
articles:
is_published:
_eq: true
#Author insert permission for user
- type: create_insert_permission
args:
table: author
role: user
permission:
check:
id: X-HASURA-USER-ID
#Insert Author values
- type: insert
args:
table: author
objects:
- name: Author 1
remarks_internal: remark 1
- name: Author 2
remarks_internal: remark 2
- name: Author 3
remarks_internal: remark 3
#Insert Article values
- type: insert
args:
table: article
objects:
- title: Article 1
content: Sample article content 1
author_id: 1
is_published: false
- title: Article 2
content: Sample article content 2
author_id: 1
is_published: true
- title: Article 3
content: Sample article content 3
author_id: 2
is_published: true
- title: Article 4
content: Sample article content 4
author_id: 3
is_published: false
#Create Artist table
- type: run_sql
args:
sql: |
CREATE TABLE "Artist" (
id serial PRIMARY KEY ,
name text NOT NULL
);
- type: track_table
args:
schema: public
name: Artist
#Crete Track table
- type: run_sql
args:
sql: |
CREATE TABLE "Track" (
id serial PRIMARY KEY,
name text NOT NULL,
artist_id integer REFERENCES "Artist"("id")
);
- type: track_table
args:
schema: public
name: Track
# Insert data into Artist and Track table
- type: insert
args:
table: Artist
objects:
- name: Camilla
id: 1
- name: DSP
id: 2
- name: Akon
id: 3
- type: insert
args:
table: Track
objects:
- name: Keepup
artist_id: 1
id: 1
- name: Keepdown
artist_id: 1
id: 2
- name: Happy
artist_id: 2
id: 3
#Object relationship Track::artist_id -> Artist::id
- type: create_object_relationship
args:
name: Artist
table: Track
using:
foreign_key_constraint_on: artist_id
#Create select permssion on Track
- type: create_select_permission
args:
table: Track
role: Artist
permission:
columns: '*'
filter:
Artist:
id: X-Hasura-Artist-Id