|
|
@ -28,18 +28,25 @@ const ( |
|
|
|
FORK base.TplName = "repo/fork" |
|
|
|
FORK base.TplName = "repo/fork" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func checkContextUser(ctx *middleware.Context, uid int64) (*models.User, error) { |
|
|
|
func checkContextUser(ctx *middleware.Context, uid int64) *models.User { |
|
|
|
ctxUser := ctx.User |
|
|
|
// Not equal means current user is an organization.
|
|
|
|
if uid > 0 { |
|
|
|
if uid == ctx.User.Id || uid == 0 { |
|
|
|
org, err := models.GetUserById(uid) |
|
|
|
return ctx.User |
|
|
|
if err != models.ErrUserNotExist { |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, fmt.Errorf("GetUserById: %v", err) |
|
|
|
org, err := models.GetUserById(uid) |
|
|
|
} |
|
|
|
if err == models.ErrUserNotExist { |
|
|
|
ctxUser = org |
|
|
|
return ctx.User |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "checkContextUser", fmt.Errorf("GetUserById(%d): %v", uid, err)) |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} else if !org.IsOrganization() { |
|
|
|
|
|
|
|
ctx.Error(403) |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
return ctxUser, nil |
|
|
|
return org |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Create(ctx *middleware.Context) { |
|
|
|
func Create(ctx *middleware.Context) { |
|
|
@ -51,9 +58,8 @@ func Create(ctx *middleware.Context) { |
|
|
|
ctx.Data["Gitignores"] = models.Gitignores |
|
|
|
ctx.Data["Gitignores"] = models.Gitignores |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
|
|
|
|
|
|
|
|
ctxUser, err := checkContextUser(ctx, ctx.QueryInt64("org")) |
|
|
|
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) |
|
|
|
if err != nil { |
|
|
|
if ctx.Written() { |
|
|
|
ctx.Handle(500, "checkContextUser", err) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
@ -73,15 +79,9 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
ctx.Data["Gitignores"] = models.Gitignores |
|
|
|
ctx.Data["Gitignores"] = models.Gitignores |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
ctx.Data["Licenses"] = models.Licenses |
|
|
|
|
|
|
|
|
|
|
|
ctxUser := ctx.User |
|
|
|
ctxUser := checkContextUser(ctx, form.Uid) |
|
|
|
// Not equal means current user is an organization.
|
|
|
|
if ctx.Written() { |
|
|
|
if form.Uid != ctx.User.Id { |
|
|
|
return |
|
|
|
var err error |
|
|
|
|
|
|
|
ctxUser, err = checkContextUser(ctx, form.Uid) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "checkContextUser", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
|
|
|
|
|
|
|
@ -136,9 +136,8 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
func Migrate(ctx *middleware.Context) { |
|
|
|
func Migrate(ctx *middleware.Context) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("new_migrate") |
|
|
|
ctx.Data["Title"] = ctx.Tr("new_migrate") |
|
|
|
|
|
|
|
|
|
|
|
ctxUser, err := checkContextUser(ctx, ctx.QueryInt64("org")) |
|
|
|
ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) |
|
|
|
if err != nil { |
|
|
|
if ctx.Written() { |
|
|
|
ctx.Handle(500, "checkContextUser", err) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
@ -155,15 +154,9 @@ func Migrate(ctx *middleware.Context) { |
|
|
|
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("new_migrate") |
|
|
|
ctx.Data["Title"] = ctx.Tr("new_migrate") |
|
|
|
|
|
|
|
|
|
|
|
ctxUser := ctx.User |
|
|
|
ctxUser := checkContextUser(ctx, form.Uid) |
|
|
|
// Not equal means current user is an organization.
|
|
|
|
if ctx.Written() { |
|
|
|
if form.Uid != ctx.User.Id { |
|
|
|
return |
|
|
|
var err error |
|
|
|
|
|
|
|
ctxUser, err = checkContextUser(ctx, form.Uid) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "checkContextUser", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
|
|
|
|
|
|
|
@ -297,15 +290,9 @@ func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctxUser := ctx.User |
|
|
|
ctxUser := checkContextUser(ctx, form.Uid) |
|
|
|
// Not equal means current user is an organization.
|
|
|
|
if ctx.Written() { |
|
|
|
if form.Uid != ctx.User.Id { |
|
|
|
return |
|
|
|
var err error |
|
|
|
|
|
|
|
ctxUser, err = checkContextUser(ctx, form.Uid) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "checkContextUser", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
ctx.Data["ContextUser"] = ctxUser |
|
|
|
|
|
|
|
|
|
|
|