Skip to content

Commit

Permalink
[server] Send emails for legacy (#4391)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 authored Dec 13, 2024
2 parents 7f0d07d + 58ae5ee commit acd2f63
Show file tree
Hide file tree
Showing 27 changed files with 665 additions and 37 deletions.
14 changes: 8 additions & 6 deletions server/cmd/museum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,14 @@ func main() {
privateAPI.POST("/trash/delete", trashHandler.Delete)
privateAPI.POST("/trash/empty", trashHandler.Empty)

emergencyCtrl := &emergency.Controller{
Repo: &emergencyRepo.Repository{DB: db},
UserRepo: userRepo,
UserCtrl: userController,
}
userHandler := &api.UserHandler{
UserController: userController,
UserController: userController,
EmergencyController: emergencyCtrl,
}
publicAPI.POST("/users/ott", userHandler.SendOTT)
publicAPI.POST("/users/verify-email", userHandler.VerifyEmail)
Expand Down Expand Up @@ -606,11 +612,6 @@ func main() {
familiesJwtAuthAPI.DELETE("/family/remove-member/:id", familyHandler.RemoveMember)
familiesJwtAuthAPI.DELETE("/family/revoke-invite/:id", familyHandler.RevokeInvite)

emergencyCtrl := &emergency.Controller{
Repo: &emergencyRepo.Repository{DB: db},
UserRepo: userRepo,
UserCtrl: userController,
}
emergencyHandler := &api.EmergencyHandler{
Controller: emergencyCtrl,
}
Expand Down Expand Up @@ -665,6 +666,7 @@ func main() {
UserAuthRepo: userAuthRepo,
UserController: userController,
FamilyController: familyController,
EmergencyController: emergencyCtrl,
RemoteStoreController: remoteStoreController,
FileRepo: fileRepo,
StorageBonusRepo: storagBonusRepo,
Expand Down
2 changes: 1 addition & 1 deletion server/ente/emergency.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
UserInvitedContact ContactState = "INVITED"
UserRevokedContact ContactState = "REVOKED"
ContactAccepted ContactState = "ACCEPTED"
ContactDeleted ContactState = "DELETED"
ContactLeft ContactState = "CONTACT_LEFT"
ContactDenied ContactState = "CONTACT_DENIED"
)
Expand All @@ -48,6 +47,7 @@ type EmergencyContactEntity struct {
type RecoveryStatus string

const (
RecoveryStatusInitiated RecoveryStatus = "INITIATED"
RecoveryStatusWaiting RecoveryStatus = "WAITING"
RecoveryStatusRejected RecoveryStatus = "REJECTED"
RecoveryStatusRecovered RecoveryStatus = "RECOVERED"
Expand Down
139 changes: 139 additions & 0 deletions server/mail-templates/legacy/legacy_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{{define "legacy_base"}}
<!DOCTYPE html>
<html>
<meta content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,
minimum-scale=1" />
<style>
body {
background-color: #f0f1f3;
font-family: "Helvetica Neue", "Segoe UI", Helvetica, sans-serif;
font-size: 16px;
line-height: 27px;
margin: 0;
color: #444;
}

pre {
background: #f4f4f4f4;
padding: 2px;
}

table {
width: 100%;
border: 1px solid #ddd;
}

table td {
border-color: #ddd;
padding: 5px;
}

.wrap {
background-color: #fff;
padding: 30px;
max-width: 525px;
margin: 0 auto;
border-radius: 5px;
}

.button {
background: #0055d4;
border-radius: 3px;
text-decoration: none !important;
color: #fff !important;
font-weight: bold;
padding: 10px 30px;
display: inline-block;
}

.button:hover {
background: #111;
}

.footer {
text-align: center;
font-size: 12px;
color: #888;
}

.footer a {
color: #888;
margin-right: 5px;
}

.gutter {
padding: 30px;
}

img {
max-width: 100%;
height: auto;
}

a {
color: #0055d4;
}

a:hover {
color: #111;
}

@media screen and (max-width: 600px) {
.wrap {
max-width: auto;
}

.gutter {
padding: 10px;
}
}

.footer-icons {
padding: 4px !important;
width: 24px !important;
}
</style>

<body>
<div class="gutter" style="padding: 4px">&nbsp;</div>
<div class="wrap" style=" background-color: rgb(255, 255, 255); padding: 2px
30px 30px 30px; max-width: 525px; margin: 0 auto; border-radius: 5px;
font-size: 16px; " >
<main>
{{block "content" .}} Default Content {{end}}
</main>
</div>
<br />
<div class="footer" style="text-align: center; font-size: 12px; color:
rgb(136, 136, 136)" >
<div>
<a href="https://ente.io" target="_blank" ><img
src="https://email-assets.ente.io/ente-green.png" style="width: 100px;
padding: 24px" title="Ente" alt="Ente" /></a>
</div>
<div>
<a href="https://fosstodon.org/@ente" target="_blank" ><img
src="https://email-assets.ente.io/mastodon-icon.png"
class="footer-icons" style="width: 24px; padding: 4px" title="Mastodon"
alt="Mastodon" /></a>
<a href="https://twitter.com/enteio" target="_blank" ><img
src="https://email-assets.ente.io/twitter-icon.png" class="footer-icons"
style="width: 24px; padding: 4px" title="Twitter" alt="Twitter" /></a>
<a href="https://discord.ente.io" target="_blank" ><img
src="https://email-assets.ente.io/discord-icon.png" class="footer-icons"
style="width: 24px; padding: 4px" title="Discord" alt="Discord" /></a>
<a href="https://github.com/ente-io" target="_blank" ><img
src="https://email-assets.ente.io/github-icon.png" class="footer-icons"
style="width: 24px; padding: 4px" title="GitHub" alt="GitHub" /></a>
</div>
<p>
Ente Technologies, Inc.
<br /> 1111B S Governors Ave 6032 Dover, DE 19904
</p>
<br />
</div>
</body>
</html>
{{end}}

10 changes: 10 additions & 0 deletions server/mail-templates/legacy/legacy_invite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.LegacyContact}}</strong> has invited you to be their trusted contact. </p>

<p>As a trusted contact, you can recover {{.LegacyContact}}'s account in their absence.</p>
<p>To accept the invite, please open the Ente Photos app, and navigate to <strong>Settings > Account > Legacy</strong>.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
9 changes: 9 additions & 0 deletions server/mail-templates/legacy/legacy_invite_accepted.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has accepted your request to be your trusted contact. </p>

<p>As a trusted contact, {{.TrustedContact}} can recover your account in your absence.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/legacy_invite_rejected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has rejected your request to be a trusted contact. </p>

<p>If you need help, please reply to this email</p>
{{end}}
10 changes: 10 additions & 0 deletions server/mail-templates/legacy/legacy_invite_sent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{define "content"}}
<p>Hello,</p>

<p>You have invited <strong>{{.TrustedContact}}</strong> to be your trusted contact. </p>

<p> As a trusted contact, {{.TrustedContact}} can recover your account in your absence. </p>
<p>If you want to cancel the invite, please navigate to <strong>Settings -> Account -> Legacy </strong> in the Ente Photos app. </p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/legacy_left.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has removed themselves from being your trusted contact.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/legacy_removed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.LegacyContact}}</strong> has removed you as their trusted contact.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/recovery_cancelled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedUser}}</strong> has cancelled the process of recovering your account.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/recovery_completed_legacy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has changed the password and can now access your account.

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/recovery_completed_trusted.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p>You can now access <strong>{{.LegacyContact}}'s</strong> account with the new password you setup on Ente.</p>

