work on adding group support
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-10 09:16:52 +11:00
parent 48611b22c9
commit 0899b07d47
6 changed files with 83 additions and 12 deletions

View File

@@ -6,11 +6,11 @@ import (
)
type Group struct {
GroupId int `db:"GroupId"`
GroupName string `db:"GroupName"`
LdapGroup bool `db:"LdapGroup"`
LdapDn string `db:"LdapDN"`
Admin bool `db:"Admin"`
GroupId int `db:"GroupId" json:"groupId"`
GroupName string `db:"GroupName" json:"groupName"`
LdapGroup bool `db:"LdapGroup" json:"ldapGroup"`
LdapDn string `db:"LdapDN" json:"ldapDn"`
Admin bool `db:"Admin" json:"admin"`
}
// GroupGetByName queries the database for the specified group name
@@ -53,3 +53,30 @@ func GroupList() ([]Group, error) {
return results, nil
}
// GroupAdd adds a new group definition to the database
func (g *Group) GroupAdd() (*Group, error) {
var err error
// Validate role not already in use
_, err = GroupGetByName(g.GroupName)
if err != nil && err.Error() == "group not found" {
log.Printf("GroupAdd confirmed no existing group, continuing with creation of group '%s'\n", g.GroupName)
result, err := db.NamedExec(("INSERT INTO groups (GroupName, LdapGroup, LdapDn, Admin) VALUES (:GroupName, :LdapGroup, :LdapDn, :Admin);"), g)
if err != nil {
log.Printf("GroupAdd error executing sql record : '%s'\n", err)
return &Group{}, err
} else {
affected, _ := result.RowsAffected()
id, _ := result.LastInsertId()
log.Printf("GroupAdd insert returned result id '%d' affecting %d row(s).\n", id, affected)
}
} else {
log.Printf("GroupAdd group name already exists : '%v'\n", err)
}
return g, nil
}