fix(webui): resolve a selected org's workspaces as the caller, wire selection into gateway and harness, and let a member start tasks in the org they selected
This commit is contained in:
1 parent
c3d49cbc6c
commit
4bb473c0b0
12 files changed
+101
-21
No files matched your search
@@ -420,6 +420,8 @@ SELECT
|
||||
$10::text
|
||||
FROM number, (SELECT COALESCE(
|
||||
(SELECT a.org_id FROM org_agents a WHERE a.identity_id = $7),
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
|
||||
AND m.org_id = $11::text LIMIT 1),
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
|
||||
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
||||
'org-sys'
|
||||
|
||||
@@ -88,6 +88,8 @@ SELECT
|
||||
sqlc.arg(draft_digest)::text
|
||||
FROM number, (SELECT COALESCE(
|
||||
(SELECT a.org_id FROM org_agents a WHERE a.identity_id = sqlc.arg(identity)),
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = sqlc.arg(identity)
|
||||
AND m.org_id = sqlc.narg(scope_org)::text LIMIT 1),
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = sqlc.arg(identity)
|
||||
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
||||
'org-sys'
|
||||
|
||||
@@ -81,7 +81,7 @@ func (c Callers) resolve(ctx context.Context) (context.Context, error) {
|
||||
}
|
||||
// The forwarded org is a claim: the membership check, not the metadata,
|
||||
// decides whether the call may act there.
|
||||
p, err = p.Select(ctx, org.OrgID(first(md, OrgKey)), c.Workspaces)
|
||||
p, err = p.Select(org.WithOrg(access.WithPrincipal(ctx, p), p.Org), org.OrgID(first(md, OrgKey)), c.Workspaces)
|
||||
if err != nil {
|
||||
if errors.Is(err, access.ErrNotMember) {
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
|
||||
@@ -109,6 +109,16 @@ func orgFor(ctx context.Context, requested string) org.OrgID {
|
||||
return caller
|
||||
}
|
||||
|
||||
// memberOrgFor is orgFor, also naming any org the caller is a member of: a
|
||||
// member selecting an org needs that org's workspaces to act in it, and sees
|
||||
// nothing it could not already see as a member.
|
||||
func memberOrgFor(ctx context.Context, requested string) org.OrgID {
|
||||
if p, ok := access.PrincipalFromContext(ctx); ok && requested != "" && p.Member(org.OrgID(requested)) {
|
||||
return org.OrgID(requested)
|
||||
}
|
||||
return orgFor(ctx, requested)
|
||||
}
|
||||
|
||||
func (s *orgServer) GetOrg(ctx context.Context, r *pb.GetOrgRequest) (*pb.GetOrgResponse, error) {
|
||||
if s.deps.Orgs == nil {
|
||||
return nil, errOrgsUnavailable
|
||||
@@ -144,7 +154,7 @@ func (s *orgServer) ListWorkspaces(ctx context.Context, r *pb.ListWorkspacesRequ
|
||||
if s.deps.Orgs == nil {
|
||||
return nil, errOrgsUnavailable
|
||||
}
|
||||
values, err := s.deps.Orgs.ListWorkspaces(ctx, orgFor(ctx, r.GetOrgId()))
|
||||
values, err := s.deps.Orgs.ListWorkspaces(ctx, memberOrgFor(ctx, r.GetOrgId()))
|
||||
if err != nil {
|
||||
return nil, s.orgErr("ListWorkspaces", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user