Skip to content

Commit

Permalink
Enable sending an email to users not found in the Google Workspace di…
Browse files Browse the repository at this point in the history
…rectory (#666)
  • Loading branch information
jfreda authored Apr 4, 2024
1 parent 4978772 commit 0a9b320
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/api/v2/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ func MeHandler(srv server.Server) http.Handler {
nil,
"user_email", userEmail,
)

// If configured, send an email to the user to notify them that their
// account was not found in the directory.
if srv.Config.Email != nil && srv.Config.Email.Enabled &&
srv.Config.GoogleWorkspace != nil &&
srv.Config.GoogleWorkspace.UserNotFoundEmail != nil &&
srv.Config.GoogleWorkspace.UserNotFoundEmail.Enabled &&
srv.Config.GoogleWorkspace.UserNotFoundEmail.Body != "" &&
srv.Config.GoogleWorkspace.UserNotFoundEmail.Subject != "" {
_, err = srv.GWService.SendEmail(
[]string{userEmail},
srv.Config.Email.FromAddress,
srv.Config.GoogleWorkspace.UserNotFoundEmail.Subject,
srv.Config.GoogleWorkspace.UserNotFoundEmail.Body,
)
if err != nil {
srv.Logger.Error("error sending user not found email",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"user_email", userEmail,
)
} else {
srv.Logger.Info("user not found email sent",
"method", r.Method,
"path", r.URL.Path,
"user_email", userEmail,
)
}
}

return
}
p := ppl[0]
Expand Down
18 changes: 18 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ type GoogleWorkspace struct {
// create_docs_as_user is true in the auth block, so document notification
// settings will be the same as when a user creates their own document.
TemporaryDraftsFolder string `hcl:"temporary_drafts_folder,optional"`

// UserNotFoundEmail is the configuration to send an email when a user is not
// found in Google Workspace.
UserNotFoundEmail *GoogleWorkspaceUserNotFoundEmail `hcl:"user_not_found_email,block"`
}

// GoogleWorkspaceOAuth2 is the configuration to use OAuth 2.0 to access Google
Expand All @@ -249,6 +253,20 @@ type GoogleWorkspaceOAuth2 struct {
RedirectURI string `hcl:"redirect_uri,optional"`
}

// GoogleWorkspaceUserNotFoundEmail is the configuration to send an email when a
// user is not found in Google Workspace.
type GoogleWorkspaceUserNotFoundEmail struct {
// Body is the body of the email.
Body string `hcl:"body,optional"`

// Enabled enables sending an email when a user is not found in Google
// Workspace.
Enabled bool `hcl:"enabled,optional"`

// Subject is the subject of the email.
Subject string `hcl:"subject,optional"`
}

// Jira is the configuration for Hermes to work with Jira.
type Jira struct {
// APIToken is the API token for authenticating to Jira.
Expand Down

0 comments on commit 0a9b320

Please sign in to comment.