initial commit (#980)

Co-authored-by: Christian Beutel <>
This commit is contained in:
Flomp
2026-05-11 11:11:09 +02:00
committed by GitHub
parent 868010459f
commit b2753c29d2
3 changed files with 37 additions and 15 deletions

View File

@@ -62,6 +62,17 @@ func RemoteListGet(e *core.RequestEvent) error {
} }
} }
reqInfo, err := e.RequestInfo()
if err != nil {
return err
}
canAccess, err := e.App.CanAccessRecord(record, reqInfo, record.Collection().ViewRule)
if err != nil || !canAccess {
return e.ForbiddenError("forbidden", err)
}
return expandAndReturn(e, record, expandQuery) return expandAndReturn(e, record, expandQuery)
} }

View File

@@ -73,6 +73,17 @@ func RemoteTrailGet(e *core.RequestEvent) error {
} }
} }
reqInfo, err := e.RequestInfo()
if err != nil {
return err
}
canAccess, err := e.App.CanAccessRecord(record, reqInfo, record.Collection().ViewRule)
if err != nil || !canAccess {
return e.ForbiddenError("forbidden", err)
}
return expandAndReturn(e, record, expandQuery) return expandAndReturn(e, record, expandQuery)
} }

View File

@@ -60,6 +60,19 @@ func RemoteTrailCommentsList(e *core.RequestEvent) error {
return err return err
} }
reqInfo, err := e.RequestInfo()
if err != nil {
return err
}
filteredRecords := []*core.Record{}
for _, record := range records {
canAccess, _ := e.App.CanAccessRecord(record, reqInfo, record.Collection().ListRule)
if canAccess {
filteredRecords = append(filteredRecords, record)
}
}
// 3. Get total count for pagination metadata // 3. Get total count for pagination metadata
var totalItems int var totalItems int
err = e.App.DB(). err = e.App.DB().
@@ -73,7 +86,7 @@ func RemoteTrailCommentsList(e *core.RequestEvent) error {
// 4. Handle Expand // 4. Handle Expand
if expandQuery != "" { if expandQuery != "" {
errs := e.App.ExpandRecords(records, strings.Split(expandQuery, ","), nil) errs := e.App.ExpandRecords(filteredRecords, strings.Split(expandQuery, ","), nil)
if len(errs) > 0 { if len(errs) > 0 {
fmt.Printf("Expand errors: %v\n", errs) fmt.Printf("Expand errors: %v\n", errs)
} }
@@ -85,7 +98,7 @@ func RemoteTrailCommentsList(e *core.RequestEvent) error {
"perPage": perPage, "perPage": perPage,
"totalItems": totalItems, "totalItems": totalItems,
"totalPages": (totalItems + perPage - 1) / perPage, "totalPages": (totalItems + perPage - 1) / perPage,
"items": records, "items": filteredRecords,
}) })
} }
@@ -171,16 +184,3 @@ func syncRemoteComments(e *core.RequestEvent, trail *core.Record) error {
return nil return nil
}) })
} }
func expandAndReturnList(e *core.RequestEvent, records []*core.Record, query string) error {
if query != "" {
expandPaths := strings.Split(query, ",")
errs := e.App.ExpandRecords(records, expandPaths, nil)
if len(errs) > 0 {
fmt.Printf("Expand errors: %v\n", errs)
}
}
return e.JSON(http.StatusOK, records)
}