Started working on namespaces

This commit is contained in:
kolaente 2018-06-14 17:43:00 +02:00
parent ac0a50663d
commit bd2bf24813
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 48 additions and 1 deletions

View File

@ -7,6 +7,8 @@ type Namespace struct {
Description string `xorm:"varchar(700) autoincr not null" json:"description"`
OwnerID int64 `xorm:"int(11) autoincr not null" json:"owner_id"`
Owner User `xorm:"-"`
Created int64 `xorm:"created" json:"created"`
Updated int64 `xorm:"updated" json:"updated"`
}
@ -32,4 +34,39 @@ const (
NamespaceRightWrite
// Can manage a namespace, can do everything
NamespaceRightAdmin
)
)
func (user User) IsNamespaceAdmin(namespace Namespace) (ok bool, err error) {
// Owners always have admin rights
if user.ID == namespace.Owner.ID {
return true, nil
}
// Check if that user is in a team which has admin rights to that namespace
return
}
// CreateOrUpdateNamespace does what it says
func CreateOrUpdateNamespace(namespace *Namespace) (err error) {
// Check if the User exists
_, _, err = GetUserByID(namespace.Owner.ID)
if err != nil {
return
}
if namespace.ID == 0 {
_, err = x.Insert(namespace)
if err != nil {
return
}
} else {
_, err = x.ID(namespace.ID).Update(namespace)
if err != nil {
return
}
}
return
}

View File

@ -63,3 +63,13 @@ type TeamList struct {
func (TeamList) TableName() string {
return "team_list"
}
func GetAllTeamsByNamespaceID(id int64) (teams []*Team, err error) {
err = x.Table("teams").
Join("INNER", "team_namespaces", "teams.id = team_id").
Where("teams.namespace_id = ?", id).
Find(teams)
return
}