mirror of https://github.com/go-gitea/gitea.git
better fork permission check
This commit is contained in:
parent
9db4acc62e
commit
e3bdfd51ff
|
@ -1421,6 +1421,13 @@ func IsStaring(uid, repoId int64) bool {
|
||||||
// \___ / \____/|__| |__|_ \
|
// \___ / \____/|__| |__|_ \
|
||||||
// \/ \/
|
// \/ \/
|
||||||
|
|
||||||
|
// HasForkedRepo checks if given user has already forked a repository with given ID.
|
||||||
|
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
|
||||||
|
repo := new(Repository)
|
||||||
|
has, _ := x.Where("owner_id=? AND fork_id=?", ownerID, repoID).Get(repo)
|
||||||
|
return repo, has
|
||||||
|
}
|
||||||
|
|
||||||
func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
|
func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
|
||||||
repo := &Repository{
|
repo := &Repository{
|
||||||
OwnerId: u.Id,
|
OwnerId: u.Id,
|
||||||
|
|
|
@ -78,6 +78,12 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repo, has := models.HasForkedRepo(ctxUser.Id, forkRepo.Id)
|
||||||
|
if has {
|
||||||
|
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check ownership of organization.
|
// Check ownership of organization.
|
||||||
if ctxUser.IsOrganization() {
|
if ctxUser.IsOrganization() {
|
||||||
if !ctxUser.IsOwnedBy(ctx.User.Id) {
|
if !ctxUser.IsOwnedBy(ctx.User.Id) {
|
||||||
|
|
|
@ -24,11 +24,13 @@
|
||||||
{{.SignedUser.Name}}
|
{{.SignedUser.Name}}
|
||||||
</div>
|
</div>
|
||||||
{{range .Orgs}}
|
{{range .Orgs}}
|
||||||
|
{{if .IsOwnedBy $.SignedUser.Id}}
|
||||||
<div class="item" data-value="{{.Id}}">
|
<div class="item" data-value="{{.Id}}">
|
||||||
<img class="ui mini avatar image" src="{{.AvatarLink}}">
|
<img class="ui mini avatar image" src="{{.AvatarLink}}">
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue