Browse Source

Add auth param to all methods

master
kolaente 5 months ago
parent
commit
26386be9a9
Signed by: konrad GPG Key ID: F40E70337AB24C9B
  1. 6
      Readme.md
  2. 2
      handler/delete.go
  3. 2
      handler/read_one.go
  4. 2
      handler/update.go
  5. 6
      web.go

6
Readme.md

@ -70,10 +70,10 @@ This interface defines methods to Create/Read/ReadAll/Update/Delete something. I
```go
type CRUDable interface {
Create(*xorm.Session, Auth) error
ReadOne(*xorm.Session) error
ReadOne(*xorm.Session, Auth) error
ReadAll(s *xorm.Session, auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error)
Update(*xorm.Session) error
Delete(*xorm.Session) error
Update(*xorm.Session, Auth) error
Delete(*xorm.Session, Auth) error
}
```

2
handler/delete.go

@ -66,7 +66,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusForbidden)
}
err = currentStruct.Delete(s)
err = currentStruct.Delete(s, currentAuth)
if err != nil {
_ = s.Rollback()
return HandleHTTPError(err, ctx)

2
handler/read_one.go

@ -63,7 +63,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
}
// Get our object
err = currentStruct.ReadOne(s)
err = currentStruct.ReadOne(s, currentAuth)
if err != nil {
_ = s.Rollback()
return HandleHTTPError(err, ctx)

2
handler/update.go

@ -68,7 +68,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
}
// Do the update
err = currentStruct.Update(s)
err = currentStruct.Update(s, currentAuth)
if err != nil {
_ = s.Rollback()
return HandleHTTPError(err, ctx)

6
web.go

@ -31,10 +31,10 @@ type Rights interface {
// CRUDable defines the crud methods
type CRUDable interface {
Create(*xorm.Session, Auth) error
ReadOne(*xorm.Session) error
ReadOne(*xorm.Session, Auth) error
ReadAll(s *xorm.Session, auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error)
Update(*xorm.Session) error
Delete(*xorm.Session) error
Update(*xorm.Session, Auth) error
Delete(*xorm.Session, Auth) error
}
// HTTPErrorProcessor is executed when the defined error is thrown, it will make sure the user sees an appropriate error message and http status code

Loading…
Cancel
Save