feat(profile): persist candidate edits and enforce company access

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 14:15:16 +03:00
1 parent 3ab6bd91a3
commit 73c7caa225
67 files changed
+5286 -229

No files matched your search

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/google/uuid"
@@ -19,6 +20,8 @@ import (
type OrganizationOperations interface {
Create(ctx context.Context, command organization.CreateCommand) (organization.CreateResult, error)
Get(ctx context.Context, actorID, organizationID uuid.UUID) (domain.Organization, error)
AuthorizeCompany(ctx context.Context, actorID, organizationID uuid.UUID) (organization.CompanyAccess, error)
ListMyOrganizations(ctx context.Context, command organization.OrganizationListCommand) (outbound.OrganizationPage, error)
Update(ctx context.Context, command organization.UpdateCommand) (domain.Organization, error)
}
@@ -45,6 +48,18 @@ func (handler *Handler) GetOrganization(
return handler.organization.GetOrganization(ctx, params)
}
// ListMyOrganizations delegates the session-scoped company directory to its
// business-area handler.
func (handler *Handler) ListMyOrganizations(
ctx context.Context,
params api.ListMyOrganizationsParams,
) (api.ListMyOrganizationsRes, error) {
if handler.organization == nil {
return handler.UnimplementedHandler.ListMyOrganizations(ctx, params)
}
return handler.organization.ListMyOrganizations(ctx, params)
}
// UpdateOrganization delegates company edits to their business-area handler.
func (handler *Handler) UpdateOrganization(
ctx context.Context,
@@ -68,6 +83,17 @@ func NewOrganizationHandler(operations OrganizationOperations, publicOrigin stri
return &OrganizationHandler{operations: operations, publicOrigin: publicOrigin}
}
// AuthorizeCompany delegates current owner membership checks to the use case.
func (handler *OrganizationHandler) AuthorizeCompany(
ctx context.Context,
actorID, organizationID uuid.UUID,
) (organization.CompanyAccess, error) {
if handler == nil || handler.operations == nil {
return organization.CompanyAccess{}, errors.New("OrganizationHandler.AuthorizeCompany - organization operations are not configured")
}
return handler.operations.AuthorizeCompany(ctx, actorID, organizationID)
}
func (handler *OrganizationHandler) CreateOrganization(
ctx context.Context,
request *api.OrganizationCreate,
@@ -146,6 +172,53 @@ func (handler *OrganizationHandler) UpdateOrganization(
}, nil
}
func (handler *OrganizationHandler) ListMyOrganizations(
ctx context.Context,
params api.ListMyOrganizationsParams,
) (api.ListMyOrganizationsRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
return (*api.ListMyOrganizationsUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
command, paramErr := organizationListCommand(principal.UserID, params)
if paramErr != nil {
return organizationListInvalid(ctx, paramErr.pointer), nil
}
page, err := handler.operations.ListMyOrganizations(ctx, command)
if err != nil {
switch {
case errors.Is(err, organization.ErrForbidden):
return (*api.ListMyOrganizationsForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, organization.ErrEmailNotVerified):
return (*api.ListMyOrganizationsForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
case errors.Is(err, domain.ErrInvalidMembership):
return organizationListInvalid(ctx, "cursor"), nil
default:
return nil, err
}
}
items := make([]api.MyOrganization, 0, len(page.Items))
for _, item := range page.Items {
items = append(items, myOrganizationFromDomain(item))
}
var nextCursor api.NilString
nextCursor.SetToNull()
if page.HasMore && len(page.Items) > 0 {
cursor, err := encodeOrganizationCursor(principal.UserID, outbound.OrganizationPositionOf(page.Items[len(page.Items)-1]))
if err != nil {
return nil, fmt.Errorf("OrganizationHandler.ListMyOrganizations - encode cursor: %w", err)
}
nextCursor.SetTo(cursor)
}
return &api.MyOrganizationListHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: api.MyOrganizationList{
Items: items,
Page: api.PageInfo{HasMore: page.HasMore, NextCursor: nextCursor},
},
}, nil
}
func createProfileInput(request *api.OrganizationCreate) domain.OrganizationProfileInput {
contacts := request.Contacts.Or(api.OrganizationContactChannels{})
description, _ := request.Description.Get()
@@ -321,7 +394,7 @@ func createOrganizationFailure(ctx context.Context, err error) (api.CreateOrgani
func getOrganizationFailure(ctx context.Context, err error) (api.GetOrganizationRes, error) {
switch {
case errors.Is(err, organization.ErrForbidden):
case errors.Is(err, organization.ErrForbidden), errors.Is(err, outbound.ErrOrganizationManagerRequired):
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, organization.ErrEmailNotVerified):
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil