diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-08-26 18:11:15 +0800 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-08-26 18:11:15 +0800 |
commit | 74b31566cf5caaf6bf73584e621d56ca99c048d1 (patch) | |
tree | 078a8428e5241d13600482301444684720a77283 /models/repo.go | |
parent | f2c263c54facdcbc9375a47535c0389fd7d05875 (diff) | |
download | gitea-74b31566cf5caaf6bf73584e621d56ca99c048d1.tar.gz gitea-74b31566cf5caaf6bf73584e621d56ca99c048d1.zip |
Finsih add/remove repo in organization
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/models/repo.go b/models/repo.go index f5d1ca834e..c3e9423f45 100644 --- a/models/repo.go +++ b/models/repo.go @@ -519,12 +519,11 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror sess.Rollback() return nil, err } - us, err := GetTeamMembers(u.Id, t.Id) - if err != nil { + if err = t.GetMembers(); err != nil { sess.Rollback() return nil, err } - for _, u := range us { + for _, u := range t.Members { access.Id = 0 access.UserName = u.LowerName if _, err = sess.Insert(access); err != nil { @@ -963,6 +962,37 @@ func GetCollaborators(repoName string) (us []*User, err error) { return us, nil } +type SearchOption struct { + Keyword string + Uid int64 + Limit int +} + +// SearchRepositoryByName returns given number of repositories whose name contains keyword. +func SearchRepositoryByName(opt SearchOption) (repos []*Repository, err error) { + // Prevent SQL inject. + opt.Keyword = strings.TrimSpace(opt.Keyword) + if len(opt.Keyword) == 0 { + return repos, nil + } + + opt.Keyword = strings.Split(opt.Keyword, " ")[0] + if len(opt.Keyword) == 0 { + return repos, nil + } + opt.Keyword = strings.ToLower(opt.Keyword) + + repos = make([]*Repository, 0, opt.Limit) + + // Append conditions. + sess := x.Limit(opt.Limit) + if opt.Uid > 0 { + sess.Where("owner_id=?", opt.Uid) + } + sess.And("lower_name like '%" + opt.Keyword + "%'").Find(&repos) + return repos, err +} + // Watch is connection request for receiving repository notifycation. type Watch struct { Id int64 |