upd(system): rename to rest/permission
This commit is contained in:
parent
b380eef81b
commit
c697ae2e13
@ -565,7 +565,7 @@
|
||||
{
|
||||
"title": "Permissions",
|
||||
"parameters": {},
|
||||
"entrypoint": "permissions",
|
||||
"entrypoint": "permission",
|
||||
"path": "/permissions",
|
||||
"authentication": [
|
||||
"Client ID",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"Title": "Permissions",
|
||||
"Interface": "Permissions",
|
||||
"Interface": "Permission",
|
||||
"Struct": [
|
||||
{
|
||||
"imports": [
|
||||
@ -10,8 +10,8 @@ package handlers
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `permissions.go`, `permissions.util.go` or `permissions_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `permissions.go`
|
||||
You may edit `permission.go`, `permission.util.go` or `permission_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `permission.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
@ -26,38 +26,38 @@ import (
|
||||
)
|
||||
|
||||
// Internal API interface
|
||||
type PermissionsAPI interface {
|
||||
Get(context.Context, *request.PermissionsGet) (interface{}, error)
|
||||
Delete(context.Context, *request.PermissionsDelete) (interface{}, error)
|
||||
Update(context.Context, *request.PermissionsUpdate) (interface{}, error)
|
||||
type PermissionAPI interface {
|
||||
Get(context.Context, *request.PermissionGet) (interface{}, error)
|
||||
Delete(context.Context, *request.PermissionDelete) (interface{}, error)
|
||||
Update(context.Context, *request.PermissionUpdate) (interface{}, error)
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
type Permissions struct {
|
||||
type Permission struct {
|
||||
Get func(http.ResponseWriter, *http.Request)
|
||||
Delete func(http.ResponseWriter, *http.Request)
|
||||
Update func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
func NewPermissions(ph PermissionsAPI) *Permissions {
|
||||
return &Permissions{
|
||||
func NewPermission(ph PermissionAPI) *Permission {
|
||||
return &Permission{
|
||||
Get: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewPermissionsGet()
|
||||
params := request.NewPermissionGet()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return ph.Get(r.Context(), params)
|
||||
})
|
||||
},
|
||||
Delete: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewPermissionsDelete()
|
||||
params := request.NewPermissionDelete()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return ph.Delete(r.Context(), params)
|
||||
})
|
||||
},
|
||||
Update: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewPermissionsUpdate()
|
||||
params := request.NewPermissionUpdate()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return ph.Update(r.Context(), params)
|
||||
})
|
||||
@ -65,7 +65,7 @@ func NewPermissions(ph PermissionsAPI) *Permissions {
|
||||
}
|
||||
}
|
||||
|
||||
func (ph *Permissions) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) {
|
||||
func (ph *Permission) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middlewares...)
|
||||
r.Route("/permissions", func(r chi.Router) {
|
||||
38
system/rest/permission.go
Normal file
38
system/rest/permission.go
Normal file
@ -0,0 +1,38 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/system/rest/request"
|
||||
"github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Permission struct {
|
||||
svc struct {
|
||||
perm service.PermissionService
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func (Permission) New() *Permission {
|
||||
ctrl := &Permission{}
|
||||
ctrl.svc.perm = service.DefaultPermission
|
||||
return ctrl
|
||||
}
|
||||
|
||||
func (ctrl *Permission) Get(ctx context.Context, r *request.PermissionGet) (interface{}, error) {
|
||||
return ctrl.svc.perm.Get(r.RoleID)
|
||||
}
|
||||
|
||||
func (ctrl *Permission) Delete(ctx context.Context, r *request.PermissionDelete) (interface{}, error) {
|
||||
return ctrl.svc.perm.Delete(r.RoleID)
|
||||
}
|
||||
|
||||
func (ctrl *Permission) Update(ctx context.Context, r *request.PermissionUpdate) (interface{}, error) {
|
||||
return ctrl.svc.perm.Update(r.RoleID, r.Permissions)
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/crusttech/crust/system/rest/request"
|
||||
"github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Permissions struct {
|
||||
svc struct {
|
||||
perm service.PermissionService
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
func (Permissions) New() *Permissions {
|
||||
return &Permissions{}
|
||||
}
|
||||
|
||||
func (ctrl *Permissions) Get(ctx context.Context, r *request.PermissionsGet) (interface{}, error) {
|
||||
return ctrl.svc.perm.Get(r.RoleID)
|
||||
}
|
||||
|
||||
func (ctrl *Permissions) Delete(ctx context.Context, r *request.PermissionsDelete) (interface{}, error) {
|
||||
return ctrl.svc.perm.Delete(r.RoleID)
|
||||
}
|
||||
|
||||
func (ctrl *Permissions) Update(ctx context.Context, r *request.PermissionsUpdate) (interface{}, error) {
|
||||
return ctrl.svc.perm.Update(r.RoleID, r.Permissions)
|
||||
}
|
||||
@ -10,8 +10,8 @@ package request
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `permissions.go`, `permissions.util.go` or `permissions_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `permissions.go`
|
||||
You may edit `permission.go`, `permission.util.go` or `permission_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `permission.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
@ -31,16 +31,16 @@ import (
|
||||
var _ = chi.URLParam
|
||||
var _ = multipart.FileHeader{}
|
||||
|
||||
// Permissions get request parameters
|
||||
type PermissionsGet struct {
|
||||
// Permission get request parameters
|
||||
type PermissionGet struct {
|
||||
RoleID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewPermissionsGet() *PermissionsGet {
|
||||
return &PermissionsGet{}
|
||||
func NewPermissionGet() *PermissionGet {
|
||||
return &PermissionGet{}
|
||||
}
|
||||
|
||||
func (pe *PermissionsGet) Fill(r *http.Request) (err error) {
|
||||
func (pe *PermissionGet) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(pe)
|
||||
|
||||
@ -72,18 +72,18 @@ func (pe *PermissionsGet) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewPermissionsGet()
|
||||
var _ RequestFiller = NewPermissionGet()
|
||||
|
||||
// Permissions delete request parameters
|
||||
type PermissionsDelete struct {
|
||||
// Permission delete request parameters
|
||||
type PermissionDelete struct {
|
||||
RoleID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewPermissionsDelete() *PermissionsDelete {
|
||||
return &PermissionsDelete{}
|
||||
func NewPermissionDelete() *PermissionDelete {
|
||||
return &PermissionDelete{}
|
||||
}
|
||||
|
||||
func (pe *PermissionsDelete) Fill(r *http.Request) (err error) {
|
||||
func (pe *PermissionDelete) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(pe)
|
||||
|
||||
@ -115,19 +115,19 @@ func (pe *PermissionsDelete) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewPermissionsDelete()
|
||||
var _ RequestFiller = NewPermissionDelete()
|
||||
|
||||
// Permissions update request parameters
|
||||
type PermissionsUpdate struct {
|
||||
// Permission update request parameters
|
||||
type PermissionUpdate struct {
|
||||
RoleID uint64 `json:",string"`
|
||||
Permissions []rules.Rule
|
||||
}
|
||||
|
||||
func NewPermissionsUpdate() *PermissionsUpdate {
|
||||
return &PermissionsUpdate{}
|
||||
func NewPermissionUpdate() *PermissionUpdate {
|
||||
return &PermissionUpdate{}
|
||||
}
|
||||
|
||||
func (pe *PermissionsUpdate) Fill(r *http.Request) (err error) {
|
||||
func (pe *PermissionUpdate) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(pe)
|
||||
|
||||
@ -159,4 +159,4 @@ func (pe *PermissionsUpdate) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewPermissionsUpdate()
|
||||
var _ RequestFiller = NewPermissionUpdate()
|
||||
@ -49,7 +49,7 @@ func MountRoutes(oidcConfig *config.OIDC, socialConfig *config.Social, jwtEncode
|
||||
handlers.NewUser(User{}.New()).MountRoutes(r)
|
||||
handlers.NewRole(Role{}.New()).MountRoutes(r)
|
||||
handlers.NewOrganisation(Organisation{}.New()).MountRoutes(r)
|
||||
handlers.NewPermissions(Permissions{}.New()).MountRoutes(r)
|
||||
handlers.NewPermission(Permission{}.New()).MountRoutes(r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user