-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add template RBAC #4125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add template RBAC #4125
Changes from 1 commit
5a47132
03f69bf
91a358d
8f837b7
8378c9b
54a0d13
72ea751
d533a16
f56fcf9
f162694
ea25c08
5a081eb
072b3e4
205c36c
ba32928
5c6344f
ef15908
8ab5200
c040e8e
1f4ceee
7cc71e1
131d5ed
8c3ee6a
fe2af91
0218c4e
6883106
4fbd9be
c96a6ca
57ba8b3
c66d247
0af367a
f6c3f51
6e72286
44bcbde
0f80beb
d274d62
943c76b
7f7f1d3
967a1a9
1324991
bd34d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| BEGIN; | ||
|
|
||
| ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}'; | ||
|
|
||
| CREATE TYPE template_role AS ENUM ( | ||
| 'read', | ||
| 'write', | ||
| 'admin' | ||
| ); | ||
|
|
||
| COMMIT; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
|
||
| "github.com/google/uuid" | ||
| "golang.org/x/xerrors" | ||
| ) | ||
|
|
||
| // customQuerier encompasses all non-generated queries. | ||
| // It provides a flexible way to write queries for cases | ||
| // where sqlc proves inadequate. | ||
| type customQuerier interface { | ||
| templateQuerier | ||
| } | ||
|
|
||
| type templateQuerier interface { | ||
| UpdateTemplateUserACLByID(ctx context.Context, id uuid.UUID, acl UserACL) error | ||
| } | ||
|
|
||
| type TemplateUser struct { | ||
| User | ||
| Role TemplateRole `db:"role"` | ||
| } | ||
|
|
||
| func (q *sqlQuerier) UpdateTemplateUserACLByID(ctx context.Context, id uuid.UUID, acl UserACL) error { | ||
| raw, err := json.Marshal(acl) | ||
| if err != nil { | ||
| return xerrors.Errorf("marshal user acl: %w", err) | ||
| } | ||
|
|
||
| const query = ` | ||
| UPDATE | ||
| templates | ||
| SET | ||
| user_acl = $2 | ||
| WHERE | ||
| id = $1` | ||
|
|
||
| _, err = q.db.ExecContext(ctx, query, id.String(), raw) | ||
| if err != nil { | ||
| return xerrors.Errorf("update user acl: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package database |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this be done with
sqlcinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it exposes a
json.RawMessagethrough the API. I wanted to preserve type safety as much as possible since we can't enforce the jsonb structure in the DB