Ability to create account for members
This commit is contained in:
parent
07db65f63f
commit
2e332b8f3e
5 changed files with 138 additions and 16 deletions
57
helpers/authelia/groups.go
Normal file
57
helpers/authelia/groups.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package authelia
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
)
|
||||
|
||||
func GetPersonGroups(userid uint) []string {
|
||||
var groups []string
|
||||
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return groups
|
||||
}
|
||||
|
||||
var person models.Person
|
||||
db.Preload("Section").Find(&person, "id = ?", userid)
|
||||
|
||||
if person.SectionID <= 0 {
|
||||
return groups
|
||||
}
|
||||
|
||||
groups = append(groups, fmt.Sprintf(
|
||||
"section_%s",
|
||||
strings.ReplaceAll(person.Section.ShortName, " ", "_"),
|
||||
))
|
||||
|
||||
if person.Section.ParentSectionID == nil {
|
||||
return groups
|
||||
}
|
||||
|
||||
parentID := person.Section.ParentSectionID
|
||||
for {
|
||||
var section models.Section
|
||||
db.Preload("parent_section").Find(§ion, "id = ?", parentID)
|
||||
|
||||
if section.ID <= 0 {
|
||||
return groups
|
||||
}
|
||||
|
||||
groups = append(groups, fmt.Sprintf(
|
||||
"section_%s",
|
||||
strings.ReplaceAll(section.ShortName, " ", "_"),
|
||||
))
|
||||
|
||||
if section.ParentSectionID != nil {
|
||||
parentID = person.Section.ParentSectionID
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return groups
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue