diff options
Diffstat (limited to 'models/org_team.go')
-rw-r--r-- | models/org_team.go | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/models/org_team.go b/models/org_team.go index 0c0a1e7b79..214790703c 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -39,12 +39,16 @@ type Team struct { // SearchTeamOptions holds the search options type SearchTeamOptions struct { + ListOptions UserID int64 Keyword string OrgID int64 IncludeDesc bool - PageSize int - Page int +} + +// SearchMembersOptions holds the search options +type SearchMembersOptions struct { + ListOptions } // SearchTeam search for teams. Caller is responsible to check permissions. @@ -160,9 +164,13 @@ func (t *Team) getRepositories(e Engine) error { Find(&t.Repos) } -// GetRepositories returns all repositories in team of organization. -func (t *Team) GetRepositories() error { - return t.getRepositories(x) +// GetRepositories returns paginated repositories in team of organization. +func (t *Team) GetRepositories(opts *SearchTeamOptions) error { + if opts.Page == 0 { + return t.getRepositories(x) + } + + return t.getRepositories(opts.getPaginatedSession()) } func (t *Team) getMembers(e Engine) (err error) { @@ -170,9 +178,13 @@ func (t *Team) getMembers(e Engine) (err error) { return err } -// GetMembers returns all members in team of organization. -func (t *Team) GetMembers() (err error) { - return t.getMembers(x) +// GetMembers returns paginated members in team of organization. +func (t *Team) GetMembers(opts *SearchMembersOptions) (err error) { + if opts.Page == 0 { + return t.getMembers(x) + } + + return t.getMembers(opts.getPaginatedSession()) } // AddMember adds new membership of the team to the organization, @@ -642,7 +654,7 @@ func UpdateTeam(t *Team, authChanged bool, includeAllChanged bool) (err error) { // DeleteTeam deletes given team. // It's caller's responsibility to assign organization ID. func DeleteTeam(t *Team) error { - if err := t.GetRepositories(); err != nil { + if err := t.GetRepositories(&SearchTeamOptions{}); err != nil { return err } @@ -747,11 +759,14 @@ func GetTeamMembers(teamID int64) ([]*User, error) { return getTeamMembers(x, teamID) } -func getUserTeams(e Engine, userID int64) (teams []*Team, err error) { - return teams, e. +func getUserTeams(e Engine, userID int64, listOptions ListOptions) (teams []*Team, err error) { + sess := e. Join("INNER", "team_user", "team_user.team_id = team.id"). - Where("team_user.uid=?", userID). - Find(&teams) + Where("team_user.uid=?", userID) + if listOptions.Page != 0 { + sess = listOptions.setSessionPagination(sess) + } + return teams, sess.Find(&teams) } func getUserOrgTeams(e Engine, orgID, userID int64) (teams []*Team, err error) { @@ -778,8 +793,8 @@ func GetUserOrgTeams(orgID, userID int64) ([]*Team, error) { } // GetUserTeams returns all teams that user belongs across all organizations. -func GetUserTeams(userID int64) ([]*Team, error) { - return getUserTeams(x, userID) +func GetUserTeams(userID int64, listOptions ListOptions) ([]*Team, error) { + return getUserTeams(x, userID, listOptions) } // AddTeamMember adds new membership of given team to given organization, @@ -795,7 +810,7 @@ func AddTeamMember(team *Team, userID int64) error { } // Get team and its repositories. - if err := team.GetRepositories(); err != nil { + if err := team.GetRepositories(&SearchTeamOptions{}); err != nil { return err } |