graphql-engine/server/tests-py/queries/graphql_mutation/update/permissions/setup.yaml
2018-09-18 11:51:57 +05:30

146 lines
2.6 KiB
YAML

type: bulk
args:
#Author table
- type: run_sql
args:
sql: |
create table author(
id serial primary key,
name text unique
);
- type: track_table
args:
schema: public
name: author
#Article table
- type: run_sql
args:
sql: |
CREATE TABLE article (
id SERIAL,
title TEXT,
version TEXT,
content TEXT,
author_id INTEGER REFERENCES author(id),
is_published BOOLEAN,
published_on TIMESTAMP,
PRIMARY KEY (id,version)
)
- type: track_table
args:
schema: public
name: article
#Object relationship
- type: create_object_relationship
args:
table: article
name: author
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
#Person table
- type: run_sql
args:
sql: |
CREATE TABLE person (
id SERIAL PRIMARY KEY,
details JSONB NOT NULL
)
- type: track_table
args:
schema: public
name: person
#Insert Author table data
- type: insert
args:
table: author
objects:
- id: 1
name: Author 1
- id: 2
name: Author 2
#Insert aticle table data
- type: insert
args:
table: article
objects:
- id: 1
version: 1.0.0
content: Sample article 1, content version 1.0.0
title: Article 1
author_id: 1
is_published: true
- id: 2
content: Sample article 1, content version 1.0.1
version: 1.0.1
title: Article 1
author_id: 1
is_published: false
- id: 3
content: Sample article 2, content version 1.0.2
version: 1.0.0
title: Article 2
author_id: 2
is_published: false
#Author select permission for user
- type: create_select_permission
args:
table: author
role: user
permission:
columns: '*'
filter:
id: X-HASURA-USER-ID
#Article select permission for user
- type: create_select_permission
args:
table: article
role: user
permission:
columns: '*'
filter:
$or:
- author_id: X-HASURA-USER-ID
- is_published: true
#Article update permission for user
#Allow modifications only on unpublished articles
- type: create_update_permission
args:
table: article
role: user
permission:
columns:
- title
- content
- is_published
- published_on
- version
filter:
$and:
- author_id: X-HASURA-USER-ID
- is_published: false