web/web.go

67 lines
2.2 KiB
Go
Raw Permalink Normal View History

2018-11-30 23:10:43 +00:00
// Copyright (c) 2018 Vikunja and contributors.
2018-11-30 21:36:20 +00:00
//
// This program is free software: you can redistribute it and/or modify
2018-11-30 23:10:43 +00:00
// it under the terms of the GNU Lesser General Public License as published by
2018-11-30 21:36:20 +00:00
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-11-30 23:10:43 +00:00
// GNU Lesser General Public License for more details.
2018-11-30 21:36:20 +00:00
//
2018-11-30 23:10:43 +00:00
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-11-30 21:36:20 +00:00
package web
2020-12-22 14:46:43 +00:00
import (
"github.com/labstack/echo/v4"
"xorm.io/xorm"
)
2018-11-30 21:36:20 +00:00
// Rights defines rights methods
type Rights interface {
2020-12-22 14:46:43 +00:00
CanRead(*xorm.Session, Auth) (bool, int, error)
CanDelete(*xorm.Session, Auth) (bool, error)
CanUpdate(*xorm.Session, Auth) (bool, error)
CanCreate(*xorm.Session, Auth) (bool, error)
2018-11-30 21:36:20 +00:00
}
// CRUDable defines the crud methods
type CRUDable interface {
2020-12-22 14:46:43 +00:00
Create(*xorm.Session, Auth) error
2021-01-31 20:10:03 +00:00
ReadOne(*xorm.Session, Auth) error
2020-12-22 14:46:43 +00:00
ReadAll(s *xorm.Session, auth Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error)
2021-01-31 20:10:03 +00:00
Update(*xorm.Session, Auth) error
Delete(*xorm.Session, Auth) error
2018-11-30 21:36:20 +00:00
}
// HTTPErrorProcessor is executed when the defined error is thrown, it will make sure the user sees an appropriate error message and http status code
type HTTPErrorProcessor interface {
HTTPError() HTTPError
}
// HTTPError holds informations about an http error
type HTTPError struct {
HTTPCode int `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
}
// Auth defines the authentication interface used to get some auth thing
type Auth interface {
// Most of the time, we need an ID from the auth object only. Having this method saves the need to cast it.
GetID() int64
2018-11-30 21:36:20 +00:00
}
// Authprovider is a holder for the implementation of an authprovider by the application
type Authprovider interface {
GetAuthObject(echo.Context) (Auth, error)
}
// Auths holds the authobject
type Auths struct {
AuthObject func(echo.Context) (Auth, error)
}