Separate news permission level

This commit is contained in:
LittleSheep 2025-02-15 18:09:51 +08:00
parent a9b8fbf558
commit 48b2a8d470
2 changed files with 21 additions and 6 deletions

View File

@ -1,10 +1,11 @@
package models
type NewsSource struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
Source string `json:"source"`
Depth int `json:"depth"`
Enabled bool `json:"enabled"`
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
Source string `json:"source"`
Depth int `json:"depth"`
Enabled bool `json:"enabled"`
Advanced bool `json:"advanced"`
}

View File

@ -1,6 +1,7 @@
package api
import (
"git.solsynth.dev/hypernet/reader/pkg/internal/services"
"time"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
@ -48,6 +49,19 @@ func listNewsArticles(c *fiber.Ctx) error {
tx = tx.Where("source = ?", source)
}
isAdvanced := false
if err := sec.EnsureGrantedPerm(c, "ListNewsAdvanced", true); err == nil {
isAdvanced = true
}
var sources []string
for _, srv := range services.NewsSources {
if !isAdvanced && srv.Advanced {
continue
}
sources = append(sources, srv.ID)
}
var count int64
countTx := tx
if err := countTx.Model(&models.NewsArticle{}).Count(&count).Error; err != nil {