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 }