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.
This commit is contained in:
parent
770cc1dbb3
commit
6fb7e84ce1
4 changed files with 62 additions and 0 deletions
|
@ -685,6 +685,10 @@ func buildFilterQueryString(path string, filter *Filter) string {
|
||||||
values.Set("feed_id", strconv.FormatInt(filter.FeedID, 10))
|
values.Set("feed_id", strconv.FormatInt(filter.FeedID, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.GloballyVisible {
|
||||||
|
values.Set("globally_visible", "true")
|
||||||
|
}
|
||||||
|
|
||||||
for _, status := range filter.Statuses {
|
for _, status := range filter.Statuses {
|
||||||
values.Add("status", status)
|
values.Add("status", status)
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,6 +278,7 @@ type Filter struct {
|
||||||
CategoryID int64
|
CategoryID int64
|
||||||
FeedID int64
|
FeedID int64
|
||||||
Statuses []string
|
Statuses []string
|
||||||
|
GloballyVisible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// EntryResultSet represents the response when fetching entries.
|
// EntryResultSet represents the response when fetching entries.
|
||||||
|
|
|
@ -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) {
|
func TestGetEntryEndpoints(t *testing.T) {
|
||||||
testConfig := newIntegrationTestConfig()
|
testConfig := newIntegrationTestConfig()
|
||||||
if !testConfig.isConfigured() {
|
if !testConfig.isConfigured() {
|
||||||
|
|
|
@ -149,6 +149,15 @@ func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int
|
||||||
builder.WithLimit(limit)
|
builder.WithLimit(limit)
|
||||||
builder.WithTags(tags)
|
builder.WithTags(tags)
|
||||||
builder.WithEnclosures()
|
builder.WithEnclosures()
|
||||||
|
|
||||||
|
if request.HasQueryParam(r, "globally_visible") {
|
||||||
|
globallyVisible := request.QueryBoolParam(r, "globally_visible", true)
|
||||||
|
|
||||||
|
if globallyVisible {
|
||||||
|
builder.WithGloballyVisible()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configureFilters(builder, r)
|
configureFilters(builder, r)
|
||||||
|
|
||||||
entries, err := builder.GetEntries()
|
entries, err := builder.GetEntries()
|
||||||
|
|
Loading…
Reference in a new issue