Implement guard on empty full name before NDA is signed
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -47,6 +47,15 @@ type (
|
||||
IdentityID gid.GID `json:"uid"`
|
||||
Email mail.Addr `json:"email"`
|
||||
}
|
||||
|
||||
ChangeEmailRequest struct {
|
||||
NewEmail mail.Addr
|
||||
Password string
|
||||
}
|
||||
|
||||
UpdateIdentityRequest struct {
|
||||
FullName string `json:"fullName"`
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,11 +66,6 @@ func NewAccountService(svc *Service) *AccountService {
|
||||
return &AccountService{Service: svc}
|
||||
}
|
||||
|
||||
type ChangeEmailRequest struct {
|
||||
NewEmail mail.Addr
|
||||
Password string
|
||||
}
|
||||
|
||||
func (req ChangeEmailRequest) Validate() error {
|
||||
v := validator.New()
|
||||
|
||||
@@ -70,6 +74,14 @@ func (req ChangeEmailRequest) Validate() error {
|
||||
return v.Error()
|
||||
}
|
||||
|
||||
func (req UpdateIdentityRequest) Validate() error {
|
||||
v := validator.New()
|
||||
|
||||
v.Check(req.FullName, "full_name", validator.NotEmpty(), validator.MinLen(2), validator.MaxLen(255))
|
||||
|
||||
return v.Error()
|
||||
}
|
||||
|
||||
func (s AccountService) ChangeEmail(ctx context.Context, identityID gid.GID, req *ChangeEmailRequest) error {
|
||||
if err := req.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid request: %w", err)
|
||||
@@ -339,6 +351,42 @@ func (s AccountService) GetIdentity(ctx context.Context, identityID gid.GID) (*c
|
||||
return identity, nil
|
||||
}
|
||||
|
||||
func (s AccountService) UpdateIdentity(ctx context.Context, identityID gid.GID, req *UpdateIdentityRequest) (*coredata.Identity, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("invalid request: %w", err)
|
||||
}
|
||||
|
||||
identity := &coredata.Identity{}
|
||||
|
||||
err := s.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
err := identity.LoadByID(ctx, tx, identityID)
|
||||
if err != nil {
|
||||
if err == coredata.ErrResourceNotFound {
|
||||
return NewIdentityNotFoundError(identityID)
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot load identity: %w", err)
|
||||
}
|
||||
|
||||
identity.FullName = req.FullName
|
||||
identity.UpdatedAt = time.Now()
|
||||
|
||||
if err := identity.Update(ctx, tx); err != nil {
|
||||
return fmt.Errorf("cannot update identity: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return identity, nil
|
||||
}
|
||||
|
||||
func (s AccountService) ListPersonalAPIKeys(
|
||||
ctx context.Context,
|
||||
identityID gid.GID,
|
||||
|
||||
@@ -61,7 +61,6 @@ type (
|
||||
}
|
||||
|
||||
SendMagicLinkRequest struct {
|
||||
FullName string
|
||||
Email mail.Addr
|
||||
URLPath string
|
||||
OrganizationID gid.GID
|
||||
@@ -75,7 +74,6 @@ type (
|
||||
}
|
||||
|
||||
MagicLinkData struct {
|
||||
FullName string `json:"fullName"`
|
||||
Email mail.Addr `json:"email"`
|
||||
Continue *string `json:"continue"`
|
||||
}
|
||||
@@ -552,7 +550,6 @@ func (s AuthService) SendMagicLink(ctx context.Context, req *SendMagicLinkReques
|
||||
TokenTypeMagicLink,
|
||||
s.magicLinkTokenValidity,
|
||||
MagicLinkData{
|
||||
FullName: req.FullName,
|
||||
Email: req.Email,
|
||||
Continue: req.Continue,
|
||||
},
|
||||
@@ -574,9 +571,20 @@ func (s AuthService) SendMagicLink(ctx context.Context, req *SendMagicLinkReques
|
||||
return fmt.Errorf("cannot insert token: %w", err)
|
||||
}
|
||||
|
||||
fullName := req.FullName
|
||||
fullName := req.Email.Username()
|
||||
identity := &coredata.Identity{}
|
||||
organization := &coredata.Organization{}
|
||||
|
||||
if err := identity.LoadByEmail(ctx, tx, req.Email); err == nil {
|
||||
if identity.FullName != "" {
|
||||
fullName = identity.FullName
|
||||
}
|
||||
} else {
|
||||
if !errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return fmt.Errorf("cannot load identity: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := organization.LoadByID(ctx, tx, coredata.NewNoScope(), req.OrganizationID); err != nil {
|
||||
return fmt.Errorf("cannot load organization: %w", err)
|
||||
}
|
||||
@@ -675,10 +683,6 @@ func (s AuthService) OpenSessionWithMagicLink(ctx context.Context, tokenString s
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if identity.FullName == "" {
|
||||
identity.FullName = payload.Data.FullName
|
||||
}
|
||||
|
||||
if err := identity.Insert(ctx, tx); err != nil {
|
||||
return fmt.Errorf("cannot create identity: %w", err)
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ func newNDADirective(
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
// We need full name before user signs NDA
|
||||
if identity.FullName == "" {
|
||||
return nil, gqlutils.FullNameRequiredf(ctx, "full name is required")
|
||||
}
|
||||
|
||||
if sig.Status != coredata.ElectronicSignatureStatusCompleted {
|
||||
return nil, gqlutils.NDASignatureRequiredf(ctx, "NDA signature required")
|
||||
}
|
||||
|
||||
@@ -611,7 +611,6 @@ type DocumentAccess implements Node {
|
||||
}
|
||||
|
||||
input SendMagicLinkInput {
|
||||
fullName: String!
|
||||
email: EmailAddr!
|
||||
continue: String
|
||||
}
|
||||
@@ -628,6 +627,14 @@ type VerifyMagicLinkPayload {
|
||||
continue: String
|
||||
}
|
||||
|
||||
input UpdateFullNameInput {
|
||||
fullName: String!
|
||||
}
|
||||
|
||||
type UpdateFullNamePayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type RequestDocumentAccessPayload {
|
||||
document: Document
|
||||
}
|
||||
@@ -827,6 +834,8 @@ type Mutation {
|
||||
@session(required: OPTIONAL)
|
||||
verifyMagicLink(input: VerifyMagicLinkInput!): VerifyMagicLinkPayload
|
||||
@session(required: OPTIONAL)
|
||||
updateFullName(input: UpdateFullNameInput!): UpdateFullNamePayload
|
||||
@session(required: PRESENT)
|
||||
|
||||
requestAllAccesses: RequestAccessesPayload! @session(required: PRESENT) @nda
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ type ComplexityRoot struct {
|
||||
RequestReportAccess func(childComplexity int, input types.RequestReportAccessInput) int
|
||||
RequestTrustCenterFileAccess func(childComplexity int, input types.RequestTrustCenterFileAccessInput) int
|
||||
SendMagicLink func(childComplexity int, input types.SendMagicLinkInput) int
|
||||
UpdateFullName func(childComplexity int, input types.UpdateFullNameInput) int
|
||||
VerifyMagicLink func(childComplexity int, input types.VerifyMagicLinkInput) int
|
||||
}
|
||||
|
||||
@@ -289,6 +290,10 @@ type ComplexityRoot struct {
|
||||
Node func(childComplexity int) int
|
||||
}
|
||||
|
||||
UpdateFullNamePayload struct {
|
||||
Success func(childComplexity int) int
|
||||
}
|
||||
|
||||
Vendor struct {
|
||||
Category func(childComplexity int) int
|
||||
Countries func(childComplexity int) int
|
||||
@@ -333,6 +338,7 @@ type FrameworkResolver interface {
|
||||
type MutationResolver interface {
|
||||
SendMagicLink(ctx context.Context, input types.SendMagicLinkInput) (*types.SendMagicLinkPayload, error)
|
||||
VerifyMagicLink(ctx context.Context, input types.VerifyMagicLinkInput) (*types.VerifyMagicLinkPayload, error)
|
||||
UpdateFullName(ctx context.Context, input types.UpdateFullNameInput) (*types.UpdateFullNamePayload, error)
|
||||
RequestAllAccesses(ctx context.Context) (*types.RequestAccessesPayload, error)
|
||||
ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error)
|
||||
ExportReportPDF(ctx context.Context, input types.ExportReportPDFInput) (*types.ExportReportPDFPayload, error)
|
||||
@@ -800,6 +806,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
}
|
||||
|
||||
return e.ComplexityRoot.Mutation.SendMagicLink(childComplexity, args["input"].(types.SendMagicLinkInput)), true
|
||||
case "Mutation.updateFullName":
|
||||
if e.ComplexityRoot.Mutation.UpdateFullName == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_updateFullName_args(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.ComplexityRoot.Mutation.UpdateFullName(childComplexity, args["input"].(types.UpdateFullNameInput)), true
|
||||
case "Mutation.verifyMagicLink":
|
||||
if e.ComplexityRoot.Mutation.VerifyMagicLink == nil {
|
||||
break
|
||||
@@ -1245,6 +1262,13 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
|
||||
return e.ComplexityRoot.TrustCenterReferenceEdge.Node(childComplexity), true
|
||||
|
||||
case "UpdateFullNamePayload.success":
|
||||
if e.ComplexityRoot.UpdateFullNamePayload.Success == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.ComplexityRoot.UpdateFullNamePayload.Success(childComplexity), true
|
||||
|
||||
case "Vendor.category":
|
||||
if e.ComplexityRoot.Vendor.Category == nil {
|
||||
break
|
||||
@@ -1344,6 +1368,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||
ec.unmarshalInputRequestReportAccessInput,
|
||||
ec.unmarshalInputRequestTrustCenterFileAccessInput,
|
||||
ec.unmarshalInputSendMagicLinkInput,
|
||||
ec.unmarshalInputUpdateFullNameInput,
|
||||
ec.unmarshalInputVerifyMagicLinkInput,
|
||||
)
|
||||
first := true
|
||||
@@ -2033,7 +2058,6 @@ type DocumentAccess implements Node {
|
||||
}
|
||||
|
||||
input SendMagicLinkInput {
|
||||
fullName: String!
|
||||
email: EmailAddr!
|
||||
continue: String
|
||||
}
|
||||
@@ -2050,6 +2074,14 @@ type VerifyMagicLinkPayload {
|
||||
continue: String
|
||||
}
|
||||
|
||||
input UpdateFullNameInput {
|
||||
fullName: String!
|
||||
}
|
||||
|
||||
type UpdateFullNamePayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type RequestDocumentAccessPayload {
|
||||
document: Document
|
||||
}
|
||||
@@ -2249,6 +2281,8 @@ type Mutation {
|
||||
@session(required: OPTIONAL)
|
||||
verifyMagicLink(input: VerifyMagicLinkInput!): VerifyMagicLinkPayload
|
||||
@session(required: OPTIONAL)
|
||||
updateFullName(input: UpdateFullNameInput!): UpdateFullNamePayload
|
||||
@session(required: PRESENT)
|
||||
|
||||
requestAllAccesses: RequestAccessesPayload! @session(required: PRESENT) @nda
|
||||
|
||||
@@ -2439,6 +2473,17 @@ func (ec *executionContext) field_Mutation_sendMagicLink_args(ctx context.Contex
|
||||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_updateFullName_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", ec.unmarshalNUpdateFullNameInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐUpdateFullNameInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["input"] = arg0
|
||||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_verifyMagicLink_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
@@ -4390,6 +4435,69 @@ func (ec *executionContext) fieldContext_Mutation_verifyMagicLink(ctx context.Co
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_updateFullName(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
ec.OperationContext,
|
||||
field,
|
||||
ec.fieldContext_Mutation_updateFullName,
|
||||
func(ctx context.Context) (any, error) {
|
||||
fc := graphql.GetFieldContext(ctx)
|
||||
return ec.Resolvers.Mutation().UpdateFullName(ctx, fc.Args["input"].(types.UpdateFullNameInput))
|
||||
},
|
||||
func(ctx context.Context, next graphql.Resolver) graphql.Resolver {
|
||||
directive0 := next
|
||||
|
||||
directive1 := func(ctx context.Context) (any, error) {
|
||||
required, err := ec.unmarshalNSessionRequirement2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋgqlutilsᚋdirectivesᚋsessionᚐSessionRequirement(ctx, "PRESENT")
|
||||
if err != nil {
|
||||
var zeroVal *types.UpdateFullNamePayload
|
||||
return zeroVal, err
|
||||
}
|
||||
if ec.Directives.Session == nil {
|
||||
var zeroVal *types.UpdateFullNamePayload
|
||||
return zeroVal, errors.New("directive session is not implemented")
|
||||
}
|
||||
return ec.Directives.Session(ctx, nil, directive0, required)
|
||||
}
|
||||
|
||||
next = directive1
|
||||
return next
|
||||
},
|
||||
ec.marshalOUpdateFullNamePayload2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐUpdateFullNamePayload,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_updateFullName(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
switch field.Name {
|
||||
case "success":
|
||||
return ec.fieldContext_UpdateFullNamePayload_success(ctx, field)
|
||||
}
|
||||
return nil, fmt.Errorf("no field named %q was found under type UpdateFullNamePayload", field.Name)
|
||||
},
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = ec.Recover(ctx, r)
|
||||
ec.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
if fc.Args, err = ec.field_Mutation_updateFullName_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return fc, err
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_requestAllAccesses(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
@@ -7405,6 +7513,35 @@ func (ec *executionContext) fieldContext_TrustCenterReferenceEdge_node(_ context
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _UpdateFullNamePayload_success(ctx context.Context, field graphql.CollectedField, obj *types.UpdateFullNamePayload) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
ec.OperationContext,
|
||||
field,
|
||||
ec.fieldContext_UpdateFullNamePayload_success,
|
||||
func(ctx context.Context) (any, error) {
|
||||
return obj.Success, nil
|
||||
},
|
||||
nil,
|
||||
ec.marshalNBoolean2bool,
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_UpdateFullNamePayload_success(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "UpdateFullNamePayload",
|
||||
Field: field,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type Boolean does not have child fields")
|
||||
},
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Vendor_id(ctx context.Context, field graphql.CollectedField, obj *types.Vendor) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
@@ -9508,20 +9645,13 @@ func (ec *executionContext) unmarshalInputSendMagicLinkInput(ctx context.Context
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"fullName", "email", "continue"}
|
||||
fieldsInOrder := [...]string{"email", "continue"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "fullName":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("fullName"))
|
||||
data, err := ec.unmarshalNString2string(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.FullName = data
|
||||
case "email":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email"))
|
||||
data, err := ec.unmarshalNEmailAddr2goᚗproboᚗincᚋproboᚋpkgᚋmailᚐAddr(ctx, v)
|
||||
@@ -9541,6 +9671,32 @@ func (ec *executionContext) unmarshalInputSendMagicLinkInput(ctx context.Context
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputUpdateFullNameInput(ctx context.Context, obj any) (types.UpdateFullNameInput, error) {
|
||||
var it types.UpdateFullNameInput
|
||||
asMap := map[string]any{}
|
||||
for k, v := range obj.(map[string]any) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"fullName"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "fullName":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("fullName"))
|
||||
data, err := ec.unmarshalNString2string(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.FullName = data
|
||||
}
|
||||
}
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputVerifyMagicLinkInput(ctx context.Context, obj any) (types.VerifyMagicLinkInput, error) {
|
||||
var it types.VerifyMagicLinkInput
|
||||
asMap := map[string]any{}
|
||||
@@ -10722,6 +10878,10 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_verifyMagicLink(ctx, field)
|
||||
})
|
||||
case "updateFullName":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_updateFullName(ctx, field)
|
||||
})
|
||||
case "requestAllAccesses":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_requestAllAccesses(ctx, field)
|
||||
@@ -12331,6 +12491,45 @@ func (ec *executionContext) _TrustCenterReferenceEdge(ctx context.Context, sel a
|
||||
return out
|
||||
}
|
||||
|
||||
var updateFullNamePayloadImplementors = []string{"UpdateFullNamePayload"}
|
||||
|
||||
func (ec *executionContext) _UpdateFullNamePayload(ctx context.Context, sel ast.SelectionSet, obj *types.UpdateFullNamePayload) graphql.Marshaler {
|
||||
fields := graphql.CollectFields(ec.OperationContext, sel, updateFullNamePayloadImplementors)
|
||||
|
||||
out := graphql.NewFieldSet(fields)
|
||||
deferred := make(map[string]*graphql.FieldSet)
|
||||
for i, field := range fields {
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("UpdateFullNamePayload")
|
||||
case "success":
|
||||
out.Values[i] = ec._UpdateFullNamePayload_success(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
}
|
||||
out.Dispatch(ctx)
|
||||
if out.Invalids > 0 {
|
||||
return graphql.Null
|
||||
}
|
||||
|
||||
atomic.AddInt32(&ec.Deferred, int32(len(deferred)))
|
||||
|
||||
for label, dfs := range deferred {
|
||||
ec.ProcessDeferredGroup(graphql.DeferredGroup{
|
||||
Label: label,
|
||||
Path: graphql.GetPath(ctx),
|
||||
FieldSet: dfs,
|
||||
Context: ctx,
|
||||
})
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
var vendorImplementors = []string{"Vendor", "Node"}
|
||||
|
||||
func (ec *executionContext) _Vendor(ctx context.Context, sel ast.SelectionSet, obj *types.Vendor) graphql.Marshaler {
|
||||
@@ -14226,6 +14425,11 @@ func (ec *executionContext) marshalNTrustCenterReferenceEdge2ᚖgoᚗproboᚗinc
|
||||
return ec._TrustCenterReferenceEdge(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNUpdateFullNameInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐUpdateFullNameInput(ctx context.Context, v any) (types.UpdateFullNameInput, error) {
|
||||
res, err := ec.unmarshalInputUpdateFullNameInput(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNVendor2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐVendor(ctx context.Context, sel ast.SelectionSet, v *types.Vendor) graphql.Marshaler {
|
||||
if v == nil {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
@@ -14712,6 +14916,13 @@ func (ec *executionContext) marshalOTrustCenterFile2ᚖgoᚗproboᚗincᚋprobo
|
||||
return ec._TrustCenterFile(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalOUpdateFullNamePayload2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐUpdateFullNamePayload(ctx context.Context, sel ast.SelectionSet, v *types.UpdateFullNamePayload) graphql.Marshaler {
|
||||
if v == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
return ec._UpdateFullNamePayload(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalOVerifyMagicLinkPayload2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐVerifyMagicLinkPayload(ctx context.Context, sel ast.SelectionSet, v *types.VerifyMagicLinkPayload) graphql.Marshaler {
|
||||
if v == nil {
|
||||
return graphql.Null
|
||||
|
||||
@@ -213,7 +213,6 @@ type RequestTrustCenterFileAccessInput struct {
|
||||
}
|
||||
|
||||
type SendMagicLinkInput struct {
|
||||
FullName string `json:"fullName"`
|
||||
Email mail.Addr `json:"email"`
|
||||
Continue *string `json:"continue,omitempty"`
|
||||
}
|
||||
@@ -294,6 +293,14 @@ type TrustCenterReferenceEdge struct {
|
||||
Node *TrustCenterReference `json:"node"`
|
||||
}
|
||||
|
||||
type UpdateFullNameInput struct {
|
||||
FullName string `json:"fullName"`
|
||||
}
|
||||
|
||||
type UpdateFullNamePayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type Vendor struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -192,7 +192,6 @@ func (r *mutationResolver) SendMagicLink(ctx context.Context, input types.SendMa
|
||||
}
|
||||
|
||||
req := &iam.SendMagicLinkRequest{
|
||||
FullName: input.FullName,
|
||||
Email: input.Email,
|
||||
CompliancePageID: &trustCenter.ID,
|
||||
OrganizationID: trustCenter.OrganizationID,
|
||||
@@ -273,6 +272,49 @@ func (r *mutationResolver) VerifyMagicLink(ctx context.Context, input types.Veri
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateFullName is the resolver for the updateFullName field.
|
||||
func (r *mutationResolver) UpdateFullName(ctx context.Context, input types.UpdateFullNameInput) (*types.UpdateFullNamePayload, error) {
|
||||
identity := authn.IdentityFromContext(ctx)
|
||||
if identity == nil {
|
||||
return nil, gqlutils.Unauthenticatedf(ctx, "authentication is required to request access")
|
||||
}
|
||||
|
||||
identity, err := r.iam.AccountService.UpdateIdentity(ctx, identity.ID, &iam.UpdateIdentityRequest{
|
||||
FullName: input.FullName,
|
||||
})
|
||||
if err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot update identity", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
compliancePage := compliancepage.CompliancePageFromContext(ctx)
|
||||
|
||||
profile, err := r.iam.OrganizationService.GetProfileForIdentityAndOrganization(ctx, identity.ID, compliancePage.OrganizationID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrProfileNotFound](err); !ok {
|
||||
r.logger.ErrorCtx(ctx, "cannot get profile", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
if profile.Source == coredata.ProfileSourceManual {
|
||||
if _, err := r.iam.OrganizationService.UpdateUser(ctx, &iam.UpdateUserRequest{
|
||||
ID: profile.ID,
|
||||
FullName: identity.FullName,
|
||||
AdditionalEmailAddresses: profile.AdditionalEmailAddresses,
|
||||
Kind: profile.Kind,
|
||||
Position: profile.Position,
|
||||
ContractStartDate: &profile.ContractStartDate,
|
||||
ContractEndDate: &profile.ContractEndDate,
|
||||
}); err != nil {
|
||||
r.logger.ErrorCtx(ctx, "cannot update profile", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
return &types.UpdateFullNamePayload{Success: true}, nil
|
||||
}
|
||||
|
||||
// RequestAllAccesses is the resolver for the requestAllAccesses field.
|
||||
func (r *mutationResolver) RequestAllAccesses(ctx context.Context) (*types.RequestAccessesPayload, error) {
|
||||
trustCenter := compliancepage.CompliancePageFromContext(ctx)
|
||||
|
||||
@@ -66,6 +66,20 @@ func AssumptionRequiredf(ctx context.Context, format string, a ...any) *gqlerror
|
||||
return AssumptionRequired(ctx, fmt.Errorf(format, a...))
|
||||
}
|
||||
|
||||
func FullNameRequired(ctx context.Context, err error) *gqlerror.Error {
|
||||
return &gqlerror.Error{
|
||||
Message: err.Error(),
|
||||
Path: graphql.GetPath(ctx),
|
||||
Extensions: map[string]any{
|
||||
"code": "FULL_NAME_REQUIRED",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func FullNameRequiredf(ctx context.Context, format string, a ...any) *gqlerror.Error {
|
||||
return FullNameRequired(ctx, fmt.Errorf(format, a...))
|
||||
}
|
||||
|
||||
func NDASignatureRequired(ctx context.Context, err error) *gqlerror.Error {
|
||||
return &gqlerror.Error{
|
||||
Message: err.Error(),
|
||||
|
||||
@@ -187,7 +187,7 @@ func (s TrustCenterAccessService) Request(
|
||||
return fmt.Errorf("cannot load trust center: %w", err)
|
||||
}
|
||||
|
||||
access := &coredata.TrustCenterAccess{}
|
||||
access = &coredata.TrustCenterAccess{}
|
||||
if err := access.LoadByTrustCenterIDAndIdentityID(ctx, tx, s.svc.scope, req.TrustCenterID, req.IdentityID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance page membership: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user