mirror of
https://github.com/go-gitea/gitea
synced 2024-11-10 17:25:54 +01:00
Merge pull request #130 from 0xbaadf00d/feature/ordering-org-user
Ordering organizations and users by name
This commit is contained in:
commit
b5bfab9855
@ -65,14 +65,12 @@ func (org *User) GetMembers() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
org.Members = make([]*User, len(ous))
|
var ids = make([]int64, len(ous))
|
||||||
for i, ou := range ous {
|
for i, ou := range ous {
|
||||||
org.Members[i], err = GetUserByID(ou.Uid)
|
ids[i] = ou.Uid
|
||||||
if err != nil {
|
}
|
||||||
|
org.Members, err = GetUsersByIDs(ids)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMember adds new member to organization.
|
// AddMember adds new member to organization.
|
||||||
@ -190,7 +188,7 @@ func CountOrganizations() int64 {
|
|||||||
// Organizations returns number of organizations in given page.
|
// Organizations returns number of organizations in given page.
|
||||||
func Organizations(page, pageSize int) ([]*User, error) {
|
func Organizations(page, pageSize int) ([]*User, error) {
|
||||||
orgs := make([]*User, 0, pageSize)
|
orgs := make([]*User, 0, pageSize)
|
||||||
return orgs, x.Limit(pageSize, (page-1)*pageSize).Where("type=1").Asc("id").Find(&orgs)
|
return orgs, x.Limit(pageSize, (page-1)*pageSize).Where("type=1").Asc("name").Find(&orgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOrganization completely and permanently deletes everything of organization.
|
// DeleteOrganization completely and permanently deletes everything of organization.
|
||||||
@ -260,8 +258,11 @@ func getOrgsByUserID(sess *xorm.Session, userID int64, showAll bool) ([]*User, e
|
|||||||
if !showAll {
|
if !showAll {
|
||||||
sess.And("`org_user`.is_public=?", true)
|
sess.And("`org_user`.is_public=?", true)
|
||||||
}
|
}
|
||||||
return orgs, sess.And("`org_user`.uid=?", userID).
|
return orgs, sess.
|
||||||
Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs)
|
And("`org_user`.uid=?", userID).
|
||||||
|
Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").
|
||||||
|
Asc("`user`.name").
|
||||||
|
Find(&orgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrgsByUserID returns a list of organizations that the given user ID
|
// GetOrgsByUserID returns a list of organizations that the given user ID
|
||||||
@ -278,8 +279,12 @@ func GetOrgsByUserIDDesc(userID int64, desc string, showAll bool) ([]*User, erro
|
|||||||
|
|
||||||
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
|
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
|
||||||
orgs := make([]*User, 0, 10)
|
orgs := make([]*User, 0, 10)
|
||||||
return orgs, sess.Where("`org_user`.uid=?", userID).And("`org_user`.is_owner=?", true).
|
return orgs, sess.
|
||||||
Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").Find(&orgs)
|
Where("`org_user`.uid=?", userID).
|
||||||
|
And("`org_user`.is_owner=?", true).
|
||||||
|
Join("INNER", "`org_user`", "`org_user`.org_id=`user`.id").
|
||||||
|
Asc("`user`.name").
|
||||||
|
Find(&orgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
|
// GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
|
||||||
@ -298,12 +303,16 @@ func GetOwnedOrgsByUserIDDesc(userID int64, desc string) ([]*User, error) {
|
|||||||
// GetOrgUsersByUserID returns all organization-user relations by user ID.
|
// GetOrgUsersByUserID returns all organization-user relations by user ID.
|
||||||
func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
|
func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
|
||||||
ous := make([]*OrgUser, 0, 10)
|
ous := make([]*OrgUser, 0, 10)
|
||||||
sess := x.Where("uid=?", uid)
|
sess := x.
|
||||||
|
Join("LEFT", "user", `"org_user".org_id="user".id`).
|
||||||
|
Where(`"org_user".uid=?`, uid)
|
||||||
if !all {
|
if !all {
|
||||||
// Only show public organizations
|
// Only show public organizations
|
||||||
sess.And("is_public=?", true)
|
sess.And("is_public=?", true)
|
||||||
}
|
}
|
||||||
err := sess.Find(&ous)
|
err := sess.
|
||||||
|
Asc("`user`.name").
|
||||||
|
Find(&ous)
|
||||||
return ous, err
|
return ous, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,10 +459,14 @@ func RemoveOrgRepo(orgID, repoID int64) error {
|
|||||||
|
|
||||||
func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, error) {
|
func (org *User) getUserTeams(e Engine, userID int64, cols ...string) ([]*Team, error) {
|
||||||
teams := make([]*Team, 0, org.NumTeams)
|
teams := make([]*Team, 0, org.NumTeams)
|
||||||
return teams, e.Where("team_user.org_id = ?", org.ID).
|
return teams, e.
|
||||||
And("team_user.uid = ?", userID).
|
Where("`team_user`.org_id = ?", org.ID).
|
||||||
Join("INNER", "team_user", "team_user.team_id = team.id").
|
Join("INNER", "team_user", "`team_user`.team_id = team.id").
|
||||||
Cols(cols...).Find(&teams)
|
Join("INNER", "user", "`user`.id=team_user.uid").
|
||||||
|
And("`team_user`.uid = ?", userID).
|
||||||
|
Asc("`user`.name").
|
||||||
|
Cols(cols...).
|
||||||
|
Find(&teams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserTeamIDs returns of all team IDs of the organization that user is memeber of.
|
// GetUserTeamIDs returns of all team IDs of the organization that user is memeber of.
|
||||||
|
@ -578,7 +578,7 @@ func CountUsers() int64 {
|
|||||||
// Users returns number of users in given page.
|
// Users returns number of users in given page.
|
||||||
func Users(page, pageSize int) ([]*User, error) {
|
func Users(page, pageSize int) ([]*User, error) {
|
||||||
users := make([]*User, 0, pageSize)
|
users := make([]*User, 0, pageSize)
|
||||||
return users, x.Limit(pageSize, (page-1)*pageSize).Where("type=0").Asc("id").Find(&users)
|
return users, x.Limit(pageSize, (page-1)*pageSize).Where("type=0").Asc("name").Find(&users)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user by erify code
|
// get user by erify code
|
||||||
@ -923,6 +923,13 @@ func GetUserEmailsByNames(names []string) []string {
|
|||||||
return mails
|
return mails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsersByIDs returns all resolved users from a list of Ids.
|
||||||
|
func GetUsersByIDs(ids []int64) ([]*User, error) {
|
||||||
|
ous := make([]*User, 0, len(ids))
|
||||||
|
err := x.In("id", ids).Asc("name").Find(&ous)
|
||||||
|
return ous, err
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserIDsByNames returns a slice of ids corresponds to names.
|
// GetUserIDsByNames returns a slice of ids corresponds to names.
|
||||||
func GetUserIDsByNames(names []string) []int64 {
|
func GetUserIDsByNames(names []string) []int64 {
|
||||||
ids := make([]int64, 0, len(names))
|
ids := make([]int64, 0, len(names))
|
||||||
|
@ -27,7 +27,7 @@ func Repos(ctx *context.Context) {
|
|||||||
Ranger: models.Repositories,
|
Ranger: models.Repositories,
|
||||||
Private: true,
|
Private: true,
|
||||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "owner_id ASC, name ASC, id ASC",
|
||||||
TplName: REPOS,
|
TplName: REPOS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ func ExploreUsers(ctx *context.Context) {
|
|||||||
Counter: models.CountUsers,
|
Counter: models.CountUsers,
|
||||||
Ranger: models.Users,
|
Ranger: models.Users,
|
||||||
PageSize: setting.UI.ExplorePagingNum,
|
PageSize: setting.UI.ExplorePagingNum,
|
||||||
OrderBy: "updated_unix DESC",
|
OrderBy: "name ASC",
|
||||||
TplName: EXPLORE_USERS,
|
TplName: EXPLORE_USERS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ func ExploreOrganizations(ctx *context.Context) {
|
|||||||
Counter: models.CountOrganizations,
|
Counter: models.CountOrganizations,
|
||||||
Ranger: models.Organizations,
|
Ranger: models.Organizations,
|
||||||
PageSize: setting.UI.ExplorePagingNum,
|
PageSize: setting.UI.ExplorePagingNum,
|
||||||
OrderBy: "updated_unix DESC",
|
OrderBy: "name ASC",
|
||||||
TplName: EXPLORE_ORGANIZATIONS,
|
TplName: EXPLORE_ORGANIZATIONS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user