Skip to content

Commit

Permalink
Fixes Errors, Self Review
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs committed Dec 28, 2023
1 parent fd3fe6e commit 6c7b461
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/server/pactasrv/audit_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func (s *Server) ListAuditLogs(ctx context.Context, request api.ListAuditLogsReq
if err != nil {
return nil, err
}
// TODO(#12) implement additional authorization, ensuring for example that:
// TODO(#12) implement additional authorizations, ensuring for example that:
// - every generated query has reasonable limits + only filters by allowed search terms
// - the actor is allowed to see the audit logs of the actor_owner, but not of other actor_owners
// - initiative admins should be able to see audit logs of the initiative, but not initiative members
// - admins should be able to see all
Expand Down
4 changes: 3 additions & 1 deletion db/sqldb/golden/human_readable_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ CREATE TYPE audit_log_actor_type AS ENUM (
'USER',
'ADMIN',
'SUPER_ADMIN',
'SYSTEM');
'SYSTEM',
'OWNER',
'PUBLIC');
CREATE TYPE audit_log_target_type AS ENUM (
'USER',
'PORTFOLIO',
Expand Down
4 changes: 3 additions & 1 deletion db/sqldb/golden/schema_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ CREATE TYPE public.audit_log_actor_type AS ENUM (
'USER',
'ADMIN',
'SUPER_ADMIN',
'SYSTEM'
'SYSTEM',
'OWNER',
'PUBLIC'
);


Expand Down
19 changes: 19 additions & 0 deletions db/sqldb/migrations/0007_audit_log_actor_type.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN;

-- There isn't a way to delete a value from an enum, so this is the workaround
-- https://stackoverflow.com/a/56777227/17909149

ALTER TABLE audit_log ALTER actor_type TYPE TEXT;

DROP TYPE audit_log_actor_type;
CREATE TYPE audit_log_actor_type AS ENUM (
'USER',
'ADMIN',
'SUPER_ADMIN',
'SYSTEM');

ALTER TABLE audit_log
ALTER actor_type TYPE actor_type
USING actor_type::actor_type;

COMMIT;
6 changes: 6 additions & 0 deletions db/sqldb/migrations/0007_audit_log_actor_type.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TYPE audit_log_actor_type ADD VALUE 'OWNER';
ALTER TYPE audit_log_actor_type ADD VALUE 'PUBLIC';

COMMIT;
1 change: 1 addition & 0 deletions db/sqldb/sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestSchemaHistory(t *testing.T) {
{ID: 4, Version: 4}, // 0004_audit_log_tweaks
{ID: 5, Version: 5}, // 0005_json_blob_type
{ID: 6, Version: 6}, // 0006_initiative_primary_key
{ID: 7, Version: 7}, // 0007_audit_log_actor_type
}

if diff := cmp.Diff(want, got); diff != "" {
Expand Down

0 comments on commit 6c7b461

Please sign in to comment.