mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Refactor User.Id to User.ID
This commit is contained in:
parent
46e96c008c
commit
1f2e173a74
79 changed files with 333 additions and 328 deletions
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
|
||||
team := &models.Team{
|
||||
OrgID: ctx.Org.Organization.Id,
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
|
@ -37,7 +37,7 @@ func AddTeamMember(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if err := ctx.Org.Team.AddMember(u.Id); err != nil {
|
||||
if err := ctx.Org.Team.AddMember(u.ID); err != nil {
|
||||
ctx.Error(500, "AddMember", err)
|
||||
return
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func RemoveTeamMember(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Org.Team.RemoveMember(u.Id); err != nil {
|
||||
if err := ctx.Org.Team.RemoveMember(u.ID); err != nil {
|
||||
ctx.Error(500, "RemoveMember", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -147,5 +147,5 @@ func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
user.CreateUserPublicKey(ctx, form, u.Id)
|
||||
user.CreateUserPublicKey(ctx, form, u.ID)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func RepoAssignment() macaron.Handler {
|
|||
ctx.Repo.Owner = owner
|
||||
|
||||
// Get repository.
|
||||
repo, err := models.GetRepositoryByName(owner.Id, repoName)
|
||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
|
|
|
@ -23,7 +23,7 @@ func ToUser(u *models.User) *api.User {
|
|||
}
|
||||
|
||||
return &api.User{
|
||||
ID: u.Id,
|
||||
ID: u.ID,
|
||||
UserName: u.Name,
|
||||
FullName: u.FullName,
|
||||
Email: u.Email,
|
||||
|
@ -194,7 +194,7 @@ func ToIssue(issue *models.Issue) *api.Issue {
|
|||
|
||||
func ToOrganization(org *models.User) *api.Organization {
|
||||
return &api.Organization{
|
||||
ID: org.Id,
|
||||
ID: org.ID,
|
||||
AvatarUrl: org.AvatarLink(),
|
||||
UserName: org.Name,
|
||||
FullName: org.FullName,
|
||||
|
|
|
@ -48,7 +48,7 @@ func Get(ctx *context.APIContext) {
|
|||
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
|
||||
func Edit(ctx *context.APIContext, form api.EditOrgOption) {
|
||||
org := ctx.Org.Organization
|
||||
if !org.IsOwnedBy(ctx.User.Id) {
|
||||
if !org.IsOwnedBy(ctx.User.ID) {
|
||||
ctx.Status(403)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
issue := &models.Issue{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Name: form.Title,
|
||||
PosterID: ctx.User.Id,
|
||||
PosterID: ctx.User.ID,
|
||||
Poster: ctx.User,
|
||||
Content: form.Body,
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
|||
}
|
||||
return
|
||||
}
|
||||
issue.AssigneeID = assignee.Id
|
||||
issue.AssigneeID = assignee.ID
|
||||
}
|
||||
issue.MilestoneID = form.Milestone
|
||||
} else {
|
||||
|
@ -109,7 +109,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
return
|
||||
}
|
||||
|
||||
if !issue.IsPoster(ctx.User.Id) && !ctx.Repo.IsWriter() {
|
||||
if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
return
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
|||
}
|
||||
return
|
||||
}
|
||||
issue.AssigneeID = assignee.Id
|
||||
issue.AssigneeID = assignee.ID
|
||||
}
|
||||
|
||||
if err = models.UpdateIssueUserByAssignee(issue); err != nil {
|
||||
|
|
|
@ -27,7 +27,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
// Check visibility.
|
||||
if ctx.IsSigned && opts.OwnerID > 0 {
|
||||
if ctx.User.Id == opts.OwnerID {
|
||||
if ctx.User.ID == opts.OwnerID {
|
||||
opts.Private = true
|
||||
} else {
|
||||
u, err := models.GetUserByID(opts.OwnerID)
|
||||
|
@ -38,7 +38,7 @@ func Search(ctx *context.APIContext) {
|
|||
})
|
||||
return
|
||||
}
|
||||
if u.IsOrganization() && u.IsOwnedBy(ctx.User.Id) {
|
||||
if u.IsOrganization() && u.IsOwnedBy(ctx.User.ID) {
|
||||
opts.Private = true
|
||||
}
|
||||
// FIXME: how about collaborators?
|
||||
|
@ -78,7 +78,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
func ListMyRepos(ctx *context.APIContext) {
|
||||
ownRepos, err := models.GetRepositories(ctx.User.Id, true)
|
||||
ownRepos, err := models.GetRepositories(ctx.User.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetRepositories", err)
|
||||
return
|
||||
|
@ -126,7 +126,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
|||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
if repo != nil {
|
||||
if err = models.DeleteRepository(ctx.User.Id, repo.ID); err != nil {
|
||||
if err = models.DeleteRepository(ctx.User.ID, repo.ID); err != nil {
|
||||
log.Error(4, "DeleteRepository: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
|||
return
|
||||
}
|
||||
|
||||
if !org.IsOwnedBy(ctx.User.Id) {
|
||||
if !org.IsOwnedBy(ctx.User.ID) {
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
|||
ctxUser := ctx.User
|
||||
// Not equal means context user is an organization,
|
||||
// or is another user/organization if current user is admin.
|
||||
if form.Uid != ctxUser.Id {
|
||||
if form.Uid != ctxUser.ID {
|
||||
org, err := models.GetUserByID(form.Uid)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
|
@ -191,7 +191,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
|||
|
||||
if ctxUser.IsOrganization() && !ctx.User.IsAdmin {
|
||||
// Check ownership of organization.
|
||||
if !ctxUser.IsOwnedBy(ctx.User.Id) {
|
||||
if !ctxUser.IsOwnedBy(ctx.User.ID) {
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
|||
})
|
||||
if err != nil {
|
||||
if repo != nil {
|
||||
if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
|
||||
if errDelete := models.DeleteRepository(ctxUser.ID, repo.ID); errDelete != nil {
|
||||
log.Error(4, "DeleteRepository: %v", errDelete)
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByName(owner.Id, ctx.Params(":reponame"))
|
||||
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
|
@ -279,12 +279,12 @@ func Delete(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) {
|
||||
if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.ID) {
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(owner.Id, repo.ID); err != nil {
|
||||
if err := models.DeleteRepository(owner.ID, repo.ID); err != nil {
|
||||
ctx.Error(500, "DeleteRepository", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
|
||||
func ListAccessTokens(ctx *context.APIContext) {
|
||||
tokens, err := models.ListAccessTokens(ctx.User.Id)
|
||||
tokens, err := models.ListAccessTokens(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "ListAccessTokens", err)
|
||||
return
|
||||
|
@ -29,7 +29,7 @@ func ListAccessTokens(ctx *context.APIContext) {
|
|||
// https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
|
||||
func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
|
||||
t := &models.AccessToken{
|
||||
UID: ctx.User.Id,
|
||||
UID: ctx.User.ID,
|
||||
Name: form.Name,
|
||||
}
|
||||
if err := models.NewAccessToken(t); err != nil {
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
|
||||
func ListEmails(ctx *context.APIContext) {
|
||||
emails, err := models.GetEmailAddresses(ctx.User.Id)
|
||||
emails, err := models.GetEmailAddresses(ctx.User.ID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetEmailAddresses", err)
|
||||
return
|
||||
|
@ -37,7 +37,7 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
|
|||
emails := make([]*models.EmailAddress, len(form.Emails))
|
||||
for i := range form.Emails {
|
||||
emails[i] = &models.EmailAddress{
|
||||
UID: ctx.User.Id,
|
||||
UID: ctx.User.ID,
|
||||
Email: form.Emails[i],
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func CheckMyFollowing(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
checkUserFollowing(ctx, ctx.User, target.Id)
|
||||
checkUserFollowing(ctx, ctx.User, target.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
|
||||
|
@ -91,7 +91,7 @@ func CheckFollowing(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
checkUserFollowing(ctx, u, target.Id)
|
||||
checkUserFollowing(ctx, u, target.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
|
||||
|
@ -100,7 +100,7 @@ func Follow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if err := models.FollowUser(ctx.User.Id, target.Id); err != nil {
|
||||
if err := models.FollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
ctx.Error(500, "FollowUser", err)
|
||||
return
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func Unfollow(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if err := models.UnfollowUser(ctx.User.Id, target.Id); err != nil {
|
||||
if err := models.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
||||
ctx.Error(500, "UnfollowUser", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func listPublicKeys(ctx *context.APIContext, uid int64) {
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
|
||||
func ListMyPublicKeys(ctx *context.APIContext) {
|
||||
listPublicKeys(ctx, ctx.User.Id)
|
||||
listPublicKeys(ctx, ctx.User.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
|
||||
|
@ -63,7 +63,7 @@ func ListPublicKeys(ctx *context.APIContext) {
|
|||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
listPublicKeys(ctx, user.Id)
|
||||
listPublicKeys(ctx, user.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
|
||||
|
@ -101,7 +101,7 @@ func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid
|
|||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
|
||||
func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
CreateUserPublicKey(ctx, form, ctx.User.Id)
|
||||
CreateUserPublicKey(ctx, form, ctx.User.ID)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
|
||||
|
|
|
@ -36,7 +36,7 @@ func Search(ctx *context.APIContext) {
|
|||
results := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
results[i] = &api.User{
|
||||
ID: users[i].Id,
|
||||
ID: users[i].ID,
|
||||
UserName: users[i].Name,
|
||||
AvatarUrl: users[i].AvatarLink(),
|
||||
FullName: users[i].FullName,
|
||||
|
@ -68,5 +68,5 @@ func GetInfo(ctx *context.APIContext) {
|
|||
if !ctx.IsSigned {
|
||||
u.Email = ""
|
||||
}
|
||||
ctx.JSON(200, &api.User{u.Id, u.Name, u.FullName, u.Email, u.AvatarLink()})
|
||||
ctx.JSON(200, &api.User{u.ID, u.Name, u.FullName, u.Email, u.AvatarLink()})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue