|
@@ -10,6 +10,16 @@ import (
|
|
|
"github.com/gogits/gogs/modules/base"
|
|
|
)
|
|
|
|
|
|
+
|
|
|
+func (org *User) IsOrgOwner(uid int64) bool {
|
|
|
+ return IsOrganizationOwner(org.Id, uid)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (org *User) IsOrgMember(uid int64) bool {
|
|
|
+ return IsOrganizationMember(org.Id, uid)
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
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:"-"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (t *Team) IsMember(uid int64) bool {
|
|
|
+ return IsTeamMember(t.OrgId, t.Id, uid)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (t *Team) GetMembers() (err error) {
|
|
|
+ t.Members, err = GetTeamMembers(t.OrgId, t.Id)
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
|
|
@@ -205,6 +227,18 @@ type OrgUser struct {
|
|
|
NumTeam int
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+func IsOrganizationOwner(orgId, uid int64) bool {
|
|
|
+ has, _ := x.Where("is_owner=?", true).And("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
|
|
|
+ return has
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func IsOrganizationMember(orgId, uid int64) bool {
|
|
|
+ has, _ := x.Where("uid=?", uid).And("org_id=?", orgId).Get(new(OrgUser))
|
|
|
+ return has
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func GetOrgUsersByUserId(uid int64) ([]*OrgUser, error) {
|
|
|
ous := make([]*OrgUser, 0, 10)
|
|
@@ -219,18 +253,6 @@ func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
|
|
|
return ous, err
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func IsOrganizationOwner(orgId, uid int64) bool {
|
|
|
- has, _ := x.Where("is_owner=?", true).Get(&OrgUser{Uid: uid, OrgId: orgId})
|
|
|
- return has
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-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
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func GetTeamMembers(orgId, teamId int64) ([]*User, error) {
|
|
|
tus := make([]*TeamUser, 0, 10)
|