From fa4bc47b3e5532f7f0bc2109102a2b43ffc5c825 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Tue, 12 Jul 2022 15:38:47 +0200 Subject: [PATCH] feat: specify org member roles in org setup (#3950) --- docs/docs/apis/proto/admin.md | 1 + internal/api/grpc/admin/org.go | 1 + internal/command/org.go | 8 +++++++- proto/zitadel/admin.proto | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/docs/apis/proto/admin.md b/docs/docs/apis/proto/admin.md index 4b8106d53c..d8b8a8332a 100644 --- a/docs/docs/apis/proto/admin.md +++ b/docs/docs/apis/proto/admin.md @@ -3642,6 +3642,7 @@ this is en empty request | ----- | ---- | ----------- | ----------- | | org | SetUpOrgRequest.Org | - | message.required: true
| | [**oneof**](https://developers.google.com/protocol-buffers/docs/proto3#oneof) user.human | SetUpOrgRequest.Human | oneof field for the user managing the organisation | | +| roles | repeated string | specify Org Member Roles for the provided user (default is ORG_OWNER if roles are empty) | | diff --git a/internal/api/grpc/admin/org.go b/internal/api/grpc/admin/org.go index 71ad86d9a4..3ac515aa7c 100644 --- a/internal/api/grpc/admin/org.go +++ b/internal/api/grpc/admin/org.go @@ -66,6 +66,7 @@ func (s *Server) SetUpOrg(ctx context.Context, req *admin_pb.SetUpOrgRequest) (* Name: req.Org.Name, CustomDomain: req.Org.Domain, Human: human, + Roles: req.Roles, }, userIDs...) if err != nil { return nil, err diff --git a/internal/command/org.go b/internal/command/org.go index bf7f7a18f6..eb195505b3 100644 --- a/internal/command/org.go +++ b/internal/command/org.go @@ -19,6 +19,7 @@ type OrgSetup struct { Name string CustomDomain string Human AddHuman + Roles []string } func (c *Commands) SetUpOrg(ctx context.Context, o *OrgSetup, userIDs ...string) (string, *domain.ObjectDetails, error) { @@ -35,10 +36,15 @@ func (c *Commands) SetUpOrg(ctx context.Context, o *OrgSetup, userIDs ...string) orgAgg := org.NewAggregate(orgID) userAgg := user_repo.NewAggregate(userID, orgID) + roles := []string{domain.RoleOrgOwner} + if len(o.Roles) > 0 { + roles = o.Roles + } + validations := []preparation.Validation{ AddOrgCommand(ctx, orgAgg, o.Name, userIDs...), AddHumanCommand(userAgg, &o.Human, c.userPasswordAlg, c.userEncryption), - c.AddOrgMemberCommand(orgAgg, userID, domain.RoleOrgOwner), + c.AddOrgMemberCommand(orgAgg, userID, roles...), } if o.CustomDomain != "" { validations = append(validations, AddOrgDomain(orgAgg, o.CustomDomain)) diff --git a/proto/zitadel/admin.proto b/proto/zitadel/admin.proto index 2217a8bd97..fceb2a2848 100644 --- a/proto/zitadel/admin.proto +++ b/proto/zitadel/admin.proto @@ -3099,6 +3099,8 @@ message SetUpOrgRequest { // oneof field for the user managing the organisation Human human = 2; } + // specify Org Member Roles for the provided user (default is ORG_OWNER if roles are empty) + repeated string roles = 3; } message SetUpOrgResponse {