<p>If you need any help, please let us know by responding to this email, we'll be around.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/recovery_ready_legacy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> can now recover your account by changing the password.

<p>If you need help, please reply to this email.</p>
{{end}}
8 changes: 8 additions & 0 deletions server/mail-templates/legacy/recovery_ready_trusted.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{define "content"}}
<p>Hello,</p>

<p>You can now recover <strong>{{.LegacyContact}}'s</strong> account. </p>
<p>To change the password to <strong>{{.LegacyContact}}'s</strong> account, please navigate to <strong>Settings > Account > Legacy </strong> in the Ente Photos app. </p>

<p>If you need help, please reply to this email.</p>
{{end}}
7 changes: 7 additions & 0 deletions server/mail-templates/legacy/recovery_rejected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.LegacyContact}}</strong> has blocked your request to recover their account.</p>

<p>If you need help, please reply to this email</p>
{{end}}
9 changes: 9 additions & 0 deletions server/mail-templates/legacy/recovery_reminder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has initiated recovery on your account. After 2 days, they will be able to change the password and access your account. </p>

<p>If you want to block the recovery, please navigate to <strong>Settings > Account > Legacy </strong> in the Ente Photos app.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
9 changes: 9 additions & 0 deletions server/mail-templates/legacy/recovery_started.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{define "content"}}
<p>Hello,</p>

