Peer Manipulation
This commit is contained in:
@@ -86,22 +86,6 @@ func (abs *AbstractInstanciatedResource[T]) RefineResourceByPartnership(peerID s
|
||||
return abs
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) FilterPeer(peerID string) *dbs.Filters {
|
||||
return &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"instances": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"partnerships": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"peer_groups." + peerID: {{Operator: dbs.EXISTS.String(), Value: true}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) AddInstances(instance ResourceInstanceITF) {
|
||||
abs.Instances = append(abs.Instances, instance.(T))
|
||||
}
|
||||
@@ -121,7 +105,9 @@ func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.Data
|
||||
if len(profiles) > 0 {
|
||||
profile = profiles[0]
|
||||
} else {
|
||||
if ok, _ := peer.IsMySelf(request.PeerID); ok {
|
||||
if ok, _ := utils.IsMySelf(request.PeerID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); ok {
|
||||
profile = pricing.GetDefaultPricingProfile()
|
||||
} else {
|
||||
return nil, errors.New("no pricing profile found")
|
||||
@@ -171,7 +157,9 @@ func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.A
|
||||
|
||||
func (d *AbstractInstanciatedResource[T]) Trim() {
|
||||
d.Type = d.GetType()
|
||||
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
|
||||
if ok, _ := utils.IsMySelf(d.CreatorID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); !ok {
|
||||
for _, instance := range d.Instances {
|
||||
instance.ClearPeerGroups()
|
||||
}
|
||||
@@ -259,7 +247,9 @@ func (ri *ResourceInstance[T]) GetProfile(peerID string, partnershipIndex *int,
|
||||
prts := ri.Partnerships[*partnershipIndex]
|
||||
return prts.GetProfile(buyingIndex, strategyIndex)
|
||||
}
|
||||
if ok, _ := peer.IsMySelf(peerID); ok {
|
||||
if ok, _ := utils.IsMySelf(peerID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); ok {
|
||||
return pricing.GetDefaultPricingProfile()
|
||||
}
|
||||
return nil
|
||||
@@ -271,7 +261,9 @@ func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []strin
|
||||
pricings = append(pricings, p.GetPricingsProfiles(peerID, groups)...)
|
||||
}
|
||||
if len(pricings) == 0 {
|
||||
if ok, _ := peer.IsMySelf(peerID); ok {
|
||||
if ok, _ := utils.IsMySelf(peerID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); ok {
|
||||
pricings = append(pricings, pricing.GetDefaultPricingProfile())
|
||||
}
|
||||
}
|
||||
@@ -286,7 +278,12 @@ func (ri *ResourceInstance[T]) GetPeerGroups() ([]ResourcePartnerITF, []map[stri
|
||||
groups = append(groups, p.GetPeerGroups())
|
||||
}
|
||||
if len(groups) == 0 {
|
||||
_, id := peer.GetSelf()
|
||||
id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
}))
|
||||
if err != nil {
|
||||
return partners, groups
|
||||
}
|
||||
groups = []map[string][]string{
|
||||
{
|
||||
id: {"*"},
|
||||
@@ -358,7 +355,9 @@ func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []st
|
||||
}
|
||||
}
|
||||
if len(profiles) == 0 {
|
||||
if ok, _ := peer.IsMySelf(peerID); ok {
|
||||
if ok, _ := utils.IsMySelf(peerID, (&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
})); ok {
|
||||
profiles = append(profiles, pricing.GetDefaultPricingProfile())
|
||||
}
|
||||
}
|
||||
@@ -367,7 +366,12 @@ func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []st
|
||||
|
||||
func (rp *ResourcePartnerShip[T]) GetPeerGroups() map[string][]string {
|
||||
if len(rp.PeerGroups) == 0 {
|
||||
_, id := peer.GetSelf()
|
||||
id, err := utils.GetMySelf((&peer.Peer{}).GetAccessor(&tools.APIRequest{
|
||||
Admin: true,
|
||||
}))
|
||||
if err != nil {
|
||||
return rp.PeerGroups
|
||||
}
|
||||
return map[string][]string{
|
||||
id: {"*"},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user