aboutsummaryrefslogtreecommitdiffstats
path: root/models/org.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-06-29 16:30:41 -0400
committerUnknown <joe2010xtmf@163.com>2014-06-29 16:30:41 -0400
commite4ea5cf5984652e3966825bc2b68dd1abc3eef1c (patch)
tree7647c242061c1ab022db880733f0219f0af5bd2c /models/org.go
parent99713e1180ad149faf6442bba311fec6e501aa00 (diff)
downloadgitea-e4ea5cf5984652e3966825bc2b68dd1abc3eef1c.tar.gz
gitea-e4ea5cf5984652e3966825bc2b68dd1abc3eef1c.zip
Finish Teams page
Diffstat (limited to 'models/org.go')
-rw-r--r--models/org.go52
1 files changed, 40 insertions, 12 deletions
diff --git a/models/org.go b/models/org.go
index 29a5ac3cab..71b1efe9cf 100644
--- a/models/org.go
+++ b/models/org.go
@@ -10,6 +10,16 @@ import (
"github.com/gogits/gogs/modules/base"
)
+// IsOrgOwner returns true if given user is in the owner team.
+func (org *User) IsOrgOwner(uid int64) bool {
+ return IsOrganizationOwner(org.Id, uid)
+}
+
+// IsOrgMember returns true if given user is member of organization.
+func (org *User) IsOrgMember(uid int64) bool {
+ return IsOrganizationMember(org.Id, uid)
+}
+
// GetOwnerTeam returns owner team of organization.
func (org *User) GetOwnerTeam() (*Team, error) {
t := &Team{
@@ -167,6 +177,18 @@ type Team struct {
RepoIds string `xorm:"TEXT"`
NumMembers int
NumRepos int
+ Members []*User `xorm:"-"`
+}
+
+// IsTeamMember returns true if given user is a member of team.
+func (t *Team) IsMember(uid int64) bool {
+ return IsTeamMember(t.OrgId, t.Id, uid)
+}
+
+// GetMembers returns all members in given team of organization.
+func (t *Team) GetMembers() (err error) {
+ t.Members, err = GetTeamMembers(t.OrgId, t.Id)
+ return err
}
// NewTeam creates a record of new team.
@@ -205,6 +227,18 @@ type OrgUser struct {
NumTeam int
}
+// IsOrganizationOwner returns true if given user is in the owner team.
+func IsOrganizationOwner(orgId, uid int64) bool {
+ has, _ := x.Where("is_owner=?", true).And("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
+ return has
+}
+
+// IsOrganizationMember returns true if given user is member of organization.
+func IsOrganizationMember(orgId, uid int64) bool {
+ has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
+ return has
+}
+
// GetOrgUsersByUserId returns all organization-user relations by user ID.
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
ous := make([]*OrgUser, 0, 10)
@@ -219,18 +253,6 @@ func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
return ous, err
}
-// IsOrganizationOwner returns true if given user 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
-}
-
-// IsOrganizationMember returns true if given user is member of organization.
-func IsOrganizationMember(orgId, uid int64) bool {
- has, _ := x.Get(&OrgUser{Uid: uid, OrgId: orgId})
- return has
-}
-
// ___________ ____ ___
// \__ ___/___ _____ _____ | | \______ ___________
// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \
@@ -246,6 +268,12 @@ type TeamUser struct {
TeamId int64
}
+// IsTeamMember returns true if given user is a member of team.
+func IsTeamMember(orgId, teamId, uid int64) bool {
+ has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).And("team_id=?", teamId).Get(new(TeamUser))
+ return has
+}
+
// GetTeamMembers returns all members in given team of organization.
func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
tus := make([]*TeamUser, 0, 10)