Skip to content

Commit dd933eb

Browse files
committed
* check if orcid is empty
* remove confusion for user if record/comment is rejected * prevent overwrite
1 parent 642ea29 commit dd933eb

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/email_queue_repository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *PostgresEmailQueueRepository) GetPending(ctx context.Context, limit int
7474
}
7575

7676
func (r *PostgresEmailQueueRepository) MarkAsSent(ctx context.Context, id int64) error {
77-
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, last_error = NULL, sent_at = NOW() WHERE id = $2`, SentStatus, id)
77+
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, last_error = NULL, sent_at = NOW() WHERE id = $2 AND status = $3`, SentStatus, id, ProcessingStatus)
7878

7979
if err != nil {
8080
return fmt.Errorf("%s: failed to mark email queue item %d as sent: %w", repo, id, err)
@@ -87,7 +87,7 @@ func (r *PostgresEmailQueueRepository) MarkAsSent(ctx context.Context, id int64)
8787
}
8888

8989
func (r *PostgresEmailQueueRepository) MarkAsFailed(ctx context.Context, id int64, errMsg string) error {
90-
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, attempts = (attempts + 1), last_error = $2 WHERE id = $3`, FailedStatus, errMsg, id)
90+
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, attempts = (attempts + 1), last_error = $2 WHERE id = $3 AND status = $4`, FailedStatus, errMsg, id, ProcessingStatus)
9191

9292
if err != nil {
9393
return fmt.Errorf("%s: failed to mark email queue item %d as failed: %w", repo, id, err)
@@ -100,7 +100,7 @@ func (r *PostgresEmailQueueRepository) MarkAsFailed(ctx context.Context, id int6
100100
}
101101

102102
func (r *PostgresEmailQueueRepository) MarkForRetry(ctx context.Context, id int64, errMsg string) error {
103-
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, attempts = (attempts + 1), last_error = $2 WHERE id = $3`, PendingStatus, errMsg, id)
103+
res, err := r.db.ExecContext(ctx, `UPDATE email_queue SET status = $1, attempts = (attempts + 1), last_error = $2 WHERE id = $3 AND status = $4`, PendingStatus, errMsg, id, ProcessingStatus)
104104

105105
if err != nil {
106106
return fmt.Errorf("%s: failed to mark email queue item %d as pending for retry: %w", repo, id, err)

src/notification_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ func buildApprovedCommentBody(action string, owner string, content string) Email
7373

7474
func buildModerationBody(item string, status ModerationStatus) EmailBody {
7575
var body string
76+
var link string
7677

7778
switch status {
7879
case StatusApproved:
7980
body = fmt.Sprintf("Good news!\nYour %s has been approved by the ELN Community moderation team.\n\nIt is now available on the platform and can be shared with the community.", item)
81+
link = "\n\nYou can view it here: https://eln.community"
8082
case StatusRejected:
8183
body = fmt.Sprintf("Your %s has been reviewed by the ELN Community moderation team and was not approved for publication.\n\nIf you think this is a mistake or need more information, please contact the ELN Community team at contact@deltablot.email.", item)
84+
link = ""
8285
}
8386

84-
fullBody := fmt.Sprintf("Hello,\n\n%s\n\nYou can view it here: https://eln.community\n\nThank you for contributing to open science.", body)
85-
return buildEmailBody(fullBody)
87+
return buildEmailBody(fmt.Sprintf("Hello,\n\n%s%s\n\nThank you for contributing to open science.", body, link))
8688
}
8789

8890
func (s *NotificationService) enqueueEmail(ctx context.Context, recordId string, commentId sql.NullInt64, recipientOrcid string, subject string, bodyText string, bodyHTML string) error {

src/orcid_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func (e *EmailUnavailable) Error() string {
3939

4040
// https://info.orcid.org/documentation/api-tutorials/api-tutorial-read-data-on-a-record
4141
func GetEmail(ctx context.Context, orcid string) (string, error) {
42+
if strings.TrimSpace(orcid) == "" {
43+
return "", fmt.Errorf("%s: orcid parameter is empty", orcidService)
44+
}
4245
address := strings.Join([]string{"https://pub.orcid.org/v3.0/", orcid, "/email"}, "")
4346

4447
req, err := http.NewRequestWithContext(ctx, "GET", address, nil)

0 commit comments

Comments
 (0)