Skip to content

Commit ef92f4f

Browse files
qwerty287Stelios Malathouras
authored and
Stelios Malathouras
committedMar 28, 2022
Allow forks to org if you can create repos (go-gitea#17783)
1 parent ab2b33c commit ef92f4f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
 

‎models/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ func CanUserForkRepo(user *user_model.User, repo *Repository) (bool, error) {
766766
if repo.OwnerID != user.ID && !HasForkedRepo(user.ID, repo.ID) {
767767
return true, nil
768768
}
769-
ownedOrgs, err := GetOwnedOrgsByUserID(user.ID)
769+
ownedOrgs, err := GetOrgsCanCreateRepoByUserID(user.ID)
770770
if err != nil {
771771
return false, err
772772
}

‎routers/web/repo/pull.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ func getForkRepository(ctx *context.Context) *models.Repository {
113113

114114
ctx.Data["ForkRepo"] = forkRepo
115115

116-
ownedOrgs, err := models.GetOwnedOrgsByUserID(ctx.User.ID)
116+
ownedOrgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID)
117117
if err != nil {
118-
ctx.ServerError("GetOwnedOrgsByUserID", err)
118+
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
119119
return nil
120120
}
121121
var orgs []*models.Organization
@@ -216,13 +216,13 @@ func ForkPost(ctx *context.Context) {
216216
}
217217
}
218218

219-
// Check ownership of organization.
219+
// Check if user is allowed to create repo's on the organization.
220220
if ctxUser.IsOrganization() {
221-
isOwner, err := models.OrgFromUser(ctxUser).IsOwnedBy(ctx.User.ID)
221+
isAllowedToFork, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
222222
if err != nil {
223-
ctx.ServerError("IsOwnedBy", err)
223+
ctx.ServerError("CanCreateOrgRepo", err)
224224
return
225-
} else if !isOwner {
225+
} else if !isAllowedToFork {
226226
ctx.Error(http.StatusForbidden)
227227
return
228228
}

0 commit comments

Comments
 (0)
Please sign in to comment.