aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/org.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/models/org.go b/models/org.go
index 41611f81..5431a111 100644
--- a/models/org.go
+++ b/models/org.go
@@ -25,8 +25,8 @@ var (
ErrLastOrgOwner = errors.New("The user to remove is the last member in owner team")
)
-// IsOrgOwner returns true if given user is in the owner team.
-func (org *User) IsOrgOwner(uid int64) bool {
+// IsOwnedBy returns true if given user is in the owner team.
+func (org *User) IsOwnedBy(uid int64) bool {
return IsOrganizationOwner(org.Id, uid)
}
@@ -170,6 +170,24 @@ func CreateOrganization(org, owner *User) (*User, error) {
return org, sess.Commit()
}
+// GetOrgByName returns organization by given name.
+func GetOrgByName(name string) (*User, error) {
+ if len(name) == 0 {
+ return nil, ErrOrgNotExist
+ }
+ u := &User{
+ LowerName: strings.ToLower(name),
+ Type: ORGANIZATION,
+ }
+ has, err := x.Get(u)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrOrgNotExist
+ }
+ return u, nil
+}
+
// CountOrganizations returns number of organizations.
func CountOrganizations() int64 {
count, _ := x.Where("type=1").Count(new(User))