-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix so that user can still fork his own repository to his organizations #2699
Changes from 6 commits
f09a125
d13427d
0f894db
2b0d671
f86bd84
fa0d64e
f102aad
c1ca44a
ea6d8eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ func getForkRepository(ctx *context.Context) *models.Repository { | |
ctx.Data["repo_name"] = forkRepo.Name | ||
ctx.Data["description"] = forkRepo.Description | ||
ctx.Data["IsPrivate"] = forkRepo.IsPrivate | ||
canForkToUser := forkRepo.OwnerID != ctx.User.ID && !ctx.User.HasForkedRepo(forkRepo.ID) | ||
ctx.Data["CanForkToUser"] = canForkToUser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should a user be able to fork his own repo into his user? |
||
|
||
if err = forkRepo.GetOwner(); err != nil { | ||
ctx.Handle(500, "GetOwner", err) | ||
|
@@ -69,11 +71,23 @@ func getForkRepository(ctx *context.Context) *models.Repository { | |
ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name | ||
ctx.Data["ForkFromOwnerID"] = forkRepo.Owner.ID | ||
|
||
if err := ctx.User.GetOrganizations(true); err != nil { | ||
ctx.Handle(500, "GetOrganizations", err) | ||
if err := ctx.User.GetOwnedOrganizations(); err != nil { | ||
ctx.Handle(500, "GetOwnedOrganizations", err) | ||
return nil | ||
} | ||
ctx.Data["Orgs"] = ctx.User.Orgs | ||
var orgs []*models.User | ||
for _, org := range ctx.User.OwnedOrgs { | ||
if forkRepo.OwnerID != org.ID && !org.HasForkedRepo(forkRepo.ID) { | ||
orgs = append(orgs, org) | ||
} | ||
} | ||
ctx.Data["Orgs"] = orgs | ||
|
||
if canForkToUser { | ||
ctx.Data["ContextUser"] = ctx.User | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In both places where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ethantkoenig it is not overwritten in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I missed that you had removed that line |
||
} else if len(orgs) > 0 { | ||
ctx.Data["ContextUser"] = orgs[0] | ||
} | ||
|
||
return forkRepo | ||
} | ||
|
@@ -87,23 +101,23 @@ func Fork(ctx *context.Context) { | |
return | ||
} | ||
|
||
ctx.Data["ContextUser"] = ctx.User | ||
ctx.HTML(200, tplFork) | ||
} | ||
|
||
// ForkPost response for forking a repository | ||
func ForkPost(ctx *context.Context, form auth.CreateRepoForm) { | ||
ctx.Data["Title"] = ctx.Tr("new_fork") | ||
|
||
forkRepo := getForkRepository(ctx) | ||
ctxUser := checkContextUser(ctx, form.UID) | ||
if ctx.Written() { | ||
return | ||
} | ||
|
||
ctxUser := checkContextUser(ctx, form.UID) | ||
forkRepo := getForkRepository(ctx) | ||
if ctx.Written() { | ||
return | ||
} | ||
|
||
ctx.Data["ContextUser"] = ctxUser | ||
|
||
if ctx.HasError() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of requiring caller to specify
forkOwnerID
, we can infer it fromforkOwnerName
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethantkoenig thanks, done