mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-30 17:00:57 -06:00
improve permission code in settings service
This commit is contained in:
@@ -71,6 +71,8 @@ type permissionsServiceHandler struct {
|
||||
|
||||
func (h *permissionsServiceHandler) CheckPermission(ctx context.Context, req *permissions.CheckPermissionRequest, res *permissions.CheckPermissionResponse) error {
|
||||
r, err := h.api.CheckPermission(ctx, req)
|
||||
*res = *r
|
||||
if r != nil {
|
||||
*res = *r
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
|
||||
@@ -64,9 +65,11 @@ func (g Service) CheckPermission(ctx context.Context, req *permissions.CheckPerm
|
||||
|
||||
permission, err := g.manager.ReadPermissionByName(req.Permission, roleIDs)
|
||||
if err != nil {
|
||||
return &permissions.CheckPermissionResponse{
|
||||
Status: status.NewInternal(ctx, err.Error()),
|
||||
}, nil
|
||||
if !errors.Is(err, settings.ErrPermissionNotFound) {
|
||||
return &permissions.CheckPermissionResponse{
|
||||
Status: status.NewInternal(ctx, err.Error()),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if permission == nil {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
"github.com/owncloud/ocis/settings/pkg/proto/v0"
|
||||
)
|
||||
@@ -8,6 +10,9 @@ import (
|
||||
var (
|
||||
// Registry uses the strategy pattern as a registry
|
||||
Registry = map[string]RegisterFunc{}
|
||||
|
||||
// ErrPermissionNotFound defines a new error for when a permission was not found
|
||||
ErrPermissionNotFound = errors.New("permission not found")
|
||||
)
|
||||
|
||||
// RegisterFunc stores store constructors
|
||||
|
||||
@@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/settings/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis/settings/pkg/settings"
|
||||
"github.com/owncloud/ocis/settings/pkg/util"
|
||||
)
|
||||
|
||||
@@ -54,7 +55,7 @@ func (s Store) ReadPermissionByName(name string, roleIDs []string) (*proto.Permi
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return nil, settings.ErrPermissionNotFound
|
||||
}
|
||||
|
||||
// extractPermissionsByResource collects all permissions from the provided role that match the requested resource
|
||||
|
||||
Reference in New Issue
Block a user