make ci catalog
This commit is contained in:
+16
-6
@@ -113,12 +113,12 @@ func (o *ResourceController) Search() {
|
||||
limit, _ := strconv.Atoi(o.Ctx.Input.Query("limit"))
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
fmt.Println(o.collection(false))
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
}
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(nil, search, isDraft == "true", int64(offset), int64(limit))
|
||||
fmt.Println(col, len(s.Data), s.Err)
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
}
|
||||
mm := map[string]interface{}{}
|
||||
@@ -154,6 +154,7 @@ func GetResource(typ oclib.LibDataEnum) interface{} {
|
||||
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param is_draft query string false
|
||||
// @Param extend query string false "extend"
|
||||
// @Param offset query string false
|
||||
@@ -162,6 +163,7 @@ func GetResource(typ oclib.LibDataEnum) interface{} {
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router /:type/extended/search [post]
|
||||
func (o *ResourceController) SearchExtended() {
|
||||
fmt.Println("THERE")
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// store and return Id or post with UUIDLibDataEnum
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
@@ -175,6 +177,7 @@ func (o *ResourceController) SearchExtended() {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
}
|
||||
fmt.Println("filters", oclib.FiltersFromFlatMap(res, GetResource(col)))
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(
|
||||
oclib.FiltersFromFlatMap(res, GetResource(col)), "", isDraft == "true", int64(offset), int64(limit))
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
@@ -203,10 +206,8 @@ func (o *ResourceController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
extend := strings.Split(o.Ctx.Input.Query("extend"), ",")
|
||||
fmt.Println("COLLECTIOn", o.collection(false))
|
||||
for _, col := range o.collection(false) {
|
||||
if d := oclib.NewRequest(col, user, peerID, groups, nil).LoadOne(id); d.Data != nil {
|
||||
fmt.Println("EXTEND", d.Data.Extend(extend...), extend)
|
||||
o.Data["json"] = oclib.GetExtend(d.Data, d.Data.Extend(extend...), map[tools.DataType]map[string]interface{}{})
|
||||
break
|
||||
} else {
|
||||
@@ -235,12 +236,23 @@ func (o *ResourceController) Post() {
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &res)
|
||||
|
||||
// Block "add from discovered cache": refuse resources whose creator_id belongs to another peer.
|
||||
// Resources discovered via decentralized search must go to the workspace, not the local catalog.
|
||||
if creatorID, _ := res["creator_id"].(string); creatorID != "" && peerID != "" && creatorID != peerID {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 403,
|
||||
"err": "cannot add a resource created by another peer to the local catalog; use workspace instead",
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
// Remplace les sources privées (isReachable=false) par des clés opaques
|
||||
// avant la persistance : le vrai path ne doit jamais sortir de ce peer.
|
||||
replacePrivateSources(res)
|
||||
|
||||
data := oclib.NewRequest(libs[0], user, peerID, groups, nil).StoreOne(res)
|
||||
fmt.Println(data.Data, res["name"], libs[0])
|
||||
if data.Err == "" {
|
||||
payload, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
@@ -338,12 +350,10 @@ func (o *ResourceController) Put() {
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type/:id [delete]
|
||||
func (o *ResourceController) Delete() {
|
||||
fmt.Println("THERE")
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
for _, col := range o.collection(false) {
|
||||
data := oclib.NewRequest(col, user, peerID, groups, nil).DeleteOne(id)
|
||||
fmt.Println(col, data, id)
|
||||
if data.Err == "" {
|
||||
o.Data["json"] = data
|
||||
payload, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
|
||||
Reference in New Issue
Block a user