3
0
Files
corteza/system/rest/data_privacy.go
Vivek Patel db325fc125 Add route to list dal connections for privacy console
It will only list dal connections with minimal data.
2022-08-05 17:54:21 +05:30

64 lines
1.5 KiB
Go

package rest
import (
"context"
"github.com/cortezaproject/corteza-server/pkg/payload"
"github.com/cortezaproject/corteza-server/system/rest/request"
"github.com/cortezaproject/corteza-server/system/service"
"github.com/cortezaproject/corteza-server/system/types"
)
type (
DataPrivacy struct {
privacy service.DataPrivacyService
ac privacyAccessController
}
privacyAccessController interface {
CanGrant(context.Context) bool
}
privacyConnectionSetPayload struct {
Filter types.DalConnectionFilter `json:"filter"`
Set types.PrivacyDalConnectionSet `json:"set"`
}
)
func (DataPrivacy) New() *DataPrivacy {
return &DataPrivacy{
privacy: service.DefaultDataPrivacy,
ac: service.DefaultAccessControl,
}
}
func (ctrl DataPrivacy) ConnectionList(ctx context.Context, r *request.DataPrivacyConnectionList) (interface{}, error) {
var (
err error
set types.PrivacyDalConnectionSet
f = types.DalConnectionFilter{
ConnectionID: payload.ParseUint64s(r.ConnectionID),
Handle: r.Handle,
Type: r.Type,
Deleted: r.Deleted,
}
)
set, f, err = ctrl.privacy.FindConnections(ctx, f)
return ctrl.makeFilterConnectionPayload(ctx, set, f, err)
}
func (ctrl DataPrivacy) makeFilterConnectionPayload(_ context.Context, rr types.PrivacyDalConnectionSet, f types.DalConnectionFilter, err error) (*privacyConnectionSetPayload, error) {
if err != nil {
return nil, err
}
if len(rr) == 0 {
rr = make([]*types.PrivacyDalConnection, 0)
}
return &privacyConnectionSetPayload{Filter: f, Set: rr}, nil
}