@ -49,22 +49,67 @@ func init() {
db . RegisterModel ( new ( TeamUnit ) )
}
// SearchTeamOptions holds the search options
type SearchTeamOptions struct {
// SearchOrg TeamOptions holds the search options
type SearchOrg TeamOptions struct {
db . ListOptions
UserID int64
Keyword string
OrgID int64
IncludeDesc bool
}
// GetUserTeamOptions holds the search options.
type GetUserTeamOptions struct {
db . ListOptions
UserID int64
}
// SearchMembersOptions holds the search options
type SearchMembersOptions struct {
db . ListOptions
}
// SearchTeam search for teams. Caller is responsible to check permissions.
func SearchTeam ( opts * SearchTeamOptions ) ( [ ] * Team , int64 , error ) {
// GetUserTeams search for org teams. Caller is responsible to check permissions.
func GetUserTeams ( opts * GetUserTeamOptions ) ( [ ] * Team , int64 , error ) {
if opts . Page <= 0 {
opts . Page = 1
}
if opts . PageSize == 0 {
// Default limit
opts . PageSize = 10
}
sess := db . GetEngine ( db . DefaultContext )
sess = sess . Join ( "INNER" , "team_user" , "team_user.team_id = team.id" ) .
And ( "team_user.uid=?" , opts . UserID )
count , err := sess .
Count ( new ( Team ) )
if err != nil {
return nil , 0 , err
}
if opts . PageSize == - 1 {
opts . PageSize = int ( count )
} else {
sess = sess . Limit ( opts . PageSize , ( opts . Page - 1 ) * opts . PageSize )
}
sess = sess . Join ( "INNER" , "team_user" , "team_user.team_id = team.id" ) .
And ( "team_user.uid=?" , opts . UserID )
teams := make ( [ ] * Team , 0 , opts . PageSize )
if err = sess .
OrderBy ( "lower_name" ) .
Find ( & teams ) ; err != nil {
return nil , 0 , err
}
return teams , count , nil
}
// SearchOrgTeams search for org teams. Caller is responsible to check permissions.
func SearchOrgTeams ( opts * SearchOrgTeamOptions ) ( [ ] * Team , int64 , error ) {
if opts . Page <= 0 {
opts . Page = 1
}
@ -196,7 +241,7 @@ func (t *Team) getRepositories(e db.Engine) error {
}
// GetRepositories returns paginated repositories in team of organization.
func ( t * Team ) GetRepositories ( opts * SearchTeamOptions ) error {
func ( t * Team ) GetRepositories ( opts * SearchOrg TeamOptions ) error {
if opts . Page == 0 {
return t . getRepositories ( db . GetEngine ( db . DefaultContext ) )
}
@ -716,7 +761,7 @@ func UpdateTeam(t *Team, authChanged, 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 ( & SearchTeamOptions { } ) ; err != nil {
if err := t . GetRepositories ( & SearchOrg TeamOptions { } ) ; err != nil {
return err
}
@ -858,7 +903,7 @@ func AddTeamMember(team *Team, userID int64) error {
}
// Get team and its repositories.
if err := team . GetRepositories ( & SearchTeamOptions { } ) ; err != nil {
if err := team . GetRepositories ( & SearchOrg TeamOptions { } ) ; err != nil {
return err
}