Remove the email pipeline
The mailbox sync (Microsoft Graph and IMAP), its Claude classifier, the /email routes and the Settings page's email section are taken out while the pipeline is unused. The last commit with it is tagged email-pipeline-last; reverting this commit brings it back. The status rules the capture path shares (statusOrder, StatusAdvances, NormalizeStatus) move to job_status.go with their tests. ProcessedEmail stays in the migration, marked dormant, so its history survives for a restored pipeline. golang.org/x/oauth2 is no longer needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// REST endpoints for the job-application email pipeline: a manual
|
||||
// admin-triggered sync, and the OAuth redirect target (which has to be REST
|
||||
// because Microsoft redirects a browser to it).
|
||||
|
||||
// TriggerEmailSync backs the admin-only POST /api/email/sync and runs one sync
|
||||
// synchronously, so the response reflects the result. If the scheduler is
|
||||
// mid-sync the service refuses via TryLock and this returns 500.
|
||||
func (store *Store) TriggerEmailSync(ctx *gin.Context) {
|
||||
// A nil HTTPClient is the service's readiness flag — see
|
||||
// services.EmailSyncService.
|
||||
if store.EmailSync == nil || store.EmailSync.HTTPClient == nil {
|
||||
ctx.JSON(http.StatusServiceUnavailable, gin.H{"error": "email sync not configured or not authenticated"})
|
||||
return
|
||||
}
|
||||
|
||||
err := store.EmailSync.SyncEmails(ctx.Request.Context())
|
||||
if err != nil {
|
||||
log.Printf("[EmailSync] Manual sync error: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "sync failed", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, gin.H{"message": "sync completed"})
|
||||
}
|
||||
|
||||
// CompleteEmailAuth handles Microsoft's OAuth redirect to
|
||||
// GET /api/email/callback and stores the resulting token.
|
||||
//
|
||||
// The route is unauthenticated (Microsoft's redirect carries no site cookie),
|
||||
// which is safe only because the code is worthless without the app's client
|
||||
// secret. Note that completing auth here does not start the scheduler, which
|
||||
// only checks readiness at start-up — a restart is needed for that.
|
||||
func (store *Store) CompleteEmailAuth(ctx *gin.Context) {
|
||||
if store.EmailSync == nil {
|
||||
ctx.JSON(http.StatusServiceUnavailable, gin.H{"error": "email sync not configured"})
|
||||
return
|
||||
}
|
||||
|
||||
code := ctx.Query("code")
|
||||
if code == "" {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "missing authorization code"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := store.EmailSync.CompleteAuth(ctx.Request.Context(), code); err != nil {
|
||||
log.Printf("[EmailSync] Auth completion error: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "authentication failed"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, gin.H{"message": "email authentication successful"})
|
||||
}
|
||||
|
||||
// EmailSyncStatus backs the admin-only GET /api/email/status, which the
|
||||
// settings page reads to say whether mail is being read and, on the Graph
|
||||
// backend before sign-in, to offer the Microsoft authorisation link. Until
|
||||
// the tracker had a page of its own that link was only printed to the log.
|
||||
func (store *Store) EmailSyncStatus(ctx *gin.Context) {
|
||||
if store.EmailSync == nil || store.EmailSync.Config == nil {
|
||||
ctx.JSON(http.StatusOK, gin.H{"backend": "", "enabled": false, "ready": false})
|
||||
return
|
||||
}
|
||||
svc := store.EmailSync
|
||||
status := gin.H{
|
||||
"backend": svc.Config.Backend,
|
||||
// Enabled is the timer; a ready service can still be synced by hand.
|
||||
"enabled": svc.Config.Enabled,
|
||||
"ready": svc.HTTPClient != nil,
|
||||
}
|
||||
if svc.HTTPClient == nil && svc.OAuthConfig != nil {
|
||||
status["authUrl"] = svc.AuthURL()
|
||||
}
|
||||
ctx.JSON(http.StatusOK, status)
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// Package handlers holds the REST endpoints and the shared Store that every
|
||||
// request handler — and, through graph.Resolver, every GraphQL resolver —
|
||||
// depends on.
|
||||
package handlers
|
||||
|
||||
import (
|
||||
@@ -5,13 +8,9 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Package handlers holds the REST endpoints and the shared Store that every
|
||||
// request handler — and, through graph.Resolver, every GraphQL resolver —
|
||||
// depends on. It is built once in main and passed around by pointer.
|
||||
// Store is built once in main and passed around by pointer.
|
||||
type Store struct {
|
||||
DB *gorm.DB
|
||||
// EmailSync is the mailbox pipeline (services/email_sync.go).
|
||||
EmailSync *services.EmailSyncService
|
||||
// JobLeads is the lead fetcher (services/job_leads.go). The GraphQL
|
||||
// resolvers use it to start a run and report on one.
|
||||
JobLeads *services.JobLeadService
|
||||
|
||||
Reference in New Issue
Block a user