diff options
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/repo.go | 35 | ||||
-rw-r--r-- | routers/repo/setting.go | 44 | ||||
-rw-r--r-- | routers/repo/view.go | 8 |
3 files changed, 83 insertions, 4 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a8cfb9ad7c..6fa566e7d6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -6,6 +6,7 @@ package repo import ( + "errors" "fmt" "strings" "time" @@ -274,6 +275,10 @@ func Action(ctx *context.Context) { err = models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) case "unstar": err = models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) + case "accept_transfer": + err = acceptOrRejectRepoTransfer(ctx, true) + case "reject_transfer": + err = acceptOrRejectRepoTransfer(ctx, false) case "desc": // FIXME: this is not used if !ctx.Repo.IsOwner() { ctx.Error(404) @@ -293,6 +298,36 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.Query("redirect_to"), ctx.Repo.RepoLink) } +func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error { + repoTransfer, err := models.GetPendingRepositoryTransfer(ctx.Repo.Repository) + if err != nil { + return err + } + + if err := repoTransfer.LoadAttributes(); err != nil { + return err + } + + if !repoTransfer.CanUserAcceptTransfer(ctx.User) { + return errors.New("user does not have enough permissions") + } + + if accept { + if err := repo_service.TransferOwnership(repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil { + return err + } + ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success")) + } else { + if err := models.CancelRepositoryTransfer(ctx.Repo.Repository); err != nil { + return err + } + ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected")) + } + + ctx.Redirect(ctx.Repo.Repository.HTMLURL()) + return nil +} + // RedirectDownload return a file based on the following infos: func RedirectDownload(ctx *context.Context) { var ( diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 3e22e8804e..b35828d7b1 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -477,18 +477,54 @@ func SettingsPost(ctx *context.Context) { ctx.Repo.GitRepo.Close() ctx.Repo.GitRepo = nil } - if err = repo_service.TransferOwnership(ctx.User, newOwner, repo, nil); err != nil { + + if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, repo, nil); err != nil { if models.IsErrRepoAlreadyExist(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) + } else if models.IsErrRepoTransferInProgress(err) { + ctx.RenderWithErr(ctx.Tr("repo.settings.transfer_in_progress"), tplSettingsOptions, nil) } else { ctx.ServerError("TransferOwnership", err) } + + return + } + + log.Trace("Repository transfer process was started: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newOwner) + ctx.Flash.Success(ctx.Tr("repo.settings.transfer_started", newOwner.DisplayName())) + ctx.Redirect(setting.AppSubURL + "/" + ctx.Repo.Owner.Name + "/" + repo.Name + "/settings") + + case "cancel_transfer": + if !ctx.Repo.IsOwner() { + ctx.Error(404) + return + } + + repoTransfer, err := models.GetPendingRepositoryTransfer(ctx.Repo.Repository) + if err != nil { + if models.IsErrNoPendingTransfer(err) { + ctx.Flash.Error("repo.settings.transfer_abort_invalid") + ctx.Redirect(setting.AppSubURL + "/" + ctx.User.Name + "/" + repo.Name + "/settings") + } else { + ctx.ServerError("GetPendingRepositoryTransfer", err) + } + + return + } + + if err := repoTransfer.LoadAttributes(); err != nil { + ctx.ServerError("LoadRecipient", err) + return + } + + if err := models.CancelRepositoryTransfer(ctx.Repo.Repository); err != nil { + ctx.ServerError("CancelRepositoryTransfer", err) return } - log.Trace("Repository transferred: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newOwner) - ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed")) - ctx.Redirect(setting.AppSubURL + "/" + newOwner.Name + "/" + repo.Name) + log.Trace("Repository transfer process was cancelled: %s/%s ", ctx.Repo.Owner.Name, repo.Name) + ctx.Flash.Success(ctx.Tr("repo.settings.transfer_abort_success", repoTransfer.Recipient.Name)) + ctx.Redirect(setting.AppSubURL + "/" + ctx.Repo.Owner.Name + "/" + repo.Name + "/settings") case "delete": if !ctx.Repo.IsOwner() { diff --git a/routers/repo/view.go b/routers/repo/view.go index a5e3cbe3e4..39f16d183c 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -586,6 +586,14 @@ func Home(ctx *context.Context) { return } + if ctx.IsSigned { + // Set repo notification-status read if unread + if err := ctx.Repo.Repository.ReadBy(ctx.User.ID); err != nil { + ctx.ServerError("ReadBy", err) + return + } + } + var firstUnit *models.Unit for _, repoUnit := range ctx.Repo.Units { if repoUnit.Type == models.UnitTypeCode { |