35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package controlplanestore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
|
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
)
|
|
|
|
// ChannelOrgs answers every other org's channel settings to the Messaging
|
|
// Service, which builds one channel per org. Its ordinary reads are confined to
|
|
// the system org, and no other caller may enumerate orgs' settings.
|
|
func (s *Server) ChannelOrgs(ctx context.Context, _ *pb.ChannelOrgsRequest) (*pb.ChannelOrgsResponse, error) {
|
|
if access.SourceFromContext(ctx) != presence.Messaging {
|
|
return nil, status.Error(codes.PermissionDenied, "only the messaging service lists org channels")
|
|
}
|
|
stored, err := s.store.ListResources(ctx)
|
|
if err != nil {
|
|
return nil, mapError(err)
|
|
}
|
|
var out []*pb.Resource
|
|
for _, resource := range stored {
|
|
if resource.Kind != ChannelSettingsKind || resource.OrgID == storecontract.DefaultOrgID {
|
|
continue
|
|
}
|
|
out = append(out, resourceProto(resource))
|
|
}
|
|
return &pb.ChannelOrgsResponse{Resources: out}, nil
|
|
}
|