mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
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
|
@ -110,7 +110,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
if _, err := repo_service.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
|
||||
if _, err := repo_service.AdoptRepository(ctx.Doer, ctxUser, models.CreateRepoOptions{
|
||||
Name: repoName,
|
||||
IsPrivate: true,
|
||||
}); err != nil {
|
||||
|
@ -173,7 +173,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func PostCronTask(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ func GetAllOrgs(ctx *context.APIContext) {
|
|||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
Type: user_model.UserTypeOrganization,
|
||||
OrderBy: db.SearchOrderByAlphabetically,
|
||||
ListOptions: listOptions,
|
||||
|
|
|
@ -128,13 +128,13 @@ func CreateUser(ctx *context.APIContext) {
|
|||
}
|
||||
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.
|
||||
if form.SendNotify {
|
||||
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
|
||||
|
@ -275,9 +275,9 @@ func EditUser(ctx *context.APIContext) {
|
|||
}
|
||||
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
|
||||
|
@ -320,7 +320,7 @@ func DeleteUser(ctx *context.APIContext) {
|
|||
}
|
||||
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)
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
|
|||
}
|
||||
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)
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ func GetAllUsers(ctx *context.APIContext) {
|
|||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
Type: user_model.UserTypeIndividual,
|
||||
OrderBy: db.SearchOrderByAlphabetically,
|
||||
ListOptions: listOptions,
|
||||
|
@ -443,7 +443,7 @@ func GetAllUsers(ctx *context.APIContext) {
|
|||
|
||||
results := make([]*api.User, len(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)
|
||||
|
|
|
@ -103,7 +103,7 @@ func sudo() func(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if len(sudo) > 0 {
|
||||
if ctx.IsSigned && ctx.User.IsAdmin {
|
||||
if ctx.IsSigned && ctx.Doer.IsAdmin {
|
||||
user, err := user_model.GetUserByName(sudo)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
|
@ -113,8 +113,8 @@ func sudo() func(ctx *context.APIContext) {
|
|||
}
|
||||
return
|
||||
}
|
||||
log.Trace("Sudo from (%s) to: %s", ctx.User.Name, user.Name)
|
||||
ctx.User = user
|
||||
log.Trace("Sudo from (%s) to: %s", ctx.Doer.Name, user.Name)
|
||||
ctx.Doer = user
|
||||
} else {
|
||||
ctx.JSON(http.StatusForbidden, map[string]string{
|
||||
"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.
|
||||
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
|
||||
owner = ctx.User
|
||||
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||
owner = ctx.Doer
|
||||
} else {
|
||||
owner, err = user_model.GetUserByName(userName)
|
||||
if err != nil {
|
||||
|
@ -178,7 +178,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
repo.Owner = owner
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||
return
|
||||
|
@ -307,7 +307,7 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.User.ID)
|
||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
||||
return
|
||||
|
@ -334,7 +334,7 @@ func reqTeamMembership() func(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
orgID := ctx.Org.Team.OrgID
|
||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.User.ID)
|
||||
isOwner, err := models.IsOrganizationOwner(orgID, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
||||
return
|
||||
|
@ -342,11 +342,11 @@ func reqTeamMembership() func(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
} else if !isTeamMember {
|
||||
isOrgMember, err := models.IsOrganizationMember(orgID, ctx.User.ID)
|
||||
isOrgMember, err := models.IsOrganizationMember(orgID, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
||||
} else if isOrgMember {
|
||||
|
@ -376,7 +376,7 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
} else if !isMember {
|
||||
|
@ -392,7 +392,7 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
|||
|
||||
func reqGitHook() 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")
|
||||
return
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ func mustEnableIssues(ctx *context.APIContext) {
|
|||
if ctx.IsSigned {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||
"User in Repo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
unit.TypeIssues,
|
||||
ctx.Repo.Repository,
|
||||
ctx.Repo.Permission)
|
||||
|
@ -486,7 +486,7 @@ func mustAllowPulls(ctx *context.APIContext) {
|
|||
if ctx.IsSigned {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||
"User in Repo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
unit.TypePullRequests,
|
||||
ctx.Repo.Repository,
|
||||
ctx.Repo.Permission)
|
||||
|
@ -510,7 +510,7 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) {
|
|||
if ctx.IsSigned {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+
|
||||
"User in Repo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
unit.TypeIssues,
|
||||
unit.TypePullRequests,
|
||||
ctx.Repo.Repository,
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewAvailable(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$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 {
|
||||
|
@ -33,7 +33,7 @@ func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificatio
|
|||
}
|
||||
opts := &models.FindNotificationOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
UpdatedBeforeUnix: before,
|
||||
UpdatedAfterUnix: since,
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
opts := &models.FindNotificationOptions{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
UpdatedBeforeUnix: lastRead,
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
changed := make([]*structs.NotificationThread, len(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 {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -87,7 +87,7 @@ func ReadThread(ctx *context.APIContext) {
|
|||
targetStatus = models.NotificationStatusRead
|
||||
}
|
||||
|
||||
notif, err := models.SetNotificationStatus(n.ID, ctx.User, targetStatus)
|
||||
notif, err := models.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -109,7 +109,7 @@ func getThread(ctx *context.APIContext) *models.Notification {
|
|||
}
|
||||
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))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
opts := &models.FindNotificationOptions{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
UpdatedBeforeUnix: lastRead,
|
||||
}
|
||||
if !ctx.FormBool("all") {
|
||||
|
@ -162,7 +162,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
changed := make([]*structs.NotificationThread, 0, len(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 {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -39,7 +39,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
|||
|
||||
apiMembers := make([]*api.User, len(members))
|
||||
for i, member := range members {
|
||||
apiMembers[i] = convert.ToUser(member, ctx.User)
|
||||
apiMembers[i] = convert.ToUser(member, ctx.Doer)
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
|
@ -72,13 +72,13 @@ func ListMembers(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/UserList"
|
||||
|
||||
publicOnly := true
|
||||
if ctx.User != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
||||
if ctx.Doer != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
}
|
||||
publicOnly = !isMember && !ctx.User.IsAdmin
|
||||
publicOnly = !isMember && !ctx.Doer.IsAdmin
|
||||
}
|
||||
listMembers(ctx, publicOnly)
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ func IsMember(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if ctx.User != nil {
|
||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.User.ID)
|
||||
if ctx.Doer != nil {
|
||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
} else if userIsMember || ctx.User.IsAdmin {
|
||||
} else if userIsMember || ctx.Doer.IsAdmin {
|
||||
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(userToCheck.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
|
@ -154,7 +154,7 @@ func IsMember(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
}
|
||||
return
|
||||
} else if ctx.User.ID == userToCheck.ID {
|
||||
} else if ctx.Doer.ID == userToCheck.ID {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ func PublicizeMember(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if userToPublicize.ID != ctx.User.ID {
|
||||
if userToPublicize.ID != ctx.Doer.ID {
|
||||
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
|
||||
return
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func ConcealMember(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if userToConceal.ID != ctx.User.ID {
|
||||
if userToConceal.ID != ctx.Doer.ID {
|
||||
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
|
||||
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{
|
||||
ListOptions: listOptions,
|
||||
|
@ -71,7 +71,7 @@ func ListMyOrgs(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/OrganizationList"
|
||||
|
||||
listUserOrgs(ctx, ctx.User)
|
||||
listUserOrgs(ctx, ctx.Doer)
|
||||
}
|
||||
|
||||
// ListUserOrgs list user's orgs
|
||||
|
@ -201,7 +201,7 @@ func GetAll(ctx *context.APIContext) {
|
|||
vMode := []api.VisibleType{api.VisibleTypePublic}
|
||||
if ctx.IsSigned {
|
||||
vMode = append(vMode, api.VisibleTypeLimited)
|
||||
if ctx.User.IsAdmin {
|
||||
if ctx.Doer.IsAdmin {
|
||||
vMode = append(vMode, api.VisibleTypePrivate)
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func GetAll(ctx *context.APIContext) {
|
|||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
publicOrgs, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
ListOptions: listOptions,
|
||||
Type: user_model.UserTypeOrganization,
|
||||
OrderBy: db.SearchOrderByAlphabetically,
|
||||
|
@ -251,7 +251,7 @@ func Create(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
||||
if !ctx.User.CanCreateOrganization() {
|
||||
if !ctx.Doer.CanCreateOrganization() {
|
||||
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
||||
return
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ func Create(ctx *context.APIContext) {
|
|||
Visibility: visibility,
|
||||
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) ||
|
||||
db.IsErrNameReserved(err) ||
|
||||
db.IsErrNameCharsNotAllowed(err) ||
|
||||
|
@ -304,7 +304,7 @@ func Get(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ func ListUserTeams(ctx *context.APIContext) {
|
|||
|
||||
teams, count, err := models.GetUserTeams(&models.GetUserTeamOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserTeams", err)
|
||||
|
@ -368,11 +368,11 @@ func GetTeamMembers(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
||||
return
|
||||
} else if !isMember && !ctx.User.IsAdmin {
|
||||
} else if !isMember && !ctx.Doer.IsAdmin {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ func GetTeamMembers(ctx *context.APIContext) {
|
|||
}
|
||||
members := make([]*api.User, len(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))
|
||||
|
@ -430,7 +430,7 @@ func GetTeamMember(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
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
|
||||
|
@ -540,7 +540,7 @@ func GetTeamRepos(ctx *context.APIContext) {
|
|||
}
|
||||
repos := make([]*api.Repository, len(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 {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
||||
return
|
||||
|
@ -599,7 +599,7 @@ func AddTeamRepository(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
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)
|
||||
return
|
||||
} else if access < perm.AccessModeAdmin {
|
||||
|
@ -649,7 +649,7 @@ func RemoveTeamRepository(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
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)
|
||||
return
|
||||
} else if access < perm.AccessModeAdmin {
|
||||
|
|
|
@ -75,7 +75,7 @@ func GetBranch(ctx *context.APIContext) {
|
|||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||
return
|
||||
|
@ -117,7 +117,7 @@ func DeleteBranch(ctx *context.APIContext) {
|
|||
|
||||
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 {
|
||||
case git.IsErrBranchNotExist(err):
|
||||
ctx.NotFound(err)
|
||||
|
@ -176,7 +176,7 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
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 models.IsErrBranchDoesNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
|
||||
|
@ -211,7 +211,7 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||
return
|
||||
|
@ -270,7 +270,7 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
||||
return
|
||||
|
|
|
@ -63,7 +63,7 @@ func ListCollaborators(ctx *context.APIContext) {
|
|||
|
||||
users := make([]*api.User, len(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)
|
||||
|
@ -255,12 +255,12 @@ func GetReviewers(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||
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
|
||||
|
@ -290,5 +290,5 @@ func GetAssignees(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||
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) {
|
||||
if !canWriteFiles(ctx.Repo) {
|
||||
return nil, models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RepoName: ctx.Repo.Repository.LowerName,
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoF
|
|||
}
|
||||
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
|
||||
|
@ -448,7 +448,7 @@ func DeleteFile(ctx *context.APIContext) {
|
|||
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
||||
if !canWriteFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RepoName: ctx.Repo.Repository.LowerName,
|
||||
})
|
||||
return
|
||||
|
@ -489,7 +489,7 @@ func DeleteFile(ctx *context.APIContext) {
|
|||
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) {
|
||||
ctx.Error(http.StatusNotFound, "DeleteFile", err)
|
||||
return
|
||||
|
@ -546,7 +546,7 @@ func GetContents(ctx *context.APIContext) {
|
|||
|
||||
if !canReadFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RepoName: ctx.Repo.Repository.LowerName,
|
||||
})
|
||||
return
|
||||
|
|
|
@ -58,7 +58,7 @@ func ListForks(ctx *context.APIContext) {
|
|||
}
|
||||
apiForks := make([]*api.Repository, len(forks))
|
||||
for i, fork := range forks {
|
||||
access, err := models.AccessLevel(ctx.User, fork)
|
||||
access, err := models.AccessLevel(ctx.Doer, fork)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
|
@ -106,7 +106,7 @@ func CreateFork(ctx *context.APIContext) {
|
|||
repo := ctx.Repo.Repository
|
||||
var forker *user_model.User // user/org that will own the fork
|
||||
if form.Organization == nil {
|
||||
forker = ctx.User
|
||||
forker = ctx.Doer
|
||||
} else {
|
||||
org, err := models.GetOrgByName(*form.Organization)
|
||||
if err != nil {
|
||||
|
@ -117,7 +117,7 @@ func CreateFork(ctx *context.APIContext) {
|
|||
}
|
||||
return
|
||||
}
|
||||
isMember, err := org.IsOrgMember(ctx.User.ID)
|
||||
isMember, err := org.IsOrgMember(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
|
@ -135,7 +135,7 @@ func CreateFork(ctx *context.APIContext) {
|
|||
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,
|
||||
Name: name,
|
||||
Description: repo.Description,
|
||||
|
|
|
@ -163,8 +163,8 @@ func TestHook(ctx *context.APIContext) {
|
|||
Commits: []*api.PayloadCommit{commit},
|
||||
HeadCommit: commit,
|
||||
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
|
||||
Pusher: convert.ToUserWithAccessMode(ctx.User, perm.AccessModeNone),
|
||||
Sender: convert.ToUserWithAccessMode(ctx.User, perm.AccessModeNone),
|
||||
Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
|
||||
Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
|
||||
}); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
||||
return
|
||||
|
|
|
@ -135,7 +135,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
// 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
|
||||
OrderBy: db.SearchOrderByAlphabetically,
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
}
|
||||
if ctx.IsSigned {
|
||||
opts.Private = true
|
||||
|
@ -247,7 +247,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
|
||||
ctxUserID := int64(0)
|
||||
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
|
||||
|
@ -597,8 +597,8 @@ func CreateIssue(ctx *context.APIContext) {
|
|||
RepoID: ctx.Repo.Repository.ID,
|
||||
Repo: ctx.Repo.Repository,
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
PosterID: ctx.Doer.ID,
|
||||
Poster: ctx.Doer,
|
||||
Content: form.Body,
|
||||
Ref: form.Ref,
|
||||
DeadlineUnix: deadlineUnix,
|
||||
|
@ -651,7 +651,7 @@ func CreateIssue(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
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) {
|
||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
||||
return
|
||||
|
@ -729,7 +729,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !issue.IsPoster(ctx.User.ID) && !canWrite {
|
||||
if !issue.IsPoster(ctx.Doer.ID) && !canWrite {
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
issue.Content = *form.Body
|
||||
}
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
|
||||
return
|
||||
|
@ -759,7 +759,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
|
||||
return
|
||||
|
@ -791,7 +791,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
issue.MilestoneID != *form.Milestone {
|
||||
oldMilestoneID := issue.MilestoneID
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -808,7 +808,7 @@ func EditIssue(ctx *context.APIContext) {
|
|||
}
|
||||
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 models.IsErrDependenciesLeft(err) {
|
||||
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 {
|
||||
notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
|
||||
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -877,7 +877,7 @@ func DeleteIssue(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -946,7 +946,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -183,9 +183,9 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
|||
|
||||
var apiComments []*api.TimelineComment
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
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")))
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "CreateIssueComment", err)
|
||||
return
|
||||
|
@ -534,7 +534,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
|||
|
||||
oldContent := comment.Content
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment {
|
||||
|
@ -645,7 +645,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func AddIssueLabels(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
|||
var result []api.Reaction
|
||||
for _, r := range reactions {
|
||||
result = append(result, api.Reaction{
|
||||
User: convert.ToUser(r.User, ctx.User),
|
||||
User: convert.ToUser(r.User, ctx.Doer),
|
||||
Reaction: r.Type,
|
||||
Created: r.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -197,13 +197,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
|||
|
||||
if isCreateType {
|
||||
// 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 models.IsErrForbiddenIssueReaction(err) {
|
||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||
} else if models.IsErrReactionAlreadyExist(err) {
|
||||
ctx.JSON(http.StatusOK, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -214,13 +214,13 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
|||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
} else {
|
||||
// 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 {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
|
||||
return
|
||||
|
@ -299,7 +299,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
|||
var result []api.Reaction
|
||||
for _, r := range reactions {
|
||||
result = append(result, api.Reaction{
|
||||
User: convert.ToUser(r.User, ctx.User),
|
||||
User: convert.ToUser(r.User, ctx.Doer),
|
||||
Reaction: r.Type,
|
||||
Created: r.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -407,13 +407,13 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
|||
|
||||
if isCreateType {
|
||||
// PostIssueReaction part
|
||||
reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Reaction)
|
||||
reaction, err := models.CreateIssueReaction(ctx.Doer, issue, form.Reaction)
|
||||
if err != nil {
|
||||
if models.IsErrForbiddenIssueReaction(err) {
|
||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||
} else if models.IsErrReactionAlreadyExist(err) {
|
||||
ctx.JSON(http.StatusOK, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -424,13 +424,13 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
|||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
User: convert.ToUser(ctx.Doer, ctx.Doer),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
} else {
|
||||
// DeleteIssueReaction part
|
||||
err = models.DeleteIssueReaction(ctx.User, issue, form.Reaction)
|
||||
err = models.DeleteIssueReaction(ctx.Doer, issue, form.Reaction)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
|
||||
return
|
||||
|
|
|
@ -56,7 +56,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -179,12 +179,12 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
|
|||
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)
|
||||
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 {
|
||||
ctx.Error(http.StatusConflict, "StopwatchExists", "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":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := models.CountUserStopwatches(ctx.User.ID)
|
||||
count, err := models.CountUserStopwatches(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -128,8 +128,8 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
|||
}
|
||||
|
||||
// only admin and user for itself can change subscription
|
||||
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
|
||||
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.User.Name, user.Name))
|
||||
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.Doer.Name, user.Name))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
watching, err := models.CheckIssueWatch(ctx.User, issue)
|
||||
watching, err := models.CheckIssueWatch(ctx.Doer, issue)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -281,7 +281,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
|||
}
|
||||
apiUsers := make([]*api.User, 0, len(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)
|
||||
|
|
|
@ -108,13 +108,13 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
cantSetUser := !ctx.User.IsAdmin &&
|
||||
opts.UserID != ctx.User.ID &&
|
||||
cantSetUser := !ctx.Doer.IsAdmin &&
|
||||
opts.UserID != ctx.Doer.ID &&
|
||||
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
||||
|
||||
if cantSetUser {
|
||||
if opts.UserID == 0 {
|
||||
opts.UserID = ctx.User.ID
|
||||
opts.UserID = ctx.Doer.ID
|
||||
} else {
|
||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
||||
return
|
||||
|
@ -189,7 +189,7 @@ func AddTime(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
||||
return
|
||||
|
@ -198,9 +198,9 @@ func AddTime(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
user := ctx.User
|
||||
user := ctx.Doer
|
||||
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
|
||||
user, err = user_model.GetUserByName(form.User)
|
||||
if err != nil {
|
||||
|
@ -270,7 +270,7 @@ func ResetIssueTime(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
||||
return
|
||||
|
@ -279,7 +279,7 @@ func ResetIssueTime(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
err = models.DeleteIssueUserTimes(issue, ctx.User)
|
||||
err = models.DeleteIssueUserTimes(issue, ctx.Doer)
|
||||
if err != nil {
|
||||
if models.IsErrNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
|
||||
|
@ -341,7 +341,7 @@ func DeleteTime(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
|
||||
if !ctx.Repo.CanUseTimetracker(issue, ctx.Doer) {
|
||||
if !ctx.Repo.Repository.IsTimetrackerEnabled() {
|
||||
ctx.JSON(http.StatusBadRequest, struct{ Message string }{Message: "time tracking disabled"})
|
||||
return
|
||||
|
@ -364,7 +364,7 @@ func DeleteTime(ctx *context.APIContext) {
|
|||
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
|
||||
ctx.Status(http.StatusForbidden)
|
||||
return
|
||||
|
@ -428,7 +428,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
|||
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"))
|
||||
return
|
||||
}
|
||||
|
@ -527,13 +527,13 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
cantSetUser := !ctx.User.IsAdmin &&
|
||||
opts.UserID != ctx.User.ID &&
|
||||
cantSetUser := !ctx.Doer.IsAdmin &&
|
||||
opts.UserID != ctx.Doer.ID &&
|
||||
!ctx.IsUserRepoWriter([]unit.Type{unit.TypeIssues})
|
||||
|
||||
if cantSetUser {
|
||||
if opts.UserID == 0 {
|
||||
opts.UserID = ctx.User.ID
|
||||
opts.UserID = ctx.Doer.ID
|
||||
} else {
|
||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
||||
return
|
||||
|
@ -593,7 +593,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
|||
|
||||
opts := &models.FindTrackedTimesOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
|
@ -107,7 +107,7 @@ func ListDeployKeys(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ func GetDeployKey(ctx *context.APIContext) {
|
|||
|
||||
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
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)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, apiKey)
|
||||
|
@ -270,7 +270,7 @@ func DeleteDeploykey(ctx *context.APIContext) {
|
|||
// "403":
|
||||
// "$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) {
|
||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
||||
} else {
|
||||
|
|
|
@ -66,7 +66,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
} else if form.RepoOwnerID != 0 {
|
||||
repoOwner, err = user_model.GetUserByID(form.RepoOwnerID)
|
||||
} else {
|
||||
repoOwner = ctx.User
|
||||
repoOwner = ctx.Doer
|
||||
}
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
|
@ -82,15 +82,15 @@ func Migrate(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !ctx.User.IsAdmin {
|
||||
if !repoOwner.IsOrganization() && ctx.User.ID != repoOwner.ID {
|
||||
if !ctx.Doer.IsAdmin {
|
||||
if !repoOwner.IsOrganization() && ctx.Doer.ID != repoOwner.ID {
|
||||
ctx.Error(http.StatusForbidden, "", "Given user is not an organization.")
|
||||
return
|
||||
}
|
||||
|
||||
if repoOwner.IsOrganization() {
|
||||
// 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 {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
||||
return
|
||||
|
@ -103,7 +103,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
|
||||
remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
|
||||
if err == nil {
|
||||
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.User)
|
||||
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.Doer)
|
||||
}
|
||||
if err != nil {
|
||||
handleRemoteAddrError(ctx, err)
|
||||
|
@ -130,7 +130,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "", ctx.Tr("repo.migrate.invalid_lfs_endpoint"))
|
||||
return
|
||||
}
|
||||
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.User)
|
||||
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
|
||||
if err != nil {
|
||||
handleRemoteAddrError(ctx, err)
|
||||
return
|
||||
|
@ -167,7 +167,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
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,
|
||||
Description: opts.Description,
|
||||
OriginalURL: form.CloneAddr,
|
||||
|
@ -192,18 +192,18 @@ func Migrate(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if err == nil {
|
||||
notification.NotifyMigrateRepository(ctx.User, repoOwner, repo)
|
||||
notification.NotifyMigrateRepository(ctx.Doer, repoOwner, repo)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -79,13 +79,13 @@ func ApplyDiffPatch(ctx *context.APIContext) {
|
|||
|
||||
if !canWriteFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RepoName: ctx.Repo.Repository.LowerName,
|
||||
})
|
||||
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 models.IsErrUserCannotCommit(err) || models.IsErrFilePathProtected(err) {
|
||||
ctx.Error(http.StatusForbidden, "Access", err)
|
||||
|
|
|
@ -118,7 +118,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
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)
|
||||
|
@ -174,7 +174,7 @@ func GetPullRequest(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
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
|
||||
|
@ -363,8 +363,8 @@ func CreatePullRequest(ctx *context.APIContext) {
|
|||
prIssue := &models.Issue{
|
||||
RepoID: repo.ID,
|
||||
Title: form.Title,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
PosterID: ctx.Doer.ID,
|
||||
Poster: ctx.Doer,
|
||||
MilestoneID: milestoneID,
|
||||
IsPull: true,
|
||||
Content: form.Body,
|
||||
|
@ -420,7 +420,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -484,7 +484,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
issue := pr.Issue
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
// Send an empty array ([]) to clear all assignees from the Issue.
|
||||
|
||||
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 user_model.IsErrUserNotExist(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 {
|
||||
oldMilestoneID := issue.MilestoneID
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
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 models.IsErrDependenciesLeft(err) {
|
||||
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 {
|
||||
notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
|
||||
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||
}
|
||||
|
||||
if statusChangeComment != nil {
|
||||
notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed)
|
||||
notification.NotifyIssueChangeStatus(ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||
}
|
||||
|
||||
// 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))
|
||||
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) {
|
||||
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
|
||||
return
|
||||
|
@ -612,7 +612,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
return
|
||||
}
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx.User, pr, form.Base)
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx.Doer, pr, form.Base)
|
||||
}
|
||||
|
||||
// Refetch from database
|
||||
|
@ -627,7 +627,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
@ -737,7 +737,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
|
||||
if ctx.IsSigned {
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "IsUSerAllowedToMerge", err)
|
||||
return
|
||||
|
@ -765,7 +765,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
|
||||
// handle manually-merged mark
|
||||
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) {
|
||||
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
|
||||
|
@ -797,7 +797,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
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)
|
||||
return
|
||||
} 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) {
|
||||
ctx.Error(http.StatusInternalServerError, "IsSignedIfRequired", err)
|
||||
return
|
||||
|
@ -837,7 +837,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
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) {
|
||||
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
|
||||
|
@ -894,7 +894,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
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 {
|
||||
case git.IsErrBranchNotExist(err):
|
||||
ctx.NotFound(err)
|
||||
|
@ -907,7 +907,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
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
|
||||
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
|
||||
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
|
||||
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.Doer)
|
||||
if err != nil {
|
||||
headGitRepo.Close()
|
||||
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 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",
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
baseRepo,
|
||||
permBase)
|
||||
}
|
||||
|
@ -1008,7 +1008,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||
}
|
||||
|
||||
// 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 {
|
||||
headGitRepo.Close()
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||
|
@ -1017,7 +1017,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||
if !permHead.CanRead(unit.TypeCode) {
|
||||
if log.IsTrace() {
|
||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v",
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
headRepo,
|
||||
permHead)
|
||||
}
|
||||
|
@ -1120,7 +1120,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
|
||||
return
|
||||
|
@ -1134,7 +1134,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
|||
// default merge commit message
|
||||
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) {
|
||||
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
|
||||
return
|
||||
|
|
|
@ -97,7 +97,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.User)
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||
return
|
||||
|
@ -148,7 +148,7 @@ func GetPullReview(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -198,7 +198,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.User)
|
||||
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
|
||||
return
|
||||
|
@ -250,11 +250,11 @@ func DeletePullReview(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.User == nil {
|
||||
if ctx.Doer == nil {
|
||||
ctx.NotFound()
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if _, err := pull_service.CreateCodeComment(ctx,
|
||||
ctx.User,
|
||||
ctx.Doer,
|
||||
ctx.Repo.GitRepo,
|
||||
pr.Issue,
|
||||
line,
|
||||
|
@ -369,14 +369,14 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||
return
|
||||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -457,14 +457,14 @@ func SubmitPullReview(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||
return
|
||||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -486,7 +486,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
|
|||
switch event {
|
||||
case api.ReviewStateApproved:
|
||||
// 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"))
|
||||
return -1, true
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
|
|||
|
||||
case api.ReviewStateRequestChanges:
|
||||
// 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"))
|
||||
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
|
||||
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")
|
||||
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))
|
||||
|
||||
permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.User)
|
||||
permDoer, err := models.GetUserRepoPermission(pr.Issue.Repo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
||||
return
|
||||
|
@ -686,7 +686,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
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 models.IsErrNotValidReviewRequest(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
||||
|
@ -705,7 +705,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
}
|
||||
|
||||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
|
||||
return
|
||||
|
@ -735,7 +735,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
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 models.IsErrNotValidReviewRequest(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
|
||||
|
@ -749,7 +749,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
}
|
||||
|
||||
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 {
|
||||
ctx.ServerError("TeamReviewRequest", err)
|
||||
return
|
||||
|
@ -766,7 +766,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
}
|
||||
|
||||
if isAdd {
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.User)
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||
return
|
||||
|
@ -884,7 +884,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
|||
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 {
|
||||
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
||||
return
|
||||
|
@ -896,7 +896,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
|||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
|
|
@ -191,8 +191,8 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
}
|
||||
rel = &models.Release{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
PublisherID: ctx.User.ID,
|
||||
Publisher: ctx.User,
|
||||
PublisherID: ctx.Doer.ID,
|
||||
Publisher: ctx.Doer,
|
||||
TagName: form.TagName,
|
||||
Target: form.Target,
|
||||
Title: form.Title,
|
||||
|
@ -220,12 +220,12 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
rel.Note = form.Note
|
||||
rel.IsDraft = form.IsDraft
|
||||
rel.IsPrerelease = form.IsPrerelease
|
||||
rel.PublisherID = ctx.User.ID
|
||||
rel.PublisherID = ctx.Doer.ID
|
||||
rel.IsTag = false
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func EditRelease(ctx *context.APIContext) {
|
|||
if form.IsPrerelease != nil {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ func DeleteRelease(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 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 upload.IsErrFileTypeForbidden(err) {
|
||||
ctx.Error(http.StatusBadRequest, "DetectContentType", err)
|
||||
|
|
|
@ -110,7 +110,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
opts := &models.SearchRepoOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
Keyword: ctx.FormTrim("q"),
|
||||
OwnerID: ctx.FormInt64("uid"),
|
||||
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
|
||||
|
@ -224,7 +224,7 @@ func Search(ctx *context.APIContext) {
|
|||
})
|
||||
return
|
||||
}
|
||||
accessMode, err := models.AccessLevel(ctx.User, repo)
|
||||
accessMode, err := models.AccessLevel(ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||
OK: false,
|
||||
|
@ -247,7 +247,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
|||
if opt.AutoInit && opt.Readme == "" {
|
||||
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,
|
||||
Description: opt.Description,
|
||||
IssueLabels: opt.IssueLabels,
|
||||
|
@ -303,12 +303,12 @@ func Create(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
if ctx.User.IsOrganization() {
|
||||
if ctx.Doer.IsOrganization() {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
||||
return
|
||||
}
|
||||
CreateUserRepo(ctx, ctx.User, *opt)
|
||||
CreateUserRepo(ctx, ctx.Doer, *opt)
|
||||
}
|
||||
|
||||
// Generate Create a repository using a template
|
||||
|
@ -353,7 +353,7 @@ func Generate(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.User.IsOrganization() {
|
||||
if ctx.Doer.IsOrganization() {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
||||
return
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ func Generate(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctxUser := ctx.User
|
||||
ctxUser := ctx.Doer
|
||||
var err error
|
||||
if form.Owner != ctxUser.Name {
|
||||
ctxUser, err = user_model.GetUserByName(form.Owner)
|
||||
|
@ -391,13 +391,13 @@ func Generate(ctx *context.APIContext) {
|
|||
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.")
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.User.IsAdmin {
|
||||
canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.User.ID)
|
||||
if !ctx.Doer.IsAdmin {
|
||||
canCreate, err := models.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
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 repo_model.IsErrRepoAlreadyExist(err) {
|
||||
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
||||
|
@ -493,13 +493,13 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.User) {
|
||||
if !models.HasOrgOrUserVisible(org.AsUser(), ctx.Doer) {
|
||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.User.IsAdmin {
|
||||
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
|
||||
if !ctx.Doer.IsAdmin {
|
||||
canCreate, err := org.CanCreateOrgRepo(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
||||
return
|
||||
|
@ -569,7 +569,7 @@ func GetByID(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
perm, err := models.GetUserRepoPermission(repo, ctx.User)
|
||||
perm, err := models.GetUserRepoPermission(repo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
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
|
||||
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 {
|
||||
case repo_model.IsErrRepoAlreadyExist(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
|
||||
// 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")
|
||||
ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
|
||||
return err
|
||||
|
@ -1019,7 +1019,7 @@ func Delete(ctx *context.APIContext) {
|
|||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
canDelete, err := models.CanUserDelete(repo, ctx.User)
|
||||
canDelete, err := models.CanUserDelete(repo, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
|
||||
return
|
||||
|
@ -1032,7 +1032,7 @@ func Delete(ctx *context.APIContext) {
|
|||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestRepoEdit(t *testing.T) {
|
|||
ctx := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
ctx.Repo.Owner = ctx.User
|
||||
ctx.Repo.Owner = ctx.Doer
|
||||
description := "new description"
|
||||
website := "http://wwww.newwebsite.com"
|
||||
private := true
|
||||
|
@ -71,7 +71,7 @@ func TestRepoEditNameChange(t *testing.T) {
|
|||
ctx := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
ctx.Repo.Owner = ctx.User
|
||||
ctx.Repo.Owner = ctx.Doer
|
||||
name := "newname"
|
||||
opts := api.EditRepoOption{
|
||||
Name: &name,
|
||||
|
|
|
@ -51,7 +51,7 @@ func ListStargazers(ctx *context.APIContext) {
|
|||
}
|
||||
users := make([]*api.User, len(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))
|
||||
|
|
|
@ -62,7 +62,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
|||
Description: form.Description,
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
|||
}
|
||||
users := make([]*api.User, len(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))
|
||||
|
|
|
@ -191,7 +191,7 @@ func CreateTag(ctx *context.APIContext) {
|
|||
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) {
|
||||
ctx.Error(http.StatusConflict, "tag exist", err)
|
||||
return
|
||||
|
@ -255,7 +255,7 @@ func DeleteTag(ctx *context.APIContext) {
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
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
|
||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
||||
return
|
||||
|
@ -103,7 +103,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
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) {
|
||||
ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err)
|
||||
return
|
||||
|
@ -218,7 +218,7 @@ func acceptOrRejectRepoTransfer(ctx *context.APIContext, accept bool) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !repoTransfer.CanUserAcceptTransfer(ctx.User) {
|
||||
if !repoTransfer.CanUserAcceptTransfer(ctx.Doer) {
|
||||
ctx.Error(http.StatusForbidden, "CanUserAcceptTransfer", nil)
|
||||
return fmt.Errorf("user does not have permissions to do this")
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func NewWikiPage(ctx *context.APIContext) {
|
|||
}
|
||||
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) {
|
||||
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
|
||||
} else if models.IsErrWikiAlreadyExist(err) {
|
||||
|
@ -144,7 +144,7 @@ func EditWikiPage(ctx *context.APIContext) {
|
|||
}
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
|
|||
|
||||
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" {
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
|
|
|
@ -45,7 +45,7 @@ func ListAccessTokens(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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)
|
||||
if err != nil {
|
||||
|
@ -99,7 +99,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
|||
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
|
||||
|
||||
t := &models.AccessToken{
|
||||
UID: ctx.User.ID,
|
||||
UID: ctx.Doer.ID,
|
||||
Name: form.Name,
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
|||
if tokenID == 0 {
|
||||
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{
|
||||
Name: token,
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err)
|
||||
|
@ -180,7 +180,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
|||
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) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
|
@ -215,7 +215,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
|||
|
||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||
Name: data.Name,
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
RedirectURIs: data.RedirectURIs,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -252,7 +252,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
|
||||
return
|
||||
|
@ -288,7 +288,7 @@ func DeleteOauth2Application(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
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) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
|
@ -365,7 +365,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
|||
|
||||
app, err := auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{
|
||||
Name: data.Name,
|
||||
UserID: ctx.User.ID,
|
||||
UserID: ctx.Doer.ID,
|
||||
ID: appID,
|
||||
RedirectURIs: data.RedirectURIs,
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@ func ListEmails(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/EmailList"
|
||||
|
||||
emails, err := user_model.GetEmailAddresses(ctx.User.ID)
|
||||
emails, err := user_model.GetEmailAddresses(ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
||||
return
|
||||
|
@ -71,7 +71,7 @@ func AddEmail(ctx *context.APIContext) {
|
|||
emails := make([]*user_model.EmailAddress, len(form.Emails))
|
||||
for i := range form.Emails {
|
||||
emails[i] = &user_model.EmailAddress{
|
||||
UID: ctx.User.ID,
|
||||
UID: ctx.Doer.ID,
|
||||
Email: form.Emails[i],
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func DeleteEmail(ctx *context.APIContext) {
|
|||
for i := range form.Emails {
|
||||
emails[i] = &user_model.EmailAddress{
|
||||
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) {
|
||||
apiUsers := make([]*api.User, len(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)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func ListMyFollowers(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
listUserFollowers(ctx, ctx.User)
|
||||
listUserFollowers(ctx, ctx.Doer)
|
||||
}
|
||||
|
||||
// ListFollowers list the given user's followers
|
||||
|
@ -120,7 +120,7 @@ func ListMyFollowing(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
listUserFollowing(ctx, ctx.User)
|
||||
listUserFollowing(ctx, ctx.Doer)
|
||||
}
|
||||
|
||||
// ListFollowing list the users that the given user is following
|
||||
|
@ -184,7 +184,7 @@ func CheckMyFollowing(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
checkUserFollowing(ctx, ctx.User, target.ID)
|
||||
checkUserFollowing(ctx, ctx.Doer, target.ID)
|
||||
}
|
||||
|
||||
// CheckFollowing check if one user is following another user
|
||||
|
@ -239,7 +239,7 @@ func Follow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ func Unfollow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ func ListMyGPGKeys(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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
|
||||
|
@ -128,8 +128,8 @@ func GetGPGKey(ctx *context.APIContext) {
|
|||
|
||||
// CreateUserGPGKey creates new GPG key to given user by ID.
|
||||
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
|
||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
||||
lastToken := asymkey_model.VerificationToken(ctx.User, 0)
|
||||
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
||||
|
||||
keys, err := asymkey_model.AddGPGKey(uid, form.ArmoredKey, token, form.Signature)
|
||||
if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
||||
|
@ -156,7 +156,7 @@ func GetVerificationToken(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
||||
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||
ctx.PlainText(http.StatusOK, token)
|
||||
}
|
||||
|
||||
|
@ -178,12 +178,12 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
|
||||
token := asymkey_model.VerificationToken(ctx.User, 1)
|
||||
lastToken := asymkey_model.VerificationToken(ctx.User, 0)
|
||||
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||
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) {
|
||||
_, 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 {
|
||||
|
@ -230,7 +230,7 @@ func CreateGPGKey(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
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
|
||||
|
@ -255,7 +255,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$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) {
|
||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
||||
} else {
|
||||
|
|
|
@ -86,7 +86,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
|
|||
apiKeys := make([]*api.PublicKey, len(keys))
|
||||
for i := range keys {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func ListMyPublicKeys(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/PublicKeyList"
|
||||
|
||||
listPublicKeys(ctx, ctx.User)
|
||||
listPublicKeys(ctx, ctx.Doer)
|
||||
}
|
||||
|
||||
// ListPublicKeys list the given user's public keys
|
||||
|
@ -190,8 +190,8 @@ func GetPublicKey(ctx *context.APIContext) {
|
|||
|
||||
apiLink := composePublicKeysAPILink()
|
||||
apiKey := convert.ToPublicKey(apiLink, key)
|
||||
if ctx.User.IsAdmin || ctx.User.ID == key.OwnerID {
|
||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.User)
|
||||
if ctx.Doer.IsAdmin || ctx.Doer.ID == key.OwnerID {
|
||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Doer)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, apiKey)
|
||||
}
|
||||
|
@ -211,8 +211,8 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
|
|||
}
|
||||
apiLink := composePublicKeysAPILink()
|
||||
apiKey := convert.ToPublicKey(apiLink, key)
|
||||
if ctx.User.IsAdmin || ctx.User.ID == key.OwnerID {
|
||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.User)
|
||||
if ctx.Doer.IsAdmin || ctx.Doer.ID == key.OwnerID {
|
||||
apiKey, _ = appendPrivateInformation(apiKey, key, ctx.Doer)
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, apiKey)
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ func CreatePublicKey(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
CreateUserPublicKey(ctx, *form, ctx.User.ID)
|
||||
CreateUserPublicKey(ctx, *form, ctx.Doer.ID)
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
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) {
|
||||
ctx.NotFound()
|
||||
} 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))
|
||||
for i := range repos {
|
||||
access, err := models.AccessLevel(ctx.User, repos[i])
|
||||
access, err := models.AccessLevel(ctx.Doer, repos[i])
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
|
||||
opts := &models.SearchRepoOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
Actor: ctx.User,
|
||||
OwnerID: ctx.User.ID,
|
||||
Actor: ctx.Doer,
|
||||
OwnerID: ctx.Doer.ID,
|
||||
Private: ctx.IsSigned,
|
||||
IncludeDescription: true,
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
|
||||
return
|
||||
}
|
||||
accessMode, err := models.AccessLevel(ctx.User, repo)
|
||||
accessMode, err := models.AccessLevel(ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func GetUserSettings(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/UserSettings"
|
||||
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.User))
|
||||
ctx.JSON(http.StatusOK, convert.User2UserSettings(ctx.Doer))
|
||||
}
|
||||
|
||||
// UpdateUserSettings returns user settings
|
||||
|
@ -46,38 +46,38 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
|||
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
||||
|
||||
if form.FullName != nil {
|
||||
ctx.User.FullName = *form.FullName
|
||||
ctx.Doer.FullName = *form.FullName
|
||||
}
|
||||
if form.Description != nil {
|
||||
ctx.User.Description = *form.Description
|
||||
ctx.Doer.Description = *form.Description
|
||||
}
|
||||
if form.Website != nil {
|
||||
ctx.User.Website = *form.Website
|
||||
ctx.Doer.Website = *form.Website
|
||||
}
|
||||
if form.Location != nil {
|
||||
ctx.User.Location = *form.Location
|
||||
ctx.Doer.Location = *form.Location
|
||||
}
|
||||
if form.Language != nil {
|
||||
ctx.User.Language = *form.Language
|
||||
ctx.Doer.Language = *form.Language
|
||||
}
|
||||
if form.Theme != nil {
|
||||
ctx.User.Theme = *form.Theme
|
||||
ctx.Doer.Theme = *form.Theme
|
||||
}
|
||||
if form.DiffViewStyle != nil {
|
||||
ctx.User.DiffViewStyle = *form.DiffViewStyle
|
||||
ctx.Doer.DiffViewStyle = *form.DiffViewStyle
|
||||
}
|
||||
|
||||
if form.HideEmail != nil {
|
||||
ctx.User.KeepEmailPrivate = *form.HideEmail
|
||||
ctx.Doer.KeepEmailPrivate = *form.HideEmail
|
||||
}
|
||||
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)
|
||||
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"
|
||||
|
||||
user := GetUserByParams(ctx)
|
||||
private := user.ID == ctx.User.ID
|
||||
private := user.ID == ctx.Doer.ID
|
||||
repos, err := getStarredRepos(user, private, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||
|
@ -94,12 +94,12 @@ func GetMyStarredRepos(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
repos, err := getStarredRepos(ctx.User, true, utils.GetListOptions(ctx))
|
||||
repos, err := getStarredRepos(ctx.Doer, true, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(int64(ctx.User.NumStars))
|
||||
ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars))
|
||||
ctx.JSON(http.StatusOK, &repos)
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ func IsStarring(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$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)
|
||||
} else {
|
||||
ctx.NotFound()
|
||||
|
@ -152,7 +152,7 @@ func Star(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
|
@ -180,7 +180,7 @@ func Unstar(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||
return
|
||||
|
|
|
@ -56,7 +56,7 @@ func Search(ctx *context.APIContext) {
|
|||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
users, maxResults, err := user_model.SearchUsers(&user_model.SearchUserOptions{
|
||||
Actor: ctx.User,
|
||||
Actor: ctx.Doer,
|
||||
Keyword: ctx.FormTrim("q"),
|
||||
UID: ctx.FormInt64("uid"),
|
||||
Type: user_model.UserTypeIndividual,
|
||||
|
@ -75,7 +75,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
"data": convert.ToUsers(ctx.User, users),
|
||||
"data": convert.ToUsers(ctx.Doer, users),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -104,12 +104,12 @@ func GetInfo(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !models.IsUserVisibleToViewer(u, ctx.User) {
|
||||
if !models.IsUserVisibleToViewer(u, ctx.Doer) {
|
||||
// fake ErrUserNotExist error message to not leak information about existence
|
||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
||||
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
|
||||
|
@ -123,7 +123,7 @@ func GetAuthenticatedUser(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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
|
||||
|
@ -150,7 +150,7 @@ func GetUserHeatmapData(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
heatmap, err := models.GetUserHeatmapDataByUser(user, ctx.User)
|
||||
heatmap, err := models.GetUserHeatmapDataByUser(user, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
|
||||
return
|
||||
|
|
|
@ -61,7 +61,7 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
user := GetUserByParams(ctx)
|
||||
private := user.ID == ctx.User.ID
|
||||
private := user.ID == ctx.Doer.ID
|
||||
repos, total, err := getWatchedRepos(user, private, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
|
@ -91,7 +91,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func IsWatching(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// 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{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
|
@ -157,7 +157,7 @@ func Watch(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
||||
return
|
||||
|
@ -192,7 +192,7 @@ func Unwatch(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$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 {
|
||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue