summaryrefslogtreecommitdiffstats
path: root/modules
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 /modules
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 'modules')
-rw-r--r--modules/context/repo.go18
-rw-r--r--modules/convert/notification.go8
-rw-r--r--modules/notification/base/notifier.go2
-rw-r--r--modules/notification/base/null.go4
-rw-r--r--modules/notification/mail/mail.go6
-rw-r--r--modules/notification/notification.go7
-rw-r--r--modules/notification/ui/ui.go6
7 files changed, 50 insertions, 1 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index bf149b8158..ba3cfe9bf2 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -600,6 +600,24 @@ func RepoAssignment() func(http.Handler) http.Handler {
ctx.Data["CanCompareOrPull"] = canCompare
ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
+ if ctx.Repo.Repository.Status == models.RepositoryPendingTransfer {
+ repoTransfer, err := models.GetPendingRepositoryTransfer(ctx.Repo.Repository)
+ if err != nil {
+ ctx.ServerError("GetPendingRepositoryTransfer", err)
+ return
+ }
+
+ if err := repoTransfer.LoadAttributes(); err != nil {
+ ctx.ServerError("LoadRecipient", err)
+ return
+ }
+
+ ctx.Data["RepoTransfer"] = repoTransfer
+ if ctx.User != nil {
+ ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx.User)
+ }
+ }
+
if ctx.Query("go-get") == "1" {
ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", "branch", ctx.Repo.BranchName)
diff --git a/modules/convert/notification.go b/modules/convert/notification.go
index fff891b15d..49abe01253 100644
--- a/modules/convert/notification.go
+++ b/modules/convert/notification.go
@@ -52,8 +52,14 @@ func ToNotificationThread(n *models.Notification) *api.NotificationThread {
result.Subject = &api.NotificationSubject{
Type: "Commit",
Title: n.CommitID,
+ URL: n.Repository.HTMLURL() + "/commit/" + n.CommitID,
+ }
+ case models.NotificationSourceRepository:
+ result.Subject = &api.NotificationSubject{
+ Type: "Repository",
+ Title: n.Repository.FullName(),
+ URL: n.Repository.Link(),
}
- //unused until now
}
return result
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go
index 5bb833d275..8f8aa659b4 100644
--- a/modules/notification/base/notifier.go
+++ b/modules/notification/base/notifier.go
@@ -57,4 +57,6 @@ type Notifier interface {
NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string)
NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string)
+
+ NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository)
}
diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go
index 2386f925ce..e61b37a943 100644
--- a/modules/notification/base/null.go
+++ b/modules/notification/base/null.go
@@ -166,3 +166,7 @@ func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Reposit
// NotifySyncDeleteRef places a place holder function
func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
}
+
+// NotifyRepoPendingTransfer places a place holder function
+func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+}
diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go
index f984ea7661..f7192f5a52 100644
--- a/modules/notification/mail/mail.go
+++ b/modules/notification/mail/mail.go
@@ -170,3 +170,9 @@ func (m *mailNotifier) NotifyNewRelease(rel *models.Release) {
mailer.MailNewRelease(rel)
}
+
+func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+ if err := mailer.SendRepoTransferNotifyMail(doer, newOwner, repo); err != nil {
+ log.Error("NotifyRepoPendingTransfer: %v", err)
+ }
+}
diff --git a/modules/notification/notification.go b/modules/notification/notification.go
index d22d157bec..b574f3ccda 100644
--- a/modules/notification/notification.go
+++ b/modules/notification/notification.go
@@ -290,3 +290,10 @@ func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType,
notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
}
}
+
+// NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers
+func NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+ for _, notifier := range notifiers {
+ notifier.NotifyRepoPendingTransfer(doer, newOwner, repo)
+ }
+}
diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go
index 25ea4d91c6..b1374f5608 100644
--- a/modules/notification/ui/ui.go
+++ b/modules/notification/ui/ui.go
@@ -201,3 +201,9 @@ func (ns *notificationService) NotifyPullReviewRequest(doer *models.User, issue
_ = ns.issueQueue.Push(opts)
}
}
+
+func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) {
+ if err := models.CreateRepoTransferNotification(doer, newOwner, repo); err != nil {
+ log.Error("NotifyRepoPendingTransfer: %v", err)
+ }
+}