mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-20 03:48:47 +00:00
feat(group): group service to create, update, and delete groups (#10455)
# Which Problems Are Solved This PR adds API definition and backend implementation for GroupService to manage user groups. # How the Problems Are Solved * API definition to create, update, retrieve, and delete groups is added * Command-side implementation to create, update, and delete user groups as part of the GroupV2 API is added # Additional Changes N/A # Additional Context - Related to #10089, #9702 (parent ticket) - User contribution: https://github.com/zitadel/zitadel/pull/9428/files - Additional functionalities to list/search user groups, add permissions, manage users in groups, group scopes will be added in subsequent PRs. - Also needs documentation, which will be added once the entire feature is available --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
ee3654fe6f
commit
b81dedcaea
@@ -0,0 +1,63 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"connectrpc.com/connect"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
group_v2 "github.com/zitadel/zitadel/pkg/grpc/group/v2"
|
||||
)
|
||||
|
||||
// CreateGroup creates a new user group in the specified organization.
|
||||
func (s *Server) CreateGroup(ctx context.Context, req *connect.Request[group_v2.CreateGroupRequest]) (*connect.Response[group_v2.CreateGroupResponse], error) {
|
||||
userGroup := &command.CreateGroup{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.Msg.GetId(),
|
||||
ResourceOwner: req.Msg.GetOrganizationId(),
|
||||
},
|
||||
Name: req.Msg.GetName(),
|
||||
Description: req.Msg.GetDescription(),
|
||||
}
|
||||
|
||||
groupDetails, err := s.command.CreateGroup(ctx, userGroup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&group_v2.CreateGroupResponse{
|
||||
Id: groupDetails.ID,
|
||||
CreationDate: timestamppb.New(groupDetails.EventDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
// UpdateGroup updates a user group.
|
||||
func (s *Server) UpdateGroup(ctx context.Context, req *connect.Request[group_v2.UpdateGroupRequest]) (*connect.Response[group_v2.UpdateGroupResponse], error) {
|
||||
userGroup := &command.UpdateGroup{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: req.Msg.GetId(),
|
||||
},
|
||||
Name: req.Msg.Name,
|
||||
Description: req.Msg.Description,
|
||||
}
|
||||
|
||||
details, err := s.command.UpdateGroup(ctx, userGroup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&group_v2.UpdateGroupResponse{
|
||||
ChangeDate: timestamppb.New(details.EventDate),
|
||||
}), nil
|
||||
}
|
||||
|
||||
// DeleteGroup deletes a user group from an organization.
|
||||
func (s *Server) DeleteGroup(ctx context.Context, req *connect.Request[group_v2.DeleteGroupRequest]) (*connect.Response[group_v2.DeleteGroupResponse], error) {
|
||||
details, err := s.command.DeleteGroup(ctx, req.Msg.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connect.NewResponse(&group_v2.DeleteGroupResponse{
|
||||
DeletionDate: timestamppb.New(details.EventDate),
|
||||
}), nil
|
||||
}
|
||||
Reference in New Issue
Block a user