aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Pontus Jensen Karlsson <pontus@jensenkarlsson.se> 2024-08-08 04:46:09 +0000
committerGravatar Frédéric Guillot <f@miniflux.net> 2024-08-12 20:20:44 -0700
commit6fb7e84ce1bb38b386a6f6effd1bb3b09d2b72e0 (patch)
tree0785d15a81daf0851753c71109b162bc55e01928
parent770cc1dbb387af580b9ceba1cba9fda69e4444ed (diff)
downloadv2-6fb7e84ce1bb38b386a6f6effd1bb3b09d2b72e0.tar.gz
v2-6fb7e84ce1bb38b386a6f6effd1bb3b09d2b72e0.tar.zst
v2-6fb7e84ce1bb38b386a6f6effd1bb3b09d2b72e0.zip
feat: API: Allow filtering entries on globally_hidden
Currently there's no way through the API to mimic the Unread page of the client. This is now possible by filtering on globally_visible=true and status=unread.
-rw-r--r--client/client.go4
-rw-r--r--client/model.go1
-rw-r--r--internal/api/api_integration_test.go48
-rw-r--r--internal/api/entry.go9
4 files changed, 62 insertions, 0 deletions
diff --git a/client/client.go b/client/client.go
index 9b92b33b..2840c4e0 100644
--- a/client/client.go
+++ b/client/client.go
@@ -685,6 +685,10 @@ func buildFilterQueryString(path string, filter *Filter) string {
values.Set("feed_id", strconv.FormatInt(filter.FeedID, 10))
}
+ if filter.GloballyVisible {
+ values.Set("globally_visible", "true")
+ }
+
for _, status := range filter.Statuses {
values.Add("status", status)
}
diff --git a/client/model.go b/client/model.go
index a90762ad..57b03d6e 100644
--- a/client/model.go
+++ b/client/model.go
@@ -278,6 +278,7 @@ type Filter struct {
CategoryID int64
FeedID int64
Statuses []string
+ GloballyVisible bool
}
// EntryResultSet represents the response when fetching entries.
diff --git a/internal/api/api_integration_test.go b/internal/api/api_integration_test.go
index 9259b590..df8d93a0 100644
--- a/internal/api/api_integration_test.go
+++ b/internal/api/api_integration_test.go
@@ -1986,6 +1986,54 @@ func TestGetAllEntriesEndpointWithFilter(t *testing.T) {
}
}
+func TestGetGlobalEntriesEndpoint(t *testing.T) {
+ testConfig := newIntegrationTestConfig()
+ if !testConfig.isConfigured() {
+ t.Skip(skipIntegrationTestsMessage)
+ }
+
+ adminClient := miniflux.NewClient(testConfig.testBaseURL, testConfig.testAdminUsername, testConfig.testAdminPassword)
+
+ regularTestUser, err := adminClient.CreateUser(testConfig.genRandomUsername(), testConfig.testRegularPassword, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer adminClient.DeleteUser(regularTestUser.ID)
+
+ regularUserClient := miniflux.NewClient(testConfig.testBaseURL, regularTestUser.Username, testConfig.testRegularPassword)
+
+ feedID, err := regularUserClient.CreateFeed(&miniflux.FeedCreationRequest{
+ FeedURL: testConfig.testFeedURL,
+ HideGlobally: true,
+ })
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ /* Not filtering on GloballyVisible should return all entries */
+ feedEntries, err := regularUserClient.Entries(&miniflux.Filter{FeedID: feedID})
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(feedEntries.Entries) == 0 {
+ t.Fatalf(`Expected entries but response contained none.`)
+ }
+
+ /* Feed is hidden globally, so this should be empty */
+ globallyVisibleEntries, err := regularUserClient.Entries(&miniflux.Filter{GloballyVisible: true})
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(globallyVisibleEntries.Entries) != 0 {
+ t.Fatalf(`Expected no entries, got %d`, len(globallyVisibleEntries.Entries))
+ }
+}
+
func TestGetEntryEndpoints(t *testing.T) {
testConfig := newIntegrationTestConfig()
if !testConfig.isConfigured() {
diff --git a/internal/api/entry.go b/internal/api/entry.go
index d8fc01f6..121d2701 100644
--- a/internal/api/entry.go
+++ b/internal/api/entry.go
@@ -149,6 +149,15 @@ func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int
builder.WithLimit(limit)
builder.WithTags(tags)
builder.WithEnclosures()
+
+ if request.HasQueryParam(r, "globally_visible") {
+ globallyVisible := request.QueryBoolParam(r, "globally_visible", true)
+
+ if globallyVisible {
+ builder.WithGloballyVisible()
+ }
+ }
+
configureFilters(builder, r)
entries, err := builder.GetEntries()