Skip to content

add send email to admin when user upload new entry#79

Merged
NicolasCARPi merged 3 commits into
masterfrom
toan-2026-01-22-send-email-to-admin
Jan 26, 2026
Merged

add send email to admin when user upload new entry#79
NicolasCARPi merged 3 commits into
masterfrom
toan-2026-01-22-send-email-to-admin

Conversation

@toan-nsc
Copy link
Copy Markdown
Contributor

@toan-nsc toan-nsc commented Jan 22, 2026

Closes #70

  • Config the admin email
image - add new API KEY image
  • Already sent the request to mail service
image

Summary by CodeRabbit

  • New Features

    • Admins can be created with an optional email and admin listing shows email (or “(not set)”).
    • Automatic email notifications sent to admins when new records are uploaded; email delivery can be configured via environment variables.
    • CLI add command accepts an optional email argument.
  • Chores

    • Database schema updated to store and index admin email addresses (with rollback support).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Adds admin email storage and retrieval, CLI support to set/display emails, an SMTP2GO-backed EmailService, and async notification of admins after record creation; includes DB migrations for adding/dropping the email column and index.

Changes

Cohort / File(s) Summary
Database Schema
src/sql/007_add_admin_email.up.sql, src/sql/007_add_admin_email.down.sql
Add email VARCHAR(255) to admin_orcids and create idx_admin_orcids_email; down migration drops the index and column.
Repository Layer
src/cmd/repositories.go, src/category_repository.go
Admin struct gains Email field. AdminRepository.Add signature extended to accept email. New interface method GetAllEmails(ctx) added and implemented in PostgresAdminRepository; GetAll/Add now select/insert email.
CLI Updates
src/cmd/cli.go
admin add accepts optional email (add <orcid> [email]); addAdmin signature extended; admin listing shows Email (displays "(not set)" when empty); seed path updated to pass email.
Email Service
src/email.go
New EmailService with NewEmailService() and SendNewRecordNotification(...); builds text/HTML bodies and posts SMTP2GORequest to SMTP2GO API with timeout and gating when disabled or no recipients.
Record Handler Integration
src/record_handler.go
RecordHandler adds emailService (initialized via NewEmailService()); after successful record create/S3 upload spawns goroutine that calls GetAllEmails() and SendNewRecordNotification, logging any errors.
Dev Environment
docker-compose-dev.yml
Adds environment variables SMTP2GO_API_KEY, EMAIL_FROM_ADDRESS, and EMAIL_FROM_NAME to dev service.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Upload Client
    participant Handler as RecordHandler
    participant Repo as AdminRepository
    participant Email as EmailService
    participant SMTP as SMTP2GO API

    Client->>Handler: CreateRecord (upload)
    Handler->>Handler: Validate & store record
    Handler->>Handler: Upload file to S3
    Handler->>Handler: Spawn goroutine for notifications
    Handler->>Repo: GetAllEmails(ctx)
    Repo->>Repo: Query admin_orcids for non-empty emails
    Repo-->>Handler: []string (emails)
    Handler->>Email: SendNewRecordNotification(emails, record, siteURL)
    Email->>Email: Build text and HTML bodies
    Email->>SMTP: POST /api/email/send (SMTP2GORequest)
    SMTP-->>Email: API response
    Email-->>Handler: Return success/error
    Handler->>Handler: Log result
    Handler-->>Client: Return response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through rows of ORCIDs bright,
Poked a new column into the night,
A fluttering SMTP2GO song sent,
Admin mailboxes cheerfully went,
— Signed, a rabbit, with a tiny byte ✨📧


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@toan-nsc toan-nsc marked this pull request as draft January 22, 2026 09:19
@toan-nsc toan-nsc marked this pull request as ready for review January 23, 2026 07:05
}

// GetAllEmails retrieves all admin email addresses (non-null only)
func (r *PostgresAdminRepository) GetAllEmails(ctx context.Context) ([]string, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this function repeated from cmd/repositories.go ? Can't we share such code between web and cli?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed

@toan-nsc toan-nsc requested a review from NicolasCARPi January 25, 2026 14:32
Copy link
Copy Markdown
Member

@NicolasCARPi NicolasCARPi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

@NicolasCARPi NicolasCARPi merged commit f8bae63 into master Jan 26, 2026
2 checks passed
@NicolasCARPi NicolasCARPi deleted the toan-2026-01-22-send-email-to-admin branch January 26, 2026 19:37
NicolasCARPi added a commit that referenced this pull request Jan 29, 2026
* 'master' of github.com:deltablot/eln.community:
  fix: issue 74 version count is wrong (#80)
  add send email to admin when user upload new entry (#79)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

emails: add smtp config

3 participants