Lint models/org.go & models.go

This commit is contained in:
Bwko 2016-11-26 01:20:18 +01:00
parent 0a76d260fa
commit 0b9cf10340
2 changed files with 37 additions and 19 deletions

View file

@ -15,7 +15,9 @@ import (
)
var (
ErrOrgNotExist = errors.New("Organization does not exist")
// ErrOrgNotExist organization does not exist
ErrOrgNotExist = errors.New("Organization does not exist")
// ErrTeamNotExist team does not exist
ErrTeamNotExist = errors.New("Team does not exist")
)
@ -68,7 +70,7 @@ func (org *User) GetMembers() error {
var ids = make([]int64, len(ous))
for i, ou := range ous {
ids[i] = ou.Uid
ids[i] = ou.UID
}
org.Members, err = GetUsersByIDs(ids)
return err
@ -127,7 +129,7 @@ func CreateOrganization(org, owner *User) (err error) {
// Add initial creator to organization and owner team.
if _, err = sess.Insert(&OrgUser{
Uid: owner.ID,
UID: owner.ID,
OrgID: org.ID,
IsOwner: true,
NumTeams: 1,
@ -235,7 +237,7 @@ func DeleteOrganization(org *User) (err error) {
// OrgUser represents an organization-user relation.
type OrgUser struct {
ID int64 `xorm:"pk autoincr"`
Uid int64 `xorm:"INDEX UNIQUE(s)"`
UID int64 `xorm:"INDEX UNIQUE(s)"`
OrgID int64 `xorm:"INDEX UNIQUE(s)"`
IsPublic bool
IsOwner bool
@ -243,29 +245,29 @@ type OrgUser struct {
}
// IsOrganizationOwner returns true if given user is in the owner team.
func IsOrganizationOwner(orgId, uid int64) bool {
func IsOrganizationOwner(orgID, uid int64) bool {
has, _ := x.
Where("is_owner=?", true).
And("uid=?", uid).
And("org_id=?", orgId).
And("org_id=?", orgID).
Get(new(OrgUser))
return has
}
// IsOrganizationMember returns true if given user is member of organization.
func IsOrganizationMember(orgId, uid int64) bool {
func IsOrganizationMember(orgID, uid int64) bool {
has, _ := x.
Where("uid=?", uid).
And("org_id=?", orgId).
And("org_id=?", orgID).
Get(new(OrgUser))
return has
}
// IsPublicMembership returns true if given user public his/her membership.
func IsPublicMembership(orgId, uid int64) bool {
func IsPublicMembership(orgID, uid int64) bool {
has, _ := x.
Where("uid=?", uid).
And("org_id=?", orgId).
And("org_id=?", orgID).
And("is_public=?", true).
Get(new(OrgUser))
return has
@ -311,7 +313,7 @@ func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
return getOwnedOrgsByUserID(sess, userID)
}
// GetOwnedOrganizationsByUserIDDesc returns a list of organizations are owned by
// GetOwnedOrgsByUserIDDesc returns a list of organizations are owned by
// given user ID, ordered descending by the given condition.
func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
sess := x.NewSession()
@ -374,7 +376,7 @@ func AddOrgUser(orgID, uid int64) error {
}
ou := &OrgUser{
Uid: uid,
UID: uid,
OrgID: orgID,
}
@ -512,7 +514,7 @@ func (org *User) GetUserTeamIDs(userID int64) ([]int64, error) {
return teamIDs, nil
}
// GetTeams returns all teams that belong to organization,
// GetUserTeams returns all teams that belong to user,
// and that the user has joined.
func (org *User) GetUserTeams(userID int64) ([]*Team, error) {
return org.getUserTeams(x, userID)
@ -560,7 +562,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
return repos, repoCount, nil
}
// GetUserRepositories returns mirror repositories of the organization
// GetUserMirrorRepositories returns mirror repositories of the user
// that the user with the given userID has access to.
func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
teamIDs, err := org.GetUserTeamIDs(userID)