feat(access): edit org, workspace and object policies from the dashboard; refuse owner lockout
This commit is contained in:
1 parent
3a8879e6e9
commit
be541d6aee
20 files changed
+626
-75
No files matched your search
@@ -264,3 +264,16 @@ func (s *Store) runUpgradePhase(ctx context.Context, name string, stamps []func(
|
||||
}
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
|
||||
// OrgOwners returns the identities holding the org-wide owner role.
|
||||
func (s *Store) OrgOwners(ctx context.Context, orgID org.OrgID) ([]identity.IdentityID, error) {
|
||||
rows, err := s.queries().ListOrgOwners(ctx, string(orgID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("store: list org owners: %w", err)
|
||||
}
|
||||
out := make([]identity.IdentityID, 0, len(rows))
|
||||
for _, id := range rows {
|
||||
out = append(out, identity.IdentityID(id))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -137,6 +137,32 @@ func (q *Queries) ListMembershipsByIdentity(ctx context.Context, identityID stri
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listOrgOwners = `-- name: ListOrgOwners :many
|
||||
SELECT identity_id FROM memberships
|
||||
WHERE org_id = $1 AND workspace_id IS NULL AND role = 'owner'
|
||||
ORDER BY identity_id
|
||||
`
|
||||
|
||||
func (q *Queries) ListOrgOwners(ctx context.Context, orgID string) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, listOrgOwners, orgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var identity_id string
|
||||
if err := rows.Scan(&identity_id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, identity_id)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listOrgs = `-- name: ListOrgs :many
|
||||
SELECT id, name, created_at, updated_at FROM orgs ORDER BY created_at, id
|
||||
`
|
||||
|
||||
@@ -50,3 +50,8 @@ SELECT COALESCE(
|
||||
INSERT INTO memberships (identity_id, org_id, role)
|
||||
SELECT a.identity_id, a.org_id, 'developer' FROM org_agents a
|
||||
ON CONFLICT (identity_id, org_id, COALESCE(workspace_id, '')) DO NOTHING;
|
||||
|
||||
-- name: ListOrgOwners :many
|
||||
SELECT identity_id FROM memberships
|
||||
WHERE org_id = $1 AND workspace_id IS NULL AND role = 'owner'
|
||||
ORDER BY identity_id;
|
||||
Reference in new issue
Block a user