implement group delete
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-10 10:43:38 +11:00
parent f8000b749e
commit b828416811
3 changed files with 88 additions and 7 deletions

View File

@@ -58,7 +58,7 @@ func GroupList() ([]Group, error) {
func (g *Group) GroupAdd() (*Group, error) {
var err error
// Validate role not already in use
// Validate group not already in use
_, err = GroupGetByName(g.GroupName)
if err != nil && err.Error() == "group not found" {
@@ -80,3 +80,35 @@ func (g *Group) GroupAdd() (*Group, error) {
return g, nil
}
// GroupDelete removes a group definition to the database
func (g *Group) GroupDelete() error {
var err error
// Validate group exists
group, err := GroupGetByName(g.GroupName)
if err != nil && err.Error() == "group not found" {
log.Printf("GroupDelete unable to validate group exists : '%s'\n", err)
return err
}
// Make sure we have a group ID
if g.GroupId == 0 {
g.GroupId = group.GroupId
}
// Delete the group
log.Printf("GroupDelete confirmed group exists, continuing with deletion of group '%s'\n", g.GroupName)
result, err := db.NamedExec((`DELETE FROM group WHERE GroupId = :GroupId`), g)
if err != nil {
log.Printf("GroupDelete error executing sql delete : '%s'\n", err)
return err
} else {
affected, _ := result.RowsAffected()
id, _ := result.LastInsertId()
log.Printf("GroupDelete returned result id '%d' affecting %d row(s).\n", id, affected)
}
return nil
}