summaryrefslogtreecommitdiffstats
path: root/models/org.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-06-28 00:40:07 -0400
committerUnknown <joe2010xtmf@163.com>2014-06-28 00:40:07 -0400
commit6e448b07145fbb090e0da6deb97f244c2bfd7ba7 (patch)
treeaf17fdea008d56d154c1098d05993475c0fee652 /models/org.go
parentee9b7f322ff4c4c14952c2f83fb03e90fa583cad (diff)
downloadgitea-6e448b07145fbb090e0da6deb97f244c2bfd7ba7.tar.gz
gitea-6e448b07145fbb090e0da6deb97f244c2bfd7ba7.zip
Finish delete organization
Diffstat (limited to 'models/org.go')
-rw-r--r--models/org.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/models/org.go b/models/org.go
index 553a46aa0b..025759b001 100644
--- a/models/org.go
+++ b/models/org.go
@@ -10,6 +10,16 @@ import (
"github.com/gogits/gogs/modules/base"
)
+// GetOwnerTeam returns owner team of organization.
+func (org *User) GetOwnerTeam() (*Team, error) {
+ t := &Team{
+ OrgId: org.Id,
+ Name: OWNER_TEAM,
+ }
+ _, err := x.Get(t)
+ return t, err
+}
+
// CreateOrganization creates record of a new organization.
func CreateOrganization(org, owner *User) (*User, error) {
if !IsLegalName(org.Name) {
@@ -86,6 +96,34 @@ func CreateOrganization(org, owner *User) (*User, error) {
return org, sess.Commit()
}
+// TODO: need some kind of mechanism to record failure.
+// DeleteOrganization completely and permanently deletes everything of organization.
+func DeleteOrganization(org *User) (err error) {
+ if err := DeleteUser(org); err != nil {
+ return err
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ if _, err = sess.Delete(&Team{OrgId: org.Id}); err != nil {
+ sess.Rollback()
+ return err
+ }
+ if _, err = sess.Delete(&OrgUser{OrgId: org.Id}); err != nil {
+ sess.Rollback()
+ return err
+ }
+ if _, err = sess.Delete(&TeamUser{OrgId: org.Id}); err != nil {
+ sess.Rollback()
+ return err
+ }
+ return sess.Commit()
+}
+
type AuthorizeType int
const (
@@ -158,6 +196,12 @@ func GetOrganizationCount(u *User) (int64, error) {
return x.Where("uid=?", u.Id).Count(new(OrgUser))
}
+// IsOrganizationOwner returns true if given user ID is in the owner team.
+func IsOrganizationOwner(orgId, uid int64) bool {
+ has, _ := x.Where("is_owner=?", true).Get(&OrgUser{Uid: uid, OrgId: orgId})
+ return has
+}
+
// ___________ ____ ___
// \__ ___/___ _____ _____ | | \______ ___________
// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \