AddMember adds a member to a group within the current organization.
(ctx context.Context, req *pb.GroupServiceAddMemberRequest)
| 305 | |
| 306 | // AddMember adds a member to a group within the current organization. |
| 307 | func (g *GroupService) AddMember(ctx context.Context, req *pb.GroupServiceAddMemberRequest) (*pb.GroupServiceAddMemberResponse, error) { |
| 308 | currentUser, err := requireCurrentUser(ctx) |
| 309 | if err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | currentOrg, err := requireCurrentOrg(ctx) |
| 313 | if err != nil { |
| 314 | return nil, err |
| 315 | } |
| 316 | |
| 317 | if err := g.userHasPermissionToAddGroupMember(ctx, currentOrg.ID, req.GetGroupReference()); err != nil { |
| 318 | return nil, err |
| 319 | } |
| 320 | |
| 321 | // Parse orgID |
| 322 | orgUUID, err := uuid.Parse(currentOrg.ID) |
| 323 | if err != nil { |
| 324 | return nil, errors.BadRequest("invalid", "invalid organization ID") |
| 325 | } |
| 326 | |
| 327 | // Parse requesterID (current user) |
| 328 | requesterUUID, err := uuid.Parse(currentUser.ID) |
| 329 | if err != nil { |
| 330 | return nil, errors.BadRequest("invalid", "invalid user ID") |
| 331 | } |
| 332 | |
| 333 | // Create options for adding the member |
| 334 | addOpts := &biz.AddMemberToGroupOpts{ |
| 335 | IdentityReference: &biz.IdentityReference{}, |
| 336 | UserEmail: req.GetUserEmail(), |
| 337 | RequesterID: requesterUUID, |
| 338 | Maintainer: req.GetIsMaintainer(), |
| 339 | } |
| 340 | |
| 341 | // Parse groupID and groupName from the request |
| 342 | addOpts.ID, addOpts.Name, err = req.GetGroupReference().Parse() |
| 343 | if err != nil { |
| 344 | return nil, errors.BadRequest("invalid", fmt.Sprintf("invalid project reference: %s", err.Error())) |
| 345 | } |
| 346 | |
| 347 | // Call the business logic to add the member |
| 348 | _, err = g.groupUseCase.AddMemberToGroup(ctx, orgUUID, addOpts) |
| 349 | if err != nil { |
| 350 | return nil, handleUseCaseErr(err, g.log) |
| 351 | } |
| 352 | |
| 353 | return &pb.GroupServiceAddMemberResponse{}, nil |
| 354 | } |
| 355 | |
| 356 | // RemoveMember removes a member from a group within the current organization. |
| 357 | func (g *GroupService) RemoveMember(ctx context.Context, req *pb.GroupServiceRemoveMemberRequest) (*pb.GroupServiceRemoveMemberResponse, error) { |
nothing calls this directly
no test coverage detected