1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

feat(api): add endpoint for user integration status

This commit is contained in:
AiraNadih 2024-10-18 11:59:05 +08:00 committed by GitHub
parent 7fdb450446
commit 0adbcc3a04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 70 additions and 1 deletions

View file

@ -32,7 +32,11 @@ jobs:
- run: "go vet ./..." - run: "go vet ./..."
- uses: golangci/golangci-lint-action@v6 - uses: golangci/golangci-lint-action@v6
with: with:
args: --timeout 10m --skip-dirs tests --disable errcheck --enable sqlclosecheck --enable misspell --enable gofmt --enable goimports --enable whitespace --enable gocritic args: >
--timeout 10m
--exclude-dirs=tests
--disable errcheck
--enable sqlclosecheck,misspell,gofmt,goimports,whitespace,gocritic
- uses: dominikh/staticcheck-action@v1.3.1 - uses: dominikh/staticcheck-action@v1.3.1
with: with:
version: "2024.1.1" version: "2024.1.1"

View file

@ -185,6 +185,25 @@ func (c *Client) MarkAllAsRead(userID int64) error {
return err return err
} }
// FetchIntegrationsStatus fetches the integrations status for a user.
func (c *Client) FetchIntegrationsStatus() (bool, error) {
body, err := c.request.Get("/v1/users/integrations/status")
if err != nil {
return false, err
}
defer body.Close()
var response struct {
HasIntegrations bool `json:"has_integrations"`
}
if err := json.NewDecoder(body).Decode(&response); err != nil {
return false, fmt.Errorf("miniflux: response error (%v)", err)
}
return response.HasIntegrations, nil
}
// Discover try to find subscriptions from a website. // Discover try to find subscriptions from a website.
func (c *Client) Discover(url string) (Subscriptions, error) { func (c *Client) Discover(url string) (Subscriptions, error) {
body, err := c.request.Post("/v1/discover", map[string]string{"url": url}) body, err := c.request.Post("/v1/discover", map[string]string{"url": url})

View file

@ -37,6 +37,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
sr.HandleFunc("/users/{userID:[0-9]+}", handler.updateUser).Methods(http.MethodPut) sr.HandleFunc("/users/{userID:[0-9]+}", handler.updateUser).Methods(http.MethodPut)
sr.HandleFunc("/users/{userID:[0-9]+}", handler.removeUser).Methods(http.MethodDelete) sr.HandleFunc("/users/{userID:[0-9]+}", handler.removeUser).Methods(http.MethodDelete)
sr.HandleFunc("/users/{userID:[0-9]+}/mark-all-as-read", handler.markUserAsRead).Methods(http.MethodPut) sr.HandleFunc("/users/{userID:[0-9]+}/mark-all-as-read", handler.markUserAsRead).Methods(http.MethodPut)
sr.HandleFunc("/users/integrations/status", handler.getIntegrationsStatus).Methods(http.MethodGet)
sr.HandleFunc("/users/{username}", handler.userByUsername).Methods(http.MethodGet) sr.HandleFunc("/users/{username}", handler.userByUsername).Methods(http.MethodGet)
sr.HandleFunc("/me", handler.currentUser).Methods(http.MethodGet) sr.HandleFunc("/me", handler.currentUser).Methods(http.MethodGet)
sr.HandleFunc("/categories", handler.createCategory).Methods(http.MethodPost) sr.HandleFunc("/categories", handler.createCategory).Methods(http.MethodPost)

View file

@ -2483,6 +2483,32 @@ func TestSaveEntryEndpoint(t *testing.T) {
} }
} }
func TestFetchIntegrationsStatusEndpoint(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)
hasIntegrations, err := regularUserClient.FetchIntegrationsStatus()
if err != nil {
t.Fatalf("Failed to fetch integrations status: %v", err)
}
if hasIntegrations {
t.Fatalf("New user should not have integrations configured")
}
}
func TestFetchContentEndpoint(t *testing.T) { func TestFetchContentEndpoint(t *testing.T) {
testConfig := newIntegrationTestConfig() testConfig := newIntegrationTestConfig()
if !testConfig.isConfigured() { if !testConfig.isConfigured() {

View file

@ -130,6 +130,25 @@ func (h *handler) markUserAsRead(w http.ResponseWriter, r *http.Request) {
json.NoContent(w, r) json.NoContent(w, r)
} }
func (h *handler) getIntegrationsStatus(w http.ResponseWriter, r *http.Request) {
userID := request.UserID(r)
if _, err := h.store.UserByID(userID); err != nil {
json.NotFound(w, r)
return
}
hasIntegrations := h.store.HasSaveEntry(userID)
response := struct {
HasIntegrations bool `json:"has_integrations"`
}{
HasIntegrations: hasIntegrations,
}
json.OK(w, r, response)
}
func (h *handler) users(w http.ResponseWriter, r *http.Request) { func (h *handler) users(w http.ResponseWriter, r *http.Request) {
if !request.IsAdminUser(r) { if !request.IsAdminUser(r) {
json.Forbidden(w, r) json.Forbidden(w, r)