Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invite template id #484

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "a@b.c", 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
Loading