From 74932e6311cf70486276ce3943badf280ae7ffdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 11 Aug 2015 10:35:10 +0200 Subject: [PATCH] feat(invite): added specific email for invites to existing grafana users --- emails/templates/invited_to_org.html | 38 +++++ emails/templates/layouts/default.html | 3 - emails/templates/new_user_invite.html | 16 ++- pkg/api/org_invite.go | 51 +++++-- public/emails/invited_to_org.html | 198 ++++++++++++++++++++++++++ public/emails/new_user_invite.html | 19 ++- public/emails/reset_password.html | 3 - public/emails/welcome_on_signup.html | 3 - 8 files changed, 290 insertions(+), 41 deletions(-) create mode 100644 emails/templates/invited_to_org.html create mode 100644 public/emails/invited_to_org.html diff --git a/emails/templates/invited_to_org.html b/emails/templates/invited_to_org.html new file mode 100644 index 00000000000..5aac6e28de3 --- /dev/null +++ b/emails/templates/invited_to_org.html @@ -0,0 +1,38 @@ + + +[[Subject .Subject "[[.InvitedBy]] has added you to the Grafana organization [[.OrgName]]"]] + + + + + +
+ + + + + + +
+

You have been added to the Grafana organization [[.OrgName]]

+
+ +
+ + + + + +
+ + + + + +
+

You can switch organization in the left side menu, in the dropdown below your username.

