Skip to content

Commit

Permalink
Invite template id (#484)
Browse files Browse the repository at this point in the history
+ test
related to descope/etc#8535
  • Loading branch information
aviadl authored Dec 15, 2024
1 parent 5e9b320 commit b7ed2e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions descope/internal/mgmt/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type createUserRequest struct {
roles []string
tenants []*descope.AssociatedTenant
invite bool
templateID string
test bool
customAttributes map[string]any
verifiedEmail *bool
Expand Down Expand Up @@ -76,6 +77,10 @@ func (u *user) create(ctx context.Context, loginID, email, phone, displayName, g
if loginID == "" {
return nil, utils.NewInvalidArgumentError("loginID")
}
var templateID string
if options != nil {
templateID = options.TemplateID
}
req := makeCreateUserRequest(&createUserRequest{
loginID: loginID,
email: email,
Expand All @@ -88,6 +93,7 @@ func (u *user) create(ctx context.Context, loginID, email, phone, displayName, g
roles: roles,
tenants: tenants,
invite: invite,
templateID: templateID,
test: test,
customAttributes: customAttributes,
verifiedEmail: verifiedEmail,
Expand Down Expand Up @@ -711,6 +717,9 @@ func (u *user) History(ctx context.Context, userIDs []string) ([]*descope.UserHi
func makeCreateUserRequest(createReq *createUserRequest) map[string]any {
req := makeUpdateUserRequest(createReq)
req["invite"] = createReq.invite
if len(createReq.templateID) > 0 {
req["templateId"] = createReq.templateID
}
req["additionalLoginIds"] = createReq.additionalLoginIDs
if createReq.test {
req["test"] = true
Expand Down
3 changes: 2 additions & 1 deletion descope/internal/mgmt/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestUserCreateSuccess(t *testing.T) {
if i == 2 {
assert.True(t, true, req["sendSMS"])
assert.EqualValues(t, false, req["sendMail"])
assert.EqualValues(t, "tid", req["templateId"])
} else {
assert.Nil(t, req["sendSMS"])
assert.Nil(t, req["sendMail"])
Expand All @@ -64,7 +65,7 @@ func TestUserCreateSuccess(t *testing.T) {

sendSMS := true
sendMail := false
res, err = m.User().Invite(context.Background(), "abc", user, &descope.InviteOptions{InviteURL: "https://some.domain.com", SendSMS: &sendSMS, SendMail: &sendMail})
res, err = m.User().Invite(context.Background(), "abc", user, &descope.InviteOptions{TemplateID: "tid", InviteURL: "https://some.domain.com", SendSMS: &sendSMS, SendMail: &sendMail})
require.NoError(t, err)
require.NotNil(t, res)
require.Equal(t, "[email protected]", res.Email)
Expand Down
1 change: 1 addition & 0 deletions descope/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ type InviteOptions struct {
SendMail *bool `json:"sendMail,omitempty"` // send invite via mail, default is according to project settings
SendSMS *bool `json:"sendSMS,omitempty"` // send invite via text message, default is according to project settings
TemplateOptions map[string]string `json:"templateOptions,omitempty"` // for providing messaging template options (templates that are being sent via email / text message)
TemplateID string `json:"-"`
}

type User struct {
Expand Down

0 comments on commit b7ed2e8

Please sign in to comment.