mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Template Repositories (#8768)
* Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
committed by
Lunny Xiao
parent
74bb292fe3
commit
74a6add4d9
@@ -51,8 +51,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func getForkRepository(ctx *context.Context) *models.Repository {
|
||||
forkRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
|
||||
func getRepository(ctx *context.Context, repoID int64) *models.Repository {
|
||||
repo, err := models.GetRepositoryByID(repoID)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.NotFound("GetRepositoryByID", nil)
|
||||
@@ -62,25 +62,33 @@ func getForkRepository(ctx *context.Context) *models.Repository {
|
||||
return nil
|
||||
}
|
||||
|
||||
perm, err := models.GetUserRepoPermission(forkRepo, ctx.User)
|
||||
perm, err := models.GetUserRepoPermission(repo, ctx.User)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if forkRepo.IsEmpty || !perm.CanRead(models.UnitTypeCode) {
|
||||
if log.IsTrace() {
|
||||
if forkRepo.IsEmpty {
|
||||
log.Trace("Empty fork repository %-v", forkRepo)
|
||||
} else {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v of forkRepo %-v\n"+
|
||||
"User in forkRepo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
models.UnitTypeCode,
|
||||
ctx.Repo,
|
||||
perm)
|
||||
}
|
||||
}
|
||||
if !perm.CanRead(models.UnitTypeCode) {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
|
||||
"User in repo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
models.UnitTypeCode,
|
||||
ctx.Repo,
|
||||
perm)
|
||||
ctx.NotFound("getRepository", nil)
|
||||
return nil
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
func getForkRepository(ctx *context.Context) *models.Repository {
|
||||
forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid"))
|
||||
if ctx.Written() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if forkRepo.IsEmpty {
|
||||
log.Trace("Empty repository %-v", forkRepo)
|
||||
ctx.NotFound("getForkRepository", nil)
|
||||
return nil
|
||||
}
|
||||
@@ -90,7 +98,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
|
||||
ctx.Data["IsPrivate"] = forkRepo.IsPrivate
|
||||
canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID)
|
||||
|
||||
if err = forkRepo.GetOwner(); err != nil {
|
||||
if err := forkRepo.GetOwner(); err != nil {
|
||||
ctx.ServerError("GetOwner", err)
|
||||
return nil
|
||||
}
|
||||
@@ -109,6 +117,7 @@ func getForkRepository(ctx *context.Context) *models.Repository {
|
||||
}
|
||||
|
||||
var traverseParentRepo = forkRepo
|
||||
var err error
|
||||
for {
|
||||
if ctx.User.ID == traverseParentRepo.OwnerID {
|
||||
canForkToUser = false
|
||||
|
Reference in New Issue
Block a user