forked from NYANDEV/forgejo
Renamed ctx.User to ctx.Doer. (#19161)
Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
5495ba7660
commit
80fd25524e
129 changed files with 881 additions and 881 deletions
|
@ -77,7 +77,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) {
|
||||||
test.LoadGitRepo(t, ctx)
|
test.LoadGitRepo(t, ctx)
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getDeleteRepoFileOptions(repo)
|
opts := getDeleteRepoFileOptions(repo)
|
||||||
|
|
||||||
t.Run("Delete README.md file", func(t *testing.T) {
|
t.Run("Delete README.md file", func(t *testing.T) {
|
||||||
|
@ -117,7 +117,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getDeleteRepoFileOptions(repo)
|
opts := getDeleteRepoFileOptions(repo)
|
||||||
opts.OldBranch = ""
|
opts.OldBranch = ""
|
||||||
opts.NewBranch = ""
|
opts.NewBranch = ""
|
||||||
|
@ -147,7 +147,7 @@ func TestDeleteRepoFileErrors(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
|
|
||||||
t.Run("Bad branch", func(t *testing.T) {
|
t.Run("Bad branch", func(t *testing.T) {
|
||||||
opts := getDeleteRepoFileOptions(repo)
|
opts := getDeleteRepoFileOptions(repo)
|
||||||
|
|
|
@ -194,7 +194,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getCreateRepoFileOptions(repo)
|
opts := getCreateRepoFileOptions(repo)
|
||||||
|
|
||||||
// test
|
// test
|
||||||
|
@ -230,7 +230,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getUpdateRepoFileOptions(repo)
|
opts := getUpdateRepoFileOptions(repo)
|
||||||
|
|
||||||
// test
|
// test
|
||||||
|
@ -263,7 +263,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getUpdateRepoFileOptions(repo)
|
opts := getUpdateRepoFileOptions(repo)
|
||||||
opts.FromTreePath = "README.md"
|
opts.FromTreePath = "README.md"
|
||||||
opts.TreePath = "README_new.md" // new file name, README_new.md
|
opts.TreePath = "README_new.md" // new file name, README_new.md
|
||||||
|
@ -313,7 +313,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
opts := getUpdateRepoFileOptions(repo)
|
opts := getUpdateRepoFileOptions(repo)
|
||||||
opts.OldBranch = ""
|
opts.OldBranch = ""
|
||||||
opts.NewBranch = ""
|
opts.NewBranch = ""
|
||||||
|
@ -344,7 +344,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
|
||||||
defer ctx.Repo.GitRepo.Close()
|
defer ctx.Repo.GitRepo.Close()
|
||||||
|
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
doer := ctx.User
|
doer := ctx.Doer
|
||||||
|
|
||||||
t.Run("bad branch", func(t *testing.T) {
|
t.Run("bad branch", func(t *testing.T) {
|
||||||
opts := getUpdateRepoFileOptions(repo)
|
opts := getUpdateRepoFileOptions(repo)
|
||||||
|
|
|
@ -100,7 +100,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
|
||||||
if status == http.StatusInternalServerError {
|
if status == http.StatusInternalServerError {
|
||||||
log.ErrorWithSkip(1, "%s: %s", title, message)
|
log.ErrorWithSkip(1, "%s: %s", title, message)
|
||||||
|
|
||||||
if setting.IsProd && !(ctx.User != nil && ctx.User.IsAdmin) {
|
if setting.IsProd && !(ctx.Doer != nil && ctx.Doer.IsAdmin) {
|
||||||
message = ""
|
message = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func (ctx *APIContext) InternalServerError(err error) {
|
||||||
log.ErrorWithSkip(1, "InternalServerError: %v", err)
|
log.ErrorWithSkip(1, "InternalServerError: %v", err)
|
||||||
|
|
||||||
var message string
|
var message string
|
||||||
if !setting.IsProd || (ctx.User != nil && ctx.User.IsAdmin) {
|
if !setting.IsProd || (ctx.Doer != nil && ctx.Doer.IsAdmin) {
|
||||||
message = err.Error()
|
message = err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ func (ctx *APIContext) CheckForOTP() {
|
||||||
}
|
}
|
||||||
|
|
||||||
otpHeader := ctx.Req.Header.Get("X-Gitea-OTP")
|
otpHeader := ctx.Req.Header.Get("X-Gitea-OTP")
|
||||||
twofa, err := auth.GetTwoFactorByUID(ctx.Context.User.ID)
|
twofa, err := auth.GetTwoFactorByUID(ctx.Context.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||||
return // No 2FA enrollment for this user
|
return // No 2FA enrollment for this user
|
||||||
|
@ -248,18 +248,18 @@ func (ctx *APIContext) CheckForOTP() {
|
||||||
func APIAuth(authMethod auth_service.Method) func(*APIContext) {
|
func APIAuth(authMethod auth_service.Method) func(*APIContext) {
|
||||||
return func(ctx *APIContext) {
|
return func(ctx *APIContext) {
|
||||||
// Get user from session if logged in.
|
// Get user from session if logged in.
|
||||||
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
if ctx.Locale.Language() != ctx.User.Language {
|
if ctx.Locale.Language() != ctx.Doer.Language {
|
||||||
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
|
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
|
||||||
}
|
}
|
||||||
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth_service.BasicMethodName
|
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth_service.BasicMethodName
|
||||||
ctx.IsSigned = true
|
ctx.IsSigned = true
|
||||||
ctx.Data["IsSigned"] = ctx.IsSigned
|
ctx.Data["IsSigned"] = ctx.IsSigned
|
||||||
ctx.Data["SignedUser"] = ctx.User
|
ctx.Data["SignedUser"] = ctx.Doer
|
||||||
ctx.Data["SignedUserID"] = ctx.User.ID
|
ctx.Data["SignedUserID"] = ctx.Doer.ID
|
||||||
ctx.Data["SignedUserName"] = ctx.User.Name
|
ctx.Data["SignedUserName"] = ctx.Doer.Name
|
||||||
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
|
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["SignedUserID"] = int64(0)
|
ctx.Data["SignedUserID"] = int64(0)
|
||||||
ctx.Data["SignedUserName"] = ""
|
ctx.Data["SignedUserName"] = ""
|
||||||
|
|
|
@ -27,19 +27,19 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
// Check prohibit login users.
|
// Check prohibit login users.
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
||||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User.MustChangePassword {
|
if ctx.Doer.MustChangePassword {
|
||||||
if ctx.Req.URL.Path != "/user/settings/change_password" {
|
if ctx.Req.URL.Path != "/user/settings/change_password" {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
||||||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
||||||
|
@ -76,7 +76,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||||
}
|
}
|
||||||
ctx.Redirect(setting.AppSubURL + "/user/login")
|
ctx.Redirect(setting.AppSubURL + "/user/login")
|
||||||
return
|
return
|
||||||
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
} else if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||||
return
|
return
|
||||||
|
@ -94,7 +94,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.AdminRequired {
|
if options.AdminRequired {
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -108,15 +108,15 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||||
return func(ctx *APIContext) {
|
return func(ctx *APIContext) {
|
||||||
// Check prohibit login users.
|
// Check prohibit login users.
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||||
"message": "This account is not activated.",
|
"message": "This account is not activated.",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
||||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||||
"message": "This account is prohibited from signing in, please contact your site administrator.",
|
"message": "This account is prohibited from signing in, please contact your site administrator.",
|
||||||
|
@ -124,7 +124,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User.MustChangePassword {
|
if ctx.Doer.MustChangePassword {
|
||||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||||
"message": "You must change your password. Change it at: " + setting.AppURL + "/user/change_password",
|
"message": "You must change your password. Change it at: " + setting.AppURL + "/user/change_password",
|
||||||
})
|
})
|
||||||
|
@ -145,7 +145,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||||
"message": "Only signed in user is allowed to call APIs.",
|
"message": "Only signed in user is allowed to call APIs.",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
} else if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||||
ctx.HTML(http.StatusOK, "user/auth/activate")
|
ctx.HTML(http.StatusOK, "user/auth/activate")
|
||||||
return
|
return
|
||||||
|
@ -154,7 +154,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||||
if skip, ok := ctx.Data["SkipLocalTwoFA"]; ok && skip.(bool) {
|
if skip, ok := ctx.Data["SkipLocalTwoFA"]; ok && skip.(bool) {
|
||||||
return // Skip 2FA
|
return // Skip 2FA
|
||||||
}
|
}
|
||||||
twofa, err := auth.GetTwoFactorByUID(ctx.User.ID)
|
twofa, err := auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if auth.IsErrTwoFactorNotEnrolled(err) {
|
if auth.IsErrTwoFactorNotEnrolled(err) {
|
||||||
return // No 2FA enrollment for this user
|
return // No 2FA enrollment for this user
|
||||||
|
@ -178,7 +178,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.AdminRequired {
|
if options.AdminRequired {
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||||
"message": "You have no permission to request for this.",
|
"message": "You have no permission to request for this.",
|
||||||
})
|
})
|
||||||
|
|
|
@ -63,7 +63,7 @@ type Context struct {
|
||||||
|
|
||||||
Link string // current request URL
|
Link string // current request URL
|
||||||
EscapedLink string
|
EscapedLink string
|
||||||
User *user_model.User
|
Doer *user_model.User
|
||||||
IsSigned bool
|
IsSigned bool
|
||||||
IsBasicAuth bool
|
IsBasicAuth bool
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func (ctx *Context) GetData() map[string]interface{} {
|
||||||
|
|
||||||
// IsUserSiteAdmin returns true if current user is a site admin
|
// IsUserSiteAdmin returns true if current user is a site admin
|
||||||
func (ctx *Context) IsUserSiteAdmin() bool {
|
func (ctx *Context) IsUserSiteAdmin() bool {
|
||||||
return ctx.IsSigned && ctx.User.IsAdmin
|
return ctx.IsSigned && ctx.Doer.IsAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsUserRepoOwner returns true if current user owns current repo
|
// IsUserRepoOwner returns true if current user owns current repo
|
||||||
|
@ -574,10 +574,10 @@ func GetContext(req *http.Request) *Context {
|
||||||
// GetContextUser returns context user
|
// GetContextUser returns context user
|
||||||
func GetContextUser(req *http.Request) *user_model.User {
|
func GetContextUser(req *http.Request) *user_model.User {
|
||||||
if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
|
if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
|
||||||
return apiContext.User
|
return apiContext.Doer
|
||||||
}
|
}
|
||||||
if ctx, ok := req.Context().Value(contextKey).(*Context); ok {
|
if ctx, ok := req.Context().Value(contextKey).(*Context); ok {
|
||||||
return ctx.User
|
return ctx.Doer
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -599,18 +599,18 @@ func getCsrfOpts() CsrfOptions {
|
||||||
// Auth converts auth.Auth as a middleware
|
// Auth converts auth.Auth as a middleware
|
||||||
func Auth(authMethod auth.Method) func(*Context) {
|
func Auth(authMethod auth.Method) func(*Context) {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
ctx.User = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
ctx.Doer = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
if ctx.Locale.Language() != ctx.User.Language {
|
if ctx.Locale.Language() != ctx.Doer.Language {
|
||||||
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
|
ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
|
||||||
}
|
}
|
||||||
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
|
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
|
||||||
ctx.IsSigned = true
|
ctx.IsSigned = true
|
||||||
ctx.Data["IsSigned"] = ctx.IsSigned
|
ctx.Data["IsSigned"] = ctx.IsSigned
|
||||||
ctx.Data["SignedUser"] = ctx.User
|
ctx.Data["SignedUser"] = ctx.Doer
|
||||||
ctx.Data["SignedUserID"] = ctx.User.ID
|
ctx.Data["SignedUserID"] = ctx.Doer.ID
|
||||||
ctx.Data["SignedUserName"] = ctx.User.Name
|
ctx.Data["SignedUserName"] = ctx.Doer.Name
|
||||||
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
|
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["SignedUserID"] = int64(0)
|
ctx.Data["SignedUserID"] = int64(0)
|
||||||
ctx.Data["SignedUserName"] = ""
|
ctx.Data["SignedUserName"] = ""
|
||||||
|
|
|
@ -77,14 +77,14 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||||
ctx.Data["OrgTeams"] = teams
|
ctx.Data["OrgTeams"] = teams
|
||||||
|
|
||||||
// Admin has super access.
|
// Admin has super access.
|
||||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
if ctx.IsSigned && ctx.Doer.IsAdmin {
|
||||||
ctx.Org.IsOwner = true
|
ctx.Org.IsOwner = true
|
||||||
ctx.Org.IsMember = true
|
ctx.Org.IsMember = true
|
||||||
ctx.Org.IsTeamMember = true
|
ctx.Org.IsTeamMember = true
|
||||||
ctx.Org.IsTeamAdmin = true
|
ctx.Org.IsTeamAdmin = true
|
||||||
ctx.Org.CanCreateOrgRepo = true
|
ctx.Org.CanCreateOrgRepo = true
|
||||||
} else if ctx.IsSigned {
|
} else if ctx.IsSigned {
|
||||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID)
|
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("IsOwnedBy", err)
|
ctx.ServerError("IsOwnedBy", err)
|
||||||
return
|
return
|
||||||
|
@ -96,12 +96,12 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||||
ctx.Org.IsTeamAdmin = true
|
ctx.Org.IsTeamAdmin = true
|
||||||
ctx.Org.CanCreateOrgRepo = true
|
ctx.Org.CanCreateOrgRepo = true
|
||||||
} else {
|
} else {
|
||||||
ctx.Org.IsMember, err = org.IsOrgMember(ctx.User.ID)
|
ctx.Org.IsMember, err = org.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("IsOrgMember", err)
|
ctx.ServerError("IsOrgMember", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.User.ID)
|
ctx.Org.CanCreateOrgRepo, err = org.CanCreateOrgRepo(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanCreateOrgRepo", err)
|
ctx.ServerError("CanCreateOrgRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -133,7 +133,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||||
if ctx.Org.IsOwner {
|
if ctx.Org.IsOwner {
|
||||||
shouldSeeAllTeams = true
|
shouldSeeAllTeams = true
|
||||||
} else {
|
} else {
|
||||||
teams, err := org.GetUserTeams(ctx.User.ID)
|
teams, err := org.GetUserTeams(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserTeams", err)
|
ctx.ServerError("GetUserTeams", err)
|
||||||
return
|
return
|
||||||
|
@ -152,7 +152,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Org.Teams, err = org.GetUserTeams(ctx.User.ID)
|
ctx.Org.Teams, err = org.GetUserTeams(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserTeams", err)
|
ctx.ServerError("GetUserTeams", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -49,7 +49,7 @@ func RequireRepoReader(unitType unit.Type) func(ctx *Context) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
unitType,
|
unitType,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
|
@ -80,7 +80,7 @@ func RequireRepoReaderOr(unitTypes ...unit.Type) func(ctx *Context) {
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
format = "Permission Denied: User %-v cannot read ["
|
format = "Permission Denied: User %-v cannot read ["
|
||||||
args = append(args, ctx.User)
|
args = append(args, ctx.Doer)
|
||||||
} else {
|
} else {
|
||||||
format = "Permission Denied: Anonymous user cannot read ["
|
format = "Permission Denied: Anonymous user cannot read ["
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
perm, err := models.GetUserRepoPermission(templateRepo, ctx.User)
|
perm, err := models.GetUserRepoPermission(templateRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -346,7 +346,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.User)
|
ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -422,8 +422,8 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
repoName = strings.TrimSuffix(repoName, ".atom")
|
repoName = strings.TrimSuffix(repoName, ".atom")
|
||||||
|
|
||||||
// Check if the user is the same as the repository owner
|
// Check if the user is the same as the repository owner
|
||||||
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
|
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||||
owner = ctx.User
|
owner = ctx.Doer
|
||||||
} else {
|
} else {
|
||||||
owner, err = user_model.GetUserByName(userName)
|
owner, err = user_model.GetUserByName(userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -502,14 +502,14 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
|
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
|
||||||
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
|
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
|
||||||
|
|
||||||
canSignedUserFork, err := models.CanUserForkRepo(ctx.User, ctx.Repo.Repository)
|
canSignedUserFork, err := models.CanUserForkRepo(ctx.Doer, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanUserForkRepo", err)
|
ctx.ServerError("CanUserForkRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
ctx.Data["CanSignedUserFork"] = canSignedUserFork
|
||||||
|
|
||||||
userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx.User, ctx.Repo.Repository)
|
userAndOrgForks, err := models.GetForksByUserAndOrgs(ctx.Doer, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetForksByUserAndOrgs", err)
|
ctx.ServerError("GetForksByUserAndOrgs", err)
|
||||||
return
|
return
|
||||||
|
@ -532,8 +532,8 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
|
ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
|
||||||
|
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx.User.ID, repo.ID)
|
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx.Doer.ID, repo.ID)
|
||||||
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx.User.ID, repo.ID)
|
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx.Doer.ID, repo.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.IsFork {
|
if repo.IsFork {
|
||||||
|
@ -633,7 +633,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
|
|
||||||
// People who have push access or have forked repository can propose a new pull request.
|
// People who have push access or have forked repository can propose a new pull request.
|
||||||
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) ||
|
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) ||
|
||||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID))
|
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||||
canCompare := false
|
canCompare := false
|
||||||
|
|
||||||
// Pull request is allowed if this is a fork repository
|
// Pull request is allowed if this is a fork repository
|
||||||
|
@ -669,8 +669,8 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["RepoTransfer"] = repoTransfer
|
ctx.Data["RepoTransfer"] = repoTransfer
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx.User)
|
ctx.Data["CanUserAcceptTransfer"] = repoTransfer.CanUserAcceptTransfer(ctx.Doer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -950,7 +950,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
// GitHookService checks if repository Git hooks service has been enabled.
|
// GitHookService checks if repository Git hooks service has been enabled.
|
||||||
func GitHookService() func(ctx *Context) {
|
func GitHookService() func(ctx *Context) {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if !ctx.User.CanEditGitHook() {
|
if !ctx.Doer.CanEditGitHook() {
|
||||||
ctx.NotFound("GitHookService", nil)
|
ctx.NotFound("GitHookService", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
|
||||||
ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID)
|
ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
|
ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
|
||||||
ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User)
|
ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx.Repo.Repository, ctx.Doer)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
|
||||||
|
|
||||||
// LoadUser load a user into a test context.
|
// LoadUser load a user into a test context.
|
||||||
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
|
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
|
||||||
ctx.User = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
|
ctx.Doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
|
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
|
||||||
|
|
|
@ -110,7 +110,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := repo_service.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
|
if _, err := repo_service.AdoptRepository(ctx.Doer, ctxUser, models.CreateRepoOptions{
|
||||||
Name: repoName,
|
Name: repoName,
|
||||||
IsPrivate: true,
|
IsPrivate: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -173,7 +173,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteUnadoptedRepository(ctx.User, ctxUser, repoName); err != nil {
|
if err := repo_service.DeleteUnadoptedRepository(ctx.Doer, ctxUser, repoName); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ func PostCronTask(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
task.Run()
|
task.Run()
|
||||||
log.Trace("Cron Task %s started by admin(%s)", task.Name, ctx.User.Name)
|
log.Trace("Cron Task %s started by admin(%s)", task.Name, ctx.Doer.Name)
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ func GetAllOrgs(ctx *context.APIContext) {
|
||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeOrganization,
|
Type: user_model.UserTypeOrganization,
|
||||||
OrderBy: db.SearchOrderByAlphabetically,
|
OrderBy: db.SearchOrderByAlphabetically,
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
|
|
|
@ -128,13 +128,13 @@ func CreateUser(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account created by admin (%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
// Send email notification.
|
// Send email notification.
|
||||||
if form.SendNotify {
|
if form.SendNotify {
|
||||||
mailer.SendRegisterNotifyMail(u)
|
mailer.SendRegisterNotifyMail(u)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToUser(u, ctx.User))
|
ctx.JSON(http.StatusCreated, convert.ToUser(u, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditUser api for modifying a user's information
|
// EditUser api for modifying a user's information
|
||||||
|
@ -275,9 +275,9 @@ func EditUser(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account profile updated by admin (%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser api for deleting a user
|
// DeleteUser api for deleting a user
|
||||||
|
@ -320,7 +320,7 @@ func DeleteUser(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account deleted by admin(%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Key deleted by admin(%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Key deleted by admin(%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ func GetAllUsers(ctx *context.APIContext) {
|
||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeIndividual,
|
Type: user_model.UserTypeIndividual,
|
||||||
OrderBy: db.SearchOrderByAlphabetically,
|
OrderBy: db.SearchOrderByAlphabetically,
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
|
@ -443,7 +443,7 @@ func GetAllUsers(ctx *context.APIContext) {
|
||||||
|
|
||||||
results := make([]*api.User, len(users))
|
results := make([]*api.User, len(users))
|
||||||
for i := range users {
|
for i := range users {
|
||||||
results[i] = convert.ToUser(users[i], ctx.User)
|
results[i] = convert.ToUser(users[i], ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||||
|
|
|
@ -103,7 +103,7 @@ func sudo() func(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sudo) > 0 {
|
if len(sudo) > 0 {
|
||||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
if ctx.IsSigned && ctx.Doer.IsAdmin {
|
||||||
user, err := user_model.GetUserByName(sudo)
|
user, err := user_model.GetUserByName(sudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
|
@ -113,8 +113,8 @@ func sudo() func(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Sudo from (%s) to: %s", ctx.User.Name, user.Name)
|
log.Trace("Sudo from (%s) to: %s", ctx.Doer.Name, user.Name)
|
||||||
ctx.User = user
|
ctx.Doer = user
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||||
"message": "Only administrators allowed to sudo.",
|
"message": "Only administrators allowed to sudo.",
|
||||||
|
@ -136,8 +136,8 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check if the user is the same as the repository owner.
|
// Check if the user is the same as the repository owner.
|
||||||
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
|
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||||
owner = ctx.User
|
owner = ctx.Doer
|
||||||
} else {
|
} else {
|
||||||
owner, err = user_model.GetUserByName(userName)
|
owner, err = user_model.GetUserByName(userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -178,7 +178,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
repo.Owner = owner
|
repo.Owner = owner
|
||||||
ctx.Repo.Repository = repo
|
ctx.Repo.Repository = repo
|
||||||
|
|
||||||
ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.User)
|
ctx.Repo.Permission, err = models.GetUserRepoPermission(repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -307,7 +307,7 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.User.ID)
|
isOwner, err := models.IsOrganizationOwner(orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
||||||
return
|
return
|
||||||
|
@ -334,7 +334,7 @@ func reqTeamMembership() func(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID := ctx.Org.Team.OrgID
|
orgID := ctx.Org.Team.OrgID
|
||||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.User.ID)
|
isOwner, err := models.IsOrganizationOwner(orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
||||||
return
|
return
|
||||||
|
@ -342,11 +342,11 @@ func reqTeamMembership() func(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isTeamMember, err := models.IsTeamMember(orgID, ctx.Org.Team.ID, ctx.User.ID); err != nil {
|
if isTeamMember, err := models.IsTeamMember(orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsTeamMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsTeamMember", err)
|
||||||
return
|
return
|
||||||
} else if !isTeamMember {
|
} else if !isTeamMember {
|
||||||
isOrgMember, err := models.IsOrganizationMember(orgID, ctx.User.ID)
|
isOrgMember, err := models.IsOrganizationMember(orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
||||||
} else if isOrgMember {
|
} else if isOrgMember {
|
||||||
|
@ -376,7 +376,7 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isMember, err := models.IsOrganizationMember(orgID, ctx.User.ID); err != nil {
|
if isMember, err := models.IsOrganizationMember(orgID, ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
||||||
return
|
return
|
||||||
} else if !isMember {
|
} else if !isMember {
|
||||||
|
@ -392,7 +392,7 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
||||||
|
|
||||||
func reqGitHook() func(ctx *context.APIContext) {
|
func reqGitHook() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.User.CanEditGitHook() {
|
if !ctx.Doer.CanEditGitHook() {
|
||||||
ctx.Error(http.StatusForbidden, "", "must be allowed to edit Git hooks")
|
ctx.Error(http.StatusForbidden, "", "must be allowed to edit Git hooks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -463,7 +463,7 @@ func mustEnableIssues(ctx *context.APIContext) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
unit.TypeIssues,
|
unit.TypeIssues,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
|
@ -486,7 +486,7 @@ func mustAllowPulls(ctx *context.APIContext) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
unit.TypePullRequests,
|
unit.TypePullRequests,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
|
@ -510,7 +510,7 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+
|
log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
unit.TypeIssues,
|
unit.TypeIssues,
|
||||||
unit.TypePullRequests,
|
unit.TypePullRequests,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
|
|
|
@ -22,7 +22,7 @@ func NewAvailable(ctx *context.APIContext) {
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/NotificationCount"
|
// "$ref": "#/responses/NotificationCount"
|
||||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.User)})
|
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.Doer)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
|
func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
|
||||||
|
@ -33,7 +33,7 @@ func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificatio
|
||||||
}
|
}
|
||||||
opts := &models.FindNotificationOptions{
|
opts := &models.FindNotificationOptions{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
UpdatedBeforeUnix: before,
|
UpdatedBeforeUnix: before,
|
||||||
UpdatedAfterUnix: since,
|
UpdatedAfterUnix: since,
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &models.FindNotificationOptions{
|
opts := &models.FindNotificationOptions{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
UpdatedBeforeUnix: lastRead,
|
UpdatedBeforeUnix: lastRead,
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
changed := make([]*structs.NotificationThread, len(nl))
|
changed := make([]*structs.NotificationThread, len(nl))
|
||||||
|
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
|
notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -87,7 +87,7 @@ func ReadThread(ctx *context.APIContext) {
|
||||||
targetStatus = models.NotificationStatusRead
|
targetStatus = models.NotificationStatusRead
|
||||||
}
|
}
|
||||||
|
|
||||||
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
|
notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
@ -109,7 +109,7 @@ func getThread(ctx *context.APIContext) *models.Notification {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if n.UserID != ctx.User.ID && !ctx.User.IsAdmin {
|
if n.UserID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "GetNotificationByID", fmt.Errorf("only user itself and admin are allowed to read/change this thread %d", n.ID))
|
ctx.Error(http.StatusForbidden, "GetNotificationByID", fmt.Errorf("only user itself and admin are allowed to read/change this thread %d", n.ID))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts := &models.FindNotificationOptions{
|
opts := &models.FindNotificationOptions{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
UpdatedBeforeUnix: lastRead,
|
UpdatedBeforeUnix: lastRead,
|
||||||
}
|
}
|
||||||
if !ctx.FormBool("all") {
|
if !ctx.FormBool("all") {
|
||||||
|
@ -162,7 +162,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||||
changed := make([]*structs.NotificationThread, 0, len(nl))
|
changed := make([]*structs.NotificationThread, 0, len(nl))
|
||||||
|
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
|
notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -39,7 +39,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||||
|
|
||||||
apiMembers := make([]*api.User, len(members))
|
apiMembers := make([]*api.User, len(members))
|
||||||
for i, member := range members {
|
for i, member := range members {
|
||||||
apiMembers[i] = convert.ToUser(member, ctx.User)
|
apiMembers[i] = convert.ToUser(member, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
@ -72,13 +72,13 @@ func ListMembers(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/UserList"
|
// "$ref": "#/responses/UserList"
|
||||||
|
|
||||||
publicOnly := true
|
publicOnly := true
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
publicOnly = !isMember && !ctx.User.IsAdmin
|
publicOnly = !isMember && !ctx.Doer.IsAdmin
|
||||||
}
|
}
|
||||||
listMembers(ctx, publicOnly)
|
listMembers(ctx, publicOnly)
|
||||||
}
|
}
|
||||||
|
@ -139,12 +139,12 @@ func IsMember(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||||
return
|
return
|
||||||
} else if userIsMember || ctx.User.IsAdmin {
|
} else if userIsMember || ctx.Doer.IsAdmin {
|
||||||
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(userToCheck.ID)
|
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(userToCheck.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||||
|
@ -154,7 +154,7 @@ func IsMember(ctx *context.APIContext) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if ctx.User.ID == userToCheck.ID {
|
} else if ctx.Doer.ID == userToCheck.ID {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func PublicizeMember(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if userToPublicize.ID != ctx.User.ID {
|
if userToPublicize.ID != ctx.Doer.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
|
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ func ConcealMember(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if userToConceal.ID != ctx.User.ID {
|
if userToConceal.ID != ctx.Doer.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
|
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
|
|
||||||
func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
|
func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
|
||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
|
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == u.ID)
|
||||||
|
|
||||||
opts := models.FindOrgOptions{
|
opts := models.FindOrgOptions{
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
|
@ -71,7 +71,7 @@ func ListMyOrgs(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/OrganizationList"
|
// "$ref": "#/responses/OrganizationList"
|
||||||
|
|
||||||
listUserOrgs(ctx, ctx.User)
|
listUserOrgs(ctx, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListUserOrgs list user's orgs
|
// ListUserOrgs list user's orgs
|
||||||
|
@ -201,7 +201,7 @@ func GetAll(ctx *context.APIContext) {
|
||||||
vMode := []api.VisibleType{api.VisibleTypePublic}
|
vMode := []api.VisibleType{api.VisibleTypePublic}
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
vMode = append(vMode, api.VisibleTypeLimited)
|
vMode = append(vMode, api.VisibleTypeLimited)
|
||||||
if ctx.User.IsAdmin {
|
if ctx.Doer.IsAdmin {
|
||||||
vMode = append(vMode, api.VisibleTypePrivate)
|
vMode = append(vMode, api.VisibleTypePrivate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func GetAll(ctx *context.APIContext) {
|
||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
Type: user_model.UserTypeOrganization,
|
Type: user_model.UserTypeOrganization,
|
||||||
OrderBy: db.SearchOrderByAlphabetically,
|
OrderBy: db.SearchOrderByAlphabetically,
|
||||||
|
@ -251,7 +251,7 @@ func Create(ctx *context.APIContext) {
|
||||||
// "422":
|
// "422":
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
||||||
if !ctx.User.CanCreateOrganization() {
|
if !ctx.Doer.CanCreateOrganization() {
|
||||||
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ func Create(ctx *context.APIContext) {
|
||||||
Visibility: visibility,
|
Visibility: visibility,
|
||||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||||
}
|
}
|
||||||
if err := models.CreateOrganization(org, ctx.User); err != nil {
|
if err := models.CreateOrganization(org, ctx.Doer); err != nil {
|
||||||
if user_model.IsErrUserAlreadyExist(err) ||
|
if user_model.IsErrUserAlreadyExist(err) ||
|
||||||
db.IsErrNameReserved(err) ||
|
db.IsErrNameReserved(err) ||
|
||||||
db.IsErrNameCharsNotAllowed(err) ||
|
db.IsErrNameCharsNotAllowed(err) ||
|
||||||
|
@ -304,7 +304,7 @@ func Get(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/Organization"
|
// "$ref": "#/responses/Organization"
|
||||||
|
|
||||||
if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.User) {
|
if !models.HasOrgOrUserVisible(ctx.Org.Organization.AsUser(), ctx.Doer) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func ListUserTeams(ctx *context.APIContext) {
|
||||||
|
|
||||||
teams, count, err := models.GetUserTeams(&models.GetUserTeamOptions{
|
teams, count, err := models.GetUserTeams(&models.GetUserTeamOptions{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserTeams", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserTeams", err)
|
||||||
|
@ -368,11 +368,11 @@ func GetTeamMembers(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/UserList"
|
// "$ref": "#/responses/UserList"
|
||||||
|
|
||||||
isMember, err := models.IsOrganizationMember(ctx.Org.Team.OrgID, ctx.User.ID)
|
isMember, err := models.IsOrganizationMember(ctx.Org.Team.OrgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
||||||
return
|
return
|
||||||
} else if !isMember && !ctx.User.IsAdmin {
|
} else if !isMember && !ctx.Doer.IsAdmin {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ func GetTeamMembers(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
members := make([]*api.User, len(ctx.Org.Team.Members))
|
members := make([]*api.User, len(ctx.Org.Team.Members))
|
||||||
for i, member := range ctx.Org.Team.Members {
|
for i, member := range ctx.Org.Team.Members {
|
||||||
members[i] = convert.ToUser(member, ctx.User)
|
members[i] = convert.ToUser(member, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(int64(ctx.Org.Team.NumMembers))
|
ctx.SetTotalCountHeader(int64(ctx.Org.Team.NumMembers))
|
||||||
|
@ -430,7 +430,7 @@ func GetTeamMember(ctx *context.APIContext) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTeamMember api for add a member to a team
|
// AddTeamMember api for add a member to a team
|
||||||
|
@ -540,7 +540,7 @@ func GetTeamRepos(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
repos := make([]*api.Repository, len(team.Repos))
|
repos := make([]*api.Repository, len(team.Repos))
|
||||||
for i, repo := range team.Repos {
|
for i, repo := range team.Repos {
|
||||||
access, err := models.AccessLevel(ctx.User, repo)
|
access, err := models.AccessLevel(ctx.Doer, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
||||||
return
|
return
|
||||||
|
@ -599,7 +599,7 @@ func AddTeamRepository(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if access, err := models.AccessLevel(ctx.User, repo); err != nil {
|
if access, err := models.AccessLevel(ctx.Doer, repo); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
return
|
return
|
||||||
} else if access < perm.AccessModeAdmin {
|
} else if access < perm.AccessModeAdmin {
|
||||||
|
@ -649,7 +649,7 @@ func RemoveTeamRepository(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if access, err := models.AccessLevel(ctx.User, repo); err != nil {
|
if access, err := models.AccessLevel(ctx.Doer, repo); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
return
|
return
|
||||||
} else if access < perm.AccessModeAdmin {
|
} else if access < perm.AccessModeAdmin {
|
||||||
|
|
|
@ -75,7 +75,7 @@ func GetBranch(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
br, err := convert.ToBranch(ctx.Repo.Repository, branch, c, branchProtection, ctx.User, ctx.Repo.IsAdmin())
|
br, err := convert.ToBranch(ctx.Repo.Repository, branch, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||||
return
|
return
|
||||||
|
@ -117,7 +117,7 @@ func DeleteBranch(ctx *context.APIContext) {
|
||||||
|
|
||||||
branchName := ctx.Params("*")
|
branchName := ctx.Params("*")
|
||||||
|
|
||||||
if err := repo_service.DeleteBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil {
|
if err := repo_service.DeleteBranch(ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case git.IsErrBranchNotExist(err):
|
case git.IsErrBranchNotExist(err):
|
||||||
ctx.NotFound(err)
|
ctx.NotFound(err)
|
||||||
|
@ -176,7 +176,7 @@ func CreateBranch(ctx *context.APIContext) {
|
||||||
opt.OldBranchName = ctx.Repo.Repository.DefaultBranch
|
opt.OldBranchName = ctx.Repo.Repository.DefaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
err := repo_service.CreateNewBranch(ctx, ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
|
err := repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrBranchDoesNotExist(err) {
|
if models.IsErrBranchDoesNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
|
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
|
||||||
|
@ -211,7 +211,7 @@ func CreateBranch(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
br, err := convert.ToBranch(ctx.Repo.Repository, branch, commit, branchProtection, ctx.User, ctx.Repo.IsAdmin())
|
br, err := convert.ToBranch(ctx.Repo.Repository, branch, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||||
return
|
return
|
||||||
|
@ -270,7 +270,7 @@ func ListBranches(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.User, ctx.Repo.IsAdmin())
|
apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -63,7 +63,7 @@ func ListCollaborators(ctx *context.APIContext) {
|
||||||
|
|
||||||
users := make([]*api.User, len(collaborators))
|
users := make([]*api.User, len(collaborators))
|
||||||
for i, collaborator := range collaborators {
|
for i, collaborator := range collaborators {
|
||||||
users[i] = convert.ToUser(collaborator.User, ctx.User)
|
users[i] = convert.ToUser(collaborator.User, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
@ -255,12 +255,12 @@ func GetReviewers(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/UserList"
|
// "$ref": "#/responses/UserList"
|
||||||
|
|
||||||
reviewers, err := models.GetReviewers(ctx.Repo.Repository, ctx.User.ID, 0)
|
reviewers, err := models.GetReviewers(ctx.Repo.Repository, ctx.Doer.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, reviewers))
|
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.Doer, reviewers))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAssignees return all users that have write access and can be assigned to issues
|
// GetAssignees return all users that have write access and can be assigned to issues
|
||||||
|
@ -290,5 +290,5 @@ func GetAssignees(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, assignees))
|
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.Doer, assignees))
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,7 @@ func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
|
||||||
func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoFileOptions) (*api.FileResponse, error) {
|
func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoFileOptions) (*api.FileResponse, error) {
|
||||||
if !canWriteFiles(ctx.Repo) {
|
if !canWriteFiles(ctx.Repo) {
|
||||||
return nil, models.ErrUserDoesNotHaveAccessToRepo{
|
return nil, models.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoF
|
||||||
}
|
}
|
||||||
opts.Content = string(content)
|
opts.Content = string(content)
|
||||||
|
|
||||||
return files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts)
|
return files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFile Delete a file in a repository
|
// DeleteFile Delete a file in a repository
|
||||||
|
@ -448,7 +448,7 @@ func DeleteFile(ctx *context.APIContext) {
|
||||||
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
||||||
if !canWriteFiles(ctx.Repo) {
|
if !canWriteFiles(ctx.Repo) {
|
||||||
ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
|
ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -489,7 +489,7 @@ func DeleteFile(ctx *context.APIContext) {
|
||||||
opts.Message = ctx.Tr("repo.editor.delete", opts.TreePath)
|
opts.Message = ctx.Tr("repo.editor.delete", opts.TreePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileResponse, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts); err != nil {
|
if fileResponse, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, opts); err != nil {
|
||||||
if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
|
if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteFile", err)
|
ctx.Error(http.StatusNotFound, "DeleteFile", err)
|
||||||
return
|
return
|
||||||
|
@ -546,7 +546,7 @@ func GetContents(ctx *context.APIContext) {
|
||||||
|
|
||||||
if !canReadFiles(ctx.Repo) {
|
if !canReadFiles(ctx.Repo) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
|
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
|
@ -58,7 +58,7 @@ func ListForks(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
apiForks := make([]*api.Repository, len(forks))
|
apiForks := make([]*api.Repository, len(forks))
|
||||||
for i, fork := range forks {
|
for i, fork := range forks {
|
||||||
access, err := models.AccessLevel(ctx.User, fork)
|
access, err := models.AccessLevel(ctx.Doer, fork)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
return
|
return
|
||||||
|
@ -106,7 +106,7 @@ func CreateFork(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
var forker *user_model.User // user/org that will own the fork
|
var forker *user_model.User // user/org that will own the fork
|
||||||
if form.Organization == nil {
|
if form.Organization == nil {
|
||||||
forker = ctx.User
|
forker = ctx.Doer
|
||||||
} else {
|
} else {
|
||||||
org, err := models.GetOrgByName(*form.Organization)
|
org, err := models.GetOrgByName(*form.Organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,7 +117,7 @@ func CreateFork(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isMember, err := org.IsOrgMember(ctx.User.ID)
|
isMember, err := org.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||||
return
|
return
|
||||||
|
@ -135,7 +135,7 @@ func CreateFork(ctx *context.APIContext) {
|
||||||
name = *form.Name
|
name = *form.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
fork, err := repo_service.ForkRepository(ctx.User, forker, repo_service.ForkRepoOptions{
|
fork, err := repo_service.ForkRepository(ctx.Doer, forker, repo_service.ForkRepoOptions{
|
||||||
BaseRepo: repo,
|
BaseRepo: repo,
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: repo.Description,
|
Description: repo.Description,
|
||||||
|
|
|
@ -163,8 +163,8 @@ func TestHook(ctx *context.APIContext) {
|
||||||
Commits: []*api.PayloadCommit{commit},
|
Commits: []*api.PayloadCommit{commit},
|
||||||
HeadCommit: commit,
|
HeadCommit: commit,
|
||||||
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
|
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
|
||||||
Pusher: convert.ToUserWithAccessMode(ctx.User, perm.AccessModeNone),
|
Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
|
||||||
Sender: convert.ToUserWithAccessMode(ctx.User, perm.AccessModeNone),
|
Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -135,7 +135,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
// This needs to be a column that is not nil in fixtures or
|
// This needs to be a column that is not nil in fixtures or
|
||||||
// MySQL will return different results when sorting by null in some cases
|
// MySQL will return different results when sorting by null in some cases
|
||||||
OrderBy: db.SearchOrderByAlphabetically,
|
OrderBy: db.SearchOrderByAlphabetically,
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
}
|
}
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
opts.Private = true
|
opts.Private = true
|
||||||
|
@ -247,7 +247,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
|
|
||||||
ctxUserID := int64(0)
|
ctxUserID := int64(0)
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
ctxUserID = ctx.User.ID
|
ctxUserID = ctx.Doer.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested
|
// Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested
|
||||||
|
@ -597,8 +597,8 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Repo: ctx.Repo.Repository,
|
Repo: ctx.Repo.Repository,
|
||||||
Title: form.Title,
|
Title: form.Title,
|
||||||
PosterID: ctx.User.ID,
|
PosterID: ctx.Doer.ID,
|
||||||
Poster: ctx.User,
|
Poster: ctx.Doer,
|
||||||
Content: form.Body,
|
Content: form.Body,
|
||||||
Ref: form.Ref,
|
Ref: form.Ref,
|
||||||
DeadlineUnix: deadlineUnix,
|
DeadlineUnix: deadlineUnix,
|
||||||
|
@ -651,7 +651,7 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.Closed {
|
if form.Closed {
|
||||||
if err := issue_service.ChangeStatus(issue, ctx.User, true); err != nil {
|
if err := issue_service.ChangeStatus(issue, ctx.Doer, true); err != nil {
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||||
return
|
return
|
||||||
|
@ -729,7 +729,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !issue.IsPoster(ctx.User.ID) && !canWrite {
|
if !issue.IsPoster(ctx.Doer.ID) && !canWrite {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -742,7 +742,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
issue.Content = *form.Body
|
issue.Content = *form.Body
|
||||||
}
|
}
|
||||||
if form.Ref != nil {
|
if form.Ref != nil {
|
||||||
err = issue_service.ChangeIssueRef(issue, ctx.User, *form.Ref)
|
err = issue_service.ChangeIssueRef(issue, ctx.Doer, *form.Ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
|
||||||
return
|
return
|
||||||
|
@ -759,7 +759,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
|
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -780,7 +780,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
oneAssignee = *form.Assignee
|
oneAssignee = *form.Assignee
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue_service.UpdateAssignees(issue, oneAssignee, form.Assignees, ctx.User)
|
err = issue_service.UpdateAssignees(issue, oneAssignee, form.Assignees, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
|
||||||
return
|
return
|
||||||
|
@ -791,7 +791,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
issue.MilestoneID != *form.Milestone {
|
issue.MilestoneID != *form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = *form.Milestone
|
issue.MilestoneID = *form.Milestone
|
||||||
if err = issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -808,7 +808,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
|
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
|
||||||
}
|
}
|
||||||
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
|
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||||
|
@ -819,11 +819,11 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if titleChanged {
|
if titleChanged {
|
||||||
notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
|
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
if statusChangeComment != nil {
|
if statusChangeComment != nil {
|
||||||
notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed)
|
notification.NotifyIssueChangeStatus(ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refetch from database to assign some automatic values
|
// Refetch from database to assign some automatic values
|
||||||
|
@ -877,7 +877,7 @@ func DeleteIssue(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.DeleteIssue(ctx.User, ctx.Repo.GitRepo, issue); err != nil {
|
if err = issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -946,7 +946,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||||
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
|
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,9 +183,9 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||||
|
|
||||||
var apiComments []*api.TimelineComment
|
var apiComments []*api.TimelineComment
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx.User, comment, issue.RepoID) {
|
if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx.Doer, comment, issue.RepoID) {
|
||||||
comment.Issue = issue
|
comment.Issue = issue
|
||||||
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.User))
|
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.Doer))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,12 +347,12 @@ func CreateIssueComment(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin {
|
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked")))
|
ctx.Error(http.StatusForbidden, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := comment_service.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil)
|
comment, err := comment_service.CreateIssueComment(ctx.Doer, ctx.Repo.Repository, issue, form.Body, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateIssueComment", err)
|
ctx.Error(http.StatusInternalServerError, "CreateIssueComment", err)
|
||||||
return
|
return
|
||||||
|
@ -534,7 +534,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
|
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -546,7 +546,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
|
|
||||||
oldContent := comment.Content
|
oldContent := comment.Content
|
||||||
comment.Content = form.Body
|
comment.Content = form.Body
|
||||||
if err := comment_service.UpdateComment(comment, ctx.User, oldContent); err != nil {
|
if err := comment_service.UpdateComment(comment, ctx.Doer, oldContent); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateComment", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -637,7 +637,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
|
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
} else if comment.Type != models.CommentTypeComment {
|
} else if comment.Type != models.CommentTypeComment {
|
||||||
|
@ -645,7 +645,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = comment_service.DeleteComment(ctx.User, comment); err != nil {
|
if err = comment_service.DeleteComment(ctx.Doer, comment); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentByID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteCommentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ func AddIssueLabels(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.AddLabels(issue, ctx.User, labels); err != nil {
|
if err = issue_service.AddLabels(issue, ctx.Doer, labels); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddLabels", err)
|
ctx.Error(http.StatusInternalServerError, "AddLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.RemoveLabel(issue, ctx.User, label); err != nil {
|
if err := issue_service.RemoveLabel(issue, ctx.Doer, label); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ReplaceLabels(issue, ctx.User, labels); err != nil {
|
if err := issue_service.ReplaceLabels(issue, ctx.Doer, labels); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
|
ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ClearLabels(issue, ctx.User); err != nil {
|
if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
|
ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
||||||
var result []api.Reaction
|
var result []api.Reaction
|
||||||
for _, r := range reactions {
|
for _, r := range reactions {
|
||||||
result = append(result, api.Reaction{
|
result = append(result, api.Reaction{
|
||||||
User: convert.ToUser(r.User, ctx.User),
|
User: convert.ToUser(r.User, ctx.Doer),
|
||||||
Reaction: r.Type,
|
Reaction: r.Type,
|
||||||
Created: r.CreatedUnix.AsTime(),
|
Created: r.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
|
@ -197,13 +197,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
|
|
||||||
if isCreateType {
|
if isCreateType {
|
||||||
// PostIssueCommentReaction part
|
// PostIssueCommentReaction part
|
||||||
reaction, err := models.CreateCommentReaction(ctx.User, comment.Issue, comment, form.Reaction)
|
reaction, err := models.CreateCommentReaction(ctx.Doer, comment.Issue, comment, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrForbiddenIssueReaction(err) {
|
if models.IsErrForbiddenIssueReaction(err) {
|
||||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||||
} else if models.IsErrReactionAlreadyExist(err) {
|
} else if models.IsErrReactionAlreadyExist(err) {
|
||||||
ctx.JSON(http.StatusOK, api.Reaction{
|
ctx.JSON(http.StatusOK, api.Reaction{
|
||||||
User: convert.ToUser(ctx.User, ctx.User),
|
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||||
Reaction: reaction.Type,
|
Reaction: reaction.Type,
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
|
@ -214,13 +214,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||||
User: convert.ToUser(ctx.User, ctx.User),
|
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||||
Reaction: reaction.Type,
|
Reaction: reaction.Type,
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// DeleteIssueCommentReaction part
|
// DeleteIssueCommentReaction part
|
||||||
err = models.DeleteCommentReaction(ctx.User, comment.Issue, comment, form.Reaction)
|
err = models.DeleteCommentReaction(ctx.Doer, comment.Issue, comment, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
|
||||||
return
|
return
|
||||||
|
@ -299,7 +299,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
||||||
var result []api.Reaction
|
var result []api.Reaction
|
||||||
for _, r := range reactions {
|
for _, r := range reactions {
|
||||||
result = append(result, api.Reaction{
|
result = append(result, api.Reaction{
|
||||||
User: convert.ToUser(r.User, ctx.User),
|
User: convert.ToUser(r.User, ctx.Doer),
|
||||||
Reaction: r.Type,
|
Reaction: r.Type,
|
||||||
Created: r.CreatedUnix.AsTime(),
|
Created: r.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
|
@ -407,13 +407,13 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
|
|
||||||
if isCreateType {
|
if isCreateType {
|
||||||
// PostIssueReaction part
|
// PostIssueReaction part
|
||||||
reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Reaction)
|
reaction, err := models.CreateIssueReaction(ctx.Doer, issue, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrForbiddenIssueReaction(err) {
|
if models.IsErrForbiddenIssueReaction(err) {
|
||||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||||
} else if models.IsErrReactionAlreadyExist(err) {
|
} else if models.IsErrReactionAlreadyExist(err) {
|
||||||
ctx.JSON(http.StatusOK, api.Reaction{
|
ctx.JSON(http.StatusOK, api.Reaction{
|
||||||
User: convert.ToUser(ctx.User, ctx.User),
|
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||||
Reaction: reaction.Type,
|
Reaction: reaction.Type,
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
|
@ -424,13 +424,13 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||||
User: convert.ToUser(ctx.User, ctx.User),
|
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||||
Reaction: reaction.Type,
|
Reaction: reaction.Type,
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// DeleteIssueReaction part
|
// DeleteIssueReaction part
|
||||||
err = models.DeleteIssueReaction(ctx.User, issue, form.Reaction)
|
err = models.DeleteIssueReaction(ctx.Doer, issue, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -56,7 +56,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.User, issue); err != nil {
|
if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.User, issue); err != nil {
|
if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CancelStopwatch(ctx.User, issue); err != nil {
|
if err := models.CancelStopwatch(ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
|
ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -179,12 +179,12 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
|
||||||
return nil, errors.New("Unable to write to PRs")
|
return nil, errors.New("Unable to write to PRs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return nil, errors.New("Cannot use time tracker")
|
return nil, errors.New("Cannot use time tracker")
|
||||||
}
|
}
|
||||||
|
|
||||||
if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist {
|
if models.StopwatchExists(ctx.Doer.ID, issue.ID) != shouldExist {
|
||||||
if shouldExist {
|
if shouldExist {
|
||||||
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
|
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
|
||||||
err = errors.New("cannot stop/cancel a non existent stopwatch")
|
err = errors.New("cannot stop/cancel a non existent stopwatch")
|
||||||
|
@ -220,13 +220,13 @@ func GetStopwatches(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/StopWatchList"
|
// "$ref": "#/responses/StopWatchList"
|
||||||
|
|
||||||
sws, err := models.GetUserStopwatches(ctx.User.ID, utils.GetListOptions(ctx))
|
sws, err := models.GetUserStopwatches(ctx.Doer.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := models.CountUserStopwatches(ctx.User.ID)
|
count, err := models.CountUserStopwatches(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -128,8 +128,8 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only admin and user for itself can change subscription
|
// only admin and user for itself can change subscription
|
||||||
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
|
if user.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.User.Name, user.Name))
|
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.Doer.Name, user.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
watching, err := models.CheckIssueWatch(ctx.User, issue)
|
watching, err := models.CheckIssueWatch(ctx.Doer, issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
|
@ -281,7 +281,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
apiUsers := make([]*api.User, 0, len(users))
|
apiUsers := make([]*api.User, 0, len(users))
|
||||||
for _, v := range users {
|
for _, v := range users {
|
||||||
apiUsers = append(apiUsers, convert.ToUser(v, ctx.User))
|
apiUsers = append(apiUsers, convert.ToUser(v, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := models.CountIssueWatchers(issue.ID)
|
count, err := models.CountIssueWatchers(issue.ID)
|
||||||
|
|
|
@ -108,13 +108,13 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cantSetUser := !ctx.User.IsAdmin &&
|
cantSetUser := !ctx.Doer.IsAdmin &&
|
||||||
opts.UserID != ctx.User.ID &&
|
opts.UserID != ctx.Doer.ID &&
|
||||||
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
||||||
|
|
||||||
if cantSetUser {
|
if cantSetUser {
|
||||||
if opts.UserID == 0 {
|
if opts.UserID == 0 {
|
||||||
opts.UserID = ctx.User.ID
|
opts.UserID = ctx.Doer.ID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
|
@ -189,7 +189,7 @@ func AddTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||||
return
|
return
|
||||||
|
@ -198,9 +198,9 @@ func AddTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := ctx.User
|
user := ctx.Doer
|
||||||
if form.User != "" {
|
if form.User != "" {
|
||||||
if (ctx.IsUserRepoAdmin() && ctx.User.Name != form.User) || ctx.User.IsAdmin {
|
if (ctx.IsUserRepoAdmin() && ctx.Doer.Name != form.User) || ctx.Doer.IsAdmin {
|
||||||
// allow only RepoAdmin, Admin and User to add time
|
// allow only RepoAdmin, Admin and User to add time
|
||||||
user, err = user_model.GetUserByName(form.User)
|
user, err = user_model.GetUserByName(form.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -270,7 +270,7 @@ func ResetIssueTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||||
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
||||||
return
|
return
|
||||||
|
@ -279,7 +279,7 @@ func ResetIssueTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.DeleteIssueUserTimes(issue, ctx.User)
|
err = models.DeleteIssueUserTimes(issue, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrNotExist(err) {
|
if models.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
|
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
|
||||||
|
@ -341,7 +341,7 @@ func DeleteTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||||
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
||||||
return
|
return
|
||||||
|
@ -364,7 +364,7 @@ func DeleteTime(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsAdmin && time.UserID != ctx.User.ID {
|
if !ctx.Doer.IsAdmin && time.UserID != ctx.Doer.ID {
|
||||||
// Only Admin and User itself can delete their time
|
// Only Admin and User itself can delete their time
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
|
@ -428,7 +428,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsUserRepoAdmin() && !ctx.User.IsAdmin && ctx.User.ID != user.ID {
|
if !ctx.IsUserRepoAdmin() && !ctx.Doer.IsAdmin && ctx.Doer.ID != user.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -527,13 +527,13 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cantSetUser := !ctx.User.IsAdmin &&
|
cantSetUser := !ctx.Doer.IsAdmin &&
|
||||||
opts.UserID != ctx.User.ID &&
|
opts.UserID != ctx.Doer.ID &&
|
||||||
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
||||||
|
|
||||||
if cantSetUser {
|
if cantSetUser {
|
||||||
if opts.UserID == 0 {
|
if opts.UserID == 0 {
|
||||||
opts.UserID = ctx.User.ID
|
opts.UserID = ctx.Doer.ID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
|
@ -593,7 +593,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
||||||
|
|
||||||
opts := &models.FindTrackedTimesOptions{
|
opts := &models.FindTrackedTimesOptions{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -107,7 +107,7 @@ func ListDeployKeys(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
|
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
|
||||||
if ctx.User.IsAdmin || ((ctx.Repo.Repository.ID == keys[i].RepoID) && (ctx.User.ID == ctx.Repo.Owner.ID)) {
|
if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == keys[i].RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) {
|
||||||
apiKeys[i], _ = appendPrivateInformation(apiKeys[i], keys[i], ctx.Repo.Repository)
|
apiKeys[i], _ = appendPrivateInformation(apiKeys[i], keys[i], ctx.Repo.Repository)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func GetDeployKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
apiKey := convert.ToDeployKey(apiLink, key)
|
apiKey := convert.ToDeployKey(apiLink, key)
|
||||||
if ctx.User.IsAdmin || ((ctx.Repo.Repository.ID == key.RepoID) && (ctx.User.ID == ctx.Repo.Owner.ID)) {
|
if ctx.Doer.IsAdmin || ((ctx.Repo.Repository.ID == key.RepoID) && (ctx.Doer.ID == ctx.Repo.Owner.ID)) {
|
||||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Repo.Repository)
|
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Repo.Repository)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiKey)
|
ctx.JSON(http.StatusOK, apiKey)
|
||||||
|
@ -270,7 +270,7 @@ func DeleteDeploykey(ctx *context.APIContext) {
|
||||||
// "403":
|
// "403":
|
||||||
// "$ref": "#/responses/forbidden"
|
// "$ref": "#/responses/forbidden"
|
||||||
|
|
||||||
if err := asymkey_service.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
if err := asymkey_service.DeleteDeployKey(ctx.Doer, ctx.ParamsInt64(":id")); err != nil {
|
||||||
if asymkey_model.IsErrKeyAccessDenied(err) {
|
if asymkey_model.IsErrKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -66,7 +66,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
} else if form.RepoOwnerID != 0 {
|
} else if form.RepoOwnerID != 0 {
|
||||||
repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
|
repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
|
||||||
} else {
|
} else {
|
||||||
repoOwner = ctx.User
|
repoOwner = ctx.Doer
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
|
@ -82,15 +82,15 @@ func Migrate(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
if !repoOwner.IsOrganization() && ctx.User.ID != repoOwner.ID {
|
if !repoOwner.IsOrganization() && ctx.Doer.ID != repoOwner.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not an organization.")
|
ctx.Error(http.StatusForbidden, "", "Given user is not an organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoOwner.IsOrganization() {
|
if repoOwner.IsOrganization() {
|
||||||
// Check ownership of organization.
|
// Check ownership of organization.
|
||||||
isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.User.ID)
|
isOwner, err := models.OrgFromUser(repoOwner).IsOwnedBy(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
||||||
return
|
return
|
||||||
|
@ -103,7 +103,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
|
|
||||||
remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
|
remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.User)
|
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.Doer)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleRemoteAddrError(ctx, err)
|
handleRemoteAddrError(ctx, err)
|
||||||
|
@ -130,7 +130,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "", ctx.Tr("repo.migrate.invalid_lfs_endpoint"))
|
ctx.Error(http.StatusInternalServerError, "", ctx.Tr("repo.migrate.invalid_lfs_endpoint"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.User)
|
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleRemoteAddrError(ctx, err)
|
handleRemoteAddrError(ctx, err)
|
||||||
return
|
return
|
||||||
|
@ -167,7 +167,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
opts.Releases = false
|
opts.Releases = false
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := repo_module.CreateRepository(ctx.User, repoOwner, models.CreateRepoOptions{
|
repo, err := repo_module.CreateRepository(ctx.Doer, repoOwner, models.CreateRepoOptions{
|
||||||
Name: opts.RepoName,
|
Name: opts.RepoName,
|
||||||
Description: opts.Description,
|
Description: opts.Description,
|
||||||
OriginalURL: form.CloneAddr,
|
OriginalURL: form.CloneAddr,
|
||||||
|
@ -192,18 +192,18 @@ func Migrate(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
notification.NotifyMigrateRepository(ctx.User, repoOwner, repo)
|
notification.NotifyMigrateRepository(ctx.Doer, repoOwner, repo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo != nil {
|
if repo != nil {
|
||||||
if errDelete := models.DeleteRepository(ctx.User, repoOwner.ID, repo.ID); errDelete != nil {
|
if errDelete := models.DeleteRepository(ctx.Doer, repoOwner.ID, repo.ID); errDelete != nil {
|
||||||
log.Error("DeleteRepository: %v", errDelete)
|
log.Error("DeleteRepository: %v", errDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if repo, err = migrations.MigrateRepository(graceful.GetManager().HammerContext(), ctx.User, repoOwner.Name, opts, nil); err != nil {
|
if repo, err = migrations.MigrateRepository(graceful.GetManager().HammerContext(), ctx.Doer, repoOwner.Name, opts, nil); err != nil {
|
||||||
handleMigrateError(ctx, repoOwner, remoteAddr, err)
|
handleMigrateError(ctx, repoOwner, remoteAddr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,13 +79,13 @@ func ApplyDiffPatch(ctx *context.APIContext) {
|
||||||
|
|
||||||
if !canWriteFiles(ctx.Repo) {
|
if !canWriteFiles(ctx.Repo) {
|
||||||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", models.ErrUserDoesNotHaveAccessToRepo{
|
ctx.Error(http.StatusInternalServerError, "ApplyPatch", models.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.User, opts)
|
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserCannotCommit(err) || models.IsErrFilePathProtected(err) {
|
if models.IsErrUserCannotCommit(err) || models.IsErrFilePathProtected(err) {
|
||||||
ctx.Error(http.StatusForbidden, "Access", err)
|
ctx.Error(http.StatusForbidden, "Access", err)
|
||||||
|
|
|
@ -118,7 +118,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiPrs[i] = convert.ToAPIPullRequest(ctx, prs[i], ctx.User)
|
apiPrs[i] = convert.ToAPIPullRequest(ctx, prs[i], ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||||
|
@ -174,7 +174,7 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.User))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
||||||
|
@ -363,8 +363,8 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
prIssue := &models.Issue{
|
prIssue := &models.Issue{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Title: form.Title,
|
Title: form.Title,
|
||||||
PosterID: ctx.User.ID,
|
PosterID: ctx.Doer.ID,
|
||||||
Poster: ctx.User,
|
Poster: ctx.Doer,
|
||||||
MilestoneID: milestoneID,
|
MilestoneID: milestoneID,
|
||||||
IsPull: true,
|
IsPull: true,
|
||||||
Content: form.Body,
|
Content: form.Body,
|
||||||
|
@ -420,7 +420,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
|
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
|
ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditPullRequest does what it says
|
// EditPullRequest does what it says
|
||||||
|
@ -484,7 +484,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
issue := pr.Issue
|
issue := pr.Issue
|
||||||
issue.Repo = ctx.Repo.Repository
|
issue.Repo = ctx.Repo.Repository
|
||||||
|
|
||||||
if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(unit.TypePullRequests) {
|
if !issue.IsPoster(ctx.Doer.ID) && !ctx.Repo.CanWrite(unit.TypePullRequests) {
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
|
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -522,7 +522,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
// Send an empty array ([]) to clear all assignees from the Issue.
|
// Send an empty array ([]) to clear all assignees from the Issue.
|
||||||
|
|
||||||
if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
|
if ctx.Repo.CanWrite(unit.TypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
|
||||||
err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.User)
|
err = issue_service.UpdateAssignees(issue, form.Assignee, form.Assignees, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||||
|
@ -537,7 +537,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
issue.MilestoneID != form.Milestone {
|
issue.MilestoneID != form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = form.Milestone
|
issue.MilestoneID = form.Milestone
|
||||||
if err = issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -560,7 +560,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
labels = append(labels, orgLabels...)
|
labels = append(labels, orgLabels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.ReplaceLabels(labels, ctx.User); err != nil {
|
if err = issue.ReplaceLabels(labels, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
|
ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -573,7 +573,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
|
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
|
||||||
}
|
}
|
||||||
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
|
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
|
||||||
|
@ -584,11 +584,11 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if titleChanged {
|
if titleChanged {
|
||||||
notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
|
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
if statusChangeComment != nil {
|
if statusChangeComment != nil {
|
||||||
notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed)
|
notification.NotifyIssueChangeStatus(ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// change pull target branch
|
// change pull target branch
|
||||||
|
@ -597,7 +597,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
|
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.User, form.Base); err != nil {
|
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, form.Base); err != nil {
|
||||||
if models.IsErrPullRequestAlreadyExists(err) {
|
if models.IsErrPullRequestAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
|
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
|
||||||
return
|
return
|
||||||
|
@ -612,7 +612,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
notification.NotifyPullRequestChangeTargetBranch(ctx.User, pr, form.Base)
|
notification.NotifyPullRequestChangeTargetBranch(ctx.Doer, pr, form.Base)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refetch from database
|
// Refetch from database
|
||||||
|
@ -627,7 +627,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this should be 200, not 201
|
// TODO this should be 200, not 201
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
|
ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPullRequestMerged checks if a PR exists given an index
|
// IsPullRequestMerged checks if a PR exists given an index
|
||||||
|
@ -737,7 +737,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
// Update issue-user.
|
// Update issue-user.
|
||||||
if err = pr.Issue.ReadBy(ctx.User.ID); err != nil {
|
if err = pr.Issue.ReadBy(ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
|
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, ctx.Repo.Permission, ctx.User)
|
allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, ctx.Repo.Permission, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsUSerAllowedToMerge", err)
|
ctx.Error(http.StatusInternalServerError, "IsUSerAllowedToMerge", err)
|
||||||
return
|
return
|
||||||
|
@ -765,7 +765,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
// handle manually-merged mark
|
// handle manually-merged mark
|
||||||
if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged {
|
if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged {
|
||||||
if err = pull_service.MergedManually(pr, ctx.User, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
|
if err = pull_service.MergedManually(pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
|
||||||
if models.IsErrInvalidMergeStyle(err) {
|
if models.IsErrInvalidMergeStyle(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||||
return
|
return
|
||||||
|
@ -797,7 +797,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if form.ForceMerge != nil && *form.ForceMerge {
|
if form.ForceMerge != nil && *form.ForceMerge {
|
||||||
if isRepoAdmin, err := models.IsUserRepoAdmin(pr.BaseRepo, ctx.User); err != nil {
|
if isRepoAdmin, err := models.IsUserRepoAdmin(pr.BaseRepo, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsUserRepoAdmin", err)
|
ctx.Error(http.StatusInternalServerError, "IsUserRepoAdmin", err)
|
||||||
return
|
return
|
||||||
} else if !isRepoAdmin {
|
} else if !isRepoAdmin {
|
||||||
|
@ -809,7 +809,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := pull_service.IsSignedIfRequired(ctx, pr, ctx.User); err != nil {
|
if _, err := pull_service.IsSignedIfRequired(ctx, pr, ctx.Doer); err != nil {
|
||||||
if !asymkey_service.IsErrWontSign(err) {
|
if !asymkey_service.IsErrWontSign(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsSignedIfRequired", err)
|
ctx.Error(http.StatusInternalServerError, "IsSignedIfRequired", err)
|
||||||
return
|
return
|
||||||
|
@ -837,7 +837,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
message += "\n\n" + form.MergeMessageField
|
message += "\n\n" + form.MergeMessageField
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pull_service.Merge(ctx, pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
|
if err := pull_service.Merge(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
|
||||||
if models.IsErrInvalidMergeStyle(err) {
|
if models.IsErrInvalidMergeStyle(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||||
return
|
return
|
||||||
|
@ -894,7 +894,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
defer headRepo.Close()
|
defer headRepo.Close()
|
||||||
}
|
}
|
||||||
if err := repo_service.DeleteBranch(ctx.User, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
|
if err := repo_service.DeleteBranch(ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case git.IsErrBranchNotExist(err):
|
case git.IsErrBranchNotExist(err):
|
||||||
ctx.NotFound(err)
|
ctx.NotFound(err)
|
||||||
|
@ -907,7 +907,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
|
if err := models.AddDeletePRBranchComment(ctx.Doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
|
||||||
// Do not fail here as branch has already been deleted
|
// Do not fail here as branch has already been deleted
|
||||||
log.Error("DeleteBranch: %v", err)
|
log.Error("DeleteBranch: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -989,7 +989,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
}
|
}
|
||||||
|
|
||||||
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
|
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
|
||||||
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
|
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
headGitRepo.Close()
|
headGitRepo.Close()
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||||
|
@ -998,7 +998,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) {
|
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
log.Trace("Permission Denied: User %-v cannot create/read pull requests or cannot read code in Repo %-v\nUser in baseRepo has Permissions: %-+v",
|
log.Trace("Permission Denied: User %-v cannot create/read pull requests or cannot read code in Repo %-v\nUser in baseRepo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
baseRepo,
|
baseRepo,
|
||||||
permBase)
|
permBase)
|
||||||
}
|
}
|
||||||
|
@ -1008,7 +1008,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
}
|
}
|
||||||
|
|
||||||
// user should have permission to read headrepo's codes
|
// user should have permission to read headrepo's codes
|
||||||
permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
|
permHead, err := models.GetUserRepoPermission(headRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
headGitRepo.Close()
|
headGitRepo.Close()
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||||
|
@ -1017,7 +1017,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
if !permHead.CanRead(unit.TypeCode) {
|
if !permHead.CanRead(unit.TypeCode) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
headRepo,
|
headRepo,
|
||||||
permHead)
|
permHead)
|
||||||
}
|
}
|
||||||
|
@ -1120,7 +1120,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
rebase := ctx.FormString("style") == "rebase"
|
rebase := ctx.FormString("style") == "rebase"
|
||||||
|
|
||||||
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(pr, ctx.User)
|
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(pr, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
|
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
|
||||||
return
|
return
|
||||||
|
@ -1134,7 +1134,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||||
// default merge commit message
|
// default merge commit message
|
||||||
message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch)
|
message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch)
|
||||||
|
|
||||||
if err = pull_service.Update(ctx, pr, ctx.User, message, rebase); err != nil {
|
if err = pull_service.Update(ctx, pr, ctx.Doer, message, rebase); err != nil {
|
||||||
if models.IsErrMergeConflicts(err) {
|
if models.IsErrMergeConflicts(err) {
|
||||||
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
|
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
|
||||||
return
|
return
|
||||||
|
|
|
@ -97,7 +97,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.User)
|
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||||
return
|
return
|
||||||
|
@ -148,7 +148,7 @@ func GetPullReview(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||||
return
|
return
|
||||||
|
@ -198,7 +198,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.User)
|
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
|
||||||
return
|
return
|
||||||
|
@ -250,11 +250,11 @@ func DeletePullReview(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User == nil {
|
if ctx.Doer == nil {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.User.IsAdmin && ctx.User.ID != review.ReviewerID {
|
if !ctx.Doer.IsAdmin && ctx.Doer.ID != review.ReviewerID {
|
||||||
ctx.Error(http.StatusForbidden, "only admin and user itself can delete a review", nil)
|
ctx.Error(http.StatusForbidden, "only admin and user itself can delete a review", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := pull_service.CreateCodeComment(ctx,
|
if _, err := pull_service.CreateCodeComment(ctx,
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
ctx.Repo.GitRepo,
|
ctx.Repo.GitRepo,
|
||||||
pr.Issue,
|
pr.Issue,
|
||||||
line,
|
line,
|
||||||
|
@ -369,14 +369,14 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create review and associate all pending review comments
|
// create review and associate all pending review comments
|
||||||
review, _, err := pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
review, _, err := pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||||
return
|
return
|
||||||
|
@ -457,14 +457,14 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create review and associate all pending review comments
|
// create review and associate all pending review comments
|
||||||
review, _, err = pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
review, _, err = pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||||
return
|
return
|
||||||
|
@ -486,7 +486,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
|
||||||
switch event {
|
switch event {
|
||||||
case api.ReviewStateApproved:
|
case api.ReviewStateApproved:
|
||||||
// can not approve your own PR
|
// can not approve your own PR
|
||||||
if pr.Issue.IsPoster(ctx.User.ID) {
|
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("approve your own pull is not allowed"))
|
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("approve your own pull is not allowed"))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
|
@ -495,7 +495,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
|
||||||
|
|
||||||
case api.ReviewStateRequestChanges:
|
case api.ReviewStateRequestChanges:
|
||||||
// can not reject your own PR
|
// can not reject your own PR
|
||||||
if pr.Issue.IsPoster(ctx.User.ID) {
|
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("reject your own pull is not allowed"))
|
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("reject your own pull is not allowed"))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that the user has access to this review if it is pending
|
// make sure that the user has access to this review if it is pending
|
||||||
if review.Type == models.ReviewTypePending && review.ReviewerID != ctx.User.ID && !ctx.User.IsAdmin {
|
if review.Type == models.ReviewTypePending && review.ReviewerID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.NotFound("GetReviewByID")
|
ctx.NotFound("GetReviewByID")
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
|
|
||||||
reviewers := make([]*user_model.User, 0, len(opts.Reviewers))
|
reviewers := make([]*user_model.User, 0, len(opts.Reviewers))
|
||||||
|
|
||||||
permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.User)
|
permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -686,7 +686,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue_service.IsValidReviewRequest(reviewer, ctx.User, isAdd, pr.Issue, &permDoer)
|
err = issue_service.IsValidReviewRequest(reviewer, ctx.Doer, isAdd, pr.Issue, &permDoer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrNotValidReviewRequest(err) {
|
if models.IsErrNotValidReviewRequest(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
||||||
|
@ -705,7 +705,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, reviewer := range reviewers {
|
for _, reviewer := range reviewers {
|
||||||
comment, err := issue_service.ReviewRequest(pr.Issue, ctx.User, reviewer, isAdd)
|
comment, err := issue_service.ReviewRequest(pr.Issue, ctx.Doer, reviewer, isAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
|
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
|
||||||
return
|
return
|
||||||
|
@ -735,7 +735,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue_service.IsValidTeamReviewRequest(teamReviewer, ctx.User, isAdd, pr.Issue)
|
err = issue_service.IsValidTeamReviewRequest(teamReviewer, ctx.Doer, isAdd, pr.Issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrNotValidReviewRequest(err) {
|
if models.IsErrNotValidReviewRequest(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
||||||
|
@ -749,7 +749,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, teamReviewer := range teamReviewers {
|
for _, teamReviewer := range teamReviewers {
|
||||||
comment, err := issue_service.TeamReviewRequest(pr.Issue, ctx.User, teamReviewer, isAdd)
|
comment, err := issue_service.TeamReviewRequest(pr.Issue, ctx.Doer, teamReviewer, isAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("TeamReviewRequest", err)
|
ctx.ServerError("TeamReviewRequest", err)
|
||||||
return
|
return
|
||||||
|
@ -766,7 +766,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
if isAdd {
|
if isAdd {
|
||||||
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.User)
|
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||||
return
|
return
|
||||||
|
@ -884,7 +884,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.User, isDismiss)
|
_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.Doer, isDismiss)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
||||||
return
|
return
|
||||||
|
@ -896,7 +896,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -191,8 +191,8 @@ func CreateRelease(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
rel = &models.Release{
|
rel = &models.Release{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
PublisherID: ctx.User.ID,
|
PublisherID: ctx.Doer.ID,
|
||||||
Publisher: ctx.User,
|
Publisher: ctx.Doer,
|
||||||
TagName: form.TagName,
|
TagName: form.TagName,
|
||||||
Target: form.Target,
|
Target: form.Target,
|
||||||
Title: form.Title,
|
Title: form.Title,
|
||||||
|
@ -220,12 +220,12 @@ func CreateRelease(ctx *context.APIContext) {
|
||||||
rel.Note = form.Note
|
rel.Note = form.Note
|
||||||
rel.IsDraft = form.IsDraft
|
rel.IsDraft = form.IsDraft
|
||||||
rel.IsPrerelease = form.IsPrerelease
|
rel.IsPrerelease = form.IsPrerelease
|
||||||
rel.PublisherID = ctx.User.ID
|
rel.PublisherID = ctx.Doer.ID
|
||||||
rel.IsTag = false
|
rel.IsTag = false
|
||||||
rel.Repo = ctx.Repo.Repository
|
rel.Repo = ctx.Repo.Repository
|
||||||
rel.Publisher = ctx.User
|
rel.Publisher = ctx.Doer
|
||||||
|
|
||||||
if err = releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
if err = releaseservice.UpdateRelease(ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ func EditRelease(ctx *context.APIContext) {
|
||||||
if form.IsPrerelease != nil {
|
if form.IsPrerelease != nil {
|
||||||
rel.IsPrerelease = *form.IsPrerelease
|
rel.IsPrerelease = *form.IsPrerelease
|
||||||
}
|
}
|
||||||
if err := releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
if err := releaseservice.UpdateRelease(ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ func DeleteRelease(ctx *context.APIContext) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := releaseservice.DeleteReleaseByID(ctx, id, ctx.User, false); err != nil {
|
if err := releaseservice.DeleteReleaseByID(ctx, id, ctx.Doer, false); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new attachment and save the file
|
// Create a new attachment and save the file
|
||||||
attach, err := attachment.UploadAttachment(file, ctx.User.ID, release.RepoID, releaseID, filename, setting.Repository.Release.AllowedTypes)
|
attach, err := attachment.UploadAttachment(file, ctx.Doer.ID, release.RepoID, releaseID, filename, setting.Repository.Release.AllowedTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "DetectContentType", err)
|
ctx.Error(http.StatusBadRequest, "DetectContentType", err)
|
||||||
|
|
|
@ -110,7 +110,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = releaseservice.DeleteReleaseByID(ctx, release.ID, ctx.User, false); err != nil {
|
if err = releaseservice.DeleteReleaseByID(ctx, release.ID, ctx.Doer, false); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ func Search(ctx *context.APIContext) {
|
||||||
|
|
||||||
opts := &models.SearchRepoOptions{
|
opts := &models.SearchRepoOptions{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Keyword: ctx.FormTrim("q"),
|
Keyword: ctx.FormTrim("q"),
|
||||||
OwnerID: ctx.FormInt64("uid"),
|
OwnerID: ctx.FormInt64("uid"),
|
||||||
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
|
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
|
||||||
|
@ -224,7 +224,7 @@ func Search(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessMode, err := models.AccessLevel(ctx.User, repo)
|
accessMode, err := models.AccessLevel(ctx.Doer, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||||
OK: false,
|
OK: false,
|
||||||
|
@ -247,7 +247,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
||||||
if opt.AutoInit && opt.Readme == "" {
|
if opt.AutoInit && opt.Readme == "" {
|
||||||
opt.Readme = "Default"
|
opt.Readme = "Default"
|
||||||
}
|
}
|
||||||
repo, err := repo_service.CreateRepository(ctx.User, owner, models.CreateRepoOptions{
|
repo, err := repo_service.CreateRepository(ctx.Doer, owner, models.CreateRepoOptions{
|
||||||
Name: opt.Name,
|
Name: opt.Name,
|
||||||
Description: opt.Description,
|
Description: opt.Description,
|
||||||
IssueLabels: opt.IssueLabels,
|
IssueLabels: opt.IssueLabels,
|
||||||
|
@ -303,12 +303,12 @@ func Create(ctx *context.APIContext) {
|
||||||
// "422":
|
// "422":
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||||
if ctx.User.IsOrganization() {
|
if ctx.Doer.IsOrganization() {
|
||||||
// Shouldn't reach this condition, but just in case.
|
// Shouldn't reach this condition, but just in case.
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
CreateUserRepo(ctx, ctx.User, *opt)
|
CreateUserRepo(ctx, ctx.Doer, *opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Create a repository using a template
|
// Generate Create a repository using a template
|
||||||
|
@ -353,7 +353,7 @@ func Generate(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User.IsOrganization() {
|
if ctx.Doer.IsOrganization() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ func Generate(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxUser := ctx.User
|
ctxUser := ctx.Doer
|
||||||
var err error
|
var err error
|
||||||
if form.Owner != ctxUser.Name {
|
if form.Owner != ctxUser.Name {
|
||||||
ctxUser, err = user_model.GetUserByName(form.Owner)
|
ctxUser, err = user_model.GetUserByName(form.Owner)
|
||||||
|
@ -391,13 +391,13 @@ func Generate(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsAdmin && !ctxUser.IsOrganization() {
|
if !ctx.Doer.IsAdmin && !ctxUser.IsOrganization() {
|
||||||
ctx.Error(http.StatusForbidden, "", "Only admin can generate repository for other user.")
|
ctx.Error(http.StatusForbidden, "", "Only admin can generate repository for other user.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
|
canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanCreateOrgRepo", err)
|
ctx.ServerError("CanCreateOrgRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -408,7 +408,7 @@ func Generate(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := repo_service.GenerateRepository(ctx.User, ctxUser, ctx.Repo.Repository, opts)
|
repo, err := repo_service.GenerateRepository(ctx.Doer, ctxUser, ctx.Repo.Repository, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoAlreadyExist(err) {
|
if repo_model.IsErrRepoAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
||||||
|
@ -493,13 +493,13 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
|
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.Doer) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
|
canCreate, err := org.CanCreateOrgRepo(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -569,7 +569,7 @@ func GetByID(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
perm, err := models.GetUserRepoPermission(repo, ctx.User)
|
perm, err := models.GetUserRepoPermission(repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
return
|
return
|
||||||
|
@ -653,7 +653,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
}
|
}
|
||||||
// Check if repository name has been changed and not just a case change
|
// Check if repository name has been changed and not just a case change
|
||||||
if repo.LowerName != strings.ToLower(newRepoName) {
|
if repo.LowerName != strings.ToLower(newRepoName) {
|
||||||
if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil {
|
if err := repo_service.ChangeRepositoryName(ctx.Doer, repo, newRepoName); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrRepoAlreadyExist(err):
|
case repo_model.IsErrRepoAlreadyExist(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
|
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
|
||||||
|
@ -694,7 +694,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
|
|
||||||
visibilityChanged = repo.IsPrivate != *opts.Private
|
visibilityChanged = repo.IsPrivate != *opts.Private
|
||||||
// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
|
// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
|
||||||
if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.User.IsAdmin {
|
if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.Doer.IsAdmin {
|
||||||
err := fmt.Errorf("cannot change private repository to public")
|
err := fmt.Errorf("cannot change private repository to public")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
|
ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
|
||||||
return err
|
return err
|
||||||
|
@ -1019,7 +1019,7 @@ func Delete(ctx *context.APIContext) {
|
||||||
owner := ctx.Repo.Owner
|
owner := ctx.Repo.Owner
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
|
|
||||||
canDelete, err := models.CanUserDelete(repo, ctx.User)
|
canDelete, err := models.CanUserDelete(repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
|
ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
|
||||||
return
|
return
|
||||||
|
@ -1032,7 +1032,7 @@ func Delete(ctx *context.APIContext) {
|
||||||
ctx.Repo.GitRepo.Close()
|
ctx.Repo.GitRepo.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteRepository(ctx, ctx.User, repo, true); err != nil {
|
if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestRepoEdit(t *testing.T) {
|
||||||
ctx := test.MockContext(t, "user2/repo1")
|
ctx := test.MockContext(t, "user2/repo1")
|
||||||
test.LoadRepo(t, ctx, 1)
|
test.LoadRepo(t, ctx, 1)
|
||||||
test.LoadUser(t, ctx, 2)
|
test.LoadUser(t, ctx, 2)
|
||||||
ctx.Repo.Owner = ctx.User
|
ctx.Repo.Owner = ctx.Doer
|
||||||
description := "new description"
|
description := "new description"
|
||||||
website := "http://wwww.newwebsite.com"
|
website := "http://wwww.newwebsite.com"
|
||||||
private := true
|
private := true
|
||||||
|
@ -71,7 +71,7 @@ func TestRepoEditNameChange(t *testing.T) {
|
||||||
ctx := test.MockContext(t, "user2/repo1")
|
ctx := test.MockContext(t, "user2/repo1")
|
||||||
test.LoadRepo(t, ctx, 1)
|
test.LoadRepo(t, ctx, 1)
|
||||||
test.LoadUser(t, ctx, 2)
|
test.LoadUser(t, ctx, 2)
|
||||||
ctx.Repo.Owner = ctx.User
|
ctx.Repo.Owner = ctx.Doer
|
||||||
name := "newname"
|
name := "newname"
|
||||||
opts := api.EditRepoOption{
|
opts := api.EditRepoOption{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
|
|
|
@ -51,7 +51,7 @@ func ListStargazers(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
users := make([]*api.User, len(stargazers))
|
users := make([]*api.User, len(stargazers))
|
||||||
for i, stargazer := range stargazers {
|
for i, stargazer := range stargazers {
|
||||||
users[i] = convert.ToUser(stargazer, ctx.User)
|
users[i] = convert.ToUser(stargazer, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumStars))
|
ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumStars))
|
||||||
|
|
|
@ -62,7 +62,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
||||||
Description: form.Description,
|
Description: form.Description,
|
||||||
Context: form.Context,
|
Context: form.Context,
|
||||||
}
|
}
|
||||||
if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.User, sha, status); err != nil {
|
if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
|
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
users := make([]*api.User, len(subscribers))
|
users := make([]*api.User, len(subscribers))
|
||||||
for i, subscriber := range subscribers {
|
for i, subscriber := range subscribers {
|
||||||
users[i] = convert.ToUser(subscriber, ctx.User)
|
users[i] = convert.ToUser(subscriber, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumWatches))
|
ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumWatches))
|
||||||
|
|
|
@ -191,7 +191,7 @@ func CreateTag(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := releaseservice.CreateNewTag(ctx, ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
|
if err := releaseservice.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
|
||||||
if models.IsErrTagAlreadyExists(err) {
|
if models.IsErrTagAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusConflict, "tag exist", err)
|
ctx.Error(http.StatusConflict, "tag exist", err)
|
||||||
return
|
return
|
||||||
|
@ -255,7 +255,7 @@ func DeleteTag(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = releaseservice.DeleteReleaseByID(ctx, tag.ID, ctx.User, true); err != nil {
|
if err = releaseservice.DeleteReleaseByID(ctx, tag.ID, ctx.Doer, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ func Transfer(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if newOwner.Type == user_model.UserTypeOrganization {
|
if newOwner.Type == user_model.UserTypeOrganization {
|
||||||
if !ctx.User.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) {
|
if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.Doer.ID) {
|
||||||
// The user shouldn't know about this organization
|
// The user shouldn't know about this organization
|
||||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
||||||
return
|
return
|
||||||
|
@ -103,7 +103,7 @@ func Transfer(ctx *context.APIContext) {
|
||||||
ctx.Repo.GitRepo = nil
|
ctx.Repo.GitRepo = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil {
|
if err := repo_service.StartRepositoryTransfer(ctx.Doer, newOwner, ctx.Repo.Repository, teams); err != nil {
|
||||||
if models.IsErrRepoTransferInProgress(err) {
|
if models.IsErrRepoTransferInProgress(err) {
|
||||||
ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err)
|
ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err)
|
||||||
return
|
return
|
||||||
|
@ -218,7 +218,7 @@ func acceptOrRejectRepoTransfer(ctx *context.APIContext, accept bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !repoTransfer.CanUserAcceptTransfer(ctx.User) {
|
if !repoTransfer.CanUserAcceptTransfer(ctx.Doer) {
|
||||||
ctx.Error(http.StatusForbidden, "CanUserAcceptTransfer", nil)
|
ctx.Error(http.StatusForbidden, "CanUserAcceptTransfer", nil)
|
||||||
return fmt.Errorf("user does not have permissions to do this")
|
return fmt.Errorf("user does not have permissions to do this")
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
form.ContentBase64 = string(content)
|
form.ContentBase64 = string(content)
|
||||||
|
|
||||||
if err := wiki_service.AddWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
|
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
|
||||||
if models.IsErrWikiReservedName(err) {
|
if models.IsErrWikiReservedName(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
|
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
|
||||||
} else if models.IsErrWikiAlreadyExist(err) {
|
} else if models.IsErrWikiAlreadyExist(err) {
|
||||||
|
@ -144,7 +144,7 @@ func EditWikiPage(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
form.ContentBase64 = string(content)
|
form.ContentBase64 = string(content)
|
||||||
|
|
||||||
if err := wiki_service.EditWikiPage(ctx, ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
|
if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
|
ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
|
||||||
|
|
||||||
wikiName := wiki_service.NormalizeWikiName(ctx.Params(":pageName"))
|
wikiName := wiki_service.NormalizeWikiName(ctx.Params(":pageName"))
|
||||||
|
|
||||||
if err := wiki_service.DeleteWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName); err != nil {
|
if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil {
|
||||||
if err.Error() == "file does not exist" {
|
if err.Error() == "file does not exist" {
|
||||||
ctx.NotFound(err)
|
ctx.NotFound(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -45,7 +45,7 @@ func ListAccessTokens(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/AccessTokenList"
|
// "$ref": "#/responses/AccessTokenList"
|
||||||
|
|
||||||
opts := models.ListAccessTokensOptions{UserID: ctx.User.ID, ListOptions: utils.GetListOptions(ctx)}
|
opts := models.ListAccessTokensOptions{UserID: ctx.Doer.ID, ListOptions: utils.GetListOptions(ctx)}
|
||||||
|
|
||||||
count, err := models.CountAccessTokens(opts)
|
count, err := models.CountAccessTokens(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,7 +99,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
|
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
|
||||||
|
|
||||||
t := &models.AccessToken{
|
t := &models.AccessToken{
|
||||||
UID: ctx.User.ID,
|
UID: ctx.Doer.ID,
|
||||||
Name: form.Name,
|
Name: form.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||||
if tokenID == 0 {
|
if tokenID == 0 {
|
||||||
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{
|
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{
|
||||||
Name: token,
|
Name: token,
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err)
|
ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err)
|
||||||
|
@ -180,7 +180,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.DeleteAccessTokenByID(tokenID, ctx.User.ID); err != nil {
|
if err := models.DeleteAccessTokenByID(tokenID, ctx.Doer.ID); err != nil {
|
||||||
if models.IsErrAccessTokenNotExist(err) {
|
if models.IsErrAccessTokenNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
|
@ -215,7 +215,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
||||||
|
|
||||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RedirectURIs: data.RedirectURIs,
|
RedirectURIs: data.RedirectURIs,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -252,7 +252,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/OAuth2ApplicationList"
|
// "$ref": "#/responses/OAuth2ApplicationList"
|
||||||
|
|
||||||
apps, total, err := auth.ListOAuth2Applications(ctx.User.ID, utils.GetListOptions(ctx))
|
apps, total, err := auth.ListOAuth2Applications(ctx.Doer.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
|
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
|
||||||
return
|
return
|
||||||
|
@ -288,7 +288,7 @@ func DeleteOauth2Application(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
appID := ctx.ParamsInt64(":id")
|
appID := ctx.ParamsInt64(":id")
|
||||||
if err := auth.DeleteOAuth2Application(appID, ctx.User.ID); err != nil {
|
if err := auth.DeleteOAuth2Application(appID, ctx.Doer.ID); err != nil {
|
||||||
if auth.IsErrOAuthApplicationNotFound(err) {
|
if auth.IsErrOAuthApplicationNotFound(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,7 +365,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
||||||
|
|
||||||
app, err := auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{
|
app, err := auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
UserID: ctx.User.ID,
|
UserID: ctx.Doer.ID,
|
||||||
ID: appID,
|
ID: appID,
|
||||||
RedirectURIs: data.RedirectURIs,
|
RedirectURIs: data.RedirectURIs,
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@ func ListEmails(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/EmailList"
|
// "$ref": "#/responses/EmailList"
|
||||||
|
|
||||||
emails, err := user_model.GetEmailAddresses(ctx.User.ID)
|
emails, err := user_model.GetEmailAddresses(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
||||||
return
|
return
|
||||||
|
@ -71,7 +71,7 @@ func AddEmail(ctx *context.APIContext) {
|
||||||
emails := make([]*user_model.EmailAddress, len(form.Emails))
|
emails := make([]*user_model.EmailAddress, len(form.Emails))
|
||||||
for i := range form.Emails {
|
for i := range form.Emails {
|
||||||
emails[i] = &user_model.EmailAddress{
|
emails[i] = &user_model.EmailAddress{
|
||||||
UID: ctx.User.ID,
|
UID: ctx.Doer.ID,
|
||||||
Email: form.Emails[i],
|
Email: form.Emails[i],
|
||||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func DeleteEmail(ctx *context.APIContext) {
|
||||||
for i := range form.Emails {
|
for i := range form.Emails {
|
||||||
emails[i] = &user_model.EmailAddress{
|
emails[i] = &user_model.EmailAddress{
|
||||||
Email: form.Emails[i],
|
Email: form.Emails[i],
|
||||||
UID: ctx.User.ID,
|
UID: ctx.Doer.ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
|
func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
|
||||||
apiUsers := make([]*api.User, len(users))
|
apiUsers := make([]*api.User, len(users))
|
||||||
for i := range users {
|
for i := range users {
|
||||||
apiUsers[i] = convert.ToUser(users[i], ctx.User)
|
apiUsers[i] = convert.ToUser(users[i], ctx.Doer)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, &apiUsers)
|
ctx.JSON(http.StatusOK, &apiUsers)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func ListMyFollowers(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/UserList"
|
// "$ref": "#/responses/UserList"
|
||||||
|
|
||||||
listUserFollowers(ctx, ctx.User)
|
listUserFollowers(ctx, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFollowers list the given user's followers
|
// ListFollowers list the given user's followers
|
||||||
|
@ -120,7 +120,7 @@ func ListMyFollowing(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/UserList"
|
// "$ref": "#/responses/UserList"
|
||||||
|
|
||||||
listUserFollowing(ctx, ctx.User)
|
listUserFollowing(ctx, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFollowing list the users that the given user is following
|
// ListFollowing list the users that the given user is following
|
||||||
|
@ -184,7 +184,7 @@ func CheckMyFollowing(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
checkUserFollowing(ctx, ctx.User, target.ID)
|
checkUserFollowing(ctx, ctx.Doer, target.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckFollowing check if one user is following another user
|
// CheckFollowing check if one user is following another user
|
||||||
|
@ -239,7 +239,7 @@ func Follow(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := user_model.FollowUser(ctx.User.ID, target.ID); err != nil {
|
if err := user_model.FollowUser(ctx.Doer.ID, target.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func Unfollow(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := user_model.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
if err := user_model.UnfollowUser(ctx.Doer.ID, target.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ func ListMyGPGKeys(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/GPGKeyList"
|
// "$ref": "#/responses/GPGKeyList"
|
||||||
|
|
||||||
listGPGKeys(ctx, ctx.User.ID, utils.GetListOptions(ctx))
|
listGPGKeys(ctx, ctx.Doer.ID, utils.GetListOptions(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGPGKey get the GPG key based on a id
|
// GetGPGKey get the GPG key based on a id
|
||||||
|
@ -128,8 +128,8 @@ func GetGPGKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
// CreateUserGPGKey creates new GPG key to given user by ID.
|
// CreateUserGPGKey creates new GPG key to given user by ID.
|
||||||
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
|
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
|
||||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||||
lastToken := asymkey_model.VerificationToken(ctx.User, 0)
|
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
||||||
|
|
||||||
keys, err := asymkey_model.AddGPGKey(uid, form.ArmoredKey, token, form.Signature)
|
keys, err := asymkey_model.AddGPGKey(uid, form.ArmoredKey, token, form.Signature)
|
||||||
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
||||||
|
@ -156,7 +156,7 @@ func GetVerificationToken(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||||
ctx.PlainText(http.StatusOK, token)
|
ctx.PlainText(http.StatusOK, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,12 +178,12 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
|
|
||||||
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
|
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
|
||||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||||
lastToken := asymkey_model.VerificationToken(ctx.User, 0)
|
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
||||||
|
|
||||||
_, err := asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, token, form.Signature)
|
_, err := asymkey_model.VerifyGPGKey(ctx.Doer.ID, form.KeyID, token, form.Signature)
|
||||||
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
||||||
_, err = asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, lastToken, form.Signature)
|
_, err = asymkey_model.VerifyGPGKey(ctx.Doer.ID, form.KeyID, lastToken, form.Signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -230,7 +230,7 @@ func CreateGPGKey(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
|
|
||||||
form := web.GetForm(ctx).(*api.CreateGPGKeyOption)
|
form := web.GetForm(ctx).(*api.CreateGPGKeyOption)
|
||||||
CreateUserGPGKey(ctx, *form, ctx.User.ID)
|
CreateUserGPGKey(ctx, *form, ctx.Doer.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteGPGKey remove a GPG key belonging to the authenticated user
|
// DeleteGPGKey remove a GPG key belonging to the authenticated user
|
||||||
|
@ -255,7 +255,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := asymkey_model.DeleteGPGKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
if err := asymkey_model.DeleteGPGKey(ctx.Doer, ctx.ParamsInt64(":id")); err != nil {
|
||||||
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
|
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
|
||||||
apiKeys := make([]*api.PublicKey, len(keys))
|
apiKeys := make([]*api.PublicKey, len(keys))
|
||||||
for i := range keys {
|
for i := range keys {
|
||||||
apiKeys[i] = convert.ToPublicKey(apiLink, keys[i])
|
apiKeys[i] = convert.ToPublicKey(apiLink, keys[i])
|
||||||
if ctx.User.IsAdmin || ctx.User.ID == keys[i].OwnerID {
|
if ctx.Doer.IsAdmin || ctx.Doer.ID == keys[i].OwnerID {
|
||||||
apiKeys[i], _ = appendPrivateInformation(apiKeys[i], keys[i], user)
|
apiKeys[i], _ = appendPrivateInformation(apiKeys[i], keys[i], user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func ListMyPublicKeys(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/PublicKeyList"
|
// "$ref": "#/responses/PublicKeyList"
|
||||||
|
|
||||||
listPublicKeys(ctx, ctx.User)
|
listPublicKeys(ctx, ctx.Doer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPublicKeys list the given user's public keys
|
// ListPublicKeys list the given user's public keys
|
||||||
|
@ -190,8 +190,8 @@ func GetPublicKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiLink := composePublicKeysAPILink()
|
apiLink := composePublicKeysAPILink()
|
||||||
apiKey := convert.ToPublicKey(apiLink, key)
|
apiKey := convert.ToPublicKey(apiLink, key)
|
||||||
if ctx.User.IsAdmin || ctx.User.ID == key.OwnerID {
|
if ctx.Doer.IsAdmin || ctx.Doer.ID == key.OwnerID {
|
||||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.User)
|
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Doer)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiKey)
|
ctx.JSON(http.StatusOK, apiKey)
|
||||||
}
|
}
|
||||||
|
@ -211,8 +211,8 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
|
||||||
}
|
}
|
||||||
apiLink := composePublicKeysAPILink()
|
apiLink := composePublicKeysAPILink()
|
||||||
apiKey := convert.ToPublicKey(apiLink, key)
|
apiKey := convert.ToPublicKey(apiLink, key)
|
||||||
if ctx.User.IsAdmin || ctx.User.ID == key.OwnerID {
|
if ctx.Doer.IsAdmin || ctx.Doer.ID == key.OwnerID {
|
||||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.User)
|
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Doer)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, apiKey)
|
ctx.JSON(http.StatusCreated, apiKey)
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ func CreatePublicKey(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
|
|
||||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||||
CreateUserPublicKey(ctx, *form, ctx.User.ID)
|
CreateUserPublicKey(ctx, *form, ctx.Doer.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePublicKey delete one public key
|
// DeletePublicKey delete one public key
|
||||||
|
@ -272,7 +272,7 @@ func DeletePublicKey(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
|
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := asymkey_service.DeletePublicKey(ctx.User, id); err != nil {
|
if err := asymkey_service.DeletePublicKey(ctx.Doer, id); err != nil {
|
||||||
if asymkey_model.IsErrKeyNotExist(err) {
|
if asymkey_model.IsErrKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else if asymkey_model.IsErrKeyAccessDenied(err) {
|
} else if asymkey_model.IsErrKeyAccessDenied(err) {
|
||||||
|
|
|
@ -39,12 +39,12 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
|
||||||
|
|
||||||
apiRepos := make([]*api.Repository, 0, len(repos))
|
apiRepos := make([]*api.Repository, 0, len(repos))
|
||||||
for i := range repos {
|
for i := range repos {
|
||||||
access, err := models.AccessLevel(ctx.User, repos[i])
|
access, err := models.AccessLevel(ctx.Doer, repos[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.IsSigned && ctx.User.IsAdmin || access >= perm.AccessModeRead {
|
if ctx.IsSigned && ctx.Doer.IsAdmin || access >= perm.AccessModeRead {
|
||||||
apiRepos = append(apiRepos, convert.ToRepo(repos[i], access))
|
apiRepos = append(apiRepos, convert.ToRepo(repos[i], access))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
opts := &models.SearchRepoOptions{
|
opts := &models.SearchRepoOptions{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
OwnerID: ctx.User.ID,
|
OwnerID: ctx.Doer.ID,
|
||||||
Private: ctx.IsSigned,
|
Private: ctx.IsSigned,
|
||||||
IncludeDescription: true,
|
IncludeDescription: true,
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
|
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessMode, err := models.AccessLevel(ctx.User, repo)
|
accessMode, err := models.AccessLevel(ctx.Doer, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func GetUserSettings(ctx *context.APIContext) {
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/UserSettings"
|
// "$ref": "#/responses/UserSettings"
|
||||||
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.User))
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserSettings returns user settings
|
// UpdateUserSettings returns user settings
|
||||||
|
@ -46,38 +46,38 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
||||||
|
|
||||||
if form.FullName != nil {
|
if form.FullName != nil {
|
||||||
ctx.User.FullName = *form.FullName
|
ctx.Doer.FullName = *form.FullName
|
||||||
}
|
}
|
||||||
if form.Description != nil {
|
if form.Description != nil {
|
||||||
ctx.User.Description = *form.Description
|
ctx.Doer.Description = *form.Description
|
||||||
}
|
}
|
||||||
if form.Website != nil {
|
if form.Website != nil {
|
||||||
ctx.User.Website = *form.Website
|
ctx.Doer.Website = *form.Website
|
||||||
}
|
}
|
||||||
if form.Location != nil {
|
if form.Location != nil {
|
||||||
ctx.User.Location = *form.Location
|
ctx.Doer.Location = *form.Location
|
||||||
}
|
}
|
||||||
if form.Language != nil {
|
if form.Language != nil {
|
||||||
ctx.User.Language = *form.Language
|
ctx.Doer.Language = *form.Language
|
||||||
}
|
}
|
||||||
if form.Theme != nil {
|
if form.Theme != nil {
|
||||||
ctx.User.Theme = *form.Theme
|
ctx.Doer.Theme = *form.Theme
|
||||||
}
|
}
|
||||||
if form.DiffViewStyle != nil {
|
if form.DiffViewStyle != nil {
|
||||||
ctx.User.DiffViewStyle = *form.DiffViewStyle
|
ctx.Doer.DiffViewStyle = *form.DiffViewStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.HideEmail != nil {
|
if form.HideEmail != nil {
|
||||||
ctx.User.KeepEmailPrivate = *form.HideEmail
|
ctx.Doer.KeepEmailPrivate = *form.HideEmail
|
||||||
}
|
}
|
||||||
if form.HideActivity != nil {
|
if form.HideActivity != nil {
|
||||||
ctx.User.KeepActivityPrivate = *form.HideActivity
|
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_model.UpdateUser(ctx.User, false); err != nil {
|
if err := user_model.UpdateUser(ctx.Doer, false); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.User))
|
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func GetStarredRepos(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/RepositoryList"
|
// "$ref": "#/responses/RepositoryList"
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
private := user.ID == ctx.User.ID
|
private := user.ID == ctx.Doer.ID
|
||||||
repos, err := getStarredRepos(user, private, utils.GetListOptions(ctx))
|
repos, err := getStarredRepos(user, private, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||||
|
@ -94,12 +94,12 @@ func GetMyStarredRepos(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/RepositoryList"
|
// "$ref": "#/responses/RepositoryList"
|
||||||
|
|
||||||
repos, err := getStarredRepos(ctx.User, true, utils.GetListOptions(ctx))
|
repos, err := getStarredRepos(ctx.Doer, true, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(int64(ctx.User.NumStars))
|
ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars))
|
||||||
ctx.JSON(http.StatusOK, &repos)
|
ctx.JSON(http.StatusOK, &repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ func IsStarring(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if repo_model.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) {
|
if repo_model.IsStaring(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
|
@ -152,7 +152,7 @@ func Star(ctx *context.APIContext) {
|
||||||
// "204":
|
// "204":
|
||||||
// "$ref": "#/responses/empty"
|
// "$ref": "#/responses/empty"
|
||||||
|
|
||||||
err := repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
err := repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -180,7 +180,7 @@ func Unstar(ctx *context.APIContext) {
|
||||||
// "204":
|
// "204":
|
||||||
// "$ref": "#/responses/empty"
|
// "$ref": "#/responses/empty"
|
||||||
|
|
||||||
err := repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
err := repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -56,7 +56,7 @@ func Search(ctx *context.APIContext) {
|
||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Keyword: ctx.FormTrim("q"),
|
Keyword: ctx.FormTrim("q"),
|
||||||
UID: ctx.FormInt64("uid"),
|
UID: ctx.FormInt64("uid"),
|
||||||
Type: user_model.UserTypeIndividual,
|
Type: user_model.UserTypeIndividual,
|
||||||
|
@ -75,7 +75,7 @@ func Search(ctx *context.APIContext) {
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||||
"ok": true,
|
"ok": true,
|
||||||
"data": convert.ToUsers(ctx.User, users),
|
"data": convert.ToUsers(ctx.Doer, users),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +104,12 @@ func GetInfo(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !models.IsUserVisibleToViewer(u, ctx.User) {
|
if !models.IsUserVisibleToViewer(u, ctx.Doer) {
|
||||||
// fake ErrUserNotExist error message to not leak information about existence
|
// fake ErrUserNotExist error message to not leak information about existence
|
||||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuthenticatedUser get current user's information
|
// GetAuthenticatedUser get current user's information
|
||||||
|
@ -123,7 +123,7 @@ func GetAuthenticatedUser(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/User"
|
// "$ref": "#/responses/User"
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx.User, ctx.User))
|
ctx.JSON(http.StatusOK, convert.ToUser(ctx.Doer, ctx.Doer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserHeatmapData is the handler to get a users heatmap
|
// GetUserHeatmapData is the handler to get a users heatmap
|
||||||
|
@ -150,7 +150,7 @@ func GetUserHeatmapData(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
heatmap, err := models.GetUserHeatmapDataByUser(user, ctx.User)
|
heatmap, err := models.GetUserHeatmapDataByUser(user, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
|
ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -61,7 +61,7 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/RepositoryList"
|
// "$ref": "#/responses/RepositoryList"
|
||||||
|
|
||||||
user := GetUserByParams(ctx)
|
user := GetUserByParams(ctx)
|
||||||
private := user.ID == ctx.User.ID
|
private := user.ID == ctx.Doer.ID
|
||||||
repos, total, err := getWatchedRepos(user, private, utils.GetListOptions(ctx))
|
repos, total, err := getWatchedRepos(user, private, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||||
|
@ -91,7 +91,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/RepositoryList"
|
// "$ref": "#/responses/RepositoryList"
|
||||||
|
|
||||||
repos, total, err := getWatchedRepos(ctx.User, true, utils.GetListOptions(ctx))
|
repos, total, err := getWatchedRepos(ctx.Doer, true, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func IsWatching(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// description: User is not watching this repo or repo do not exist
|
// description: User is not watching this repo or repo do not exist
|
||||||
|
|
||||||
if repo_model.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
|
if repo_model.IsWatching(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||||
Subscribed: true,
|
Subscribed: true,
|
||||||
Ignored: false,
|
Ignored: false,
|
||||||
|
@ -157,7 +157,7 @@ func Watch(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/WatchInfo"
|
// "$ref": "#/responses/WatchInfo"
|
||||||
|
|
||||||
err := repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -192,7 +192,7 @@ func Unwatch(ctx *context.APIContext) {
|
||||||
// "204":
|
// "204":
|
||||||
// "$ref": "#/responses/empty"
|
// "$ref": "#/responses/empty"
|
||||||
|
|
||||||
err := repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -149,7 +149,7 @@ func DashboardPost(ctx *context.Context) {
|
||||||
if form.Op != "" {
|
if form.Op != "" {
|
||||||
task := cron.GetTask(form.Op)
|
task := cron.GetTask(form.Op)
|
||||||
if task != nil {
|
if task != nil {
|
||||||
go task.RunWithUser(ctx.User, nil)
|
go task.RunWithUser(ctx.Doer, nil)
|
||||||
ctx.Flash.Success(ctx.Tr("admin.dashboard.task.started", ctx.Tr("admin.dashboard."+form.Op)))
|
ctx.Flash.Success(ctx.Tr("admin.dashboard.task.started", ctx.Tr("admin.dashboard."+form.Op)))
|
||||||
} else {
|
} else {
|
||||||
ctx.Flash.Error(ctx.Tr("admin.dashboard.task.unknown", form.Op))
|
ctx.Flash.Error(ctx.Tr("admin.dashboard.task.unknown", form.Op))
|
||||||
|
|
|
@ -310,7 +310,7 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("Authentication created by admin(%s): %s", ctx.User.Name, form.Name)
|
log.Trace("Authentication created by admin(%s): %s", ctx.Doer.Name, form.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.auths.new_success", form.Name))
|
ctx.Flash.Success(ctx.Tr("admin.auths.new_success", form.Name))
|
||||||
ctx.Redirect(setting.AppSubURL + "/admin/auths")
|
ctx.Redirect(setting.AppSubURL + "/admin/auths")
|
||||||
|
@ -413,7 +413,7 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Authentication changed by admin(%s): %d", ctx.User.Name, source.ID)
|
log.Trace("Authentication changed by admin(%s): %d", ctx.Doer.Name, source.ID)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
|
ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
|
||||||
ctx.Redirect(setting.AppSubURL + "/admin/auths/" + strconv.FormatInt(form.ID, 10))
|
ctx.Redirect(setting.AppSubURL + "/admin/auths/" + strconv.FormatInt(form.ID, 10))
|
||||||
|
@ -438,7 +438,7 @@ func DeleteAuthSource(ctx *context.Context) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Authentication deleted by admin(%s): %d", ctx.User.Name, source.ID)
|
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||||
|
|
|
@ -87,7 +87,7 @@ func Emails(ctx *context.Context) {
|
||||||
emails[i].SearchEmailResult = *baseEmails[i]
|
emails[i].SearchEmailResult = *baseEmails[i]
|
||||||
// Don't let the admin deactivate its own primary email address
|
// Don't let the admin deactivate its own primary email address
|
||||||
// We already know the user is admin
|
// We already know the user is admin
|
||||||
emails[i].CanChange = ctx.User.ID != emails[i].UID || !emails[i].IsPrimary
|
emails[i].CanChange = ctx.Doer.ID != emails[i].UID || !emails[i].IsPrimary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Data["Keyword"] = opts.Keyword
|
ctx.Data["Keyword"] = opts.Keyword
|
||||||
|
|
|
@ -73,7 +73,7 @@ func EmptyNotices(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.User.Name, 0)
|
log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.Doer.Name, 0)
|
||||||
ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
|
ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
|
||||||
ctx.Redirect(setting.AppSubURL + "/admin/notices")
|
ctx.Redirect(setting.AppSubURL + "/admin/notices")
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func Organizations(ctx *context.Context) {
|
||||||
ctx.Data["PageIsAdminOrganizations"] = true
|
ctx.Data["PageIsAdminOrganizations"] = true
|
||||||
|
|
||||||
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeOrganization,
|
Type: user_model.UserTypeOrganization,
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
PageSize: setting.UI.Admin.OrgPagingNum,
|
PageSize: setting.UI.Admin.OrgPagingNum,
|
||||||
|
|
|
@ -52,7 +52,7 @@ func DeleteRepo(ctx *context.Context) {
|
||||||
ctx.Repo.GitRepo.Close()
|
ctx.Repo.GitRepo.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteRepository(ctx, ctx.User, repo, true); err != nil {
|
if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil {
|
||||||
ctx.ServerError("DeleteRepository", err)
|
ctx.ServerError("DeleteRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
||||||
if has || !isDir {
|
if has || !isDir {
|
||||||
// Fallthrough to failure mode
|
// Fallthrough to failure mode
|
||||||
} else if action == "adopt" {
|
} else if action == "adopt" {
|
||||||
if _, err := repo_service.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
|
if _, err := repo_service.AdoptRepository(ctx.Doer, ctxUser, models.CreateRepoOptions{
|
||||||
Name: dirSplit[1],
|
Name: dirSplit[1],
|
||||||
IsPrivate: true,
|
IsPrivate: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -157,7 +157,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
ctx.Flash.Success(ctx.Tr("repo.adopt_preexisting_success", dir))
|
ctx.Flash.Success(ctx.Tr("repo.adopt_preexisting_success", dir))
|
||||||
} else if action == "delete" {
|
} else if action == "delete" {
|
||||||
if err := repo_service.DeleteUnadoptedRepository(ctx.User, ctxUser, dirSplit[1]); err != nil {
|
if err := repo_service.DeleteUnadoptedRepository(ctx.Doer, ctxUser, dirSplit[1]); err != nil {
|
||||||
ctx.ServerError("repository.AdoptRepository", err)
|
ctx.ServerError("repository.AdoptRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ func Users(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeIndividual,
|
Type: user_model.UserTypeIndividual,
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
PageSize: setting.UI.Admin.UserPagingNum,
|
PageSize: setting.UI.Admin.UserPagingNum,
|
||||||
|
@ -191,7 +191,7 @@ func NewUserPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account created by admin (%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
// Send email notification.
|
// Send email notification.
|
||||||
if form.SendNotify {
|
if form.SendNotify {
|
||||||
|
@ -379,7 +379,7 @@ func EditUserPost(ctx *context.Context) {
|
||||||
u.Visibility = form.Visibility
|
u.Visibility = form.Visibility
|
||||||
|
|
||||||
// skip self Prohibit Login
|
// skip self Prohibit Login
|
||||||
if ctx.User.ID == u.ID {
|
if ctx.Doer.ID == u.ID {
|
||||||
u.ProhibitLogin = false
|
u.ProhibitLogin = false
|
||||||
} else {
|
} else {
|
||||||
u.ProhibitLogin = form.ProhibitLogin
|
u.ProhibitLogin = form.ProhibitLogin
|
||||||
|
@ -398,7 +398,7 @@ func EditUserPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account profile updated by admin (%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success"))
|
ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success"))
|
||||||
ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid")))
|
ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid")))
|
||||||
|
@ -429,7 +429,7 @@ func DeleteUser(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("Account deleted by admin (%s): %s", ctx.User.Name, u.Name)
|
log.Trace("Account deleted by admin (%s): %s", ctx.Doer.Name, u.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("admin.users.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("admin.users.deletion_success"))
|
||||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
|
||||||
ID: 2,
|
ID: 2,
|
||||||
}).(*user_model.User)
|
}).(*user_model.User)
|
||||||
|
|
||||||
ctx.User = u
|
ctx.Doer = u
|
||||||
|
|
||||||
username := "gitea"
|
username := "gitea"
|
||||||
email := "gitea@gitea.io"
|
email := "gitea@gitea.io"
|
||||||
|
@ -64,7 +64,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
|
||||||
ID: 2,
|
ID: 2,
|
||||||
}).(*user_model.User)
|
}).(*user_model.User)
|
||||||
|
|
||||||
ctx.User = u
|
ctx.Doer = u
|
||||||
|
|
||||||
username := "gitea"
|
username := "gitea"
|
||||||
email := "gitea@gitea.io"
|
email := "gitea@gitea.io"
|
||||||
|
@ -101,7 +101,7 @@ func TestNewUserPost_InvalidEmail(t *testing.T) {
|
||||||
ID: 2,
|
ID: 2,
|
||||||
}).(*user_model.User)
|
}).(*user_model.User)
|
||||||
|
|
||||||
ctx.User = u
|
ctx.Doer = u
|
||||||
|
|
||||||
username := "gitea"
|
username := "gitea"
|
||||||
email := "gitea@gitea.io\r\n"
|
email := "gitea@gitea.io\r\n"
|
||||||
|
@ -131,7 +131,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
|
||||||
ID: 2,
|
ID: 2,
|
||||||
}).(*user_model.User)
|
}).(*user_model.User)
|
||||||
|
|
||||||
ctx.User = u
|
ctx.Doer = u
|
||||||
|
|
||||||
username := "gitea"
|
username := "gitea"
|
||||||
email := "gitea@gitea.io"
|
email := "gitea@gitea.io"
|
||||||
|
@ -169,7 +169,7 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) {
|
||||||
ID: 2,
|
ID: 2,
|
||||||
}).(*user_model.User)
|
}).(*user_model.User)
|
||||||
|
|
||||||
ctx.User = u
|
ctx.Doer = u
|
||||||
|
|
||||||
username := "gitea"
|
username := "gitea"
|
||||||
email := "gitea@gitea.io"
|
email := "gitea@gitea.io"
|
||||||
|
|
|
@ -393,8 +393,8 @@ func HandleSignOut(ctx *context.Context) {
|
||||||
|
|
||||||
// SignOut sign out from login status
|
// SignOut sign out from login status
|
||||||
func SignOut(ctx *context.Context) {
|
func SignOut(ctx *context.Context) {
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
eventsource.GetManager().SendMessageBlocking(ctx.User.ID, &eventsource.Event{
|
eventsource.GetManager().SendMessageBlocking(ctx.Doer.ID, &eventsource.Event{
|
||||||
Name: "logout",
|
Name: "logout",
|
||||||
Data: ctx.Session.ID(),
|
Data: ctx.Session.ID(),
|
||||||
})
|
})
|
||||||
|
@ -649,19 +649,19 @@ func Activate(ctx *context.Context) {
|
||||||
|
|
||||||
if len(code) == 0 {
|
if len(code) == 0 {
|
||||||
ctx.Data["IsActivatePage"] = true
|
ctx.Data["IsActivatePage"] = true
|
||||||
if ctx.User == nil || ctx.User.IsActive {
|
if ctx.Doer == nil || ctx.Doer.IsActive {
|
||||||
ctx.NotFound("invalid user", nil)
|
ctx.NotFound("invalid user", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Resend confirmation email.
|
// Resend confirmation email.
|
||||||
if setting.Service.RegisterEmailConfirm {
|
if setting.Service.RegisterEmailConfirm {
|
||||||
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
|
if ctx.Cache.IsExist("MailResendLimit_" + ctx.Doer.LowerName) {
|
||||||
ctx.Data["ResendLimited"] = true
|
ctx.Data["ResendLimited"] = true
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
|
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())
|
||||||
mailer.SendActivateAccountMail(ctx.Locale, ctx.User)
|
mailer.SendActivateAccountMail(ctx.Locale, ctx.Doer)
|
||||||
|
|
||||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil {
|
||||||
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
log.Error("Set cache(MailResendLimit) fail: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,21 +267,21 @@ type userInfoResponse struct {
|
||||||
|
|
||||||
// InfoOAuth manages request for userinfo endpoint
|
// InfoOAuth manages request for userinfo endpoint
|
||||||
func InfoOAuth(ctx *context.Context) {
|
func InfoOAuth(ctx *context.Context) {
|
||||||
if ctx.User == nil || ctx.Data["AuthedMethod"] != (&auth_service.OAuth2{}).Name() {
|
if ctx.Doer == nil || ctx.Data["AuthedMethod"] != (&auth_service.OAuth2{}).Name() {
|
||||||
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm=""`)
|
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm=""`)
|
||||||
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
|
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response := &userInfoResponse{
|
response := &userInfoResponse{
|
||||||
Sub: fmt.Sprint(ctx.User.ID),
|
Sub: fmt.Sprint(ctx.Doer.ID),
|
||||||
Name: ctx.User.FullName,
|
Name: ctx.Doer.FullName,
|
||||||
Username: ctx.User.Name,
|
Username: ctx.Doer.Name,
|
||||||
Email: ctx.User.Email,
|
Email: ctx.Doer.Email,
|
||||||
Picture: ctx.User.AvatarLink(),
|
Picture: ctx.Doer.AvatarLink(),
|
||||||
}
|
}
|
||||||
|
|
||||||
groups, err := getOAuthGroupsForUser(ctx.User)
|
groups, err := getOAuthGroupsForUser(ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Oauth groups for user", err)
|
ctx.ServerError("Oauth groups for user", err)
|
||||||
return
|
return
|
||||||
|
@ -317,7 +317,7 @@ func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
|
||||||
|
|
||||||
// IntrospectOAuth introspects an oauth token
|
// IntrospectOAuth introspects an oauth token
|
||||||
func IntrospectOAuth(ctx *context.Context) {
|
func IntrospectOAuth(ctx *context.Context) {
|
||||||
if ctx.User == nil {
|
if ctx.Doer == nil {
|
||||||
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm=""`)
|
ctx.Resp.Header().Set("WWW-Authenticate", `Bearer realm=""`)
|
||||||
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
|
ctx.PlainText(http.StatusUnauthorized, "no valid authorization")
|
||||||
return
|
return
|
||||||
|
@ -438,7 +438,7 @@ func AuthorizeOAuth(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
grant, err := app.GetGrantByUserID(ctx.User.ID)
|
grant, err := app.GetGrantByUserID(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleServerError(ctx, form.State, form.RedirectURI)
|
handleServerError(ctx, form.State, form.RedirectURI)
|
||||||
return
|
return
|
||||||
|
@ -515,7 +515,7 @@ func GrantApplicationOAuth(ctx *context.Context) {
|
||||||
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
|
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
grant, err := app.CreateGrant(ctx.User.ID, form.Scope)
|
grant, err := app.CreateGrant(ctx.Doer.ID, form.Scope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleAuthorizeError(ctx, AuthorizeError{
|
handleAuthorizeError(ctx, AuthorizeError{
|
||||||
State: form.State,
|
State: form.State,
|
||||||
|
|
|
@ -103,7 +103,7 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
|
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
|
||||||
ctx.Data["Code"] = code
|
ctx.Data["Code"] = code
|
||||||
|
|
||||||
if nil != ctx.User {
|
if nil != ctx.Doer {
|
||||||
ctx.Data["user_signed_in"] = true
|
ctx.Data["user_signed_in"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ func commonResetPassword(ctx *context.Context) (*user_model.User, *auth.TwoFacto
|
||||||
// Show the user that they are affecting the account that they intended to
|
// Show the user that they are affecting the account that they intended to
|
||||||
ctx.Data["user_email"] = u.Email
|
ctx.Data["user_email"] = u.Email
|
||||||
|
|
||||||
if nil != ctx.User && u.ID != ctx.User.ID {
|
if nil != ctx.Doer && u.ID != ctx.Doer.ID {
|
||||||
ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email))
|
ctx.Flash.Error(ctx.Tr("auth.reset_password_wrong_user", ctx.Doer.Email, u.Email))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ func MustChangePasswordPost(ctx *context.Context) {
|
||||||
ctx.HTML(http.StatusOK, tplMustChangePassword)
|
ctx.HTML(http.StatusOK, tplMustChangePassword)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := ctx.User
|
u := ctx.Doer
|
||||||
// Make sure only requests for users who are eligible to change their password via
|
// Make sure only requests for users who are eligible to change their password via
|
||||||
// this method passes through
|
// this method passes through
|
||||||
if !u.MustChangePassword {
|
if !u.MustChangePassword {
|
||||||
|
|
|
@ -48,7 +48,7 @@ func Events(ctx *context.Context) {
|
||||||
|
|
||||||
shutdownCtx := graceful.GetManager().ShutdownContext()
|
shutdownCtx := graceful.GetManager().ShutdownContext()
|
||||||
|
|
||||||
uid := ctx.User.ID
|
uid := ctx.Doer.ID
|
||||||
|
|
||||||
messageChan := eventsource.GetManager().Register(uid)
|
messageChan := eventsource.GetManager().Register(uid)
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ loop:
|
||||||
}
|
}
|
||||||
_, err := event.WriteTo(ctx.Resp)
|
_, err := event.WriteTo(ctx.Resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to write to EventStream for user %s: %v", ctx.User.Name, err)
|
log.Error("Unable to write to EventStream for user %s: %v", ctx.Doer.Name, err)
|
||||||
go unregister()
|
go unregister()
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ loop:
|
||||||
go unregister()
|
go unregister()
|
||||||
break loop
|
break loop
|
||||||
case <-stopwatchTimer.C:
|
case <-stopwatchTimer.C:
|
||||||
sws, err := models.GetUserStopwatches(ctx.User.ID, db.ListOptions{})
|
sws, err := models.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to GetUserStopwatches: %v", err)
|
log.Error("Unable to GetUserStopwatches: %v", err)
|
||||||
continue
|
continue
|
||||||
|
@ -114,7 +114,7 @@ loop:
|
||||||
Data: string(dataBs),
|
Data: string(dataBs),
|
||||||
}).WriteTo(ctx.Resp)
|
}).WriteTo(ctx.Resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to write to EventStream for user %s: %v", ctx.User.Name, err)
|
log.Error("Unable to write to EventStream for user %s: %v", ctx.Doer.Name, err)
|
||||||
go unregister()
|
go unregister()
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ loop:
|
||||||
|
|
||||||
_, err := event.WriteTo(ctx.Resp)
|
_, err := event.WriteTo(ctx.Resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to write to EventStream for user %s: %v", ctx.User.Name, err)
|
log.Error("Unable to write to EventStream for user %s: %v", ctx.Doer.Name, err)
|
||||||
go unregister()
|
go unregister()
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,13 @@ func Code(ctx *context.Context) {
|
||||||
err error
|
err error
|
||||||
isAdmin bool
|
isAdmin bool
|
||||||
)
|
)
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
isAdmin = ctx.User.IsAdmin
|
isAdmin = ctx.Doer.IsAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
// guest user or non-admin user
|
// guest user or non-admin user
|
||||||
if ctx.User == nil || !isAdmin {
|
if ctx.Doer == nil || !isAdmin {
|
||||||
repoIDs, err = models.FindUserAccessibleRepoIDs(ctx.User)
|
repoIDs, err = models.FindUserAccessibleRepoIDs(ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchResults", err)
|
ctx.ServerError("SearchResults", err)
|
||||||
return
|
return
|
||||||
|
@ -69,7 +69,7 @@ func Code(ctx *context.Context) {
|
||||||
)
|
)
|
||||||
|
|
||||||
// if non-admin login user, we need check UnitTypeCode at first
|
// if non-admin login user, we need check UnitTypeCode at first
|
||||||
if ctx.User != nil && len(repoIDs) > 0 {
|
if ctx.Doer != nil && len(repoIDs) > 0 {
|
||||||
repoMaps, err := repo_model.GetRepositoriesMapByIDs(repoIDs)
|
repoMaps, err := repo_model.GetRepositoriesMapByIDs(repoIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchResults", err)
|
ctx.ServerError("SearchResults", err)
|
||||||
|
@ -79,7 +79,7 @@ func Code(ctx *context.Context) {
|
||||||
rightRepoMap := make(map[int64]*repo_model.Repository, len(repoMaps))
|
rightRepoMap := make(map[int64]*repo_model.Repository, len(repoMaps))
|
||||||
repoIDs = make([]int64, 0, len(repoMaps))
|
repoIDs = make([]int64, 0, len(repoMaps))
|
||||||
for id, repo := range repoMaps {
|
for id, repo := range repoMaps {
|
||||||
if models.CheckRepoUnitUser(repo, ctx.User, unit.TypeCode) {
|
if models.CheckRepoUnitUser(repo, ctx.Doer, unit.TypeCode) {
|
||||||
rightRepoMap[id] = repo
|
rightRepoMap[id] = repo
|
||||||
repoIDs = append(repoIDs, id)
|
repoIDs = append(repoIDs, id)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ func Code(ctx *context.Context) {
|
||||||
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
|
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
|
||||||
}
|
}
|
||||||
// if non-login user or isAdmin, no need to check UnitTypeCode
|
// if non-login user or isAdmin, no need to check UnitTypeCode
|
||||||
} else if (ctx.User == nil && len(repoIDs) > 0) || isAdmin {
|
} else if (ctx.Doer == nil && len(repoIDs) > 0) || isAdmin {
|
||||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if code_indexer.IsAvailable() {
|
if code_indexer.IsAvailable() {
|
||||||
|
|
|
@ -27,12 +27,12 @@ func Organizations(ctx *context.Context) {
|
||||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||||
|
|
||||||
visibleTypes := []structs.VisibleType{structs.VisibleTypePublic}
|
visibleTypes := []structs.VisibleType{structs.VisibleTypePublic}
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate)
|
visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeOrganization,
|
Type: user_model.UserTypeOrganization,
|
||||||
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
|
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
|
||||||
Visible: visibleTypes,
|
Visible: visibleTypes,
|
||||||
|
|
|
@ -86,7 +86,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: opts.PageSize,
|
PageSize: opts.PageSize,
|
||||||
},
|
},
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
OrderBy: orderBy,
|
OrderBy: orderBy,
|
||||||
Private: opts.Private,
|
Private: opts.Private,
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
|
@ -124,14 +124,14 @@ func Repos(ctx *context.Context) {
|
||||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||||
|
|
||||||
var ownerID int64
|
var ownerID int64
|
||||||
if ctx.User != nil && !ctx.User.IsAdmin {
|
if ctx.Doer != nil && !ctx.Doer.IsAdmin {
|
||||||
ownerID = ctx.User.ID
|
ownerID = ctx.Doer.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderRepoSearch(ctx, &RepoSearchOptions{
|
RenderRepoSearch(ctx, &RepoSearchOptions{
|
||||||
PageSize: setting.UI.ExplorePagingNum,
|
PageSize: setting.UI.ExplorePagingNum,
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
Private: ctx.User != nil,
|
Private: ctx.Doer != nil,
|
||||||
TplName: tplExploreRepos,
|
TplName: tplExploreRepos,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ func Users(ctx *context.Context) {
|
||||||
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||||
|
|
||||||
RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
RenderUserSearch(ctx, &user_model.SearchUserOptions{
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Type: user_model.UserTypeIndividual,
|
Type: user_model.UserTypeIndividual,
|
||||||
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
|
ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum},
|
||||||
IsActive: util.OptionalBoolTrue,
|
IsActive: util.OptionalBoolTrue,
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType string) {
|
func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType string) {
|
||||||
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
|
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
|
||||||
RequestedUser: ctxUser,
|
RequestedUser: ctxUser,
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
IncludePrivate: false,
|
IncludePrivate: false,
|
||||||
OnlyPerformedBy: !ctxUser.IsOrganization(),
|
OnlyPerformedBy: !ctxUser.IsOrganization(),
|
||||||
IncludeDeleted: false,
|
IncludeDeleted: false,
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
func ShowRepoFeed(ctx *context.Context, repo *repo_model.Repository, formatType string) {
|
func ShowRepoFeed(ctx *context.Context, repo *repo_model.Repository, formatType string) {
|
||||||
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
|
actions, err := models.GetFeeds(ctx, models.GetFeedsOptions{
|
||||||
RequestedRepo: repo,
|
RequestedRepo: repo,
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
IncludePrivate: true,
|
IncludePrivate: true,
|
||||||
Date: ctx.FormString("date"),
|
Date: ctx.FormString("date"),
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,14 +25,14 @@ const (
|
||||||
// Home render home page
|
// Home render home page
|
||||||
func Home(ctx *context.Context) {
|
func Home(ctx *context.Context) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
if !ctx.Doer.IsActive && setting.Service.RegisterEmailConfirm {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
||||||
ctx.HTML(http.StatusOK, auth.TplActivate)
|
ctx.HTML(http.StatusOK, auth.TplActivate)
|
||||||
} else if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
} else if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
||||||
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
log.Info("Failed authentication attempt for %s from %s", ctx.Doer.Name, ctx.RemoteAddr())
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
||||||
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
|
||||||
} else if ctx.User.MustChangePassword {
|
} else if ctx.Doer.MustChangePassword {
|
||||||
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
||||||
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
||||||
middleware.SetRedirectToCookie(ctx.Resp, setting.AppSubURL+ctx.Req.URL.RequestURI())
|
middleware.SetRedirectToCookie(ctx.Resp, setting.AppSubURL+ctx.Req.URL.RequestURI())
|
||||||
|
|
|
@ -39,7 +39,7 @@ func Home(ctx *context.Context) {
|
||||||
|
|
||||||
org := ctx.Org.Organization
|
org := ctx.Org.Organization
|
||||||
|
|
||||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
|
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.Doer) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func Home(ctx *context.Context) {
|
||||||
OwnerID: org.ID,
|
OwnerID: org.ID,
|
||||||
OrderBy: orderBy,
|
OrderBy: orderBy,
|
||||||
Private: ctx.IsSigned,
|
Private: ctx.IsSigned,
|
||||||
Actor: ctx.User,
|
Actor: ctx.Doer,
|
||||||
Language: language,
|
Language: language,
|
||||||
IncludeDescription: setting.UI.SearchRepoDescription,
|
IncludeDescription: setting.UI.SearchRepoDescription,
|
||||||
})
|
})
|
||||||
|
@ -128,13 +128,13 @@ func Home(ctx *context.Context) {
|
||||||
ListOptions: db.ListOptions{Page: 1, PageSize: 25},
|
ListOptions: db.ListOptions{Page: 1, PageSize: 25},
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
isMember, err := org.IsOrgMember(ctx.User.ID)
|
isMember, err := org.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
opts.PublicOnly = !isMember && !ctx.User.IsAdmin
|
opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
members, _, err := models.FindOrgMembers(opts)
|
members, _, err := models.FindOrgMembers(opts)
|
||||||
|
|
|
@ -36,13 +36,13 @@ func Members(ctx *context.Context) {
|
||||||
PublicOnly: true,
|
PublicOnly: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
opts.PublicOnly = !isMember && !ctx.User.IsAdmin
|
opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
total, err := models.CountOrgMembers(opts)
|
total, err := models.CountOrgMembers(opts)
|
||||||
|
@ -80,13 +80,13 @@ func MembersAction(ctx *context.Context) {
|
||||||
var err error
|
var err error
|
||||||
switch ctx.Params(":action") {
|
switch ctx.Params(":action") {
|
||||||
case "private":
|
case "private":
|
||||||
if ctx.User.ID != uid && !ctx.Org.IsOwner {
|
if ctx.Doer.ID != uid && !ctx.Org.IsOwner {
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.Error(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = models.ChangeOrgUserStatus(org.ID, uid, false)
|
err = models.ChangeOrgUserStatus(org.ID, uid, false)
|
||||||
case "public":
|
case "public":
|
||||||
if ctx.User.ID != uid && !ctx.Org.IsOwner {
|
if ctx.Doer.ID != uid && !ctx.Org.IsOwner {
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.Error(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func MembersAction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "leave":
|
case "leave":
|
||||||
err = org.RemoveMember(ctx.User.ID)
|
err = org.RemoveMember(ctx.Doer.ID)
|
||||||
if models.IsErrLastOrgOwner(err) {
|
if models.IsErrLastOrgOwner(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||||
|
|
|
@ -29,7 +29,7 @@ const (
|
||||||
func Create(ctx *context.Context) {
|
func Create(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("new_org")
|
ctx.Data["Title"] = ctx.Tr("new_org")
|
||||||
ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode
|
ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode
|
||||||
if !ctx.User.CanCreateOrganization() {
|
if !ctx.Doer.CanCreateOrganization() {
|
||||||
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func CreatePost(ctx *context.Context) {
|
||||||
form := *web.GetForm(ctx).(*forms.CreateOrgForm)
|
form := *web.GetForm(ctx).(*forms.CreateOrgForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("new_org")
|
ctx.Data["Title"] = ctx.Tr("new_org")
|
||||||
|
|
||||||
if !ctx.User.CanCreateOrganization() {
|
if !ctx.Doer.CanCreateOrganization() {
|
||||||
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func CreatePost(ctx *context.Context) {
|
||||||
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateOrganization(org, ctx.User); err != nil {
|
if err := models.CreateOrganization(org, ctx.Doer); err != nil {
|
||||||
ctx.Data["Err_OrgName"] = true
|
ctx.Data["Err_OrgName"] = true
|
||||||
switch {
|
switch {
|
||||||
case user_model.IsErrUserAlreadyExist(err):
|
case user_model.IsErrUserAlreadyExist(err):
|
||||||
|
|
|
@ -96,7 +96,7 @@ func SettingsPost(ctx *context.Context) {
|
||||||
org.Name = form.Name
|
org.Name = form.Name
|
||||||
org.LowerName = strings.ToLower(form.Name)
|
org.LowerName = strings.ToLower(form.Name)
|
||||||
|
|
||||||
if ctx.User.IsAdmin {
|
if ctx.Doer.IsAdmin {
|
||||||
org.MaxRepoCreation = form.MaxRepoCreation
|
org.MaxRepoCreation = form.MaxRepoCreation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,9 +69,9 @@ func TeamsAction(ctx *context.Context) {
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.Error(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = ctx.Org.Team.AddMember(ctx.User.ID)
|
err = ctx.Org.Team.AddMember(ctx.Doer.ID)
|
||||||
case "leave":
|
case "leave":
|
||||||
err = ctx.Org.Team.RemoveMember(ctx.User.ID)
|
err = ctx.Org.Team.RemoveMember(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrLastOrgOwner(err) {
|
if models.IsErrLastOrgOwner(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||||
|
|
|
@ -44,7 +44,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
attach, err := attachment.UploadAttachment(file, ctx.User.ID, repoID, 0, header.Filename, allowedTypes)
|
attach, err := attachment.UploadAttachment(file, ctx.Doer.ID, repoID, 0, header.Filename, allowedTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusBadRequest, err.Error())
|
ctx.Error(http.StatusBadRequest, err.Error())
|
||||||
|
@ -68,7 +68,7 @@ func DeleteAttachment(ctx *context.Context) {
|
||||||
ctx.Error(http.StatusBadRequest, err.Error())
|
ctx.Error(http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) {
|
if !ctx.IsSigned || (ctx.Doer.ID != attach.UploaderID) {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,12 @@ func GetAttachment(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if repository == nil { // If not linked
|
if repository == nil { // If not linked
|
||||||
if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) { // We block if not the uploader
|
if !(ctx.IsSigned && attach.UploaderID == ctx.Doer.ID) { // We block if not the uploader
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.Error(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else { // If we have the repository we check access
|
} else { // If we have the repository we check access
|
||||||
perm, err := models.GetUserRepoPermission(repository, ctx.User)
|
perm, err := models.GetUserRepoPermission(repository, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error())
|
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
@ -56,7 +56,7 @@ func Branches(ctx *context.Context) {
|
||||||
ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode)
|
ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode)
|
||||||
ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror
|
ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror
|
||||||
ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) ||
|
ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) ||
|
||||||
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID))
|
(ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID))
|
||||||
ctx.Data["PageIsViewCode"] = true
|
ctx.Data["PageIsViewCode"] = true
|
||||||
ctx.Data["PageIsBranches"] = true
|
ctx.Data["PageIsBranches"] = true
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func DeleteBranchPost(ctx *context.Context) {
|
||||||
defer redirect(ctx)
|
defer redirect(ctx)
|
||||||
branchName := ctx.FormString("name")
|
branchName := ctx.FormString("name")
|
||||||
|
|
||||||
if err := repo_service.DeleteBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil {
|
if err := repo_service.DeleteBranch(ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case git.IsErrBranchNotExist(err):
|
case git.IsErrBranchNotExist(err):
|
||||||
log.Debug("DeleteBranch: Can't delete non existing branch '%s'", branchName)
|
log.Debug("DeleteBranch: Can't delete non existing branch '%s'", branchName)
|
||||||
|
@ -129,7 +129,7 @@ func RestoreBranchPost(ctx *context.Context) {
|
||||||
if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{
|
if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{
|
||||||
Remote: ctx.Repo.Repository.RepoPath(),
|
Remote: ctx.Repo.Repository.RepoPath(),
|
||||||
Branch: fmt.Sprintf("%s:%s%s", deletedBranch.Commit, git.BranchPrefix, deletedBranch.Name),
|
Branch: fmt.Sprintf("%s:%s%s", deletedBranch.Commit, git.BranchPrefix, deletedBranch.Name),
|
||||||
Env: models.PushingEnvironment(ctx.User, ctx.Repo.Repository),
|
Env: models.PushingEnvironment(ctx.Doer, ctx.Repo.Repository),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
if strings.Contains(err.Error(), "already exists") {
|
if strings.Contains(err.Error(), "already exists") {
|
||||||
log.Debug("RestoreBranch: Can't restore branch '%s', since one with same name already exist", deletedBranch.Name)
|
log.Debug("RestoreBranch: Can't restore branch '%s', since one with same name already exist", deletedBranch.Name)
|
||||||
|
@ -147,8 +147,8 @@ func RestoreBranchPost(ctx *context.Context) {
|
||||||
RefFullName: git.BranchPrefix + deletedBranch.Name,
|
RefFullName: git.BranchPrefix + deletedBranch.Name,
|
||||||
OldCommitID: git.EmptySHA,
|
OldCommitID: git.EmptySHA,
|
||||||
NewCommitID: deletedBranch.Commit,
|
NewCommitID: deletedBranch.Commit,
|
||||||
PusherID: ctx.User.ID,
|
PusherID: ctx.Doer.ID,
|
||||||
PusherName: ctx.User.Name,
|
PusherName: ctx.Doer.Name,
|
||||||
RepoUserName: ctx.Repo.Owner.Name,
|
RepoUserName: ctx.Repo.Owner.Name,
|
||||||
RepoName: ctx.Repo.Repository.Name,
|
RepoName: ctx.Repo.Repository.Name,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -364,11 +364,11 @@ func CreateBranch(ctx *context.Context) {
|
||||||
if ctx.Repo.IsViewBranch {
|
if ctx.Repo.IsViewBranch {
|
||||||
target = ctx.Repo.BranchName
|
target = ctx.Repo.BranchName
|
||||||
}
|
}
|
||||||
err = release_service.CreateNewTag(ctx, ctx.User, ctx.Repo.Repository, target, form.NewBranchName, "")
|
err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, target, form.NewBranchName, "")
|
||||||
} else if ctx.Repo.IsViewBranch {
|
} else if ctx.Repo.IsViewBranch {
|
||||||
err = repo_service.CreateNewBranch(ctx, ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
|
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
|
||||||
} else {
|
} else {
|
||||||
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
|
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrTagAlreadyExists(err) {
|
if models.IsErrTagAlreadyExists(err) {
|
||||||
|
|
|
@ -127,7 +127,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||||
|
|
||||||
// First lets try the simple plain read-tree -m approach
|
// First lets try the simple plain read-tree -m approach
|
||||||
opts.Content = sha
|
opts.Content = sha
|
||||||
if _, err := files.CherryPick(ctx, ctx.Repo.Repository, ctx.User, form.Revert, opts); err != nil {
|
if _, err := files.CherryPick(ctx, ctx.Repo.Repository, ctx.Doer, form.Revert, opts); err != nil {
|
||||||
if models.IsErrBranchAlreadyExists(err) {
|
if models.IsErrBranchAlreadyExists(err) {
|
||||||
// User has specified a branch that already exists
|
// User has specified a branch that already exists
|
||||||
branchErr := err.(models.ErrBranchAlreadyExists)
|
branchErr := err.(models.ErrBranchAlreadyExists)
|
||||||
|
@ -164,7 +164,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||||
opts.Content = buf.String()
|
opts.Content = buf.String()
|
||||||
ctx.Data["FileContent"] = opts.Content
|
ctx.Data["FileContent"] = opts.Content
|
||||||
|
|
||||||
if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.User, opts); err != nil {
|
if _, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts); err != nil {
|
||||||
if models.IsErrBranchAlreadyExists(err) {
|
if models.IsErrBranchAlreadyExists(err) {
|
||||||
// User has specified a branch that already exists
|
// User has specified a branch that already exists
|
||||||
branchErr := err.(models.ErrBranchAlreadyExists)
|
branchErr := err.(models.ErrBranchAlreadyExists)
|
||||||
|
|
|
@ -338,8 +338,8 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
// check if they have a fork of the base repo and offer that as
|
// check if they have a fork of the base repo and offer that as
|
||||||
// "OwnForkRepo"
|
// "OwnForkRepo"
|
||||||
var ownForkRepo *repo_model.Repository
|
var ownForkRepo *repo_model.Repository
|
||||||
if ctx.User != nil && baseRepo.OwnerID != ctx.User.ID {
|
if ctx.Doer != nil && baseRepo.OwnerID != ctx.Doer.ID {
|
||||||
repo := repo_model.GetForkedRepo(ctx.User.ID, baseRepo.ID)
|
repo := repo_model.GetForkedRepo(ctx.Doer.ID, baseRepo.ID)
|
||||||
if repo != nil {
|
if repo != nil {
|
||||||
ownForkRepo = repo
|
ownForkRepo = repo
|
||||||
ctx.Data["OwnForkRepo"] = ownForkRepo
|
ctx.Data["OwnForkRepo"] = ownForkRepo
|
||||||
|
@ -354,7 +354,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
has = true
|
has = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. If the ctx.User has their own fork of the baseRepo and the headUser is the ctx.User
|
// 4. If the ctx.Doer has their own fork of the baseRepo and the headUser is the ctx.Doer
|
||||||
// set the headRepo to the ownFork
|
// set the headRepo to the ownFork
|
||||||
if !has && ownForkRepo != nil && ownForkRepo.OwnerID == ci.HeadUser.ID {
|
if !has && ownForkRepo != nil && ownForkRepo.OwnerID == ci.HeadUser.ID {
|
||||||
ci.HeadRepo = ownForkRepo
|
ci.HeadRepo = ownForkRepo
|
||||||
|
@ -393,10 +393,10 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
|
|
||||||
ctx.Data["HeadRepo"] = ci.HeadRepo
|
ctx.Data["HeadRepo"] = ci.HeadRepo
|
||||||
|
|
||||||
// Now we need to assert that the ctx.User has permission to read
|
// Now we need to assert that the ctx.Doer has permission to read
|
||||||
// the baseRepo's code and pulls
|
// the baseRepo's code and pulls
|
||||||
// (NOT headRepo's)
|
// (NOT headRepo's)
|
||||||
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
|
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -404,7 +404,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
if !permBase.CanRead(unit.TypeCode) {
|
if !permBase.CanRead(unit.TypeCode) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
baseRepo,
|
baseRepo,
|
||||||
permBase)
|
permBase)
|
||||||
}
|
}
|
||||||
|
@ -414,8 +414,8 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
|
|
||||||
// If we're not merging from the same repo:
|
// If we're not merging from the same repo:
|
||||||
if !isSameRepo {
|
if !isSameRepo {
|
||||||
// Assert ctx.User has permission to read headRepo's codes
|
// Assert ctx.Doer has permission to read headRepo's codes
|
||||||
permHead, err := models.GetUserRepoPermission(ci.HeadRepo, ctx.User)
|
permHead, err := models.GetUserRepoPermission(ci.HeadRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -423,7 +423,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
if !permHead.CanRead(unit.TypeCode) {
|
if !permHead.CanRead(unit.TypeCode) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
ci.HeadRepo,
|
ci.HeadRepo,
|
||||||
permHead)
|
permHead)
|
||||||
}
|
}
|
||||||
|
@ -439,7 +439,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
if rootRepo != nil &&
|
if rootRepo != nil &&
|
||||||
rootRepo.ID != ci.HeadRepo.ID &&
|
rootRepo.ID != ci.HeadRepo.ID &&
|
||||||
rootRepo.ID != baseRepo.ID {
|
rootRepo.ID != baseRepo.ID {
|
||||||
canRead := models.CheckRepoUnitUser(rootRepo, ctx.User, unit.TypeCode)
|
canRead := models.CheckRepoUnitUser(rootRepo, ctx.Doer, unit.TypeCode)
|
||||||
if canRead {
|
if canRead {
|
||||||
ctx.Data["RootRepo"] = rootRepo
|
ctx.Data["RootRepo"] = rootRepo
|
||||||
if !fileOnly {
|
if !fileOnly {
|
||||||
|
@ -464,7 +464,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
ownForkRepo.ID != ci.HeadRepo.ID &&
|
ownForkRepo.ID != ci.HeadRepo.ID &&
|
||||||
ownForkRepo.ID != baseRepo.ID &&
|
ownForkRepo.ID != baseRepo.ID &&
|
||||||
(rootRepo == nil || ownForkRepo.ID != rootRepo.ID) {
|
(rootRepo == nil || ownForkRepo.ID != rootRepo.ID) {
|
||||||
canRead := models.CheckRepoUnitUser(ownForkRepo, ctx.User, unit.TypeCode)
|
canRead := models.CheckRepoUnitUser(ownForkRepo, ctx.Doer, unit.TypeCode)
|
||||||
if canRead {
|
if canRead {
|
||||||
ctx.Data["OwnForkRepo"] = ownForkRepo
|
ctx.Data["OwnForkRepo"] = ownForkRepo
|
||||||
if !fileOnly {
|
if !fileOnly {
|
||||||
|
@ -506,7 +506,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||||
if ctx.Data["PageIsComparePull"] == true && !permBase.CanReadIssuesOrPulls(true) {
|
if ctx.Data["PageIsComparePull"] == true && !permBase.CanReadIssuesOrPulls(true) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
log.Trace("Permission Denied: User: %-v cannot create/read pull requests in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
log.Trace("Permission Denied: User: %-v cannot create/read pull requests in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
baseRepo,
|
baseRepo,
|
||||||
permBase)
|
permBase)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func renderCommitRights(ctx *context.Context) bool {
|
func renderCommitRights(ctx *context.Context) bool {
|
||||||
canCommitToBranch, err := ctx.Repo.CanCommitToBranch(ctx, ctx.User)
|
canCommitToBranch, err := ctx.Repo.CanCommitToBranch(ctx, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("CanCommitToBranch: %v", err)
|
log.Error("CanCommitToBranch: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
|
||||||
message += "\n\n" + form.CommitMessage
|
message += "\n\n" + form.CommitMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.User, &files_service.UpdateRepoFileOptions{
|
if _, err := files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.UpdateRepoFileOptions{
|
||||||
LastCommitID: form.LastCommit,
|
LastCommitID: form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: ctx.Repo.BranchName,
|
||||||
NewBranch: branchName,
|
NewBranch: branchName,
|
||||||
|
@ -447,7 +447,7 @@ func DeleteFilePost(ctx *context.Context) {
|
||||||
message += "\n\n" + form.CommitMessage
|
message += "\n\n" + form.CommitMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.User, &files_service.DeleteRepoFileOptions{
|
if _, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.DeleteRepoFileOptions{
|
||||||
LastCommitID: form.LastCommit,
|
LastCommitID: form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: ctx.Repo.BranchName,
|
||||||
NewBranch: branchName,
|
NewBranch: branchName,
|
||||||
|
@ -653,7 +653,7 @@ func UploadFilePost(ctx *context.Context) {
|
||||||
message += "\n\n" + form.CommitMessage
|
message += "\n\n" + form.CommitMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := files_service.UploadRepoFiles(ctx, ctx.Repo.Repository, ctx.User, &files_service.UploadRepoFileOptions{
|
if err := files_service.UploadRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.UploadRepoFileOptions{
|
||||||
LastCommitID: ctx.Repo.CommitID,
|
LastCommitID: ctx.Repo.CommitID,
|
||||||
OldBranch: oldBranchName,
|
OldBranch: oldBranchName,
|
||||||
NewBranch: branchName,
|
NewBranch: branchName,
|
||||||
|
@ -798,7 +798,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) {
|
||||||
// that doesn't already exist. If we exceed 1000 tries or an error is thrown, we just return "" so the user has to
|
// that doesn't already exist. If we exceed 1000 tries or an error is thrown, we just return "" so the user has to
|
||||||
// type in the branch name themselves (will be an empty field)
|
// type in the branch name themselves (will be an empty field)
|
||||||
func GetUniquePatchBranchName(ctx *context.Context) string {
|
func GetUniquePatchBranchName(ctx *context.Context) string {
|
||||||
prefix := ctx.User.LowerName + "-patch-"
|
prefix := ctx.Doer.LowerName + "-patch-"
|
||||||
for i := 1; i <= 1000; i++ {
|
for i := 1; i <= 1000; i++ {
|
||||||
branchName := fmt.Sprintf("%s%d", prefix, i)
|
branchName := fmt.Sprintf("%s%d", prefix, i)
|
||||||
if _, err := ctx.Repo.GitRepo.GetBranch(branchName); err != nil {
|
if _, err := ctx.Repo.GitRepo.GetBranch(branchName); err != nil {
|
||||||
|
|
|
@ -178,7 +178,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true {
|
if ctx.IsBasicAuth && ctx.Data["IsApiToken"] != true {
|
||||||
_, err = auth.GetTwoFactorByUID(ctx.User.ID)
|
_, err = auth.GetTwoFactorByUID(ctx.Doer.ID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
|
// TODO: This response should be changed to "invalid credentials" for security reasons once the expectation behind it (creating an app token to authenticate) is properly documented
|
||||||
ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
|
ctx.PlainText(http.StatusUnauthorized, "Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page")
|
||||||
|
@ -189,13 +189,13 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
if !ctx.Doer.IsActive || ctx.Doer.ProhibitLogin {
|
||||||
ctx.PlainText(http.StatusForbidden, "Your account is disabled.")
|
ctx.PlainText(http.StatusForbidden, "Your account is disabled.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoExist {
|
if repoExist {
|
||||||
p, err := models.GetUserRepoPermission(repo, ctx.User)
|
p, err := models.GetUserRepoPermission(repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -220,14 +220,14 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
environ = []string{
|
environ = []string{
|
||||||
models.EnvRepoUsername + "=" + username,
|
models.EnvRepoUsername + "=" + username,
|
||||||
models.EnvRepoName + "=" + reponame,
|
models.EnvRepoName + "=" + reponame,
|
||||||
models.EnvPusherName + "=" + ctx.User.Name,
|
models.EnvPusherName + "=" + ctx.Doer.Name,
|
||||||
models.EnvPusherID + fmt.Sprintf("=%d", ctx.User.ID),
|
models.EnvPusherID + fmt.Sprintf("=%d", ctx.Doer.ID),
|
||||||
models.EnvIsDeployKey + "=false",
|
models.EnvIsDeployKey + "=false",
|
||||||
models.EnvAppURL + "=" + setting.AppURL,
|
models.EnvAppURL + "=" + setting.AppURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.User.KeepEmailPrivate {
|
if !ctx.Doer.KeepEmailPrivate {
|
||||||
environ = append(environ, models.EnvPusherEmail+"="+ctx.User.Email)
|
environ = append(environ, models.EnvPusherEmail+"="+ctx.Doer.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isWiki {
|
if isWiki {
|
||||||
|
@ -263,7 +263,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err = repo_service.PushCreateRepo(ctx.User, owner, reponame)
|
repo, err = repo_service.PushCreateRepo(ctx.Doer, owner, reponame)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("pushCreateRepo: %v", err)
|
log.Error("pushCreateRepo: %v", err)
|
||||||
ctx.Status(http.StatusNotFound)
|
ctx.Status(http.StatusNotFound)
|
||||||
|
|
|
@ -77,7 +77,7 @@ func MustAllowUserComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin {
|
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
|
ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
|
||||||
ctx.Redirect(issue.HTMLURL())
|
ctx.Redirect(issue.HTMLURL())
|
||||||
return
|
return
|
||||||
|
@ -107,9 +107,9 @@ func MustAllowPulls(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// User can send pull request if owns a forked repository.
|
// User can send pull request if owns a forked repository.
|
||||||
if ctx.IsSigned && repo_model.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID) {
|
if ctx.IsSigned && repo_model.HasForkedRepo(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.Repo.PullRequest.Allowed = true
|
ctx.Repo.PullRequest.Allowed = true
|
||||||
ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.User.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName)
|
ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.Doer.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,13 +133,13 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
switch viewType {
|
switch viewType {
|
||||||
case "created_by":
|
case "created_by":
|
||||||
posterID = ctx.User.ID
|
posterID = ctx.Doer.ID
|
||||||
case "mentioned":
|
case "mentioned":
|
||||||
mentionedID = ctx.User.ID
|
mentionedID = ctx.Doer.ID
|
||||||
case "assigned":
|
case "assigned":
|
||||||
assigneeID = ctx.User.ID
|
assigneeID = ctx.Doer.ID
|
||||||
case "review_requested":
|
case "review_requested":
|
||||||
reviewRequestedID = ctx.User.ID
|
reviewRequestedID = ctx.Doer.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||||
// Check read status
|
// Check read status
|
||||||
if !ctx.IsSigned {
|
if !ctx.IsSigned {
|
||||||
issues[i].IsRead = true
|
issues[i].IsRead = true
|
||||||
} else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
|
} else if err = issues[i].GetIsRead(ctx.Doer.ID); err != nil {
|
||||||
ctx.ServerError("GetIsRead", err)
|
ctx.ServerError("GetIsRead", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -514,7 +514,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
|
||||||
posterID = 0
|
posterID = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
reviewers, err = models.GetReviewers(repo, ctx.User.ID, posterID)
|
reviewers, err = models.GetReviewers(repo, ctx.Doer.ID, posterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetReviewers", err)
|
ctx.ServerError("GetReviewers", err)
|
||||||
return
|
return
|
||||||
|
@ -551,11 +551,11 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
|
||||||
if ctx.Repo.IsAdmin() {
|
if ctx.Repo.IsAdmin() {
|
||||||
// Admin can dismiss or re-request any review requests
|
// Admin can dismiss or re-request any review requests
|
||||||
tmp.CanChange = true
|
tmp.CanChange = true
|
||||||
} else if ctx.User != nil && ctx.User.ID == review.ReviewerID && review.Type == models.ReviewTypeRequest {
|
} else if ctx.Doer != nil && ctx.Doer.ID == review.ReviewerID && review.Type == models.ReviewTypeRequest {
|
||||||
// A user can refuse review requests
|
// A user can refuse review requests
|
||||||
tmp.CanChange = true
|
tmp.CanChange = true
|
||||||
} else if (canChooseReviewer || (ctx.User != nil && ctx.User.ID == issue.PosterID)) && review.Type != models.ReviewTypeRequest &&
|
} else if (canChooseReviewer || (ctx.Doer != nil && ctx.Doer.ID == issue.PosterID)) && review.Type != models.ReviewTypeRequest &&
|
||||||
ctx.User.ID != review.ReviewerID {
|
ctx.Doer.ID != review.ReviewerID {
|
||||||
// The poster of the PR, a manager, or official reviewers can re-request review from other reviewers
|
// The poster of the PR, a manager, or official reviewers can re-request review from other reviewers
|
||||||
tmp.CanChange = true
|
tmp.CanChange = true
|
||||||
}
|
}
|
||||||
|
@ -699,7 +699,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
|
||||||
ctx.Data["Branches"] = brs
|
ctx.Data["Branches"] = brs
|
||||||
|
|
||||||
// Contains true if the user can create issue dependencies
|
// Contains true if the user can create issue dependencies
|
||||||
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, isPull)
|
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.Doer, isPull)
|
||||||
|
|
||||||
return labels
|
return labels
|
||||||
}
|
}
|
||||||
|
@ -859,7 +859,7 @@ func DeleteIssue(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.DeleteIssue(ctx.User, ctx.Repo.GitRepo, issue); err != nil {
|
if err := issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
|
||||||
ctx.ServerError("DeleteIssueByID", err)
|
ctx.ServerError("DeleteIssueByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1008,8 +1008,8 @@ func NewIssuePost(ctx *context.Context) {
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Title: form.Title,
|
Title: form.Title,
|
||||||
PosterID: ctx.User.ID,
|
PosterID: ctx.Doer.ID,
|
||||||
Poster: ctx.User,
|
Poster: ctx.Doer,
|
||||||
MilestoneID: milestoneID,
|
MilestoneID: milestoneID,
|
||||||
Content: form.Content,
|
Content: form.Content,
|
||||||
Ref: form.Ref,
|
Ref: form.Ref,
|
||||||
|
@ -1025,7 +1025,7 @@ func NewIssuePost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectID > 0 {
|
if projectID > 0 {
|
||||||
if err := models.ChangeProjectAssign(issue, ctx.User, projectID); err != nil {
|
if err := models.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
|
||||||
ctx.ServerError("ChangeProjectAssign", err)
|
ctx.ServerError("ChangeProjectAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1177,10 +1177,10 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
|
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
|
||||||
|
|
||||||
iw := new(models.IssueWatch)
|
iw := new(models.IssueWatch)
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
iw.UserID = ctx.User.ID
|
iw.UserID = ctx.Doer.ID
|
||||||
iw.IssueID = issue.ID
|
iw.IssueID = issue.ID
|
||||||
iw.IsWatching, err = models.CheckIssueWatch(ctx.User, issue)
|
iw.IsWatching, err = models.CheckIssueWatch(ctx.Doer, issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CheckIssueWatch", err)
|
ctx.ServerError("CheckIssueWatch", err)
|
||||||
return
|
return
|
||||||
|
@ -1260,8 +1260,8 @@ func ViewIssue(ctx *context.Context) {
|
||||||
|
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests)
|
canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests)
|
||||||
if !canChooseReviewer && ctx.User != nil && ctx.IsSigned {
|
if !canChooseReviewer && ctx.Doer != nil && ctx.IsSigned {
|
||||||
canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.User)
|
canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("IsOfficialReviewer", err)
|
ctx.ServerError("IsOfficialReviewer", err)
|
||||||
return
|
return
|
||||||
|
@ -1276,7 +1276,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
|
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
// Update issue-user.
|
// Update issue-user.
|
||||||
if err = issue.ReadBy(ctx.User.ID); err != nil {
|
if err = issue.ReadBy(ctx.Doer.ID); err != nil {
|
||||||
ctx.ServerError("ReadBy", err)
|
ctx.ServerError("ReadBy", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1292,11 +1292,11 @@ func ViewIssue(ctx *context.Context) {
|
||||||
if ctx.Repo.Repository.IsTimetrackerEnabled() {
|
if ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
// Deal with the stopwatch
|
// Deal with the stopwatch
|
||||||
ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.User.ID, issue.ID)
|
ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.Doer.ID, issue.ID)
|
||||||
if !ctx.Data["IsStopwatchRunning"].(bool) {
|
if !ctx.Data["IsStopwatchRunning"].(bool) {
|
||||||
var exists bool
|
var exists bool
|
||||||
var sw *models.Stopwatch
|
var sw *models.Stopwatch
|
||||||
if exists, sw, err = models.HasUserStopwatch(ctx.User.ID); err != nil {
|
if exists, sw, err = models.HasUserStopwatch(ctx.Doer.ID); err != nil {
|
||||||
ctx.ServerError("HasUserStopwatch", err)
|
ctx.ServerError("HasUserStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1316,7 +1316,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
|
ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.User)
|
ctx.Data["CanUseTimetracker"] = ctx.Repo.CanUseTimetracker(issue, ctx.Doer)
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["CanUseTimetracker"] = false
|
ctx.Data["CanUseTimetracker"] = false
|
||||||
}
|
}
|
||||||
|
@ -1327,7 +1327,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user can use the dependencies
|
// Check if the user can use the dependencies
|
||||||
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull)
|
ctx.Data["CanCreateIssueDependencies"] = ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull)
|
||||||
|
|
||||||
// check if dependencies can be created across repositories
|
// check if dependencies can be created across repositories
|
||||||
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
|
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
|
||||||
|
@ -1511,7 +1511,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
if err := pull.LoadHeadRepo(); err != nil {
|
if err := pull.LoadHeadRepo(); err != nil {
|
||||||
log.Error("LoadHeadRepo: %v", err)
|
log.Error("LoadHeadRepo: %v", err)
|
||||||
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
|
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
|
||||||
perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.User)
|
perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
|
@ -1530,18 +1530,18 @@ func ViewIssue(ctx *context.Context) {
|
||||||
if err := pull.LoadBaseRepo(); err != nil {
|
if err := pull.LoadBaseRepo(); err != nil {
|
||||||
log.Error("LoadBaseRepo: %v", err)
|
log.Error("LoadBaseRepo: %v", err)
|
||||||
}
|
}
|
||||||
perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.User)
|
perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.ServerError("GetUserRepoPermission", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["AllowMerge"], err = pull_service.IsUserAllowedToMerge(pull, perm, ctx.User)
|
ctx.Data["AllowMerge"], err = pull_service.IsUserAllowedToMerge(pull, perm, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("IsUserAllowedToMerge", err)
|
ctx.ServerError("IsUserAllowedToMerge", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.User); err != nil {
|
if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.Doer); err != nil {
|
||||||
ctx.ServerError("CanMarkConversation", err)
|
ctx.ServerError("CanMarkConversation", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1581,8 +1581,8 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Data["ShowMergeInstructions"] = true
|
ctx.Data["ShowMergeInstructions"] = true
|
||||||
if pull.ProtectedBranch != nil {
|
if pull.ProtectedBranch != nil {
|
||||||
var showMergeInstructions bool
|
var showMergeInstructions bool
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.User.ID)
|
showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.Doer.ID)
|
||||||
}
|
}
|
||||||
cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
|
cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
|
||||||
ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
|
ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
|
||||||
|
@ -1597,8 +1597,8 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Data["ShowMergeInstructions"] = showMergeInstructions
|
ctx.Data["ShowMergeInstructions"] = showMergeInstructions
|
||||||
}
|
}
|
||||||
ctx.Data["WillSign"] = false
|
ctx.Data["WillSign"] = false
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.User, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitRefName())
|
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.Doer, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitRefName())
|
||||||
ctx.Data["WillSign"] = sign
|
ctx.Data["WillSign"] = sign
|
||||||
ctx.Data["SigningKey"] = key
|
ctx.Data["SigningKey"] = key
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1636,7 +1636,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
if pull.CanAutoMerge() || pull.IsWorkInProgress() || pull.IsChecking() {
|
if pull.CanAutoMerge() || pull.IsWorkInProgress() || pull.IsChecking() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (ctx.User.IsAdmin || ctx.Repo.IsAdmin()) && prConfig.AllowManualMerge {
|
if (ctx.Doer.IsAdmin || ctx.Repo.IsAdmin()) && prConfig.AllowManualMerge {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1663,16 +1663,16 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Data["Issue"] = issue
|
ctx.Data["Issue"] = issue
|
||||||
ctx.Data["Reference"] = issue.Ref
|
ctx.Data["Reference"] = issue.Ref
|
||||||
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + url.QueryEscape(ctx.Data["Link"].(string))
|
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + url.QueryEscape(ctx.Data["Link"].(string))
|
||||||
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
|
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID)
|
||||||
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
|
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
|
||||||
ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(unit.TypeProjects)
|
ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(unit.TypeProjects)
|
||||||
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin)
|
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.Doer.IsAdmin)
|
||||||
ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
|
ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
|
||||||
ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
|
ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
|
||||||
|
|
||||||
var hiddenCommentTypes *big.Int
|
var hiddenCommentTypes *big.Int
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
val, err := user_model.GetUserSetting(ctx.User.ID, user_model.SettingsKeyHiddenCommentTypes)
|
val, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserSetting", err)
|
ctx.ServerError("GetUserSetting", err)
|
||||||
return
|
return
|
||||||
|
@ -1754,7 +1754,7 @@ func UpdateIssueTitle(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
if !ctx.IsSigned || (!issue.IsPoster(ctx.Doer.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1765,7 +1765,7 @@ func UpdateIssueTitle(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ChangeTitle(issue, ctx.User, title); err != nil {
|
if err := issue_service.ChangeTitle(issue, ctx.Doer, title); err != nil {
|
||||||
ctx.ServerError("ChangeTitle", err)
|
ctx.ServerError("ChangeTitle", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1782,14 +1782,14 @@ func UpdateIssueRef(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) || issue.IsPull {
|
if !ctx.IsSigned || (!issue.IsPoster(ctx.Doer.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) || issue.IsPull {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ref := ctx.FormTrim("ref")
|
ref := ctx.FormTrim("ref")
|
||||||
|
|
||||||
if err := issue_service.ChangeIssueRef(issue, ctx.User, ref); err != nil {
|
if err := issue_service.ChangeIssueRef(issue, ctx.Doer, ref); err != nil {
|
||||||
ctx.ServerError("ChangeRef", err)
|
ctx.ServerError("ChangeRef", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1806,12 +1806,12 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ChangeContent(issue, ctx.User, ctx.Req.FormValue("content")); err != nil {
|
if err := issue_service.ChangeContent(issue, ctx.Doer, ctx.Req.FormValue("content")); err != nil {
|
||||||
ctx.ServerError("ChangeContent", err)
|
ctx.ServerError("ChangeContent", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1855,7 +1855,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
issue.MilestoneID = milestoneID
|
issue.MilestoneID = milestoneID
|
||||||
if err := issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err := issue_service.ChangeMilestoneAssign(issue, ctx.Doer, oldMilestoneID); err != nil {
|
||||||
ctx.ServerError("ChangeMilestoneAssign", err)
|
ctx.ServerError("ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1879,7 +1879,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
switch action {
|
switch action {
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*user_model.User{}); err != nil {
|
if err := issue_service.DeleteNotPassedAssignee(issue, ctx.Doer, []*user_model.User{}); err != nil {
|
||||||
ctx.ServerError("ClearAssignees", err)
|
ctx.ServerError("ClearAssignees", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1900,7 +1900,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = issue_service.ToggleAssignee(issue, ctx.User, assigneeID)
|
_, _, err = issue_service.ToggleAssignee(issue, ctx.Doer, assigneeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ToggleAssignee", err)
|
ctx.ServerError("ToggleAssignee", err)
|
||||||
return
|
return
|
||||||
|
@ -1972,7 +1972,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue_service.IsValidTeamReviewRequest(team, ctx.User, action == "attach", issue)
|
err = issue_service.IsValidTeamReviewRequest(team, ctx.Doer, action == "attach", issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrNotValidReviewRequest(err) {
|
if models.IsErrNotValidReviewRequest(err) {
|
||||||
log.Warn(
|
log.Warn(
|
||||||
|
@ -1987,7 +1987,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = issue_service.TeamReviewRequest(issue, ctx.User, team, action == "attach")
|
_, err = issue_service.TeamReviewRequest(issue, ctx.Doer, team, action == "attach")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("TeamReviewRequest", err)
|
ctx.ServerError("TeamReviewRequest", err)
|
||||||
return
|
return
|
||||||
|
@ -2010,7 +2010,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue_service.IsValidReviewRequest(reviewer, ctx.User, action == "attach", issue, nil)
|
err = issue_service.IsValidReviewRequest(reviewer, ctx.Doer, action == "attach", issue, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrNotValidReviewRequest(err) {
|
if models.IsErrNotValidReviewRequest(err) {
|
||||||
log.Warn(
|
log.Warn(
|
||||||
|
@ -2025,7 +2025,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = issue_service.ReviewRequest(issue, ctx.User, reviewer, action == "attach")
|
_, err = issue_service.ReviewRequest(issue, ctx.Doer, reviewer, action == "attach")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ReviewRequest", err)
|
ctx.ServerError("ReviewRequest", err)
|
||||||
return
|
return
|
||||||
|
@ -2060,7 +2060,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if issue.IsClosed != isClosed {
|
if issue.IsClosed != isClosed {
|
||||||
if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
|
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
|
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
|
||||||
"error": "cannot close this issue because it still has open dependencies",
|
"error": "cannot close this issue because it still has open dependencies",
|
||||||
|
@ -2085,7 +2085,7 @@ func NewComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
issueType := "issues"
|
issueType := "issues"
|
||||||
|
@ -2094,7 +2094,7 @@ func NewComment(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
log.NewColoredIDValue(issue.PosterID),
|
log.NewColoredIDValue(issue.PosterID),
|
||||||
issueType,
|
issueType,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
|
@ -2108,7 +2108,7 @@ func NewComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin {
|
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
|
ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
|
||||||
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
|
@ -2128,7 +2128,7 @@ func NewComment(ctx *context.Context) {
|
||||||
var comment *models.Comment
|
var comment *models.Comment
|
||||||
defer func() {
|
defer func() {
|
||||||
// Check if issue admin/poster changes the status of issue.
|
// Check if issue admin/poster changes the status of issue.
|
||||||
if (ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))) &&
|
if (ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) || (ctx.IsSigned && issue.IsPoster(ctx.Doer.ID))) &&
|
||||||
(form.Status == "reopen" || form.Status == "close") &&
|
(form.Status == "reopen" || form.Status == "close") &&
|
||||||
!(issue.IsPull && issue.PullRequest.HasMerged) {
|
!(issue.IsPull && issue.PullRequest.HasMerged) {
|
||||||
|
|
||||||
|
@ -2157,7 +2157,7 @@ func NewComment(ctx *context.Context) {
|
||||||
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
|
||||||
} else {
|
} else {
|
||||||
isClosed := form.Status == "close"
|
isClosed := form.Status == "close"
|
||||||
if err := issue_service.ChangeStatus(issue, ctx.User, isClosed); err != nil {
|
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
|
||||||
log.Error("ChangeStatus: %v", err)
|
log.Error("ChangeStatus: %v", err)
|
||||||
|
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
|
@ -2171,7 +2171,7 @@ func NewComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := stopTimerIfAvailable(ctx.User, issue); err != nil {
|
if err := stopTimerIfAvailable(ctx.Doer, issue); err != nil {
|
||||||
ctx.ServerError("CreateOrStopIssueStopwatch", err)
|
ctx.ServerError("CreateOrStopIssueStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2198,7 +2198,7 @@ func NewComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := comment_service.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
|
comment, err := comment_service.CreateIssueComment(ctx.Doer, ctx.Repo.Repository, issue, form.Content, attachments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CreateIssueComment", err)
|
ctx.ServerError("CreateIssueComment", err)
|
||||||
return
|
return
|
||||||
|
@ -2220,7 +2220,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2238,7 +2238,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = comment_service.UpdateComment(comment, ctx.User, oldContent); err != nil {
|
if err = comment_service.UpdateComment(comment, ctx.Doer, oldContent); err != nil {
|
||||||
ctx.ServerError("UpdateComment", err)
|
ctx.ServerError("UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2286,7 +2286,7 @@ func DeleteComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||||
ctx.Error(http.StatusForbidden)
|
ctx.Error(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||||
|
@ -2294,7 +2294,7 @@ func DeleteComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = comment_service.DeleteComment(ctx.User, comment); err != nil {
|
if err = comment_service.DeleteComment(ctx.Doer, comment); err != nil {
|
||||||
ctx.ServerError("DeleteCommentByID", err)
|
ctx.ServerError("DeleteCommentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2310,7 +2310,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
issueType := "issues"
|
issueType := "issues"
|
||||||
|
@ -2319,7 +2319,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
log.NewColoredIDValue(issue.PosterID),
|
log.NewColoredIDValue(issue.PosterID),
|
||||||
issueType,
|
issueType,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
|
@ -2340,7 +2340,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
|
|
||||||
switch ctx.Params(":action") {
|
switch ctx.Params(":action") {
|
||||||
case "react":
|
case "react":
|
||||||
reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Content)
|
reaction, err := models.CreateIssueReaction(ctx.Doer, issue, form.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrForbiddenIssueReaction(err) {
|
if models.IsErrForbiddenIssueReaction(err) {
|
||||||
ctx.ServerError("ChangeIssueReaction", err)
|
ctx.ServerError("ChangeIssueReaction", err)
|
||||||
|
@ -2358,7 +2358,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
||||||
|
|
||||||
log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
|
log.Trace("Reaction for issue created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, reaction.ID)
|
||||||
case "unreact":
|
case "unreact":
|
||||||
if err := models.DeleteIssueReaction(ctx.User, issue, form.Content); err != nil {
|
if err := models.DeleteIssueReaction(ctx.Doer, issue, form.Content); err != nil {
|
||||||
ctx.ServerError("DeleteIssueReaction", err)
|
ctx.ServerError("DeleteIssueReaction", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2412,7 +2412,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull)) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
issueType := "issues"
|
issueType := "issues"
|
||||||
|
@ -2421,7 +2421,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
log.NewColoredIDValue(comment.Issue.PosterID),
|
log.NewColoredIDValue(comment.Issue.PosterID),
|
||||||
issueType,
|
issueType,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
|
@ -2442,7 +2442,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
|
|
||||||
switch ctx.Params(":action") {
|
switch ctx.Params(":action") {
|
||||||
case "react":
|
case "react":
|
||||||
reaction, err := models.CreateCommentReaction(ctx.User, comment.Issue, comment, form.Content)
|
reaction, err := models.CreateCommentReaction(ctx.Doer, comment.Issue, comment, form.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrForbiddenIssueReaction(err) {
|
if models.IsErrForbiddenIssueReaction(err) {
|
||||||
ctx.ServerError("ChangeIssueReaction", err)
|
ctx.ServerError("ChangeIssueReaction", err)
|
||||||
|
@ -2460,7 +2460,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||||
|
|
||||||
log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
|
log.Trace("Reaction for comment created: %d/%d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID, reaction.ID)
|
||||||
case "unreact":
|
case "unreact":
|
||||||
if err := models.DeleteCommentReaction(ctx.User, comment.Issue, comment, form.Content); err != nil {
|
if err := models.DeleteCommentReaction(ctx.Doer, comment.Issue, comment, form.Content); err != nil {
|
||||||
ctx.ServerError("DeleteCommentReaction", err)
|
ctx.ServerError("DeleteCommentReaction", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2520,7 +2520,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.User)
|
perm, err := models.GetUserRepoPermission(c.RefRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2689,7 +2689,7 @@ func combineLabelComments(issue *models.Issue) {
|
||||||
|
|
||||||
// get all teams that current user can mention
|
// get all teams that current user can mention
|
||||||
func handleTeamMentions(ctx *context.Context) {
|
func handleTeamMentions(ctx *context.Context) {
|
||||||
if ctx.User == nil || !ctx.Repo.Owner.IsOrganization() {
|
if ctx.Doer == nil || !ctx.Repo.Owner.IsOrganization() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2698,10 +2698,10 @@ func handleTeamMentions(ctx *context.Context) {
|
||||||
var teams []*models.Team
|
var teams []*models.Team
|
||||||
org := models.OrgFromUser(ctx.Repo.Owner)
|
org := models.OrgFromUser(ctx.Repo.Owner)
|
||||||
// Admin has super access.
|
// Admin has super access.
|
||||||
if ctx.User.IsAdmin {
|
if ctx.Doer.IsAdmin {
|
||||||
isAdmin = true
|
isAdmin = true
|
||||||
} else {
|
} else {
|
||||||
isAdmin, err = org.IsOwnedBy(ctx.User.ID)
|
isAdmin, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("IsOwnedBy", err)
|
ctx.ServerError("IsOwnedBy", err)
|
||||||
return
|
return
|
||||||
|
@ -2715,7 +2715,7 @@ func handleTeamMentions(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
teams, err = org.GetUserTeams(ctx.User.ID)
|
teams, err = org.GetUserTeams(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserTeams", err)
|
ctx.ServerError("GetUserTeams", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -99,11 +99,11 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comm
|
||||||
} else if ctx.Repo.CanWrite(unit.TypeIssues) {
|
} else if ctx.Repo.CanWrite(unit.TypeIssues) {
|
||||||
if comment == nil {
|
if comment == nil {
|
||||||
// the issue poster or the history poster can soft-delete
|
// the issue poster or the history poster can soft-delete
|
||||||
canSoftDelete = ctx.User.ID == issue.PosterID || ctx.User.ID == history.PosterID
|
canSoftDelete = ctx.Doer.ID == issue.PosterID || ctx.Doer.ID == history.PosterID
|
||||||
canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
|
canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
|
||||||
} else {
|
} else {
|
||||||
// the comment poster or the history poster can soft-delete
|
// the comment poster or the history poster can soft-delete
|
||||||
canSoftDelete = ctx.User.ID == comment.PosterID || ctx.User.ID == history.PosterID
|
canSoftDelete = ctx.Doer.ID == comment.PosterID || ctx.Doer.ID == history.PosterID
|
||||||
canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
|
canSoftDelete = canSoftDelete && (history.IssueID == issue.ID)
|
||||||
canSoftDelete = canSoftDelete && (history.CommentID == comment.ID)
|
canSoftDelete = canSoftDelete && (history.CommentID == comment.ID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func AddDependency(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the Repo is allowed to have dependencies
|
// Check if the Repo is allowed to have dependencies
|
||||||
if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
|
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func AddDependency(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.CreateIssueDependency(ctx.User, issue, dep)
|
err = models.CreateIssueDependency(ctx.Doer, issue, dep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrDependencyExists(err) {
|
if models.IsErrDependencyExists(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
|
||||||
|
@ -81,7 +81,7 @@ func RemoveDependency(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the Repo is allowed to have dependencies
|
// Check if the Repo is allowed to have dependencies
|
||||||
if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
|
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func RemoveDependency(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = models.RemoveIssueDependency(ctx.User, issue, dep, depType); err != nil {
|
if err = models.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil {
|
||||||
if models.IsErrDependencyNotExists(err) {
|
if models.IsErrDependencyNotExists(err) {
|
||||||
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
|
||||||
return
|
return
|
||||||
|
|
|
@ -82,8 +82,8 @@ func RetrieveLabels(ctx *context.Context) {
|
||||||
ctx.ServerError("GetOrgByName", err)
|
ctx.ServerError("GetOrgByName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.User != nil {
|
if ctx.Doer != nil {
|
||||||
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.User.ID)
|
ctx.Org.IsOwner, err = org.IsOwnedBy(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("org.IsOwnedBy", err)
|
ctx.ServerError("org.IsOwnedBy", err)
|
||||||
return
|
return
|
||||||
|
@ -169,7 +169,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||||
switch action := ctx.FormString("action"); action {
|
switch action := ctx.FormString("action"); action {
|
||||||
case "clear":
|
case "clear":
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if err := issue_service.ClearLabels(issue, ctx.User); err != nil {
|
if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil {
|
||||||
ctx.ServerError("ClearLabels", err)
|
ctx.ServerError("ClearLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -198,14 +198,14 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||||
|
|
||||||
if action == "attach" {
|
if action == "attach" {
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if err = issue_service.AddLabel(issue, ctx.User, label); err != nil {
|
if err = issue_service.AddLabel(issue, ctx.Doer, label); err != nil {
|
||||||
ctx.ServerError("AddLabel", err)
|
ctx.ServerError("AddLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if err = issue_service.RemoveLabel(issue, ctx.User, label); err != nil {
|
if err = issue_service.RemoveLabel(issue, ctx.Doer, label); err != nil {
|
||||||
ctx.ServerError("RemoveLabel", err)
|
ctx.ServerError("RemoveLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func LockIssue(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.LockIssue(&models.IssueLockOptions{
|
if err := models.LockIssue(&models.IssueLockOptions{
|
||||||
Doer: ctx.User,
|
Doer: ctx.Doer,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Reason: form.Reason,
|
Reason: form.Reason,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -60,7 +60,7 @@ func UnlockIssue(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UnlockIssue(&models.IssueLockOptions{
|
if err := models.UnlockIssue(&models.IssueLockOptions{
|
||||||
Doer: ctx.User,
|
Doer: ctx.Doer,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.ServerError("UnlockIssue", err)
|
ctx.ServerError("UnlockIssue", err)
|
||||||
|
|
|
@ -21,16 +21,16 @@ func IssueStopwatch(c *context.Context) {
|
||||||
|
|
||||||
var showSuccessMessage bool
|
var showSuccessMessage bool
|
||||||
|
|
||||||
if !models.StopwatchExists(c.User.ID, issue.ID) {
|
if !models.StopwatchExists(c.Doer.ID, issue.ID) {
|
||||||
showSuccessMessage = true
|
showSuccessMessage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
|
||||||
c.NotFound("CanUseTimetracker", nil)
|
c.NotFound("CanUseTimetracker", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateOrStopIssueStopwatch(c.User, issue); err != nil {
|
if err := models.CreateOrStopIssueStopwatch(c.Doer, issue); err != nil {
|
||||||
c.ServerError("CreateOrStopIssueStopwatch", err)
|
c.ServerError("CreateOrStopIssueStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -49,12 +49,12 @@ func CancelStopwatch(c *context.Context) {
|
||||||
if c.Written() {
|
if c.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
|
||||||
c.NotFound("CanUseTimetracker", nil)
|
c.NotFound("CanUseTimetracker", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CancelStopwatch(c.User, issue); err != nil {
|
if err := models.CancelStopwatch(c.Doer, issue); err != nil {
|
||||||
c.ServerError("CancelStopwatch", err)
|
c.ServerError("CancelStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func GetActiveStopwatch(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, sw, err := models.HasUserStopwatch(c.User.ID)
|
_, sw, err := models.HasUserStopwatch(c.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ServerError("HasUserStopwatch", err)
|
c.ServerError("HasUserStopwatch", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,7 +22,7 @@ func AddTimeManually(c *context.Context) {
|
||||||
if c.Written() {
|
if c.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
|
||||||
c.NotFound("CanUseTimetracker", nil)
|
c.NotFound("CanUseTimetracker", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func AddTimeManually(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := models.AddTime(c.User, issue, int64(total.Seconds()), time.Now()); err != nil {
|
if _, err := models.AddTime(c.Doer, issue, int64(total.Seconds()), time.Now()); err != nil {
|
||||||
c.ServerError("AddTime", err)
|
c.ServerError("AddTime", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func DeleteTime(c *context.Context) {
|
||||||
if c.Written() {
|
if c.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !c.Repo.CanUseTimetracker(issue, c.User) {
|
if !c.Repo.CanUseTimetracker(issue, c.Doer) {
|
||||||
c.NotFound("CanUseTimetracker", nil)
|
c.NotFound("CanUseTimetracker", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func DeleteTime(c *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only OP or admin may delete
|
// only OP or admin may delete
|
||||||
if !c.IsSigned || (!c.IsUserSiteAdmin() && c.User.ID != t.UserID) {
|
if !c.IsSigned || (!c.IsUserSiteAdmin() && c.Doer.ID != t.UserID) {
|
||||||
c.Error(http.StatusForbidden, "not allowed")
|
c.Error(http.StatusForbidden, "not allowed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func IssueWatch(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
if !ctx.IsSigned || (ctx.Doer.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) {
|
||||||
if log.IsTrace() {
|
if log.IsTrace() {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
issueType := "issues"
|
issueType := "issues"
|
||||||
|
@ -29,7 +29,7 @@ func IssueWatch(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
log.Trace("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n"+
|
||||||
"User in Repo has Permissions: %-+v",
|
"User in Repo has Permissions: %-+v",
|
||||||
ctx.User,
|
ctx.Doer,
|
||||||
log.NewColoredIDValue(issue.PosterID),
|
log.NewColoredIDValue(issue.PosterID),
|
||||||
issueType,
|
issueType,
|
||||||
ctx.Repo.Repository,
|
ctx.Repo.Repository,
|
||||||
|
@ -48,7 +48,7 @@ func IssueWatch(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateOrUpdateIssueWatch(ctx.User.ID, issue.ID, watch); err != nil {
|
if err := models.CreateOrUpdateIssueWatch(ctx.Doer.ID, issue.ID, watch); err != nil {
|
||||||
ctx.ServerError("CreateOrUpdateIssueWatch", err)
|
ctx.ServerError("CreateOrUpdateIssueWatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,7 @@ func LFSLockFile(ctx *context.Context) {
|
||||||
|
|
||||||
_, err := models.CreateLFSLock(ctx.Repo.Repository, &models.LFSLock{
|
_, err := models.CreateLFSLock(ctx.Repo.Repository, &models.LFSLock{
|
||||||
Path: lockPath,
|
Path: lockPath,
|
||||||
OwnerID: ctx.User.ID,
|
OwnerID: ctx.Doer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrLFSLockAlreadyExist(err) {
|
if models.IsErrLFSLockAlreadyExist(err) {
|
||||||
|
@ -237,7 +237,7 @@ func LFSUnlock(ctx *context.Context) {
|
||||||
ctx.NotFound("LFSUnlock", nil)
|
ctx.NotFound("LFSUnlock", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.User, true)
|
_, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("LFSUnlock", err)
|
ctx.ServerError("LFSUnlock", err)
|
||||||
return
|
return
|
||||||
|
@ -476,7 +476,7 @@ func LFSPointerFiles(ctx *context.Context) {
|
||||||
// Can we fix?
|
// Can we fix?
|
||||||
// OK well that's "simple"
|
// OK well that's "simple"
|
||||||
// - we need to check whether current user has access to a repo that has access to the file
|
// - we need to check whether current user has access to a repo that has access to the file
|
||||||
result.Associatable, err = models.LFSObjectAccessible(ctx.User, pointerBlob.Oid)
|
result.Associatable, err = models.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ func LFSAutoAssociate(ctx *context.Context) {
|
||||||
metas[i].Oid = oid[:idx]
|
metas[i].Oid = oid[:idx]
|
||||||
// metas[i].RepositoryID = ctx.Repo.Repository.ID
|
// metas[i].RepositoryID = ctx.Repo.Repository.ID
|
||||||
}
|
}
|
||||||
if err := models.LFSAutoAssociate(metas, ctx.User, ctx.Repo.Repository.ID); err != nil {
|
if err := models.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil {
|
||||||
ctx.ServerError("LFSAutoAssociate", err)
|
ctx.ServerError("LFSAutoAssociate", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func SetDiffViewStyle(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
userStyle = ctx.User.DiffViewStyle
|
userStyle = ctx.Doer.DiffViewStyle
|
||||||
style string
|
style string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func SetDiffViewStyle(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["IsSplitStyle"] = style == "split"
|
ctx.Data["IsSplitStyle"] = style == "split"
|
||||||
if err := user_model.UpdateUserDiffViewStyle(ctx.User, style); err != nil {
|
if err := user_model.UpdateUserDiffViewStyle(ctx.Doer, style); err != nil {
|
||||||
ctx.ServerError("ErrUpdateDiffViewStyle", err)
|
ctx.ServerError("ErrUpdateDiffViewStyle", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ func SetWhitespaceBehavior(ctx *context.Context) {
|
||||||
whitespaceBehavior = defaultWhitespaceBehavior
|
whitespaceBehavior = defaultWhitespaceBehavior
|
||||||
}
|
}
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
userWhitespaceBehavior, err := user_model.GetUserSetting(ctx.User.ID, user_model.SettingsKeyDiffWhitespaceBehavior, defaultWhitespaceBehavior)
|
userWhitespaceBehavior, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, defaultWhitespaceBehavior)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if whitespaceBehavior == "" {
|
if whitespaceBehavior == "" {
|
||||||
whitespaceBehavior = userWhitespaceBehavior
|
whitespaceBehavior = userWhitespaceBehavior
|
||||||
} else if whitespaceBehavior != userWhitespaceBehavior {
|
} else if whitespaceBehavior != userWhitespaceBehavior {
|
||||||
_ = user_model.SetUserSetting(ctx.User.ID, user_model.SettingsKeyDiffWhitespaceBehavior, whitespaceBehavior)
|
_ = user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyDiffWhitespaceBehavior, whitespaceBehavior)
|
||||||
}
|
}
|
||||||
} // else: we can ignore the error safely
|
} // else: we can ignore the error safely
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ func MigratePost(ctx *context.Context) {
|
||||||
|
|
||||||
remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
|
remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.User)
|
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.Doer)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Data["Err_CloneAddr"] = true
|
ctx.Data["Err_CloneAddr"] = true
|
||||||
|
@ -195,7 +195,7 @@ func MigratePost(ctx *context.Context) {
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_lfs_endpoint"), tpl, &form)
|
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_lfs_endpoint"), tpl, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.User)
|
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Data["Err_LFSEndpoint"] = true
|
ctx.Data["Err_LFSEndpoint"] = true
|
||||||
handleMigrateRemoteAddrError(ctx, err, tpl, form)
|
handleMigrateRemoteAddrError(ctx, err, tpl, form)
|
||||||
|
@ -233,13 +233,13 @@ func MigratePost(ctx *context.Context) {
|
||||||
opts.Releases = false
|
opts.Releases = false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo_model.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, false)
|
err = repo_model.CheckCreateRepository(ctx.Doer, ctxUser, opts.RepoName, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
|
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = task.MigrateRepository(ctx.User, ctxUser, opts)
|
err = task.MigrateRepository(ctx.Doer, ctxUser, opts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(opts.RepoName))
|
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(opts.RepoName))
|
||||||
return
|
return
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue