Skip to content

Commit

Permalink
OCM: Pass the link to the meshdirectory service in token mail (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Jul 24, 2020
1 parent 014c93a commit 0232246
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
9 changes: 9 additions & 0 deletions changelog/unreleased/ocm-token-mail-meshdir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Enhancement: Pass the link to the meshdirectory service in token mail.

Currently, we just forward the token and the original user's domain when
forwarding an OCM invite token and expect the user to frame the forward invite
URL. This PR instead passes the link to the meshdirectory service, from where
the user can pick the provider they want to accept the invite with.

https://github.com/cs3org/reva/pull/1002
https://github.com/sciencemesh/sciencemesh/issues/139
17 changes: 14 additions & 3 deletions internal/http/services/ocmd/invites.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ import (
)

type invitesHandler struct {
smtpCredentials *smtpclient.SMTPCredentials
gatewayAddr string
smtpCredentials *smtpclient.SMTPCredentials
gatewayAddr string
meshDirectoryURL string
}

func (h *invitesHandler) init(c *Config) {
h.gatewayAddr = c.GatewaySvc
h.smtpCredentials = smtpclient.NewSMTPCredentials(c.SMTPCredentials)
h.meshDirectoryURL = c.MeshDirectoryURL
}

func (h *invitesHandler) Handler() http.Handler {
Expand Down Expand Up @@ -90,7 +92,9 @@ func (h *invitesHandler) generateInviteToken(w http.ResponseWriter, r *http.Requ
subject := fmt.Sprintf("ScienceMesh: %s wants to collaborate with you", usr.DisplayName)
body := "Hi,\n\n" +
usr.DisplayName + " (" + usr.Mail + ") wants to start sharing OCM resources with you. " +
"To accept the invite, please use the following details:\n" +
"To accept the invite, please visit the following URL:\n" +
h.meshDirectoryURL + "?token=" + token.InviteToken.Token + "&providerDomain=" + usr.Id.Idp + "\n\n" +
"Alternatively, you can visit your mesh provider and use the following details:\n" +
"Token: " + token.InviteToken.Token + "\n" +
"ProviderDomain: " + usr.Id.Idp + "\n\n" +
"Best,\nThe ScienceMesh team"
Expand Down Expand Up @@ -164,6 +168,13 @@ func (h *invitesHandler) forwardInvite(w http.ResponseWriter, r *http.Request) {
return
}

_, err = w.Write([]byte("Accepted invite from: " + r.FormValue("providerDomain")))
if err != nil {
WriteError(w, r, APIErrorServerError, "error writing token data", err)
return
}
w.WriteHeader(http.StatusOK)

log.Info().Msgf("Invite forwarded to: %s", r.FormValue("providerDomain"))
}

Expand Down
11 changes: 6 additions & 5 deletions internal/http/services/ocmd/ocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import (

// Config holds the config options that need to be passed down to all ocdav handlers
type Config struct {
SMTPCredentials *smtpclient.SMTPCredentials `mapstructure:"smtp_credentials"`
Prefix string `mapstructure:"prefix"`
Host string `mapstructure:"host"`
GatewaySvc string `mapstructure:"gatewaysvc"`
Config configData `mapstructure:"config"`
SMTPCredentials *smtpclient.SMTPCredentials `mapstructure:"smtp_credentials"`
Prefix string `mapstructure:"prefix"`
Host string `mapstructure:"host"`
GatewaySvc string `mapstructure:"gatewaysvc"`
MeshDirectoryURL string `mapstructure:"mesh_directory_url"`
Config configData `mapstructure:"config"`
}

func (c *Config) init() {
Expand Down

0 comments on commit 0232246

Please sign in to comment.