-
Notifications
You must be signed in to change notification settings - Fork 5
[FEAT] implement email service send emails for workspace invitations #21
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
Merged
martian56
merged 4 commits into
main
from
20-implement-email-service-send-emails-for-workspace-invitations
Mar 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: UI CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'ui/**' | ||
| - '.github/workflows/ui-ci.yml' | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: ui | ||
|
|
||
| jobs: | ||
| lint-and-format: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "22" | ||
| cache: npm | ||
| cache-dependency-path: ui/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Check formatting | ||
| run: npm run format:check | ||
|
|
||
| - name: Build | ||
| run: npm run build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/Devlaner/devlane/api/internal/store" | ||
| "github.com/gin-gonic/gin" | ||
| ) | ||
|
|
||
| // InvitationHandler serves public invite-by-token endpoints (no auth). | ||
| type InvitationHandler struct { | ||
| Winv *store.WorkspaceInviteStore | ||
| Ws *store.WorkspaceStore | ||
| } | ||
|
|
||
| // GetInviteByToken returns workspace invite details by token for the invite landing page. | ||
| // GET /api/invitations/by-token/?token=... | ||
| func (h *InvitationHandler) GetInviteByToken(c *gin.Context) { | ||
| token := strings.TrimSpace(c.Query("token")) | ||
| if token == "" { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "token required"}) | ||
| return | ||
| } | ||
| inv, err := h.Winv.GetByToken(c.Request.Context(), token) | ||
| if err != nil || inv == nil { | ||
| c.JSON(http.StatusNotFound, gin.H{"error": "Invite not found or expired"}) | ||
| return | ||
| } | ||
| w, err := h.Ws.GetByID(c.Request.Context(), inv.WorkspaceID) | ||
| if err != nil || w == nil { | ||
| c.JSON(http.StatusNotFound, gin.H{"error": "Workspace not found"}) | ||
| return | ||
| } | ||
| c.JSON(http.StatusOK, gin.H{ | ||
| "workspace_name": w.Name, | ||
| "workspace_slug": w.Slug, | ||
| "email": inv.Email, | ||
| "invitation_id": inv.ID.String(), | ||
| }) | ||
| } | ||
|
|
||
| // DeclineInviteByToken removes the invitation (Ignore flow). No auth required. | ||
| // POST /api/invitations/decline/ body: { "token": "..." } | ||
| func (h *InvitationHandler) DeclineInviteByToken(c *gin.Context) { | ||
| var body struct { | ||
| Token string `json:"token" binding:"required"` | ||
| } | ||
| if err := c.ShouldBindJSON(&body); err != nil { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "token required"}) | ||
| return | ||
| } | ||
| token := strings.TrimSpace(body.Token) | ||
| if token == "" { | ||
| c.JSON(http.StatusBadRequest, gin.H{"error": "token required"}) | ||
| return | ||
| } | ||
| inv, err := h.Winv.GetByToken(c.Request.Context(), token) | ||
| if err != nil || inv == nil { | ||
| c.Status(http.StatusNoContent) | ||
| return | ||
| } | ||
| if err := h.Winv.Delete(c.Request.Context(), inv.ID); err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to decline invite"}) | ||
| return | ||
| } | ||
martian56 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| c.Status(http.StatusNoContent) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package mail | ||
|
|
||
| import "log/slog" | ||
|
|
||
| // LogSendAttempt logs when an email send is about to be attempted. | ||
| // inviteURL is optional (e.g. workspace invite link); empty string is omitted from logs. | ||
| func LogSendAttempt(log *slog.Logger, to, subject, kind, inviteURL string) { | ||
| if log == nil { | ||
| return | ||
| } | ||
| attrs := []any{"to", to, "subject", subject, "kind", kind} | ||
| if inviteURL != "" { | ||
| attrs = append(attrs, "invite_url", inviteURL) | ||
| } | ||
| log.Info("mail send attempt", attrs...) | ||
martian56 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // LogSent logs successful email delivery. | ||
| func LogSent(log *slog.Logger, to, subject, inviteURL string) { | ||
| if log == nil { | ||
| return | ||
| } | ||
| attrs := []any{"to", to, "subject", subject} | ||
| if inviteURL != "" { | ||
| attrs = append(attrs, "invite_url", inviteURL) | ||
| } | ||
| log.Info("mail sent", attrs...) | ||
| } | ||
|
|
||
| // LogFailed logs a failed email send with error and optional invite URL. | ||
| func LogFailed(log *slog.Logger, to, subject, inviteURL string, err error) { | ||
| if log == nil { | ||
| return | ||
| } | ||
| attrs := []any{"to", to, "subject", subject, "error", err} | ||
| if inviteURL != "" { | ||
| attrs = append(attrs, "invite_url", inviteURL) | ||
| } | ||
| log.Error("mail send failed", attrs...) | ||
| } | ||
|
|
||
| // LogSkip logs when mail is skipped (e.g. not configured). | ||
| func LogSkip(log *slog.Logger, reason, to string, err error) { | ||
| if log == nil { | ||
| return | ||
| } | ||
| log.Warn("mail skip", "reason", reason, "to", to, "error", err) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.