diff options
author | Jonas Franz <info@jonasfranz.software> | 2017-09-18 16:52:20 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-09-18 22:52:20 +0800 |
commit | 566e8ecce0df27e09d9f3ed9503f788827cc1102 (patch) | |
tree | a48ae27031a1d62aaa20a4ac2a44b0bb332bbd73 /modules | |
parent | 6c6533fb31bbc82e7907b1dc233212045849569b (diff) | |
download | gitea-566e8ecce0df27e09d9f3ed9503f788827cc1102.tar.gz gitea-566e8ecce0df27e09d9f3ed9503f788827cc1102.zip |
Fork permission bug fixes (#2534)
* Hotfix for "Add time manually" (https://github.com/go-gitea/gitea/pull/2211#issuecomment-328780125)
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Checking if Code unit is enabled before creating a fork.
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Adding a discrete function for RepoIDAssignment
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Improved Documentation
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/repo.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index a82535a6d4..acfccfcd05 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -171,6 +171,74 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { ) ctx.Redirect(redirectPath) } +// RepoIDAssignment returns an macaron handler which assigns the repo to the context. +func RepoIDAssignment() macaron.Handler { + return func(ctx *Context) { + var ( + err error + ) + + repoID := ctx.ParamsInt64(":repoid") + + // Get repository. + repo, err := models.GetRepositoryByID(repoID) + if err != nil { + if models.IsErrRepoNotExist(err) { + ctx.Handle(404, "GetRepositoryByID", nil) + } else { + ctx.Handle(500, "GetRepositoryByID", err) + } + return + } + + if err = repo.GetOwner(); err != nil { + ctx.Handle(500, "GetOwner", err) + return + } + + // Admin has super access. + if ctx.IsSigned && ctx.User.IsAdmin { + ctx.Repo.AccessMode = models.AccessModeOwner + } else { + var userID int64 + if ctx.User != nil { + userID = ctx.User.ID + } + mode, err := models.AccessLevel(userID, repo) + if err != nil { + ctx.Handle(500, "AccessLevel", err) + return + } + ctx.Repo.AccessMode = mode + } + + // Check access. + if ctx.Repo.AccessMode == models.AccessModeNone { + if ctx.Query("go-get") == "1" { + earlyResponseForGoGetMeta(ctx) + return + } + ctx.Handle(404, "no access right", err) + return + } + ctx.Data["HasAccess"] = true + + if repo.IsMirror { + ctx.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID) + if err != nil { + ctx.Handle(500, "GetMirror", err) + return + } + ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune + ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval + ctx.Data["Mirror"] = ctx.Repo.Mirror + } + + ctx.Repo.Repository = repo + ctx.Data["RepoName"] = ctx.Repo.Repository.Name + ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare + } +} // RepoAssignment returns a macaron to handle repository assignment func RepoAssignment() macaron.Handler { |