feat(state): audit access resets, org and EDA writes
This commit is contained in:
1 parent
0cccef6bb7
commit
99b1f8a2d9
12 files changed
+758
-167
No files matched your search
@@ -11,6 +11,17 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const agentAssignmentOrg = `-- name: AgentAssignmentOrg :one
|
||||
SELECT org_id FROM org_agents WHERE identity_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) AgentAssignmentOrg(ctx context.Context, identityID string) (string, error) {
|
||||
row := q.db.QueryRow(ctx, agentAssignmentOrg, identityID)
|
||||
var org_id string
|
||||
err := row.Scan(&org_id)
|
||||
return org_id, err
|
||||
}
|
||||
|
||||
const ensureAgentOrgMembership = `-- name: EnsureAgentOrgMembership :exec
|
||||
INSERT INTO memberships (identity_id, org_id, role)
|
||||
SELECT a.identity_id, a.org_id, 'developer' FROM org_agents a
|
||||
@@ -297,7 +308,28 @@ func (q *Queries) ListWorkspaces(ctx context.Context, orgID string) ([]Workspace
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const removeMembership = `-- name: RemoveMembership :exec
|
||||
const membershipRole = `-- name: MembershipRole :one
|
||||
SELECT role FROM memberships
|
||||
WHERE identity_id = $1 AND org_id = $2
|
||||
AND COALESCE(workspace_id, '') = $3::text
|
||||
`
|
||||
|
||||
type MembershipRoleParams struct {
|
||||
IdentityID string
|
||||
OrgID string
|
||||
WorkspaceID string
|
||||
}
|
||||
|
||||
// The current role of the membership EnsureMembership/RemoveMembership targets,
|
||||
// read in the same transaction so the audit row carries both sides.
|
||||
func (q *Queries) MembershipRole(ctx context.Context, arg MembershipRoleParams) (string, error) {
|
||||
row := q.db.QueryRow(ctx, membershipRole, arg.IdentityID, arg.OrgID, arg.WorkspaceID)
|
||||
var role string
|
||||
err := row.Scan(&role)
|
||||
return role, err
|
||||
}
|
||||
|
||||
const removeMembership = `-- name: RemoveMembership :execrows
|
||||
DELETE FROM memberships
|
||||
WHERE identity_id = $1 AND org_id = $2 AND COALESCE(workspace_id, '') = $3::text
|
||||
`
|
||||
@@ -310,9 +342,12 @@ type RemoveMembershipParams struct {
|
||||
|
||||
// The workspace is matched through the same COALESCE the unique index uses, so
|
||||
// an org-wide membership (NULL) and the empty string are the same target.
|
||||
func (q *Queries) RemoveMembership(ctx context.Context, arg RemoveMembershipParams) error {
|
||||
_, err := q.db.Exec(ctx, removeMembership, arg.IdentityID, arg.OrgID, arg.WorkspaceID)
|
||||
return err
|
||||
func (q *Queries) RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, removeMembership, arg.IdentityID, arg.OrgID, arg.WorkspaceID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const resolveIdentityOrg = `-- name: ResolveIdentityOrg :one
|
||||
|
||||
Reference in new issue
Block a user