mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-21 06:51:43 +00:00
fixup! fixup! refactor(api): moving organization API resourced based
added updateOrganization
This commit is contained in:
@@ -98,7 +98,7 @@ func (s *Server) AddOrg(ctx context.Context, req *mgmt_pb.AddOrgRequest) (*mgmt_
|
||||
|
||||
func (s *Server) UpdateOrg(ctx context.Context, req *mgmt_pb.UpdateOrgRequest) (*mgmt_pb.UpdateOrgResponse, error) {
|
||||
ctxData := authz.GetCtxData(ctx)
|
||||
org, err := s.command.ChangeOrg(ctx, ctxData.OrgID, req.Name)
|
||||
org, err := s.command.UpdateOrg(ctx, ctxData.OrgID, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -187,6 +187,75 @@ func TestServer_CreateOrganization(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_UpdateOrganization(t *testing.T) {
|
||||
orgName := "new_org_name"
|
||||
orgId, err := createOrg(orgName)
|
||||
if err != nil {
|
||||
assert.Fail(t, "unable to create org")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *org.UpdateOrganizationRequest
|
||||
want *org.UpdateOrganizationResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "update org with same name",
|
||||
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
||||
req: &org.UpdateOrganizationRequest{
|
||||
Id: orgId,
|
||||
Name: orgName,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update org with new name",
|
||||
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
||||
req: &org.UpdateOrganizationRequest{
|
||||
Id: orgId,
|
||||
Name: "new org name",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update org with no id",
|
||||
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
||||
req: &org.UpdateOrganizationRequest{
|
||||
Id: orgId,
|
||||
// Name: "",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.UpdateOrganization(tt.ctx, tt.req)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func createOrg(orgName string) (string, error) {
|
||||
org, err := Client.CreateOrganization(CTX,
|
||||
&org.CreateOrganizationRequest{
|
||||
Name: orgName,
|
||||
},
|
||||
)
|
||||
|
||||
return org.OrganizationId, err
|
||||
}
|
||||
|
||||
func assertCreatedAdmin(t *testing.T, expected, got *org.CreateOrganizationResponse_CreatedAdmin) {
|
||||
if expected.GetUserId() != "" {
|
||||
assert.NotEmpty(t, got.GetUserId())
|
||||
|
@@ -22,6 +22,17 @@ func (s *Server) CreateOrganization(ctx context.Context, request *org.CreateOrga
|
||||
return createdOrganizationToPb(createdOrg)
|
||||
}
|
||||
|
||||
func (s *Server) UpdateOrganization(ctx context.Context, request *org.UpdateOrganizationRequest) (*org.UpdateOrganizationResponse, error) {
|
||||
updated_org, err := s.command.UpdateOrg(ctx, request.Id, request.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &org.UpdateOrganizationResponse{
|
||||
Details: object.DomainToDetailsPb(updated_org),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func createOrganizationRequestToCommand(request *org.CreateOrganizationRequest) (*command.OrgSetup, error) {
|
||||
admins, err := createOrganizationRequestAdminsToCommand(request.GetAdmins())
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user