add support to update permissions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -142,3 +142,29 @@ func (p *Permission) PermissionDelete() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PermissionUpdate updates an existing permission definition in the database
|
||||
func (p *Permission) PermissionUpdate() (*Permission, error) {
|
||||
|
||||
var err error
|
||||
|
||||
log.Printf("PermissionUpdate storing values '%v'\n", p)
|
||||
|
||||
if p.PermissionId == 0 {
|
||||
err = errors.New("PermissionUpdate unable to update permission with empty PermissionId field")
|
||||
log.Printf("PermissionUpdate error in pre-check : '%s'\n", err)
|
||||
return p, err
|
||||
}
|
||||
|
||||
result, err := db.NamedExec((`UPDATE permissions SET Description = :Description, ReadOnly = :ReadOnly, SafeId = :SafeId, UserId = :UserId, GroupId = :GroupId WHERE PermissionId = :PermissionId`), p)
|
||||
if err != nil {
|
||||
log.Printf("PermissionUpdate error executing sql record : '%s'\n", err)
|
||||
return &Permission{}, err
|
||||
} else {
|
||||
affected, _ := result.RowsAffected()
|
||||
id, _ := result.LastInsertId()
|
||||
log.Printf("PermissionUpdate returned result id '%d' affecting %d row(s).\n", id, affected)
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user