summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-07-02 16:42:16 -0400
committerUnknown <joe2010xtmf@163.com>2014-07-02 16:42:16 -0400
commit465dc962b5e1febdfc988419d4d03e98f777019f (patch)
tree8c0f4abc434f75a7add718e98b077cb245608062 /models
parente57aebb31667a1de54e82cd26e9bbdb8e795039d (diff)
downloadgitea-465dc962b5e1febdfc988419d4d03e98f777019f.tar.gz
gitea-465dc962b5e1febdfc988419d4d03e98f777019f.zip
Finish create organization team
Diffstat (limited to 'models')
-rw-r--r--models/org.go49
-rw-r--r--models/repo.go2
2 files changed, 47 insertions, 4 deletions
diff --git a/models/org.go b/models/org.go
index 71b1efe9cf..2625ed428d 100644
--- a/models/org.go
+++ b/models/org.go
@@ -5,11 +5,17 @@
package models
import (
+ "errors"
"strings"
"github.com/gogits/gogs/modules/base"
)
+var (
+ ErrOrgNotExist = errors.New("Organization does not exist")
+ ErrTeamAlreadyExist = errors.New("Team already exist")
+)
+
// IsOrgOwner returns true if given user is in the owner team.
func (org *User) IsOrgOwner(uid int64) bool {
return IsOrganizationOwner(org.Id, uid)
@@ -156,6 +162,13 @@ func DeleteOrganization(org *User) (err error) {
return sess.Commit()
}
+// ___________
+// \__ ___/___ _____ _____
+// | |_/ __ \\__ \ / \
+// | |\ ___/ / __ \| Y Y \
+// |____| \___ >____ /__|_| /
+// \/ \/ \/
+
type AuthorizeType int
const (
@@ -192,11 +205,41 @@ func (t *Team) GetMembers() (err error) {
}
// NewTeam creates a record of new team.
+// It's caller's responsibility to assign organization ID.
func NewTeam(t *Team) error {
- // TODO: check if same name team of organization exists.
+ has, err := x.Id(t.OrgId).Get(new(User))
+ if err != nil {
+ return err
+ } else if !has {
+ return ErrOrgNotExist
+ }
+
t.LowerName = strings.ToLower(t.Name)
- _, err := x.Insert(t)
- return err
+ has, err = x.Where("org_id=?", t.OrgId).And("lower_name=?", t.LowerName).Get(new(Team))
+ if err != nil {
+ return err
+ } else if has {
+ return ErrTeamAlreadyExist
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if _, err = sess.Insert(t); err != nil {
+ sess.Rollback()
+ return err
+ }
+
+ // Update organization number of teams.
+ rawSql := "UPDATE `user` SET num_teams = num_teams + 1 WHERE id = ?"
+ if _, err = sess.Exec(rawSql, t.OrgId); err != nil {
+ sess.Rollback()
+ return err
+ }
+ return sess.Commit()
}
// UpdateTeam updates information of team.
diff --git a/models/repo.go b/models/repo.go
index 8eec131fee..d95f8b1a71 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -158,7 +158,7 @@ func IsRepositoryExist(u *User, repoName string) (bool, error) {
}
var (
- illegalEquals = []string{"raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin"}
+ illegalEquals = []string{"raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new"}
illegalSuffixs = []string{".git"}
)