Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forks to org if you can create repos #17783

Merged
merged 8 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func CanUserForkRepo(user *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
8 changes: 4 additions & 4 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an performance regression for all pages with fork button. This should be fixed in v1.16.

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

// Check ownership of organization.
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
if ctxUser.IsOrganization() {
isOwner, err := models.OrgFromUser(ctxUser).IsOwnedBy(ctx.User.ID)
isOwner, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change the the name of this variable. isAllowedToFork

Copy link
Member

@lunny lunny Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name isOwner should also be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the comment on Line 218 ;)

qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("IsOwnedBy", err)
ctx.ServerError("CanCreateOrgRepo", err)
return
} else if !isOwner {
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Error(http.StatusForbidden)
Expand Down