<p><strong>{{.TrustedContact}}</strong> has initiated recovery on your account. After 30 days, they will be able to change the password and access your account.</p>

<p>If you want to block the recovery, please navigate to <strong>Settings > Account > Legacy </strong> in the Ente Photos app.</p>

<p>If you need help, please reply to this email.</p>
{{end}}
9 changes: 9 additions & 0 deletions server/pkg/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"errors"
"fmt"
"github.com/ente-io/museum/pkg/controller/emergency"
"github.com/ente-io/museum/pkg/controller/remotestore"
"github.com/ente-io/museum/pkg/repo/authenticator"
"net/http"
Expand Down Expand Up @@ -47,6 +48,7 @@ type AdminHandler struct {
StorageBonusRepo *storagebonus.Repository
BillingController *controller.BillingController
UserController *user.UserController
EmergencyController *emergency.Controller
FamilyController *family.Controller
RemoteStoreController *remotestore.Controller
ObjectCleanupController *controller.ObjectCleanupController
Expand Down Expand Up @@ -182,6 +184,13 @@ func (h *AdminHandler) DeleteUser(c *gin.Context) {
"req_id": requestid.Get(c),
"req_ctx": "account_deletion",
})

// todo: (neeraj) refactor this part, currently there's a circular dependency between user and emergency controllers
removeLegacyErr := h.EmergencyController.HandleAccountDeletion(c, user.ID, logger)
if removeLegacyErr != nil {
handler.Error(c, stacktrace.Propagate(removeLegacyErr, ""))
return
}
response, err := h.UserController.HandleAccountDeletion(c, user.ID, logger)
if err != nil {
handler.Error(c, stacktrace.Propagate(err, ""))
Expand Down
15 changes: 14 additions & 1 deletion server/pkg/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/ente-io/museum/pkg/controller/emergency"
"github.com/gin-contrib/requestid"
"github.com/sirupsen/logrus"
"net/http"
Expand All @@ -22,7 +23,8 @@ import (

// UserHandler exposes request handlers for all user related requests
type UserHandler struct {
UserController *user.UserController
UserController *user.UserController
EmergencyController *emergency.Controller
}

// SendOTT generates and sends an OTT to the provided email address
Expand Down Expand Up @@ -529,6 +531,17 @@ func (h *UserHandler) DeleteUser(c *gin.Context) {
handler.Error(c, stacktrace.Propagate(err, "Could not bind request params"))
return
}
// todo: (neeraj) refactor this part, currently there's a circular dependency between user and emergency controllers
removeLegacyErr := h.EmergencyController.HandleAccountDeletion(c, auth.GetUserID(c.Request.Header),
logrus.WithFields(logrus.Fields{
"user_id": auth.GetUserID(c.Request.Header),
"req_id": requestid.Get(c),
"req_ctx": "self_account_deletion",
}))
if removeLegacyErr != nil {
handler.Error(c, stacktrace.Propagate(removeLegacyErr, ""))
return
}
response, err := h.UserController.SelfDeleteAccount(c, request)
if err != nil {
handler.Error(c, stacktrace.Propagate(err, ""))
Expand Down
Loading

0 comments on commit acd2f63

Please sign in to comment.