summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-07-24 01:08:22 +0800
committerUnknwon <u@gogs.io>2016-07-24 01:08:22 +0800
commit1f2e173a745da8e4b57f96b5561a3c10054d3b76 (patch)
tree367f0f07e4fe1269ac0772e0561a4bf912b5153c /models
parent46e96c008cf966428c9dad71c7871de88186e3fe (diff)
downloadgitea-1f2e173a745da8e4b57f96b5561a3c10054d3b76.tar.gz
gitea-1f2e173a745da8e4b57f96b5561a3c10054d3b76.zip
Refactor User.Id to User.ID
Diffstat (limited to 'models')
-rw-r--r--models/access.go14
-rw-r--r--models/action.go20
-rw-r--r--models/issue.go12
-rw-r--r--models/issue_comment.go4
-rw-r--r--models/issue_mail.go2
-rw-r--r--models/login.go4
-rw-r--r--models/mail.go8
-rw-r--r--models/org.go46
-rw-r--r--models/org_team.go8
-rw-r--r--models/pull.go6
-rw-r--r--models/repo.go28
-rw-r--r--models/repo_collaboration.go2
-rw-r--r--models/ssh_key.go6
-rw-r--r--models/update.go6
-rw-r--r--models/user.go86
-rw-r--r--models/user_mail.go6
16 files changed, 129 insertions, 129 deletions
diff --git a/models/access.go b/models/access.go
index b4c1349b65..32e9b6ea8b 100644
--- a/models/access.go
+++ b/models/access.go
@@ -67,11 +67,11 @@ func accessLevel(e Engine, u *User, repo *Repository) (AccessMode, error) {
return mode, nil
}
- if u.Id == repo.OwnerID {
+ if u.ID == repo.OwnerID {
return ACCESS_MODE_OWNER, nil
}
- a := &Access{UserID: u.Id, RepoID: repo.ID}
+ a := &Access{UserID: u.ID, RepoID: repo.ID}
if has, err := e.Get(a); !has || err != nil {
return mode, err
}
@@ -97,7 +97,7 @@ func HasAccess(u *User, repo *Repository, testMode AccessMode) (bool, error) {
// GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own.
func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
accesses := make([]*Access, 0, 10)
- if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
+ if err := x.Find(&accesses, &Access{UserID: u.ID}); err != nil {
return nil, err
}
@@ -113,7 +113,7 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
}
if err = repo.GetOwner(); err != nil {
return nil, err
- } else if repo.OwnerID == u.Id {
+ } else if repo.OwnerID == u.ID {
continue
}
repos[repo] = access.Mode
@@ -124,7 +124,7 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
// GetAccessibleRepositories finds all repositories where a user has access but does not own.
func (u *User) GetAccessibleRepositories() ([]*Repository, error) {
accesses := make([]*Access, 0, 10)
- if err := x.Find(&accesses, &Access{UserID: u.Id}); err != nil {
+ if err := x.Find(&accesses, &Access{UserID: u.ID}); err != nil {
return nil, err
}
@@ -137,7 +137,7 @@ func (u *User) GetAccessibleRepositories() ([]*Repository, error) {
repoIDs = append(repoIDs, access.RepoID)
}
repos := make([]*Repository, 0, len(repoIDs))
- return repos, x.Where("owner_id != ?", u.Id).In("id", repoIDs).Desc("updated_unix").Find(&repos)
+ return repos, x.Where("owner_id != ?", u.ID).In("id", repoIDs).Desc("updated_unix").Find(&repos)
}
func maxAccessMode(modes ...AccessMode) AccessMode {
@@ -227,7 +227,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err
return fmt.Errorf("getMembers '%d': %v", t.ID, err)
}
for _, m := range t.Members {
- accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
+ accessMap[m.ID] = maxAccessMode(accessMap[m.ID], t.Authorize)
}
}
diff --git a/models/action.go b/models/action.go
index 62252c6c58..23b526ee95 100644
--- a/models/action.go
+++ b/models/action.go
@@ -184,7 +184,7 @@ func (a *Action) GetIssueContent() string {
func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
- ActUserID: u.Id,
+ ActUserID: u.ID,
ActUserName: u.Name,
ActEmail: u.Email,
OpType: ACTION_CREATE_REPO,
@@ -193,7 +193,7 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
RepoName: repo.Name,
IsPrivate: repo.IsPrivate,
}); err != nil {
- return fmt.Errorf("notify watchers '%d/%d': %v", u.Id, repo.ID, err)
+ return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err)
}
log.Trace("action.newRepoAction: %s/%s", u.Name, repo.Name)
@@ -207,7 +207,7 @@ func NewRepoAction(u *User, repo *Repository) (err error) {
func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
- ActUserID: actUser.Id,
+ ActUserID: actUser.ID,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
OpType: ACTION_RENAME_REPO,
@@ -482,7 +482,7 @@ func CommitRepoAction(
refName := git.RefEndName(refFullName)
if err = NotifyWatchers(&Action{
- ActUserID: u.Id,
+ ActUserID: u.ID,
ActUserName: userName,
ActEmail: actEmail,
OpType: opType,
@@ -506,7 +506,7 @@ func CommitRepoAction(
}
payloadSender := &api.PayloadUser{
UserName: pusher.Name,
- ID: pusher.Id,
+ ID: pusher.ID,
AvatarUrl: pusher.AvatarLink(),
}
@@ -553,7 +553,7 @@ func CommitRepoAction(
func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
- ActUserID: actUser.Id,
+ ActUserID: actUser.ID,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
OpType: ACTION_TRANSFER_REPO,
@@ -563,12 +563,12 @@ func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repos
IsPrivate: repo.IsPrivate,
Content: path.Join(oldOwner.Name, repo.Name),
}); err != nil {
- return fmt.Errorf("notify watchers '%d/%d': %v", actUser.Id, repo.ID, err)
+ return fmt.Errorf("notify watchers '%d/%d': %v", actUser.ID, repo.ID, err)
}
// Remove watch for organization.
if repo.Owner.IsOrganization() {
- if err = watchRepo(e, repo.Owner.Id, repo.ID, false); err != nil {
+ if err = watchRepo(e, repo.Owner.ID, repo.ID, false); err != nil {
return fmt.Errorf("watch repository: %v", err)
}
}
@@ -584,7 +584,7 @@ func TransferRepoAction(actUser, oldOwner, newOwner *User, repo *Repository) err
func mergePullRequestAction(e Engine, actUser *User, repo *Repository, pull *Issue) error {
return notifyWatchers(e, &Action{
- ActUserID: actUser.Id,
+ ActUserID: actUser.ID,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
OpType: ACTION_MERGE_PULL_REQUEST,
@@ -610,7 +610,7 @@ func GetFeeds(ctxUserID, userID, offset int64, isProfile bool) ([]*Action, error
if isProfile {
sess.And("is_private=?", false).And("act_user_id=?", ctxUserID)
} else if ctxUserID != -1 {
- ctxUser := &User{Id: ctxUserID}
+ ctxUser := &User{ID: ctxUserID}
if err := ctxUser.GetUserRepositories(userID); err != nil {
return nil, err
}
diff --git a/models/issue.go b/models/issue.go
index f3cbb71e8f..b8183b94e8 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -336,7 +336,7 @@ func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64,
if issue.AssigneeID > 0 {
// Silently drop invalid assignee
- valid, err := hasAccess(e, &User{Id: issue.AssigneeID}, repo, ACCESS_MODE_WRITE)
+ valid, err := hasAccess(e, &User{ID: issue.AssigneeID}, repo, ACCESS_MODE_WRITE)
if err != nil {
return fmt.Errorf("hasAccess: %v", err)
} else if !valid {
@@ -428,7 +428,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
// Notify watchers.
act := &Action{
- ActUserID: issue.Poster.Id,
+ ActUserID: issue.Poster.ID,
ActUserName: issue.Poster.Name,
ActEmail: issue.Poster.Email,
OpType: ACTION_CREATE_ISSUE,
@@ -632,7 +632,7 @@ func newIssueUsers(e *xorm.Session, repo *Repository, issue *Issue) error {
isNeedAddPoster := true
for _, u := range users {
iu.ID = 0
- iu.UID = u.Id
+ iu.UID = u.ID
iu.IsPoster = iu.UID == issue.PosterID
if isNeedAddPoster && iu.IsPoster {
isNeedAddPoster = false
@@ -736,15 +736,15 @@ func UpdateIssueMentions(issueID int64, mentions []string) error {
ids := make([]int64, 0, len(mentions))
for _, user := range users {
- ids = append(ids, user.Id)
+ ids = append(ids, user.ID)
if !user.IsOrganization() || user.NumMembers == 0 {
continue
}
memberIDs := make([]int64, 0, user.NumMembers)
- orgUsers, err := GetOrgUsersByOrgID(user.Id)
+ orgUsers, err := GetOrgUsersByOrgID(user.ID)
if err != nil {
- return fmt.Errorf("GetOrgUsersByOrgID [%d]: %v", user.Id, err)
+ return fmt.Errorf("GetOrgUsersByOrgID [%d]: %v", user.ID, err)
}
for _, orgUser := range orgUsers {
diff --git a/models/issue_comment.go b/models/issue_comment.go
index 479da92067..faa257789a 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -140,7 +140,7 @@ func (cmt *Comment) MailParticipants(opType ActionType, issue *Issue) (err error
func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
comment := &Comment{
Type: opts.Type,
- PosterID: opts.Doer.Id,
+ PosterID: opts.Doer.ID,
Poster: opts.Doer,
IssueID: opts.Issue.ID,
CommitID: opts.CommitID,
@@ -155,7 +155,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
// Compose comment action, could be plain comment, close or reopen issue/pull request.
// This object will be used to notify watchers in the end of function.
act := &Action{
- ActUserID: opts.Doer.Id,
+ ActUserID: opts.Doer.ID,
ActUserName: opts.Doer.Name,
ActEmail: opts.Doer.Email,
Content: fmt.Sprintf("%d|%s", opts.Issue.Index, strings.Split(opts.Content, "\n")[0]),
diff --git a/models/issue_mail.go b/models/issue_mail.go
index 3260de271c..5441a45460 100644
--- a/models/issue_mail.go
+++ b/models/issue_mail.go
@@ -33,7 +33,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
tos := make([]string, 0, len(watchers)) // List of email addresses.
names := make([]string, 0, len(watchers))
for i := range watchers {
- if watchers[i].UserID == doer.Id {
+ if watchers[i].UserID == doer.ID {
continue
}
diff --git a/models/login.go b/models/login.go
index 84a5c21916..1f8d3c8daf 100644
--- a/models/login.go
+++ b/models/login.go
@@ -534,7 +534,7 @@ func UserSignIn(uname, passwd string) (*User, error) {
return u, nil
}
- return nil, ErrUserNotExist{u.Id, u.Name}
+ return nil, ErrUserNotExist{u.ID, u.Name}
default:
var source LoginSource
@@ -563,5 +563,5 @@ func UserSignIn(uname, passwd string) (*User, error) {
log.Warn("Failed to login '%s' via '%s': %v", uname, source.Name, err)
}
- return nil, ErrUserNotExist{u.Id, u.Name}
+ return nil, ErrUserNotExist{u.ID, u.Name}
}
diff --git a/models/mail.go b/models/mail.go
index 9f34bbf384..6daf84f231 100644
--- a/models/mail.go
+++ b/models/mail.go
@@ -71,7 +71,7 @@ func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject,
}
msg := mailer.NewMessage([]string{u.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, %s", u.Id, info)
+ msg.Info = fmt.Sprintf("UID: %d, %s", u.ID, info)
mailer.SendAsync(msg)
}
@@ -99,7 +99,7 @@ func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
}
msg := mailer.NewMessage([]string{email.Email}, c.Tr("mail.activate_email"), body)
- msg.Info = fmt.Sprintf("UID: %d, activate email", u.Id)
+ msg.Info = fmt.Sprintf("UID: %d, activate email", u.ID)
mailer.SendAsync(msg)
}
@@ -116,7 +116,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u *User) {
}
msg := mailer.NewMessage([]string{u.Email}, c.Tr("mail.register_notify"), body)
- msg.Info = fmt.Sprintf("UID: %d, registration notify", u.Id)
+ msg.Info = fmt.Sprintf("UID: %d, registration notify", u.ID)
mailer.SendAsync(msg)
}
@@ -138,7 +138,7 @@ func SendCollaboratorMail(u, doer *User, repo *Repository) {
}
msg := mailer.NewMessage([]string{u.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.Id)
+ msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)
mailer.SendAsync(msg)
}
diff --git a/models/org.go b/models/org.go
index 9cb862dec9..c85e88d618 100644
--- a/models/org.go
+++ b/models/org.go
@@ -21,16 +21,16 @@ var (
// IsOwnedBy returns true if given user is in the owner team.
func (org *User) IsOwnedBy(uid int64) bool {
- return IsOrganizationOwner(org.Id, uid)
+ return IsOrganizationOwner(org.ID, uid)
}
// IsOrgMember returns true if given user is member of organization.
func (org *User) IsOrgMember(uid int64) bool {
- return org.IsOrganization() && IsOrganizationMember(org.Id, uid)
+ return org.IsOrganization() && IsOrganizationMember(org.ID, uid)
}
func (org *User) getTeam(e Engine, name string) (*Team, error) {
- return getTeam(e, org.Id, name)
+ return getTeam(e, org.ID, name)
}
// GetTeam returns named team of organization.
@@ -48,7 +48,7 @@ func (org *User) GetOwnerTeam() (*Team, error) {
}
func (org *User) getTeams(e Engine) error {
- return e.Where("org_id=?", org.Id).Find(&org.Teams)
+ return e.Where("org_id=?", org.ID).Find(&org.Teams)
}
// GetTeams returns all teams that belong to organization.
@@ -58,7 +58,7 @@ func (org *User) GetTeams() error {
// GetMembers returns all members of organization.
func (org *User) GetMembers() error {
- ous, err := GetOrgUsersByOrgID(org.Id)
+ ous, err := GetOrgUsersByOrgID(org.ID)
if err != nil {
return err
}
@@ -75,16 +75,16 @@ func (org *User) GetMembers() error {
// AddMember adds new member to organization.
func (org *User) AddMember(uid int64) error {
- return AddOrgUser(org.Id, uid)
+ return AddOrgUser(org.ID, uid)
}
// RemoveMember removes member from organization.
func (org *User) RemoveMember(uid int64) error {
- return RemoveOrgUser(org.Id, uid)
+ return RemoveOrgUser(org.ID, uid)
}
func (org *User) removeOrgRepo(e Engine, repoID int64) error {
- return removeOrgRepo(e, org.Id, repoID)
+ return removeOrgRepo(e, org.ID, repoID)
}
// RemoveOrgRepo removes all team-repository relations of organization.
@@ -126,8 +126,8 @@ func CreateOrganization(org, owner *User) (err error) {
// Add initial creator to organization and owner team.
if _, err = sess.Insert(&OrgUser{
- Uid: owner.Id,
- OrgID: org.Id,
+ Uid: owner.ID,
+ OrgID: org.ID,
IsOwner: true,
NumTeams: 1,
}); err != nil {
@@ -136,7 +136,7 @@ func CreateOrganization(org, owner *User) (err error) {
// Create default owner team.
t := &Team{
- OrgID: org.Id,
+ OrgID: org.ID,
LowerName: strings.ToLower(OWNER_TEAM),
Name: OWNER_TEAM,
Authorize: ACCESS_MODE_OWNER,
@@ -147,8 +147,8 @@ func CreateOrganization(org, owner *User) (err error) {
}
if _, err = sess.Insert(&TeamUser{
- Uid: owner.Id,
- OrgID: org.Id,
+ Uid: owner.ID,
+ OrgID: org.ID,
TeamID: t.ID,
}); err != nil {
return fmt.Errorf("insert team-user relation: %v", err)
@@ -204,9 +204,9 @@ func DeleteOrganization(org *User) (err error) {
}
if err = deleteBeans(sess,
- &Team{OrgID: org.Id},
- &OrgUser{OrgID: org.Id},
- &TeamUser{OrgID: org.Id},
+ &Team{OrgID: org.ID},
+ &OrgUser{OrgID: org.ID},
+ &TeamUser{OrgID: org.ID},
); err != nil {
return fmt.Errorf("deleteBeans: %v", err)
}
@@ -401,23 +401,23 @@ func RemoveOrgUser(orgId, uid int64) error {
}
// Delete all repository accesses.
- access := &Access{UserID: u.Id}
+ access := &Access{UserID: u.ID}
for _, repo := range org.Repos {
access.RepoID = repo.ID
if _, err = sess.Delete(access); err != nil {
return err
- } else if err = watchRepo(sess, u.Id, repo.ID, false); err != nil {
+ } else if err = watchRepo(sess, u.ID, repo.ID, false); err != nil {
return err
}
}
// Delete member in his/her teams.
- teams, err := getUserTeams(sess, org.Id, u.Id)
+ teams, err := getUserTeams(sess, org.ID, u.ID)
if err != nil {
return err
}
for _, t := range teams {
- if err = removeTeamMember(sess, org.Id, t.ID, u.Id); err != nil {
+ if err = removeTeamMember(sess, org.ID, t.ID, u.ID); err != nil {
return err
}
}
@@ -444,7 +444,7 @@ func (org *User) GetUserRepositories(userID int64) (err error) {
teams := make([]*Team, 0, org.NumTeams)
if err = x.Sql(`SELECT team.id FROM team
INNER JOIN team_user ON team_user.team_id = team.id
-WHERE team_user.org_id = ? AND team_user.uid = ?`, org.Id, userID).Find(&teams); err != nil {
+WHERE team_user.org_id = ? AND team_user.uid = ?`, org.ID, userID).Find(&teams); err != nil {
return fmt.Errorf("get teams: %v", err)
}
@@ -461,7 +461,7 @@ WHERE team_user.org_id = ? AND team_user.uid = ?`, org.Id, userID).Find(&teams);
if err = x.Sql(fmt.Sprintf(`SELECT repository.* FROM repository
INNER JOIN team_repo ON team_repo.repo_id = repository.id
WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (%s)
-GROUP BY repository.id`, strings.Join(teamIDs, ",")), org.Id, false).Find(&repos); err != nil {
+GROUP BY repository.id`, strings.Join(teamIDs, ",")), org.ID, false).Find(&repos); err != nil {
return fmt.Errorf("get repositories: %v", err)
}
org.Repos = repos
@@ -479,7 +479,7 @@ func (org *User) GetUserTeams(userID int64) error {
if err := x.Sql(`SELECT team.* FROM team
INNER JOIN team_user ON team_user.team_id = team.id
WHERE team_user.org_id = ? AND team_user.uid = ?`,
- org.Id, userID).Find(&teams); err != nil {
+ org.ID, userID).Find(&teams); err != nil {
return fmt.Errorf("get teams: %v", err)
}
diff --git a/models/org_team.go b/models/org_team.go
index 85af2d9838..6a6754cc99 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -106,7 +106,7 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
return fmt.Errorf("getMembers: %v", err)
}
for _, u := range t.Members {
- if err = watchRepo(e, u.Id, repo.ID, true); err != nil {
+ if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
return fmt.Errorf("watchRepo: %v", err)
}
}
@@ -162,7 +162,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
continue
}
- if err = watchRepo(e, u.Id, repo.ID, false); err != nil {
+ if err = watchRepo(e, u.ID, repo.ID, false); err != nil {
return err
}
}
@@ -341,7 +341,7 @@ func DeleteTeam(t *Team) error {
}
// Delete team-user.
- if _, err = sess.Where("org_id=?", org.Id).Where("team_id=?", t.ID).Delete(new(TeamUser)); err != nil {
+ if _, err = sess.Where("org_id=?", org.ID).Where("team_id=?", t.ID).Delete(new(TeamUser)); err != nil {
return err
}
@@ -538,7 +538,7 @@ func removeTeamMember(e Engine, orgID, teamID, uid int64) error {
// This must exist.
ou := new(OrgUser)
- _, err = e.Where("uid = ?", uid).And("org_id = ?", org.Id).Get(ou)
+ _, err = e.Where("uid = ?", uid).And("org_id = ?", org.ID).Get(ou)
if err != nil {
return err
}
diff --git a/models/pull.go b/models/pull.go
index 38fd945711..78c8d15644 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -163,7 +163,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
pr.HasMerged = true
pr.Merged = time.Now()
- pr.MergerID = doer.Id
+ pr.MergerID = doer.ID
if _, err = sess.Id(pr.ID).AllCols().Update(pr); err != nil {
return fmt.Errorf("update pull request: %v", err)
}
@@ -245,7 +245,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
},
Sender: &api.PayloadUser{
UserName: doer.Name,
- ID: doer.Id,
+ ID: doer.ID,
AvatarUrl: setting.AppUrl + doer.RelAvatarLink(),
},
}
@@ -332,7 +332,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
// Notify watchers.
act := &Action{
- ActUserID: pull.Poster.Id,
+ ActUserID: pull.Poster.ID,
ActUserName: pull.Poster.Name,
ActEmail: pull.Poster.Email,
OpType: ACTION_CREATE_PULL_REQUEST,
diff --git a/models/repo.go b/models/repo.go
index 44e2275509..1c395e583c 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -476,7 +476,7 @@ func (repo *Repository) ComposePayload() *api.PayloadRepo {
func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
has, err := e.Get(&Repository{
- OwnerID: u.Id,
+ OwnerID: u.ID,
LowerName: strings.ToLower(repoName),
})
return has && com.IsDir(RepoPath(u.Name, repoName)), err
@@ -958,7 +958,7 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
}
}
- if err = watchRepo(e, u.Id, repo.ID, true); err != nil {
+ if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
return fmt.Errorf("watchRepo: %v", err)
} else if err = newRepoAction(e, u, repo); err != nil {
return fmt.Errorf("newRepoAction: %v", err)
@@ -974,7 +974,7 @@ func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error
}
repo := &Repository{
- OwnerID: u.Id,
+ OwnerID: u.ID,
Owner: u,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
@@ -1093,7 +1093,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
// Note: we have to set value here to make sure recalculate accesses is based on
// new owner.
- repo.OwnerID = newOwner.Id
+ repo.OwnerID = newOwner.ID
repo.Owner = newOwner
// Update repository.
@@ -1110,10 +1110,10 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
// Dummy object.
collaboration := &Collaboration{RepoID: repo.ID}
for _, c := range collaborators {
- collaboration.UserID = c.Id
- if c.Id == newOwner.Id || newOwner.IsOrgMember(c.Id) {
+ collaboration.UserID = c.ID
+ if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
if _, err = sess.Delete(collaboration); err != nil {
- return fmt.Errorf("remove collaborator '%d': %v", c.Id, err)
+ return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
}
}
}
@@ -1154,13 +1154,13 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
}
// Update repository count.
- if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.Id); err != nil {
+ if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
return fmt.Errorf("increase new owner repository count: %v", err)
- } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.Id); err != nil {
+ } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
return fmt.Errorf("decrease old owner repository count: %v", err)
}
- if err = watchRepo(sess, newOwner.Id, repo.ID, true); err != nil {
+ if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
return fmt.Errorf("watchRepo: %v", err)
} else if err = transferRepoAction(sess, u, owner, newOwner, repo); err != nil {
return fmt.Errorf("transferRepoAction: %v", err)
@@ -1200,7 +1200,7 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
return ErrRepoAlreadyExist{u.Name, newRepoName}
}
- repo, err := GetRepositoryByName(u.Id, oldRepoName)
+ repo, err := GetRepositoryByName(u.ID, oldRepoName)
if err != nil {
return fmt.Errorf("GetRepositoryByName: %v", err)
}
@@ -1414,7 +1414,7 @@ func GetRepositoryByRef(ref string) (*Repository, error) {
return nil, err
}
- return GetRepositoryByName(user.Id, repoName)
+ return GetRepositoryByName(user.ID, repoName)
}
// GetRepositoryByName returns the repository by given name under user if exists.
@@ -1467,7 +1467,7 @@ func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err
}
func getRepositoryCount(e Engine, u *User) (int64, error) {
- return x.Count(&Repository{OwnerID: u.Id})
+ return x.Count(&Repository{OwnerID: u.ID})
}
// GetRepositoryCount returns the total number of repositories of user.
@@ -2025,7 +2025,7 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
repo := &Repository{
- OwnerID: u.Id,
+ OwnerID: u.ID,
Owner: u,
Name: name,
LowerName: strings.ToLower(name),
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index 3da5cf5a02..2a530f8752 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -33,7 +33,7 @@ func (c *Collaboration) ModeI18nKey() string {
func (repo *Repository) AddCollaborator(u *User) error {
collaboration := &Collaboration{
RepoID: repo.ID,
- UserID: u.Id,
+ UserID: u.ID,
}
has, err := x.Get(collaboration)
diff --git a/models/ssh_key.go b/models/ssh_key.go
index a279b48711..92f38b570a 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -562,8 +562,8 @@ func DeletePublicKey(doer *User, id int64) (err error) {
}
// Check if user has access to delete this key.
- if !doer.IsAdmin && doer.Id != key.OwnerID {
- return ErrKeyAccessDenied{doer.Id, key.ID, "public"}
+ if !doer.IsAdmin && doer.ID != key.OwnerID {
+ return ErrKeyAccessDenied{doer.ID, key.ID, "public"}
}
sess := x.NewSession()
@@ -797,7 +797,7 @@ func DeleteDeployKey(doer *User, id int64) error {
if err != nil {
return fmt.Errorf("HasAccess: %v", err)
} else if !yes {
- return ErrKeyAccessDenied{doer.Id, key.ID, "deploy"}
+ return ErrKeyAccessDenied{doer.ID, key.ID, "deploy"}
}
}
diff --git a/models/update.go b/models/update.go
index 66775ea9fb..14e5b28cf2 100644
--- a/models/update.go
+++ b/models/update.go
@@ -108,7 +108,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
return fmt.Errorf("GetUserByName: %v", err)
}
- repo, err := GetRepositoryByName(repoUser.Id, opts.RepoName)
+ repo, err := GetRepositoryByName(repoUser.ID, opts.RepoName)
if err != nil {
return fmt.Errorf("GetRepositoryByName: %v", err)
}
@@ -133,7 +133,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
}
commit := &PushCommits{}
- if err = CommitRepoAction(opts.PusherID, repoUser.Id, opts.PusherName, actEmail,
+ if err = CommitRepoAction(opts.PusherID, repoUser.ID, opts.PusherName, actEmail,
repo.ID, opts.RepoUserName, opts.RepoName, opts.RefName, commit, opts.OldCommitID, opts.NewCommitID); err != nil {
return fmt.Errorf("CommitRepoAction (tag): %v", err)
}
@@ -159,7 +159,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) {
}
}
- if err = CommitRepoAction(opts.PusherID, repoUser.Id, opts.PusherName, repoUser.Email,
+ if err = CommitRepoAction(opts.PusherID, repoUser.ID, opts.PusherName, repoUser.Email,
repo.ID, opts.RepoUserName, opts.RepoName, opts.RefName, ListToPushCommits(l),
opts.OldCommitID, opts.NewCommitID); err != nil {
return fmt.Errorf("CommitRepoAction (branch): %v", err)
diff --git a/models/user.go b/models/user.go
index 44dedccadf..5b1fd4ae51 100644
--- a/models/user.go
+++ b/models/user.go
@@ -52,7 +52,7 @@ var (
// User represents the object of individual and member of organization.
type User struct {
- Id int64
+ ID int64 `xorm:"pk autoincr"`
LowerName string `xorm:"UNIQUE NOT NULL"`
Name string `xorm:"UNIQUE NOT NULL"`
FullName string
@@ -137,7 +137,7 @@ func (u *User) IsLocal() bool {
// HasForkedRepo checks if user has already forked a repository with given ID.
func (u *User) HasForkedRepo(repoID int64) bool {
- _, has := HasForkedRepo(u.Id, repoID)
+ _, has := HasForkedRepo(u.ID, repoID)
return has
}
@@ -184,7 +184,7 @@ func (u *User) HomeLink() string {
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
func (u *User) GenerateEmailActivateCode(email string) string {
code := base.CreateTimeLimitCode(
- com.ToStr(u.Id)+email+u.LowerName+u.Passwd+u.Rands,
+ com.ToStr(u.ID)+email+u.LowerName+u.Passwd+u.Rands,
setting.Service.ActiveCodeLives, nil)
// Add tail hex username
@@ -199,7 +199,7 @@ func (u *User) GenerateActivateCode() string {
// CustomAvatarPath returns user custom avatar file path.
func (u *User) CustomAvatarPath() string {
- return filepath.Join(setting.AvatarUploadPath, com.ToStr(u.Id))
+ return filepath.Join(setting.AvatarUploadPath, com.ToStr(u.ID))
}
// GenerateRandomAvatar generates a random avatar for user.
@@ -226,13 +226,13 @@ func (u *User) GenerateRandomAvatar() error {
return fmt.Errorf("Encode: %v", err)
}
- log.Info("New random avatar created: %d", u.Id)
+ log.Info("New random avatar created: %d", u.ID)
return nil
}
func (u *User) RelAvatarLink() string {
defaultImgUrl := "/img/avatar_default.png"
- if u.Id == -1 {
+ if u.ID == -1 {
return defaultImgUrl
}
@@ -241,7 +241,7 @@ func (u *User) RelAvatarLink() string {
if !com.IsExist(u.CustomAvatarPath()) {
return defaultImgUrl
}
- return "/avatars/" + com.ToStr(u.Id)
+ return "/avatars/" + com.ToStr(u.ID)
case setting.DisableGravatar, setting.OfflineMode:
if !com.IsExist(u.CustomAvatarPath()) {
if err := u.GenerateRandomAvatar(); err != nil {
@@ -249,7 +249,7 @@ func (u *User) RelAvatarLink() string {
}
}
- return "/avatars/" + com.ToStr(u.Id)
+ return "/avatars/" + com.ToStr(u.ID)
}
return setting.GravatarSource + u.Avatar
}
@@ -266,7 +266,7 @@ func (u *User) AvatarLink() string {
// User.GetFollwoers returns range of user's followers.
func (u *User) GetFollowers(page int) ([]*User, error) {
users := make([]*User, 0, ItemsPerPage)
- sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.follow_id=?", u.Id)
+ sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.follow_id=?", u.ID)
if setting.UsePostgreSQL {
sess = sess.Join("LEFT", "follow", `"user".id=follow.user_id`)
} else {
@@ -276,13 +276,13 @@ func (u *User) GetFollowers(page int) ([]*User, error) {
}
func (u *User) IsFollowing(followID int64) bool {
- return IsFollowing(u.Id, followID)
+ return IsFollowing(u.ID, followID)
}
// GetFollowing returns range of user's following.
func (u *User) GetFollowing(page int) ([]*User, error) {
users := make([]*User, 0, ItemsPerPage)
- sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.user_id=?", u.Id)
+ sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.user_id=?", u.ID)
if setting.UsePostgreSQL {
sess = sess.Join("LEFT", "follow", `"user".id=follow.follow_id`)
} else {
@@ -350,7 +350,7 @@ func (u *User) UploadAvatar(data []byte) error {
// DeleteAvatar deletes the user's custom avatar.
func (u *User) DeleteAvatar() error {
- log.Trace("DeleteAvatar[%d]: %s", u.Id, u.CustomAvatarPath())
+ log.Trace("DeleteAvatar[%d]: %s", u.ID, u.CustomAvatarPath())
os.Remove(u.CustomAvatarPath())
u.UseCustomAvatar = false
@@ -385,16 +385,16 @@ func (u *User) IsOrganization() bool {
// IsUserOrgOwner returns true if user is in the owner team of given organization.
func (u *User) IsUserOrgOwner(orgId int64) bool {
- return IsOrganizationOwner(orgId, u.Id)
+ return IsOrganizationOwner(orgId, u.ID)
}
// IsPublicMember returns true if user public his/her membership in give organization.
func (u *User) IsPublicMember(orgId int64) bool {
- return IsPublicMembership(orgId, u.Id)
+ return IsPublicMembership(orgId, u.ID)
}
func (u *User) getOrganizationCount(e Engine) (int64, error) {
- return e.Where("uid=?", u.Id).Count(new(OrgUser))
+ return e.Where("uid=?", u.ID).Count(new(OrgUser))
}
// GetOrganizationCount returns count of membership of organization of user.
@@ -404,19 +404,19 @@ func (u *User) GetOrganizationCount() (int64, error) {
// GetRepositories returns all repositories that user owns, including private repositories.
func (u *User) GetRepositories() (err error) {
- u.Repos, err = GetRepositories(u.Id, true)
+ u.Repos, err = GetRepositories(u.ID, true)
return err
}
// GetOwnedOrganizations returns all organizations that user owns.
func (u *User) GetOwnedOrganizations() (err error) {
- u.OwnedOrgs, err = GetOwnedOrgsByUserID(u.Id)
+ u.OwnedOrgs, err = GetOwnedOrgsByUserID(u.ID)
return err
}
// GetOrganizations returns all organizations that user belongs to.
func (u *User) GetOrganizations(all bool) error {
- ous, err := GetOrgUsersByUserID(u.Id, all)
+ ous, err := GetOrgUsersByUserID(u.ID, all)
if err != nil {
return err
}
@@ -463,7 +463,7 @@ func GetUserSalt() string {
// NewFakeUser creates and returns a fake user for someone has deleted his/her account.
func NewFakeUser() *User {
return &User{
- Id: -1,
+ ID: -1,
Name: "Someone",
LowerName: "someone",
}
@@ -588,7 +588,7 @@ func VerifyUserActiveCode(code string) (user *User) {
if user = getVerifyUser(code); user != nil {
// time limit code
prefix := code[:base.TimeLimitCodeLength]
- data := com.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands
+ data := com.ToStr(user.ID) + user.Email + user.LowerName + user.Passwd + user.Rands
if base.VerifyTimeLimitCode(data, minutes, prefix) {
return user
@@ -604,7 +604,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress {
if user := getVerifyUser(code); user != nil {
// time limit code
prefix := code[:base.TimeLimitCodeLength]
- data := com.ToStr(user.Id) + email + user.LowerName + user.Passwd + user.Rands
+ data := com.ToStr(user.ID) + email + user.LowerName + user.Passwd + user.Rands
if base.VerifyTimeLimitCode(data, minutes, prefix) {
emailAddress := &EmailAddress{Email: email}
@@ -634,7 +634,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
}
// Delete all local copies of repository wiki that user owns.
- if err = x.Where("owner_id=?", u.Id).Iterate(new(Repository), func(idx int, bean interface{}) error {
+ if err = x.Where("owner_id=?", u.ID).Iterate(new(Repository), func(idx int, bean interface{}) error {
repo := bean.(*Repository)
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
return nil
@@ -649,7 +649,7 @@ func updateUser(e Engine, u *User) error {
// Organization does not need email
if !u.IsOrganization() {
u.Email = strings.ToLower(u.Email)
- has, err := e.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User))
+ has, err := e.Where("id!=?", u.ID).And("type=?", u.Type).And("email=?", u.Email).Get(new(User))
if err != nil {
return err
} else if has {
@@ -668,7 +668,7 @@ func updateUser(e Engine, u *User) error {
u.Description = base.TruncateString(u.Description, 255)
u.FullName = markdown.Sanitizer.Sanitize(u.FullName)
- _, err := e.Id(u.Id).AllCols().Update(u)
+ _, err := e.Id(u.ID).AllCols().Update(u)
return err
}
@@ -697,7 +697,7 @@ func deleteUser(e *xorm.Session, u *User) error {
if err != nil {
return fmt.Errorf("GetRepositoryCount: %v", err)
} else if count > 0 {
- return ErrUserOwnRepos{UID: u.Id}
+ return ErrUserOwnRepos{UID: u.ID}
}
// Check membership of organization.
@@ -705,12 +705,12 @@ func deleteUser(e *xorm.Session, u *User) error {
if err != nil {
return fmt.Errorf("GetOrganizationCount: %v", err)
} else if count > 0 {
- return ErrUserHasOrgs{UID: u.Id}
+ return ErrUserHasOrgs{UID: u.ID}
}
// ***** START: Watch *****
watches := make([]*Watch, 0, 10)
- if err = e.Find(&watches, &Watch{UserID: u.Id}); err != nil {
+ if err = e.Find(&watches, &Watch{UserID: u.ID}); err != nil {
return fmt.Errorf("get all watches: %v", err)
}
for i := range watches {
@@ -722,7 +722,7 @@ func deleteUser(e *xorm.Session, u *User) error {
// ***** START: Star *****
stars := make([]*Star, 0, 10)
- if err = e.Find(&stars, &Star{UID: u.Id}); err != nil {
+ if err = e.Find(&stars, &Star{UID: u.ID}); err != nil {
return fmt.Errorf("get all stars: %v", err)
}
for i := range stars {
@@ -734,7 +734,7 @@ func deleteUser(e *xorm.Session, u *User) error {
// ***** START: Follow *****
followers := make([]*Follow, 0, 10)
- if err = e.Find(&followers, &Follow{UserID: u.Id}); err != nil {
+ if err = e.Find(&followers, &Follow{UserID: u.ID}); err != nil {
return fmt.Errorf("get all followers: %v", err)
}
for i := range followers {
@@ -745,22 +745,22 @@ func deleteUser(e *xorm.Session, u *User) error {
// ***** END: Follow *****
if err = deleteBeans(e,
- &AccessToken{UID: u.Id},
- &Collaboration{UserID: u.Id},
- &Access{UserID: u.Id},
- &Watch{UserID: u.Id},
- &Star{UID: u.Id},
- &Follow{FollowID: u.Id},
- &Action{UserID: u.Id},
- &IssueUser{UID: u.Id},
- &EmailAddress{UID: u.Id},
+ &AccessToken{UID: u.ID},
+ &Collaboration{UserID: u.ID},
+ &Access{UserID: u.ID},
+ &Watch{UserID: u.ID},
+ &Star{UID: u.ID},
+ &Follow{FollowID: u.ID},
+ &Action{UserID: u.ID},
+ &IssueUser{UID: u.ID},
+ &EmailAddress{UID: u.ID},
); err != nil {
return fmt.Errorf("deleteBeans: %v", err)
}
// ***** START: PublicKey *****
keys := make([]*PublicKey, 0, 10)
- if err = e.Find(&keys, &PublicKey{OwnerID: u.Id}); err != nil {
+ if err = e.Find(&keys, &PublicKey{OwnerID: u.ID}); err != nil {
return fmt.Errorf("get all public keys: %v", err)
}
for _, key := range keys {
@@ -771,11 +771,11 @@ func deleteUser(e *xorm.Session, u *User) error {
// ***** END: PublicKey *****
// Clear assignee.
- if _, err = e.Exec("UPDATE `issue` SET assignee_id=0 WHERE assignee_id=?", u.Id); err != nil {
+ if _, err = e.Exec("UPDATE `issue` SET assignee_id=0 WHERE assignee_id=?", u.ID); err != nil {
return fmt.Errorf("clear assignee: %v", err)
}
- if _, err = e.Id(u.Id).Delete(new(User)); err != nil {
+ if _, err = e.Id(u.ID).Delete(new(User)); err != nil {
return fmt.Errorf("Delete: %v", err)
}
@@ -861,7 +861,7 @@ func GetUserByID(id int64) (*User, error) {
// GetAssigneeByID returns the user with write access of repository by given ID.
func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
- has, err := HasAccess(&User{Id: userID}, repo, ACCESS_MODE_WRITE)
+ has, err := HasAccess(&User{ID: userID}, repo, ACCESS_MODE_WRITE)
if err != nil {
return nil, err
} else if !has {
@@ -906,7 +906,7 @@ func GetUserIDsByNames(names []string) []int64 {
if err != nil {
continue
}
- ids = append(ids, u.Id)
+ ids = append(ids, u.ID)
}
return ids
}
diff --git a/models/user_mail.go b/models/user_mail.go
index bb5f29d879..9a1804c91a 100644
--- a/models/user_mail.go
+++ b/models/user_mail.go
@@ -160,7 +160,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
return ErrEmailNotActivated
}
- user := &User{Id: email.UID}
+ user := &User{ID: email.UID}
has, err = x.Get(user)
if err != nil {
return err
@@ -182,7 +182,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
}
if !has {
- formerPrimaryEmail.UID = user.Id
+ formerPrimaryEmail.UID = user.ID
formerPrimaryEmail.IsActivated = user.IsActive
if _, err = sess.Insert(formerPrimaryEmail); err != nil {
return err
@@ -190,7 +190,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
}
user.Email = email.Email
- if _, err = sess.Id(user.Id).AllCols().Update(user); err != nil {
+ if _, err = sess.Id(user.ID).AllCols().Update(user); err != nil {
return err
}