Skip to content

Commit

Permalink
Allow forks to org if you can create repos (go-gitea#17783)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored and Stelios Malathouras committed Mar 28, 2022
1 parent ab2b33c commit ef92f4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func CanUserForkRepo(user *user_model.User, repo *Repository) (bool, error) {
if repo.OwnerID != user.ID && !HasForkedRepo(user.ID, repo.ID) {
return true, nil
}
ownedOrgs, err := GetOwnedOrgsByUserID(user.ID)
ownedOrgs, err := GetOrgsCanCreateRepoByUserID(user.ID)
if err != nil {
return false, err
}
Expand Down
12 changes: 6 additions & 6 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func getForkRepository(ctx *context.Context) *models.Repository {

ctx.Data["ForkRepo"] = forkRepo

ownedOrgs, err := models.GetOwnedOrgsByUserID(ctx.User.ID)
ownedOrgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOwnedOrgsByUserID", err)
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
return nil
}
var orgs []*models.Organization
Expand Down Expand Up @@ -216,13 +216,13 @@ func ForkPost(ctx *context.Context) {
}
}

// Check ownership of organization.
// Check if user is allowed to create repo's on the organization.
if ctxUser.IsOrganization() {
isOwner, err := models.OrgFromUser(ctxUser).IsOwnedBy(ctx.User.ID)
isAllowedToFork, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
if err != nil {
ctx.ServerError("IsOwnedBy", err)
ctx.ServerError("CanCreateOrgRepo", err)
return
} else if !isOwner {
} else if !isAllowedToFork {
ctx.Error(http.StatusForbidden)
return
}
Expand Down

0 comments on commit ef92f4f

Please sign in to comment.