+
+ +
+ + diff --git a/emails/templates/layouts/default.html b/emails/templates/layouts/default.html index c5dc579fa04..0fd5b35ea48 100644 --- a/emails/templates/layouts/default.html +++ b/emails/templates/layouts/default.html @@ -44,10 +44,7 @@ diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 41215259769..d69eaabe584 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -39,16 +39,7 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response return ApiError(500, "Failed to query db for existing user check", err) } } else { - // user exists, add org role - createOrgUserCmd := m.AddOrgUserCommand{OrgId: c.OrgId, UserId: userQuery.Result.Id, Role: inviteDto.Role} - if err := bus.Dispatch(&createOrgUserCmd); err != nil { - if err == m.ErrOrgUserAlreadyAdded { - return ApiError(412, fmt.Sprintf("User %s is already added to organization", inviteDto.LoginOrEmail), err) - } - return ApiError(500, "Error while trying to create org user", err) - } else { - return ApiSuccess(fmt.Sprintf("Existing Grafana user %s added to org %s", userQuery.Result.NameOrFallback(), c.OrgName)) - } + return inviteExistingUserToOrg(c, userQuery.Result, &inviteDto) } cmd := m.CreateTempUserCommand{} @@ -71,11 +62,11 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response To: []string{inviteDto.LoginOrEmail}, Template: "new_user_invite.html", Data: map[string]interface{}{ - "NameOrEmail": util.StringsFallback2(cmd.Name, cmd.Email), - "OrgName": c.OrgName, - "Email": c.Email, - "LinkUrl": setting.ToAbsUrl("invite/" + cmd.Code), - "InvitedBy": util.StringsFallback3(c.Name, c.Email, c.Login), + "Name": util.StringsFallback2(cmd.Name, cmd.Email), + "OrgName": c.OrgName, + "Email": c.Email, + "LinkUrl": setting.ToAbsUrl("invite/" + cmd.Code), + "InvitedBy": util.StringsFallback3(c.Name, c.Email, c.Login), }, } @@ -89,6 +80,36 @@ func AddOrgInvite(c *middleware.Context, inviteDto dtos.AddInviteForm) Response return ApiSuccess(fmt.Sprintf("Created invite for %s", inviteDto.LoginOrEmail)) } +func inviteExistingUserToOrg(c *middleware.Context, user *m.User, inviteDto *dtos.AddInviteForm) Response { + // user exists, add org role + createOrgUserCmd := m.AddOrgUserCommand{OrgId: c.OrgId, UserId: user.Id, Role: inviteDto.Role} + if err := bus.Dispatch(&createOrgUserCmd); err != nil { + if err == m.ErrOrgUserAlreadyAdded { + return ApiError(412, fmt.Sprintf("User %s is already added to organization", inviteDto.LoginOrEmail), err) + } + return ApiError(500, "Error while trying to create org user", err) + } else { + + if !inviteDto.SkipEmails && util.IsEmail(user.Email) { + emailCmd := m.SendEmailCommand{ + To: []string{user.Email}, + Template: "invited_to_org.html", + Data: map[string]interface{}{ + "Name": user.NameOrFallback(), + "OrgName": c.OrgName, + "InvitedBy": util.StringsFallback3(c.Name, c.Email, c.Login), + }, + } + + if err := bus.Dispatch(&emailCmd); err != nil { + return ApiError(500, "Failed to send email invited_to_org", err) + } + } + + return ApiSuccess(fmt.Sprintf("Existing Grafana user %s added to org %s", user.NameOrFallback(), c.OrgName)) + } +} + func RevokeInvite(c *middleware.Context) Response { cmd := m.UpdateTempUserStatusCommand{ Code: c.Params(":code"), diff --git a/public/emails/invited_to_org.html b/public/emails/invited_to_org.html new file mode 100644 index 00000000000..fb61438b441 --- /dev/null +++ b/public/emails/invited_to_org.html @@ -0,0 +1,198 @@ + + + + + + + + +
- - {{> body }} - diff --git a/emails/templates/new_user_invite.html b/emails/templates/new_user_invite.html index 1071802f3cd..1368ba5a457 100644 --- a/emails/templates/new_user_invite.html +++ b/emails/templates/new_user_invite.html @@ -1,3 +1,5 @@ + + [[Subject .Subject "[[.InvitedBy]] has invited you to join Grafana"]] @@ -7,7 +9,7 @@
@@ -24,12 +26,12 @@ + + +
-

You're invited to sign up to Grafana and join [[.OrgName]]

+

You're invited to sign up to Grafana and join organization [[.OrgName]]

- - - -
- Complete Sign Up -
+
+ Complete Sign Up +
+ + + + +
+
+ + + + + +
+
+ + + + + +
+ + + + + + +
+ +
+ +
+ +
+
+ + + + + + +
+ + +{{Subject .Subject "{{.InvitedBy}} has added you to the Grafana organization {{.OrgName}}"}} + + + + + +
+ + + + + + +
+

You have been added to the Grafana organization {{.OrgName}}

+
+ +
+ + + + + +
+ + + + + +
+

You can switch organization in the left side menu, in the dropdown below your username.

+
+ +
+ + + + + + + + + + + +
+
+
+ + diff --git a/public/emails/new_user_invite.html b/public/emails/new_user_invite.html index ee9774d8c1b..aeadbb98d7b 100644 --- a/public/emails/new_user_invite.html +++ b/public/emails/new_user_invite.html @@ -125,9 +125,9 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans- @@ -170,7 +170,6 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans- -
+ - - {{Subject .Subject "{{.InvitedBy}} has invited you to join Grafana"}} +{{Subject .Subject "{{.InvitedBy}} has invited you to join Grafana"}} @@ -136,7 +136,7 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-
@@ -153,12 +153,12 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans- + + +
-

You're invited to sign up to Grafana and join {{.OrgName}}

+

You're invited to sign up to Grafana and join organization {{.OrgName}}

- - - -
- Complete Sign Up -
+
+ Complete Sign Up +
diff --git a/public/emails/reset_password.html b/public/emails/reset_password.html index ef1c98d9107..55bc0f562a5 100644 --- a/public/emails/reset_password.html +++ b/public/emails/reset_password.html @@ -125,8 +125,6 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-
- - {{Subject .Subject "Reset your Grafana password - {{.Name}}"}} @@ -170,7 +168,6 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans- -
diff --git a/public/emails/welcome_on_signup.html b/public/emails/welcome_on_signup.html index b311bfca11c..ea38a8c6671 100644 --- a/public/emails/welcome_on_signup.html +++ b/public/emails/welcome_on_signup.html @@ -125,8 +125,6 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-
- - {{Subject .Subject "Welcome to Grafana"}} @@ -165,7 +163,6 @@ font-family: 'Open Sans', 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans- -