Define *.search operations for all resources

This commit is contained in:
Denis Arh
2021-07-12 08:58:04 +02:00
parent 03344782a9
commit f630a3d9ef
43 changed files with 614 additions and 148 deletions
+93 -29
View File
@@ -18,12 +18,11 @@ package service
import (
"context"
"fmt"
"strings"
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/spf13/cast"
"strings"
)
type (
@@ -108,6 +107,11 @@ func (svc accessControl) List() (out []map[string]string) {
"any": types.ModuleRbacResource(0, 0),
"op": "record.create",
},
{
"type": types.ModuleResourceType,
"any": types.ModuleRbacResource(0, 0),
"op": "records.search",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
@@ -133,16 +137,31 @@ func (svc accessControl) List() (out []map[string]string) {
"any": types.NamespaceRbacResource(0),
"op": "module.create",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
"op": "modules.search",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
"op": "chart.create",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
"op": "charts.search",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
"op": "page.create",
},
{
"type": types.NamespaceResourceType,
"any": types.NamespaceRbacResource(0),
"op": "pages.search",
},
{
"type": types.PageResourceType,
"any": types.PageRbacResource(0, 0),
@@ -178,11 +197,6 @@ func (svc accessControl) List() (out []map[string]string) {
"any": types.ComponentRbacResource(),
"op": "grant",
},
{
"type": types.ComponentResourceType,
"any": types.ComponentRbacResource(),
"op": "namespace.create",
},
{
"type": types.ComponentResourceType,
"any": types.ComponentRbacResource(),
@@ -193,6 +207,16 @@ func (svc accessControl) List() (out []map[string]string) {
"any": types.ComponentRbacResource(),
"op": "settings.manage",
},
{
"type": types.ComponentResourceType,
"any": types.ComponentRbacResource(),
"op": "namespace.create",
},
{
"type": types.ComponentResourceType,
"any": types.ComponentRbacResource(),
"op": "namespaces.search",
},
}
func(svc interface{}) {
@@ -318,6 +342,13 @@ func (svc accessControl) CanCreateRecordOnModule(ctx context.Context, r *types.M
return svc.can(ctx, "record.create", r)
}
// CanSearchRecordsOnModule checks if current user can list, search or filter records
//
// This function is auto-generated
func (svc accessControl) CanSearchRecordsOnModule(ctx context.Context, r *types.Module) bool {
return svc.can(ctx, "records.search", r)
}
// CanReadNamespace checks if current user can read namespace
//
// This function is auto-generated
@@ -353,6 +384,13 @@ func (svc accessControl) CanCreateModuleOnNamespace(ctx context.Context, r *type
return svc.can(ctx, "module.create", r)
}
// CanSearchModulesOnNamespace checks if current user can list, search or filter module on namespace
//
// This function is auto-generated
func (svc accessControl) CanSearchModulesOnNamespace(ctx context.Context, r *types.Namespace) bool {
return svc.can(ctx, "modules.search", r)
}
// CanCreateChartOnNamespace checks if current user can create chart on namespace
//
// This function is auto-generated
@@ -360,6 +398,13 @@ func (svc accessControl) CanCreateChartOnNamespace(ctx context.Context, r *types
return svc.can(ctx, "chart.create", r)
}
// CanSearchChartsOnNamespace checks if current user can list, search or filter chart on namespace
//
// This function is auto-generated
func (svc accessControl) CanSearchChartsOnNamespace(ctx context.Context, r *types.Namespace) bool {
return svc.can(ctx, "charts.search", r)
}
// CanCreatePageOnNamespace checks if current user can create page on namespace
//
// This function is auto-generated
@@ -367,6 +412,13 @@ func (svc accessControl) CanCreatePageOnNamespace(ctx context.Context, r *types.
return svc.can(ctx, "page.create", r)
}
// CanSearchPagesOnNamespace checks if current user can list, search or filter pages on namespace
//
// This function is auto-generated
func (svc accessControl) CanSearchPagesOnNamespace(ctx context.Context, r *types.Namespace) bool {
return svc.can(ctx, "pages.search", r)
}
// CanReadPage checks if current user can read page
//
// This function is auto-generated
@@ -416,13 +468,6 @@ func (svc accessControl) CanGrant(ctx context.Context) bool {
return svc.can(ctx, "grant", &types.Component{})
}
// CanCreateNamespace checks if current user can create namespace
//
// This function is auto-generated
func (svc accessControl) CanCreateNamespace(ctx context.Context) bool {
return svc.can(ctx, "namespace.create", &types.Component{})
}
// CanReadSettings checks if current user can read settings
//
// This function is auto-generated
@@ -437,6 +482,20 @@ func (svc accessControl) CanManageSettings(ctx context.Context) bool {
return svc.can(ctx, "settings.manage", &types.Component{})
}
// CanCreateNamespace checks if current user can create namespace
//
// This function is auto-generated
func (svc accessControl) CanCreateNamespace(ctx context.Context) bool {
return svc.can(ctx, "namespace.create", &types.Component{})
}
// CanSearchNamespaces checks if current user can list, search or filter namespaces
//
// This function is auto-generated
func (svc accessControl) CanSearchNamespaces(ctx context.Context) bool {
return svc.can(ctx, "namespaces.search", &types.Component{})
}
// rbacResourceValidator validates known component's resource by routing it to the appropriate validator
//
// This function is auto-generated
@@ -479,20 +538,24 @@ func rbacResourceOperations(r string) map[string]bool {
}
case types.ModuleResourceType:
return map[string]bool{
"read": true,
"update": true,
"delete": true,
"record.create": true,
"read": true,
"update": true,
"delete": true,
"record.create": true,
"records.search": true,
}
case types.NamespaceResourceType:
return map[string]bool{
"read": true,
"update": true,
"delete": true,
"manage": true,
"module.create": true,
"chart.create": true,
"page.create": true,
"read": true,
"update": true,
"delete": true,
"manage": true,
"module.create": true,
"modules.search": true,
"chart.create": true,
"charts.search": true,
"page.create": true,
"pages.search": true,
}
case types.PageResourceType:
return map[string]bool{
@@ -508,10 +571,11 @@ func rbacResourceOperations(r string) map[string]bool {
}
case types.ComponentResourceType:
return map[string]bool{
"grant": true,
"namespace.create": true,
"settings.read": true,
"settings.manage": true,
"grant": true,
"settings.read": true,
"settings.manage": true,
"namespace.create": true,
"namespaces.search": true,
}
}
+35 -3
View File
@@ -990,12 +990,12 @@ func AttachmentErrFailedToProcessImage(mm ...*attachmentActionProps) *errors.Err
return e
}
// AttachmentErrNotAllowedToReadModule returns "compose:attachment.notAllowedToReadModule" as *errors.Error
// AttachmentErrNotAllowedToRead returns "compose:attachment.notAllowedToRead" as *errors.Error
//
//
// This function is auto-generated.
//
func AttachmentErrNotAllowedToReadModule(mm ...*attachmentActionProps) *errors.Error {
func AttachmentErrNotAllowedToRead(mm ...*attachmentActionProps) *errors.Error {
var p = &attachmentActionProps{}
if len(mm) > 0 {
p = mm[0]
@@ -1006,7 +1006,7 @@ func AttachmentErrNotAllowedToReadModule(mm ...*attachmentActionProps) *errors.E
p.Format("not allowed to read this module", nil),
errors.Meta("type", "notAllowedToReadModule"),
errors.Meta("type", "notAllowedToRead"),
errors.Meta("resource", "compose:attachment"),
// action log entry; no formatting, it will be applied inside recordAction fn.
@@ -1022,6 +1022,38 @@ func AttachmentErrNotAllowedToReadModule(mm ...*attachmentActionProps) *errors.E
return e
}
// AttachmentErrNotAllowedToSearch returns "compose:attachment.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func AttachmentErrNotAllowedToSearch(mm ...*attachmentActionProps) *errors.Error {
var p = &attachmentActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to search or list modules", nil),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:attachment"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(attachmentLogMetaKey{}, "could not search or list modules; insufficient permissions"),
errors.Meta(attachmentPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// AttachmentErrNotAllowedToReadNamespace returns "compose:attachment.notAllowedToReadNamespace" as *errors.Error
//
//
+5 -1
View File
@@ -114,10 +114,14 @@ errors:
- error: failedToProcessImage
message: "could not process image"
- error: notAllowedToReadModule
- error: notAllowedToRead
message: "not allowed to read this module"
log: "could not delete {module}; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list modules"
log: "could not search or list modules; insufficient permissions"
- error: notAllowedToReadNamespace
message: "not allowed to read this namespace"
log: "could not delete {namespace}; insufficient permissions"
+32 -32
View File
@@ -716,6 +716,38 @@ func ChartErrNotAllowedToRead(mm ...*chartActionProps) *errors.Error {
return e
}
// ChartErrNotAllowedToSearch returns "compose:chart.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func ChartErrNotAllowedToSearch(mm ...*chartActionProps) *errors.Error {
var p = &chartActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to search or list charts", nil),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:chart"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(chartLogMetaKey{}, "could not search or list charts; insufficient permissions"),
errors.Meta(chartPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// ChartErrNotAllowedToReadNamespace returns "compose:chart.notAllowedToReadNamespace" as *errors.Error
//
//
@@ -748,38 +780,6 @@ func ChartErrNotAllowedToReadNamespace(mm ...*chartActionProps) *errors.Error {
return e
}
// ChartErrNotAllowedToListCharts returns "compose:chart.notAllowedToListCharts" as *errors.Error
//
//
// This function is auto-generated.
//
func ChartErrNotAllowedToListCharts(mm ...*chartActionProps) *errors.Error {
var p = &chartActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to list charts", nil),
errors.Meta("type", "notAllowedToListCharts"),
errors.Meta("resource", "compose:chart"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(chartLogMetaKey{}, "could not list charts; insufficient permissions"),
errors.Meta(chartPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// ChartErrNotAllowedToCreate returns "compose:chart.notAllowedToCreate" as *errors.Error
//
//
+4 -4
View File
@@ -88,14 +88,14 @@ errors:
message: "not allowed to read this chart"
log: "could not read {chart}; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list charts"
log: "could not search or list charts; insufficient permissions"
- error: notAllowedToReadNamespace
message: "not allowed to read this namespace"
log: "could not read namespace {namespace}; insufficient permissions"
- error: notAllowedToListCharts
message: "not allowed to list charts"
log: "could not list charts; insufficient permissions"
- error: notAllowedToCreate
message: "not allowed to create charts"
log: "could not create charts; insufficient permissions"
+32
View File
@@ -707,6 +707,38 @@ func ModuleErrNotAllowedToRead(mm ...*moduleActionProps) *errors.Error {
return e
}
// ModuleErrNotAllowedToSearch returns "compose:module.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func ModuleErrNotAllowedToSearch(mm ...*moduleActionProps) *errors.Error {
var p = &moduleActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to search or list modules", nil),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:module"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(moduleLogMetaKey{}, "could not search or list modules; insufficient permissions"),
errors.Meta(modulePropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// ModuleErrNotAllowedToReadNamespace returns "compose:module.notAllowedToReadNamespace" as *errors.Error
//
//
+4
View File
@@ -86,6 +86,10 @@ errors:
message: "not allowed to read this module"
log: "could not read {module}; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list modules"
log: "could not search or list modules; insufficient permissions"
- error: notAllowedToReadNamespace
message: "not allowed to read this namespace"
log: "could not read namespace {namespace}; insufficient permissions"
+5 -5
View File
@@ -590,12 +590,12 @@ func NamespaceErrNotAllowedToRead(mm ...*namespaceActionProps) *errors.Error {
return e
}
// NamespaceErrNotAllowedToListNamespaces returns "compose:namespace.notAllowedToListNamespaces" as *errors.Error
// NamespaceErrNotAllowedToSearch returns "compose:namespace.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func NamespaceErrNotAllowedToListNamespaces(mm ...*namespaceActionProps) *errors.Error {
func NamespaceErrNotAllowedToSearch(mm ...*namespaceActionProps) *errors.Error {
var p = &namespaceActionProps{}
if len(mm) > 0 {
p = mm[0]
@@ -604,13 +604,13 @@ func NamespaceErrNotAllowedToListNamespaces(mm ...*namespaceActionProps) *errors
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to list this namespaces", nil),
p.Format("not allowed to search or list namespaces", nil),
errors.Meta("type", "notAllowedToListNamespaces"),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:namespace"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(namespaceLogMetaKey{}, "could not list namespaces; insufficient permissions"),
errors.Meta(namespaceLogMetaKey{}, "could not search or list namespaces; insufficient permissions"),
errors.Meta(namespacePropsMetaKey{}, p),
errors.StackSkip(1),
+3 -3
View File
@@ -73,9 +73,9 @@ errors:
message: "not allowed to read this namespace"
log: "could not read {namespace}; insufficient permissions"
- error: notAllowedToListNamespaces
message: "not allowed to list this namespaces"
log: "could not list namespaces; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list namespaces"
log: "could not search or list namespaces; insufficient permissions"
- error: notAllowedToCreate
message: "not allowed to create namespaces"
+32
View File
@@ -737,6 +737,38 @@ func PageErrNotAllowedToRead(mm ...*pageActionProps) *errors.Error {
return e
}
// PageErrNotAllowedToSearch returns "compose:page.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func PageErrNotAllowedToSearch(mm ...*pageActionProps) *errors.Error {
var p = &pageActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to search or list pages", nil),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:page"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(pageLogMetaKey{}, "could not search pages; insufficient permissions"),
errors.Meta(pagePropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// PageErrNotAllowedToReadNamespace returns "compose:page.notAllowedToReadNamespace" as *errors.Error
//
//
+4
View File
@@ -88,6 +88,10 @@ errors:
message: "not allowed to read this page"
log: "could not read {page}; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list pages"
log: "could not search pages; insufficient permissions"
- error: notAllowedToReadNamespace
message: "not allowed to read this namespace"
log: "could not read namespace {namespace}; insufficient permissions"
+32
View File
@@ -969,6 +969,38 @@ func RecordErrNotAllowedToRead(mm ...*recordActionProps) *errors.Error {
return e
}
// RecordErrNotAllowedToSearch returns "compose:record.notAllowedToSearch" as *errors.Error
//
//
// This function is auto-generated.
//
func RecordErrNotAllowedToSearch(mm ...*recordActionProps) *errors.Error {
var p = &recordActionProps{}
if len(mm) > 0 {
p = mm[0]
}
var e = errors.New(
errors.KindInternal,
p.Format("not allowed to search or list records", nil),
errors.Meta("type", "notAllowedToSearch"),
errors.Meta("resource", "compose:record"),
// action log entry; no formatting, it will be applied inside recordAction fn.
errors.Meta(recordLogMetaKey{}, "failed to search or list records; insufficient permissions"),
errors.Meta(recordPropsMetaKey{}, p),
errors.StackSkip(1),
)
if len(mm) > 0 {
}
return e
}
// RecordErrNotAllowedToReadNamespace returns "compose:record.notAllowedToReadNamespace" as *errors.Error
//
//
+4
View File
@@ -120,6 +120,10 @@ errors:
message: "not allowed to read this record"
log: "failed to read {record}; insufficient permissions"
- error: notAllowedToSearch
message: "not allowed to search or list records"
log: "failed to search or list records; insufficient permissions"
- error: notAllowedToReadNamespace
message: "not allowed to read this namespace"
log: "failed to read namespace {namespace}; insufficient permissions"