summaryrefslogtreecommitdiffstats
path: root/services/mailer/mail_repo.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-03-01 01:47:30 +0100
committerGitHub <noreply@github.com>2021-03-01 01:47:30 +0100
commita4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8 (patch)
tree92edf61ff2447e067a676832844a129050b4ec0f /services/mailer/mail_repo.go
parente0900310c4354311362ef69d15c302c215eaa2a2 (diff)
downloadgitea-a4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8.tar.gz
gitea-a4148c0f12fe5a93d2c9a40f24d4813bcfef4ff8.zip
Repository transfer has to be confirmed, if user can not create repo for new owner (#14792)
* make repo as "pending transfer" if on transfer start doer has no right to create repo in new destination * if new pending transfer ocured, create UI & Mail notifications
Diffstat (limited to 'services/mailer/mail_repo.go')
-rw-r--r--services/mailer/mail_repo.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go
new file mode 100644
index 0000000000..b9d24f4334
--- /dev/null
+++ b/services/mailer/mail_repo.go
@@ -0,0 +1,57 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package mailer
+
+import (
+ "bytes"
+ "fmt"
+
+ "code.gitea.io/gitea/models"
+)
+
+// SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
+func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Repository) error {
+ var (
+ emails []string
+ destination string
+ content bytes.Buffer
+ )
+
+ if newOwner.IsOrganization() {
+ users, err := models.GetUsersWhoCanCreateOrgRepo(newOwner.ID)
+ if err != nil {
+ return err
+ }
+
+ for i := range users {
+ emails = append(emails, users[i].Email)
+ }
+ destination = newOwner.DisplayName()
+ } else {
+ emails = []string{newOwner.Email}
+ destination = "you"
+ }
+
+ subject := fmt.Sprintf("%s would like to transfer \"%s\" to %s", doer.DisplayName(), repo.FullName(), destination)
+ data := map[string]interface{}{
+ "Doer": doer,
+ "User": repo.Owner,
+ "Repo": repo.FullName(),
+ "Link": repo.HTMLURL(),
+ "Subject": subject,
+
+ "Destination": destination,
+ }
+
+ if err := bodyTemplates.ExecuteTemplate(&content, string(mailRepoTransferNotify), data); err != nil {
+ return err
+ }
+
+ msg := NewMessage(emails, subject, content.String())
+ msg.Info = fmt.Sprintf("UID: %d, repository pending transfer notification", newOwner.ID)
+
+ SendAsync(msg)
+ return nil
+}