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

Enable sending an email to users not found in the Google Workspace directory #666

Merged
merged 1 commit into from
Apr 4, 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
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
Loading