mirror of
https://github.com/go-gitea/gitea
synced 2025-07-24 11:18:36 +00:00
Finish organization homepage
This commit is contained in:
@@ -20,6 +20,28 @@ func (org *User) GetOwnerTeam() (*Team, error) {
|
||||
return t, err
|
||||
}
|
||||
|
||||
// GetTeams returns all teams that belong to organization.
|
||||
func (org *User) GetTeams() error {
|
||||
return x.Where("org_id=?", org.Id).Find(&org.Teams)
|
||||
}
|
||||
|
||||
// GetMembers returns all members of organization.
|
||||
func (org *User) GetMembers() error {
|
||||
ous, err := GetOrgUsersByOrgId(org.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
org.Members = make([]*User, len(ous))
|
||||
for i, ou := range ous {
|
||||
org.Members[i], err = GetUserById(ou.Uid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateOrganization creates record of a new organization.
|
||||
func CreateOrganization(org, owner *User) (*User, error) {
|
||||
if !IsLegalName(org.Name) {
|
||||
@@ -132,12 +154,13 @@ const (
|
||||
ORG_ADMIN
|
||||
)
|
||||
|
||||
const OWNER_TEAM = "Owner"
|
||||
const OWNER_TEAM = "Owners"
|
||||
|
||||
// Team represents a organization team.
|
||||
type Team struct {
|
||||
Id int64
|
||||
OrgId int64 `xorm:"INDEX"`
|
||||
LowerName string
|
||||
Name string
|
||||
Description string
|
||||
Authorize AuthorizeType
|
||||
@@ -148,15 +171,19 @@ type Team struct {
|
||||
|
||||
// NewTeam creates a record of new team.
|
||||
func NewTeam(t *Team) error {
|
||||
// TODO: check if same name team of organization exists.
|
||||
t.LowerName = strings.ToLower(t.Name)
|
||||
_, err := x.Insert(t)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateTeam updates information of team.
|
||||
func UpdateTeam(t *Team) error {
|
||||
if len(t.Description) > 255 {
|
||||
t.Description = t.Description[:255]
|
||||
}
|
||||
|
||||
t.LowerName = strings.ToLower(t.Name)
|
||||
_, err := x.Id(t.Id).AllCols().Update(t)
|
||||
return err
|
||||
}
|
||||
@@ -192,16 +219,18 @@ func GetOrgUsersByOrgId(orgId int64) ([]*OrgUser, error) {
|
||||
return ous, err
|
||||
}
|
||||
|
||||
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.
|
||||
// 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
|
||||
}
|
||||
|
||||
// ___________ ____ ___
|
||||
// \__ ___/___ _____ _____ | | \______ ___________
|
||||
// | |_/ __ \\__ \ / \| | / ___// __ \_ __ \
|
||||
|
@@ -73,6 +73,8 @@ type User struct {
|
||||
Description string
|
||||
NumTeams int
|
||||
NumMembers int
|
||||
Teams []*Team `xorm:"-"`
|
||||
Members []*User `xorm:"-"`
|
||||
}
|
||||
|
||||
// HomeLink returns the user home page link.
|
||||
@@ -110,6 +112,11 @@ func (u *User) IsOrganization() bool {
|
||||
return u.Type == ORGANIZATION
|
||||
}
|
||||
|
||||
// GetOrganizationCount returns count of membership of organization of user.
|
||||
func (u *User) GetOrganizationCount() (int64, error) {
|
||||
return x.Where("uid=?", u.Id).Count(new(OrgUser))
|
||||
}
|
||||
|
||||
// GetOrganizations returns all organizations that user belongs to.
|
||||
func (u *User) GetOrganizations() error {
|
||||
ous, err := GetOrgUsersByUserId(u.Id)
|
||||
@@ -331,7 +338,7 @@ func DeleteUser(u *User) error {
|
||||
}
|
||||
|
||||
// Check membership of organization.
|
||||
count, err = GetOrganizationCount(u)
|
||||
count, err = u.GetOrganizationCount()
|
||||
if err != nil {
|
||||
return errors.New("modesl.GetRepositories(GetOrganizationCount): " + err.Error())
|
||||
} else if count > 0 {
|
||||
|
Reference in New Issue
Block a user