fix(tenant): 封堵审计文件与历史用户跨站访问
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -16,6 +17,7 @@ type Meta struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
|
TenantID uint64
|
||||||
ActorType string
|
ActorType string
|
||||||
ActorID uint64
|
ActorID uint64
|
||||||
Action string
|
Action string
|
||||||
@@ -31,7 +33,12 @@ func Append(tx *gorm.DB, entry Entry) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
tenantID := entry.TenantID
|
||||||
|
if tenantID == 0 && tx.Statement != nil && tx.Statement.Context != nil {
|
||||||
|
tenantID = tenancy.IDFromContext(tx.Statement.Context)
|
||||||
|
}
|
||||||
row := model.AuditLog{
|
row := model.AuditLog{
|
||||||
|
TenantID: tenantID,
|
||||||
ActorType: entry.ActorType,
|
ActorType: entry.ActorType,
|
||||||
ActorID: entry.ActorID,
|
ActorID: entry.ActorID,
|
||||||
Action: entry.Action,
|
Action: entry.Action,
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package auditlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/database"
|
||||||
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAppendUsesTenantFromTransactionContext(t *testing.T) {
|
||||||
|
db := database.NewTestDB()
|
||||||
|
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||||
|
|
||||||
|
var row model.AuditLog
|
||||||
|
if err := db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
return Append(tx, Entry{
|
||||||
|
ActorType: "admin",
|
||||||
|
ActorID: 1,
|
||||||
|
Action: "test.tenant_audit",
|
||||||
|
BizType: "test",
|
||||||
|
})
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := db.Where("action = ?", "test.tenant_audit").First(&row).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if row.TenantID != 101 {
|
||||||
|
t.Fatalf("audit tenant = %d, want 101", row.TenantID)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,6 +76,7 @@ func appendManagedTimeoutNotification(tx *gorm.DB, order *model.RentalOrder, tit
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return adminnotification.Append(tx, adminnotification.Entry{
|
return adminnotification.Append(tx, adminnotification.Entry{
|
||||||
|
TenantID: order.BuyerTenantID,
|
||||||
AdminUserID: *order.ManagedAdminID,
|
AdminUserID: *order.ManagedAdminID,
|
||||||
Type: "timeout",
|
Type: "timeout",
|
||||||
Title: title,
|
Title: title,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type AuditLog struct {
|
type AuditLog struct {
|
||||||
ID uint64 `gorm:"primaryKey" json:"id"`
|
ID uint64 `gorm:"primaryKey" json:"id"`
|
||||||
|
TenantID uint64 `gorm:"not null;default:0;index:idx_audit_logs_tenant_created" json:"tenant_id"`
|
||||||
ActorType string `gorm:"size:32;not null" json:"actor_type"`
|
ActorType string `gorm:"size:32;not null" json:"actor_type"`
|
||||||
ActorID uint64 `gorm:"not null;index" json:"actor_id"`
|
ActorID uint64 `gorm:"not null;index" json:"actor_id"`
|
||||||
Action string `gorm:"size:64;not null" json:"action"`
|
Action string `gorm:"size:64;not null" json:"action"`
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -26,6 +27,10 @@ func (r *Repository) List(ctx context.Context, query Query) (*PaginatedResult, e
|
|||||||
Joins("LEFT JOIN admin_users AS au ON au.id = al.actor_id AND al.actor_type = ?", "admin")
|
Joins("LEFT JOIN admin_users AS au ON au.id = al.actor_id AND al.actor_type = ?", "admin")
|
||||||
|
|
||||||
countDB := r.db.WithContext(ctx).Model(&model.AuditLog{})
|
countDB := r.db.WithContext(ctx).Model(&model.AuditLog{})
|
||||||
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
|
db = db.Where("al.tenant_id = ?", tenantID)
|
||||||
|
countDB = countDB.Where("tenant_id = ?", tenantID)
|
||||||
|
}
|
||||||
if query.ActorID > 0 {
|
if query.ActorID > 0 {
|
||||||
db = db.Where("al.actor_id = ?", query.ActorID)
|
db = db.Where("al.actor_id = ?", query.ActorID)
|
||||||
countDB = countDB.Where("actor_id = ?", query.ActorID)
|
countDB = countDB.Where("actor_id = ?", query.ActorID)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package adminaudit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/database"
|
||||||
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListIsScopedByOperatingTenant(t *testing.T) {
|
||||||
|
db := database.NewTestDB()
|
||||||
|
rows := []model.AuditLog{
|
||||||
|
{TenantID: 101, ActorType: "admin", ActorID: 1, Action: "tenant.a", BizType: "test"},
|
||||||
|
{TenantID: 202, ActorType: "admin", ActorID: 2, Action: "tenant.b", BizType: "test"},
|
||||||
|
{TenantID: 0, ActorType: "admin", ActorID: 3, Action: "platform", BizType: "test"},
|
||||||
|
}
|
||||||
|
if err := db.Create(&rows).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||||
|
result, err := NewRepository(db).List(ctx, Query{Page: 1, PageSize: 20})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
items := result.Items.([]LogDTO)
|
||||||
|
if result.Total != 1 || len(items) != 1 || items[0].Action != "tenant.a" {
|
||||||
|
t.Fatalf("tenant audit list = %+v", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -104,17 +104,8 @@ func Append(tx *gorm.DB, entries ...Entry) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tenantID := entry.TenantID
|
tenantID := entry.TenantID
|
||||||
if tenantID == 0 {
|
if tenantID == 0 && tx.Statement != nil && tx.Statement.Context != nil {
|
||||||
var row struct {
|
tenantID = tenancy.IDFromContext(tx.Statement.Context)
|
||||||
TenantID uint64
|
|
||||||
}
|
|
||||||
if err := tx.Table("admin_user_roles").
|
|
||||||
Select("tenant_id").
|
|
||||||
Where("admin_user_id = ? AND tenant_id > 0", entry.AdminUserID).
|
|
||||||
Order("tenant_id ASC").
|
|
||||||
Take(&row).Error; err == nil {
|
|
||||||
tenantID = row.TenantID
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
row := model.AdminNotification{
|
row := model.AdminNotification{
|
||||||
TenantID: tenantID,
|
TenantID: tenantID,
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import (
|
|||||||
|
|
||||||
"hfb_sys/backend/internal/database"
|
"hfb_sys/backend/internal/database"
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepositoryUnreadCountAndMarkRead(t *testing.T) {
|
func TestRepositoryUnreadCountAndMarkRead(t *testing.T) {
|
||||||
@@ -103,3 +106,31 @@ func TestRepositoryMarkReadNotFound(t *testing.T) {
|
|||||||
t.Fatalf("MarkRead() error = %v, want ErrNotificationNotFound", err)
|
t.Fatalf("MarkRead() error = %v, want ErrNotificationNotFound", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppendUsesExplicitOrContextTenant(t *testing.T) {
|
||||||
|
db := database.NewTestDB()
|
||||||
|
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 202})
|
||||||
|
appendNotification := func(entry Entry) {
|
||||||
|
t.Helper()
|
||||||
|
if err := db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
return Append(tx, entry)
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appendNotification(Entry{AdminUserID: 7, Type: "system", Title: "上下文站点", Content: "x"})
|
||||||
|
appendNotification(Entry{TenantID: 101, AdminUserID: 7, Type: "system", Title: "显式站点", Content: "y"})
|
||||||
|
if err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
return Append(tx, Entry{AdminUserID: 7, Type: "platform", Title: "平台站点", Content: "z"})
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []model.AdminNotification
|
||||||
|
if err := db.Order("id ASC").Find(&rows).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(rows) != 3 || rows[0].TenantID != 202 || rows[1].TenantID != 101 || rows[2].TenantID != 0 {
|
||||||
|
t.Fatalf("admin notification tenants = %+v", rows)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -168,7 +168,11 @@ func (r *Repository) adminListBase(ctx context.Context, query AnnouncementListQu
|
|||||||
Select("a.id, a.distribution_site_id, COALESCE(s.site_name, '') AS distribution_site_name, a.title, a.content, a.category, a.priority, a.is_pinned, a.is_important, a.is_popup, a.view_count, a.status, a.published_at, a.created_at, a.updated_at").
|
Select("a.id, a.distribution_site_id, COALESCE(s.site_name, '') AS distribution_site_name, a.title, a.content, a.category, a.priority, a.is_pinned, a.is_important, a.is_popup, a.view_count, a.status, a.published_at, a.created_at, a.updated_at").
|
||||||
Joins("LEFT JOIN distribution_sites AS s ON s.id = a.distribution_site_id")
|
Joins("LEFT JOIN distribution_sites AS s ON s.id = a.distribution_site_id")
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
base = base.Where("a.tenant_id = ?", tenantID)
|
base = base.
|
||||||
|
Where("a.tenant_id = ?", tenantID).
|
||||||
|
Where("(a.distribution_site_id = 0 OR a.distribution_site_id IS NULL)")
|
||||||
|
} else if query.AdminSiteID != nil {
|
||||||
|
base = base.Where("a.distribution_site_id = ?", *query.AdminSiteID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Status != "" {
|
if query.Status != "" {
|
||||||
@@ -177,9 +181,6 @@ func (r *Repository) adminListBase(ctx context.Context, query AnnouncementListQu
|
|||||||
if query.Category != "" {
|
if query.Category != "" {
|
||||||
base = base.Where("a.category = ?", query.Category)
|
base = base.Where("a.category = ?", query.Category)
|
||||||
}
|
}
|
||||||
if query.AdminSiteID != nil {
|
|
||||||
base = base.Where("a.distribution_site_id = ?", *query.AdminSiteID)
|
|
||||||
}
|
|
||||||
return base
|
return base
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,9 +200,13 @@ func (r *Repository) AdminGetByID(ctx context.Context, id uint64) (*Announcement
|
|||||||
|
|
||||||
// Create 创建公告
|
// Create 创建公告
|
||||||
func (r *Repository) Create(ctx context.Context, req CreateAnnouncementRequest, createdBy uint64) (*AnnouncementDTO, error) {
|
func (r *Repository) Create(ctx context.Context, req CreateAnnouncementRequest, createdBy uint64) (*AnnouncementDTO, error) {
|
||||||
|
siteID := req.DistributionSiteID
|
||||||
|
if tenancy.IDFromContext(ctx) > 0 {
|
||||||
|
siteID = 0
|
||||||
|
}
|
||||||
announcement := model.Announcement{
|
announcement := model.Announcement{
|
||||||
TenantID: tenancy.IDFromContext(ctx),
|
TenantID: tenancy.IDFromContext(ctx),
|
||||||
DistributionSiteID: req.DistributionSiteID,
|
DistributionSiteID: siteID,
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Content: req.Content,
|
Content: req.Content,
|
||||||
Category: req.Category,
|
Category: req.Category,
|
||||||
@@ -241,7 +246,9 @@ func (r *Repository) Update(ctx context.Context, id uint64, req UpdateAnnounceme
|
|||||||
|
|
||||||
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.
|
||||||
|
Where("tenant_id = ?", tenantID).
|
||||||
|
Where("(distribution_site_id = 0 OR distribution_site_id IS NULL)")
|
||||||
}
|
}
|
||||||
if err := query.Updates(updates).Error; err != nil {
|
if err := query.Updates(updates).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -255,7 +262,9 @@ func (r *Repository) Publish(ctx context.Context, id uint64) error {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.
|
||||||
|
Where("tenant_id = ?", tenantID).
|
||||||
|
Where("(distribution_site_id = 0 OR distribution_site_id IS NULL)")
|
||||||
}
|
}
|
||||||
return query.
|
return query.
|
||||||
Updates(map[string]interface{}{
|
Updates(map[string]interface{}{
|
||||||
@@ -268,7 +277,9 @@ func (r *Repository) Publish(ctx context.Context, id uint64) error {
|
|||||||
func (r *Repository) Archive(ctx context.Context, id uint64) error {
|
func (r *Repository) Archive(ctx context.Context, id uint64) error {
|
||||||
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.
|
||||||
|
Where("tenant_id = ?", tenantID).
|
||||||
|
Where("(distribution_site_id = 0 OR distribution_site_id IS NULL)")
|
||||||
}
|
}
|
||||||
return query.
|
return query.
|
||||||
Update("status", "archived").Error
|
Update("status", "archived").Error
|
||||||
@@ -279,7 +290,9 @@ func (r *Repository) Unarchive(ctx context.Context, id uint64) error {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Model(&model.Announcement{}).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.
|
||||||
|
Where("tenant_id = ?", tenantID).
|
||||||
|
Where("(distribution_site_id = 0 OR distribution_site_id IS NULL)")
|
||||||
}
|
}
|
||||||
return query.
|
return query.
|
||||||
Updates(map[string]interface{}{
|
Updates(map[string]interface{}{
|
||||||
@@ -292,7 +305,9 @@ func (r *Repository) Unarchive(ctx context.Context, id uint64) error {
|
|||||||
func (r *Repository) Delete(ctx context.Context, id uint64) error {
|
func (r *Repository) Delete(ctx context.Context, id uint64) error {
|
||||||
query := r.db.WithContext(ctx).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.
|
||||||
|
Where("tenant_id = ?", tenantID).
|
||||||
|
Where("(distribution_site_id = 0 OR distribution_site_id IS NULL)")
|
||||||
}
|
}
|
||||||
return query.Delete(&model.Announcement{}).Error
|
return query.Delete(&model.Announcement{}).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"hfb_sys/backend/internal/database"
|
"hfb_sys/backend/internal/database"
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/tenancy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestPublicScopeAndSiteIsolation 覆盖公告中心的分站可见范围:
|
// TestPublicScopeAndSiteIsolation 覆盖公告中心的分站可见范围:
|
||||||
@@ -175,6 +176,47 @@ func TestAdminListFiltersBySite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTenantAdminAnnouncementsExcludeLegacyDistributionSite(t *testing.T) {
|
||||||
|
db := database.NewTestDB()
|
||||||
|
repo := NewRepository(db)
|
||||||
|
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||||
|
site := model.DistributionSite{
|
||||||
|
SiteCode: "ann_legacy_tenant", SiteName: "历史公告站",
|
||||||
|
Domain: "ann-legacy-tenant.example.com", Status: "active",
|
||||||
|
}
|
||||||
|
if err := db.Create(&site).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
rows := []model.Announcement{
|
||||||
|
{TenantID: 101, Title: "本站公告", Content: "x", Category: "notice", Status: "draft"},
|
||||||
|
{TenantID: 101, DistributionSiteID: site.ID, Title: "历史分销公告", Content: "y", Category: "notice", Status: "draft"},
|
||||||
|
{TenantID: 202, Title: "其他站点公告", Content: "z", Category: "notice", Status: "draft"},
|
||||||
|
}
|
||||||
|
if err := db.Create(&rows).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
result, err := repo.AdminList(ctx, AnnouncementListQuery{
|
||||||
|
AdminSiteID: &site.ID, Page: 1, PageSize: 20,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
items := result.Items.([]AnnouncementDTO)
|
||||||
|
if result.Total != 1 || len(items) != 1 || items[0].Title != "本站公告" {
|
||||||
|
t.Fatalf("tenant announcement list = %+v", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
created, err := repo.Create(ctx, CreateAnnouncementRequest{
|
||||||
|
DistributionSiteID: site.ID, Title: "强制本站", Content: "content", Category: "notice",
|
||||||
|
}, 9)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if created.TenantID != 101 || created.DistributionSiteID != 0 {
|
||||||
|
t.Fatalf("tenant announcement scope = %+v", created)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestPublicPopupSelection 覆盖弹窗公告的选取口径:
|
// TestPublicPopupSelection 覆盖弹窗公告的选取口径:
|
||||||
// 只有 published + is_popup 才参与,站点范围内按优先级取最高的一条,无候选时返回 nil。
|
// 只有 published + is_popup 才参与,站点范围内按优先级取最高的一条,无候选时返回 nil。
|
||||||
func TestPublicPopupSelection(t *testing.T) {
|
func TestPublicPopupSelection(t *testing.T) {
|
||||||
|
|||||||
@@ -311,6 +311,8 @@ func writeAuthError(c *gin.Context, err error) {
|
|||||||
response.Error(c, http.StatusTooManyRequests, "login_locked", "登录失败次数过多,请 15 分钟后再试")
|
response.Error(c, http.StatusTooManyRequests, "login_locked", "登录失败次数过多,请 15 分钟后再试")
|
||||||
case errors.Is(err, ErrUserAlreadyExists):
|
case errors.Is(err, ErrUserAlreadyExists):
|
||||||
response.BadRequest(c, "该手机号已注册,请直接登录或使用短信验证码登录")
|
response.BadRequest(c, "该手机号已注册,请直接登录或使用短信验证码登录")
|
||||||
|
case errors.Is(err, ErrLegacyDistributionUser):
|
||||||
|
response.Error(c, http.StatusForbidden, "legacy_distribution_user", "该手机号属于历史分销渠道,请从原分销站点登录")
|
||||||
default:
|
default:
|
||||||
response.Error(c, http.StatusInternalServerError, "internal_error", "服务暂时不可用")
|
response.Error(c, http.StatusInternalServerError, "internal_error", "服务暂时不可用")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (r *UserRepository) FindByID(ctx context.Context, id uint64) (*model.User,
|
|||||||
var user model.User
|
var user model.User
|
||||||
query := r.db.WithContext(ctx)
|
query := r.db.WithContext(ctx)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
if err := query.First(&user, id).Error; err != nil {
|
if err := query.First(&user, id).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -52,7 +52,7 @@ func (r *UserRepository) FindActiveForToken(ctx context.Context, id uint64, toke
|
|||||||
var user model.User
|
var user model.User
|
||||||
query := r.db.WithContext(ctx)
|
query := r.db.WithContext(ctx)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
if err := query.
|
if err := query.
|
||||||
Select("id, phone, status, token_version").
|
Select("id, phone, status, token_version").
|
||||||
@@ -71,7 +71,7 @@ func (r *UserRepository) FindActiveForToken(ctx context.Context, id uint64, toke
|
|||||||
func (r *UserRepository) UpdateProfile(ctx context.Context, id uint64, nickname string, avatarURL string) (*model.User, error) {
|
func (r *UserRepository) UpdateProfile(ctx context.Context, id uint64, nickname string, avatarURL string) (*model.User, error) {
|
||||||
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", id)
|
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", id)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
if err := query.Updates(map[string]any{
|
if err := query.Updates(map[string]any{
|
||||||
"nickname": nickname,
|
"nickname": nickname,
|
||||||
@@ -98,6 +98,29 @@ func (r *UserRepository) FindOrCreateByPhone(ctx context.Context, phone string,
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
code := sanitizeTrackCode(trackCode)
|
code := sanitizeTrackCode(trackCode)
|
||||||
tenantID := tenancy.IDFromContext(ctx)
|
tenantID := tenancy.IDFromContext(ctx)
|
||||||
|
if tenantID > 0 {
|
||||||
|
var existing model.User
|
||||||
|
query := r.db.WithContext(ctx).
|
||||||
|
Where("tenant_id = ? AND phone = ? AND distribution_site_id = 0", tenantID, phone)
|
||||||
|
if err := query.First(&existing).Error; err == nil {
|
||||||
|
_ = r.db.WithContext(ctx).Model(&existing).Updates(map[string]any{
|
||||||
|
"last_login_at": now,
|
||||||
|
"updated_at": now,
|
||||||
|
}).Error
|
||||||
|
return &existing, nil
|
||||||
|
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var legacyCount int64
|
||||||
|
if err := r.db.WithContext(ctx).Model(&model.User{}).
|
||||||
|
Where("tenant_id = ? AND phone = ? AND distribution_site_id > 0", tenantID, phone).
|
||||||
|
Count(&legacyCount).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if legacyCount > 0 {
|
||||||
|
return nil, ErrLegacyDistributionUser
|
||||||
|
}
|
||||||
|
}
|
||||||
var siteID uint64
|
var siteID uint64
|
||||||
if len(siteCode) > 0 {
|
if len(siteCode) > 0 {
|
||||||
siteID = r.resolveSiteID(ctx, siteCode[0])
|
siteID = r.resolveSiteID(ctx, siteCode[0])
|
||||||
@@ -131,7 +154,7 @@ func (r *UserRepository) FindOrCreateByPhone(ctx context.Context, phone string,
|
|||||||
var found model.User
|
var found model.User
|
||||||
query := r.db.WithContext(ctx).Where("phone = ?", phone)
|
query := r.db.WithContext(ctx).Where("phone = ?", phone)
|
||||||
if tenantID > 0 {
|
if tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
if err := query.First(&found).Error; err != nil {
|
if err := query.First(&found).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -143,9 +166,20 @@ func (r *UserRepository) FindByPhone(ctx context.Context, phone string) (*model.
|
|||||||
var user model.User
|
var user model.User
|
||||||
query := r.db.WithContext(ctx).Where("phone = ?", phone)
|
query := r.db.WithContext(ctx).Where("phone = ?", phone)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
if err := query.First(&user).Error; err != nil {
|
if err := query.First(&user).Error; err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) && tenancy.IDFromContext(ctx) > 0 {
|
||||||
|
var legacyCount int64
|
||||||
|
if countErr := r.db.WithContext(ctx).Model(&model.User{}).
|
||||||
|
Where("tenant_id = ? AND phone = ? AND distribution_site_id > 0", tenancy.IDFromContext(ctx), phone).
|
||||||
|
Count(&legacyCount).Error; countErr != nil {
|
||||||
|
return nil, countErr
|
||||||
|
}
|
||||||
|
if legacyCount > 0 {
|
||||||
|
return nil, ErrLegacyDistributionUser
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &user, nil
|
return &user, nil
|
||||||
@@ -154,7 +188,7 @@ func (r *UserRepository) FindByPhone(ctx context.Context, phone string) (*model.
|
|||||||
func (r *UserRepository) SetPassword(ctx context.Context, userID uint64, hash string) error {
|
func (r *UserRepository) SetPassword(ctx context.Context, userID uint64, hash string) error {
|
||||||
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", userID)
|
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", userID)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
return query.Updates(map[string]any{
|
return query.Updates(map[string]any{
|
||||||
"password_hash": hash,
|
"password_hash": hash,
|
||||||
@@ -166,7 +200,7 @@ func (r *UserRepository) SetPassword(ctx context.Context, userID uint64, hash st
|
|||||||
func (r *UserRepository) RevokeTokens(ctx context.Context, userID uint64) error {
|
func (r *UserRepository) RevokeTokens(ctx context.Context, userID uint64) error {
|
||||||
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", userID)
|
query := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", userID)
|
||||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||||
query = query.Where("tenant_id = ?", tenantID)
|
query = query.Where("tenant_id = ? AND distribution_site_id = 0", tenantID)
|
||||||
}
|
}
|
||||||
return query.UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error
|
return query.UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error
|
||||||
}
|
}
|
||||||
@@ -175,6 +209,17 @@ func (r *UserRepository) RegisterWithPassword(ctx context.Context, phone string,
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
code := sanitizeTrackCode(trackCode)
|
code := sanitizeTrackCode(trackCode)
|
||||||
tenantID := tenancy.IDFromContext(ctx)
|
tenantID := tenancy.IDFromContext(ctx)
|
||||||
|
if tenantID > 0 {
|
||||||
|
var legacyCount int64
|
||||||
|
if err := r.db.WithContext(ctx).Model(&model.User{}).
|
||||||
|
Where("tenant_id = ? AND phone = ? AND distribution_site_id > 0", tenantID, phone).
|
||||||
|
Count(&legacyCount).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if legacyCount > 0 {
|
||||||
|
return nil, ErrLegacyDistributionUser
|
||||||
|
}
|
||||||
|
}
|
||||||
var siteID uint64
|
var siteID uint64
|
||||||
if len(siteCode) > 0 {
|
if len(siteCode) > 0 {
|
||||||
siteID = r.resolveSiteID(ctx, siteCode[0])
|
siteID = r.resolveSiteID(ctx, siteCode[0])
|
||||||
|
|||||||
@@ -22,20 +22,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
||||||
ErrInvalidPhone = errors.New("invalid phone")
|
ErrInvalidPhone = errors.New("invalid phone")
|
||||||
ErrCaptchaInvalid = errors.New("captcha invalid")
|
ErrCaptchaInvalid = errors.New("captcha invalid")
|
||||||
ErrCodeRateLimited = errors.New("sms code rate limited")
|
ErrCodeRateLimited = errors.New("sms code rate limited")
|
||||||
ErrCodeInvalid = errors.New("sms code invalid")
|
ErrCodeInvalid = errors.New("sms code invalid")
|
||||||
ErrSMSSendFailed = errors.New("sms send failed")
|
ErrSMSSendFailed = errors.New("sms send failed")
|
||||||
ErrUserDisabled = errors.New("user disabled")
|
ErrUserDisabled = errors.New("user disabled")
|
||||||
ErrInvalidPassword = errors.New("invalid password")
|
ErrInvalidPassword = errors.New("invalid password")
|
||||||
ErrInvalidOldPassword = errors.New("invalid old password")
|
ErrInvalidOldPassword = errors.New("invalid old password")
|
||||||
ErrPasswordNotSet = errors.New("password not set")
|
ErrPasswordNotSet = errors.New("password not set")
|
||||||
ErrPasswordTooWeak = errors.New("password too weak")
|
ErrPasswordTooWeak = errors.New("password too weak")
|
||||||
ErrLoginLocked = errors.New("login locked")
|
ErrLoginLocked = errors.New("login locked")
|
||||||
ErrUserAlreadyExists = errors.New("user already exists")
|
ErrUserAlreadyExists = errors.New("user already exists")
|
||||||
ErrTokenVersionMismatch = errors.New("user token version mismatch")
|
ErrLegacyDistributionUser = errors.New("user belongs to legacy distribution channel")
|
||||||
|
ErrTokenVersionMismatch = errors.New("user token version mismatch")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/database"
|
"hfb_sys/backend/internal/database"
|
||||||
@@ -85,3 +86,39 @@ func TestTenantUsersRemainSeparateRows(t *testing.T) {
|
|||||||
t.Fatalf("same phone user count = %d, want 2", count)
|
t.Fatalf("same phone user count = %d, want 2", count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLegacyDistributionUserCannotEnterTenantSite(t *testing.T) {
|
||||||
|
db := database.NewTestDB()
|
||||||
|
site := model.DistributionSite{
|
||||||
|
SiteCode: "legacy_auth_scope", SiteName: "历史分销测试站",
|
||||||
|
Domain: "legacy-auth-scope.example.com", Status: "active",
|
||||||
|
}
|
||||||
|
if err := db.Create(&site).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
legacy := model.User{
|
||||||
|
TenantID: 101, Phone: "13600000009", Status: "active",
|
||||||
|
DistributionSiteID: site.ID, TokenVersion: 1,
|
||||||
|
}
|
||||||
|
if err := db.Create(&legacy).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
repo := NewUserRepository(db)
|
||||||
|
ctx := authTenantContext(101)
|
||||||
|
|
||||||
|
if _, err := repo.FindByID(ctx, legacy.ID); err == nil {
|
||||||
|
t.Fatal("tenant site must not load legacy distribution user")
|
||||||
|
}
|
||||||
|
if _, err := repo.FindByPhone(ctx, legacy.Phone); !errors.Is(err, ErrLegacyDistributionUser) {
|
||||||
|
t.Fatalf("legacy phone login error = %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.FindOrCreateByPhone(ctx, legacy.Phone, ""); !errors.Is(err, ErrLegacyDistributionUser) {
|
||||||
|
t.Fatalf("legacy SMS login error = %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.RegisterWithPassword(ctx, legacy.Phone, "hash", ""); !errors.Is(err, ErrLegacyDistributionUser) {
|
||||||
|
t.Fatalf("legacy registration error = %v", err)
|
||||||
|
}
|
||||||
|
if _, err := repo.FindByPhone(context.Background(), legacy.Phone); err != nil {
|
||||||
|
t.Fatalf("legacy distribution domain login failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -416,6 +416,7 @@ func appendPlatformManagedAdminNotification(tx *gorm.DB, order model.RentalOrder
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return adminnotification.Append(tx, adminnotification.Entry{
|
return adminnotification.Append(tx, adminnotification.Entry{
|
||||||
|
TenantID: order.BuyerTenantID,
|
||||||
AdminUserID: *order.ManagedAdminID,
|
AdminUserID: *order.ManagedAdminID,
|
||||||
Type: typ,
|
Type: typ,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
|||||||
@@ -14,24 +14,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
service *Service
|
service *Service
|
||||||
storage *Storage
|
storage *Storage
|
||||||
objectAuthorizer ObjectAuthorizer
|
objectAuthorizer ObjectAuthorizer
|
||||||
uploadOwnerRecorder UploadOwnerRecorder
|
adminObjectAuthorizer AdminObjectAuthorizer
|
||||||
|
uploadOwnerRecorder UploadOwnerRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectAuthorizer 校验用户是否可读取指定私有对象。
|
// ObjectAuthorizer 校验用户是否可读取指定私有对象。
|
||||||
type ObjectAuthorizer func(ctx context.Context, userID uint64, key string) (bool, error)
|
type ObjectAuthorizer func(ctx context.Context, userID uint64, key string) (bool, error)
|
||||||
|
|
||||||
|
// AdminObjectAuthorizer 校验管理员是否可在当前经营站点读取指定私有对象。
|
||||||
|
type AdminObjectAuthorizer func(ctx context.Context, adminID uint64, key string) (bool, error)
|
||||||
|
|
||||||
// UploadOwnerRecorder 保存用户上传私有文件的归属。
|
// UploadOwnerRecorder 保存用户上传私有文件的归属。
|
||||||
type UploadOwnerRecorder func(ctx context.Context, userID uint64, objectKeys []string) error
|
type UploadOwnerRecorder func(ctx context.Context, userID uint64, objectKeys []string) error
|
||||||
|
|
||||||
func NewHandler(service *Service, storage *Storage, objectAuthorizer ObjectAuthorizer, uploadOwnerRecorder UploadOwnerRecorder) *Handler {
|
func NewHandler(service *Service, storage *Storage, objectAuthorizer ObjectAuthorizer, uploadOwnerRecorder UploadOwnerRecorder, adminObjectAuthorizers ...AdminObjectAuthorizer) *Handler {
|
||||||
|
var adminObjectAuthorizer AdminObjectAuthorizer
|
||||||
|
if len(adminObjectAuthorizers) > 0 {
|
||||||
|
adminObjectAuthorizer = adminObjectAuthorizers[0]
|
||||||
|
}
|
||||||
return &Handler{
|
return &Handler{
|
||||||
service: service,
|
service: service,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
objectAuthorizer: objectAuthorizer,
|
objectAuthorizer: objectAuthorizer,
|
||||||
uploadOwnerRecorder: uploadOwnerRecorder,
|
adminObjectAuthorizer: adminObjectAuthorizer,
|
||||||
|
uploadOwnerRecorder: uploadOwnerRecorder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +108,22 @@ func (h *Handler) writeObject(c *gin.Context, publicOnly bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !publicOnly {
|
if !publicOnly {
|
||||||
if _, isAdmin := c.Get("admin_id"); !isAdmin {
|
if adminIDValue, isAdmin := c.Get("admin_id"); isAdmin {
|
||||||
|
adminID, ok := adminIDValue.(uint64)
|
||||||
|
if !ok || h.adminObjectAuthorizer == nil {
|
||||||
|
response.Error(c, http.StatusForbidden, "forbidden", "无权访问该文件")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
allowed, err := h.adminObjectAuthorizer(c.Request.Context(), adminID, key)
|
||||||
|
if err != nil {
|
||||||
|
response.ServiceUnavailable(c, "文件权限校验失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !allowed {
|
||||||
|
response.Error(c, http.StatusForbidden, "forbidden", "无权访问该文件")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
userID, ok := c.Get("user_id")
|
userID, ok := c.Get("user_id")
|
||||||
if !ok {
|
if !ok {
|
||||||
response.Unauthorized(c, "缺少用户上下文")
|
response.Unauthorized(c, "缺少用户上下文")
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ func Append(tx *gorm.DB, entries ...Entry) error {
|
|||||||
} else if entry.BizType == "dispute" && entry.BizID != nil && *entry.BizID > 0 {
|
} else if entry.BizType == "dispute" && entry.BizID != nil && *entry.BizID > 0 {
|
||||||
var orderSiteID *uint64
|
var orderSiteID *uint64
|
||||||
var mode string
|
var mode string
|
||||||
row := tx.Table("order_disputes d").Joins("JOIN rental_orders o ON o.id = d.order_id").Where("d.id = ?", *entry.BizID).Select("o.distribution_site_id, o.distribution_mode").Row()
|
row := tx.Table("disputes d").Joins("JOIN rental_orders o ON o.id = d.order_id").Where("d.id = ?", *entry.BizID).Select("o.distribution_site_id, o.distribution_mode").Row()
|
||||||
if err := row.Scan(&orderSiteID, &mode); err == nil && orderSiteID != nil && mode != "two_party_distributor_receive" {
|
if err := row.Scan(&orderSiteID, &mode); err == nil && orderSiteID != nil && mode != "two_party_distributor_receive" {
|
||||||
siteID = orderSiteID
|
siteID = orderSiteID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,6 +191,27 @@ func TestNotificationTenantIsolation(t *testing.T) {
|
|||||||
if autoNotif.DistributionSiteID == nil || *autoNotif.DistributionSiteID != siteID {
|
if autoNotif.DistributionSiteID == nil || *autoNotif.DistributionSiteID != siteID {
|
||||||
t.Fatalf("autoNotif.DistributionSiteID = %v, want %d", autoNotif.DistributionSiteID, siteID)
|
t.Fatalf("autoNotif.DistributionSiteID = %v, want %d", autoNotif.DistributionSiteID, siteID)
|
||||||
}
|
}
|
||||||
|
dispute := model.Dispute{
|
||||||
|
OrderID: orderID, InitiatorID: 20, InitiatorType: "user",
|
||||||
|
TargetUserID: 21, Type: "cannot_login", Status: "open",
|
||||||
|
}
|
||||||
|
if err := db.Create(&dispute).Error; err != nil {
|
||||||
|
t.Fatalf("create dispute error: %v", err)
|
||||||
|
}
|
||||||
|
disputeID := dispute.ID
|
||||||
|
if err := Append(db, Entry{
|
||||||
|
UserID: 20, Type: "dispute", Title: "申诉自动关联分站", Content: "自动读取申诉订单站点",
|
||||||
|
BizType: "dispute", BizID: &disputeID,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("Append dispute auto lookup error: %v", err)
|
||||||
|
}
|
||||||
|
var disputeNotif model.Notification
|
||||||
|
if err := db.Where("biz_id = ? AND biz_type = 'dispute'", disputeID).First(&disputeNotif).Error; err != nil {
|
||||||
|
t.Fatalf("find dispute notification error: %v", err)
|
||||||
|
}
|
||||||
|
if disputeNotif.DistributionSiteID == nil || *disputeNotif.DistributionSiteID != siteID {
|
||||||
|
t.Fatalf("dispute notification site = %v, want %d", disputeNotif.DistributionSiteID, siteID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotificationTenantScopeAndAppendDerivation(t *testing.T) {
|
func TestNotificationTenantScopeAndAppendDerivation(t *testing.T) {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ func appendManagedAdminNotification(tx *gorm.DB, order model.RentalOrder, typ st
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return adminnotification.Append(tx, adminnotification.Entry{
|
return adminnotification.Append(tx, adminnotification.Entry{
|
||||||
|
TenantID: order.BuyerTenantID,
|
||||||
AdminUserID: adminID,
|
AdminUserID: adminID,
|
||||||
Type: typ,
|
Type: typ,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
|||||||
@@ -135,6 +135,92 @@ WHERE w.user_id = ?
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adminPrivateFileAuthorizer 将经营站点后台的私有文件访问限制在当前租户。
|
||||||
|
// 历史分销后台(tenant_id=0)保留原有平台级访问语义。
|
||||||
|
func adminPrivateFileAuthorizer(db *gorm.DB) func(context.Context, uint64, string) (bool, error) {
|
||||||
|
return func(ctx context.Context, _ uint64, key string) (bool, error) {
|
||||||
|
if db == nil || key == "" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
encodedKey := url.QueryEscape(key)
|
||||||
|
basePrefix := strings.TrimSuffix(strings.TrimSuffix(key, ".medium.jpg"), ".thumb.jpg")
|
||||||
|
encodedBasePrefix := url.QueryEscape(basePrefix)
|
||||||
|
tenantID := tenancy.IDFromContext(ctx)
|
||||||
|
|
||||||
|
queries := []struct {
|
||||||
|
sql string
|
||||||
|
args []any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
sql: "SELECT COUNT(1) FROM file_upload_owners WHERE object_key = ? AND (? = 0 OR tenant_id = ?)",
|
||||||
|
args: []any{key, tenantID, tenantID},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM game_accounts a
|
||||||
|
JOIN rental_listings l ON l.account_id = a.id
|
||||||
|
WHERE (? = 0 OR (l.source_tenant_id = ? AND (l.distribution_site_id IS NULL OR l.distribution_site_id = 0)))
|
||||||
|
AND (INSTR(a.screenshot_urls, ?) > 0 OR INSTR(a.screenshot_urls, ?) > 0 OR INSTR(a.screenshot_urls, ?) > 0 OR INSTR(a.screenshot_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM order_checkouts c
|
||||||
|
JOIN rental_orders o ON o.id = c.order_id
|
||||||
|
WHERE (? = 0 OR (o.buyer_tenant_id = ? AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||||
|
AND (INSTR(c.evidence_urls, ?) > 0 OR INSTR(c.evidence_urls, ?) > 0 OR INSTR(c.evidence_urls, ?) > 0 OR INSTR(c.evidence_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM disputes d
|
||||||
|
JOIN rental_orders o ON o.id = d.order_id
|
||||||
|
WHERE (? = 0 OR (o.buyer_tenant_id = ? AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||||
|
AND (INSTR(d.evidence_urls, ?) > 0 OR INSTR(d.evidence_urls, ?) > 0 OR INSTR(d.evidence_urls, ?) > 0 OR INSTR(d.evidence_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM handoff_records h
|
||||||
|
JOIN rental_orders o ON o.id = h.order_id
|
||||||
|
WHERE (? = 0 OR ((o.buyer_tenant_id = ? OR o.source_tenant_id = ?)
|
||||||
|
AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||||
|
AND (INSTR(h.attachment_urls, ?) > 0 OR INSTR(h.attachment_urls, ?) > 0 OR INSTR(h.attachment_urls, ?) > 0 OR INSTR(h.attachment_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM chat_messages m
|
||||||
|
JOIN chat_conversations c ON c.id = m.conversation_id
|
||||||
|
WHERE (? = 0 OR c.tenant_id = ?)
|
||||||
|
AND (INSTR(m.attachment_urls, ?) > 0 OR INSTR(m.attachment_urls, ?) > 0 OR INSTR(m.attachment_urls, ?) > 0 OR INSTR(m.attachment_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM user_payment_accounts p
|
||||||
|
JOIN users u ON u.id = p.user_id
|
||||||
|
WHERE (? = 0 OR (p.tenant_id = ? AND u.tenant_id = ? AND u.distribution_site_id = 0))
|
||||||
|
AND (INSTR(p.certificate_urls, ?) > 0 OR INSTR(p.certificate_urls, ?) > 0 OR INSTR(p.certificate_urls, ?) > 0 OR INSTR(p.certificate_urls, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT COUNT(1) FROM withdrawal_requests w
|
||||||
|
WHERE (? = 0 OR (w.tenant_id = ? AND w.distribution_site_id = 0))
|
||||||
|
AND (INSTR(w.payment_proof_url, ?) > 0 OR INSTR(w.payment_proof_url, ?) > 0 OR INSTR(w.payment_proof_url, ?) > 0 OR INSTR(w.payment_proof_url, ?) > 0)`,
|
||||||
|
args: []any{tenantID, tenantID, key, encodedKey, basePrefix, encodedBasePrefix},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, query := range queries {
|
||||||
|
var count int64
|
||||||
|
if err := db.WithContext(ctx).Raw(query.sql, query.args...).Scan(&count).Error; err != nil {
|
||||||
|
if strings.Contains(strings.ToLower(err.Error()), "doesn't exist") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// recordPrivateFileUpload 记录用户上传的原图和变体,保证草稿状态下也仅上传者可预览。
|
// recordPrivateFileUpload 记录用户上传的原图和变体,保证草稿状态下也仅上传者可预览。
|
||||||
func recordPrivateFileUpload(db *gorm.DB) func(context.Context, uint64, []string) error {
|
func recordPrivateFileUpload(db *gorm.DB) func(context.Context, uint64, []string) error {
|
||||||
return func(ctx context.Context, userID uint64, objectKeys []string) error {
|
return func(ctx context.Context, userID uint64, objectKeys []string) error {
|
||||||
|
|||||||
@@ -130,6 +130,38 @@ func TestPrivateFileAuthorizerRejectsCrossTenantOwner(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAdminPrivateFileAuthorizerScopesOperatingTenant(t *testing.T) {
|
||||||
|
db := openAuthorizerTestDB(t)
|
||||||
|
if err := database.AutoMigrateIfMissing(db, &model.FileUploadOwner{}); err != nil {
|
||||||
|
t.Fatalf("AutoMigrate() error = %v", err)
|
||||||
|
}
|
||||||
|
rows := []model.FileUploadOwner{
|
||||||
|
{TenantID: 101, UserID: 11, ObjectKey: "listing/admin-tenant-a.jpg"},
|
||||||
|
{TenantID: 202, UserID: 12, ObjectKey: "listing/admin-tenant-b.jpg"},
|
||||||
|
}
|
||||||
|
if err := db.Create(&rows).Error; err != nil {
|
||||||
|
t.Fatalf("create upload owners: %v", err)
|
||||||
|
}
|
||||||
|
authorize := adminPrivateFileAuthorizer(db)
|
||||||
|
ctxA := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||||
|
ctxB := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 202})
|
||||||
|
|
||||||
|
if allowed, err := authorize(ctxA, 1, "listing/admin-tenant-a.jpg"); err != nil || !allowed {
|
||||||
|
t.Fatalf("tenant A own file allowed=%v err=%v", allowed, err)
|
||||||
|
}
|
||||||
|
if allowed, err := authorize(ctxA, 1, "listing/admin-tenant-b.jpg"); err != nil {
|
||||||
|
t.Fatalf("tenant A cross file error=%v", err)
|
||||||
|
} else if allowed {
|
||||||
|
t.Fatal("tenant A must not read tenant B file")
|
||||||
|
}
|
||||||
|
if allowed, err := authorize(ctxB, 2, "listing/admin-tenant-b.jpg"); err != nil || !allowed {
|
||||||
|
t.Fatalf("tenant B own file allowed=%v err=%v", allowed, err)
|
||||||
|
}
|
||||||
|
if allowed, err := authorize(context.Background(), 3, "listing/admin-tenant-a.jpg"); err != nil || !allowed {
|
||||||
|
t.Fatalf("legacy admin file allowed=%v err=%v", allowed, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func openAuthorizerTestDB(t *testing.T) *gorm.DB {
|
func openAuthorizerTestDB(t *testing.T) *gorm.DB {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
db := database.NewTestDB()
|
db := database.NewTestDB()
|
||||||
|
|||||||
@@ -426,7 +426,13 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileService := filemodule.NewService(fileStorage)
|
fileService := filemodule.NewService(fileStorage)
|
||||||
fileHandler := filemodule.NewHandler(fileService, fileStorage, privateFileAuthorizer(deps.DB), recordPrivateFileUpload(deps.DB))
|
fileHandler := filemodule.NewHandler(
|
||||||
|
fileService,
|
||||||
|
fileStorage,
|
||||||
|
privateFileAuthorizer(deps.DB),
|
||||||
|
recordPrivateFileUpload(deps.DB),
|
||||||
|
adminPrivateFileAuthorizer(deps.DB),
|
||||||
|
)
|
||||||
listingService := listing.NewService(listingRepo, systemConfigRepo)
|
listingService := listing.NewService(listingRepo, systemConfigRepo)
|
||||||
listingHandler := listing.NewHandler(listingService, fileStorage, listing.HandlerOptions{
|
listingHandler := listing.NewHandler(listingService, fileStorage, listing.HandlerOptions{
|
||||||
ExternalUploadSecret: cfg.ExternalUploadSecret,
|
ExternalUploadSecret: cfg.ExternalUploadSecret,
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
-- +goose Up
|
||||||
|
|
||||||
|
ALTER TABLE audit_logs
|
||||||
|
ADD COLUMN tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
|
||||||
|
ADD KEY idx_audit_logs_tenant_created (tenant_id, created_at);
|
||||||
|
|
||||||
|
-- 仅当管理员只属于一个经营租户时才能安全回填;跨租户管理员的历史操作保持 platform=0。
|
||||||
|
UPDATE audit_logs al
|
||||||
|
JOIN (
|
||||||
|
SELECT admin_user_id, MIN(tenant_id) AS tenant_id, COUNT(DISTINCT tenant_id) AS tenant_count
|
||||||
|
FROM admin_user_roles
|
||||||
|
WHERE tenant_id > 0
|
||||||
|
GROUP BY admin_user_id
|
||||||
|
) roles ON roles.admin_user_id = al.actor_id
|
||||||
|
SET al.tenant_id = roles.tenant_id
|
||||||
|
WHERE al.actor_type = 'admin' AND roles.tenant_count = 1;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
|
||||||
|
ALTER TABLE audit_logs
|
||||||
|
DROP KEY idx_audit_logs_tenant_created,
|
||||||
|
DROP COLUMN tenant_id;
|
||||||
@@ -147,6 +147,7 @@ source_amount_cent
|
|||||||
## 6. 用户、后台和权限
|
## 6. 用户、后台和权限
|
||||||
|
|
||||||
- 同一手机号可以在两个租户分别注册。
|
- 同一手机号可以在两个租户分别注册。
|
||||||
|
- 历史分销用户只能从原分销域名登录,不进入经营站点用户体系。
|
||||||
- JWT 必须包含 `tenant_id` 和 `scope`。
|
- JWT 必须包含 `tenant_id` 和 `scope`。
|
||||||
- 用户令牌只能访问令牌所属经营租户。
|
- 用户令牌只能访问令牌所属经营租户。
|
||||||
- 短信验证码、登录失败、限流、实名和钱包 Key 都带租户。
|
- 短信验证码、登录失败、限流、实名和钱包 Key 都带租户。
|
||||||
@@ -261,6 +262,7 @@ A 站商品进入 B 站货架
|
|||||||
- 二维码池增加 `tenant_id`,订单会话使用买方租户二维码。
|
- 二维码池增加 `tenant_id`,订单会话使用买方租户二维码。
|
||||||
- 通知、短信、未读统计和消息缓存按租户隔离。
|
- 通知、短信、未读统计和消息缓存按租户隔离。
|
||||||
- 私有文件上传和读取校验租户及业务角色。
|
- 私有文件上传和读取校验租户及业务角色。
|
||||||
|
- 经营站点管理员读取私有文件时同样校验当前租户,不允许按对象 key 越站读取。
|
||||||
- 定时任务从订单、支付、会话等业务记录恢复租户,无法解析时暂停并告警。
|
- 定时任务从订单、支付、会话等业务记录恢复租户,无法解析时暂停并告警。
|
||||||
|
|
||||||
首期不做客户会话、货源会话、内部案件的复杂拆分。
|
首期不做客户会话、货源会话、内部案件的复杂拆分。
|
||||||
@@ -273,6 +275,7 @@ A 站商品进入 B 站货架
|
|||||||
- 新经营租户订单不写分销财务快照。
|
- 新经营租户订单不写分销财务快照。
|
||||||
- 历史分销订单不根据 `distribution_site_id` 猜测经营租户。
|
- 历史分销订单不根据 `distribution_site_id` 猜测经营租户。
|
||||||
- 经营站点后台、统计和公开货架默认排除 `distribution_site_id > 0` 的历史分销数据。
|
- 经营站点后台、统计和公开货架默认排除 `distribution_site_id > 0` 的历史分销数据。
|
||||||
|
- 经营站点审计日志、公告和管理员通知均显式记录所属经营租户。
|
||||||
- 现有分销 E2E 测试必须全部保持通过。
|
- 现有分销 E2E 测试必须全部保持通过。
|
||||||
|
|
||||||
## 13. 实施阶段
|
## 13. 实施阶段
|
||||||
@@ -363,6 +366,7 @@ A 站商品进入 B 站货架
|
|||||||
- 退款只使用原支付租户和原商户。
|
- 退款只使用原支付租户和原商户。
|
||||||
- 两个站点的用户、订单、支付、钱包和统计互不串数据。
|
- 两个站点的用户、订单、支付、钱包和统计互不串数据。
|
||||||
- 用户管理、申诉仲裁和钱包调账不能跨经营租户操作。
|
- 用户管理、申诉仲裁和钱包调账不能跨经营租户操作。
|
||||||
|
- 审计日志、公告、管理员通知和私有文件访问不能跨经营租户。
|
||||||
- 出货站不能关闭或封存买方已支付订单;退款只能由买方租户发起。
|
- 出货站不能关闭或封存买方已支付订单;退款只能由买方租户发起。
|
||||||
- 历史分销用户、订单、钱包和提现不会进入经营站点后台及统计。
|
- 历史分销用户、订单、钱包和提现不会进入经营站点后台及统计。
|
||||||
- 每个经营站点可以在商品详情中独立设置本站售价和展示状态。
|
- 每个经营站点可以在商品详情中独立设置本站售价和展示状态。
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
import { uploadAdminFile } from '@/shared/api/files'
|
import { uploadAdminFile } from '@/shared/api/files'
|
||||||
import { debugError } from '@/shared/utils/debug'
|
import { debugError } from '@/shared/utils/debug'
|
||||||
import { readError } from '@/shared/utils/error'
|
import { readError } from '@/shared/utils/error'
|
||||||
|
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
@@ -30,6 +31,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
const siteStore = useDistributionSiteStore()
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:visible': [value: boolean]
|
'update:visible': [value: boolean]
|
||||||
save: [data: CreateAnnouncementRequest | UpdateAnnouncementRequest]
|
save: [data: CreateAnnouncementRequest | UpdateAnnouncementRequest]
|
||||||
@@ -112,7 +114,7 @@ watch(
|
|||||||
if (val) {
|
if (val) {
|
||||||
if (props.mode === 'edit' && props.announcement) {
|
if (props.mode === 'edit' && props.announcement) {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
distribution_site_id: props.announcement.distribution_site_id,
|
distribution_site_id: siteStore.isTenant ? 0 : props.announcement.distribution_site_id,
|
||||||
title: props.announcement.title,
|
title: props.announcement.title,
|
||||||
content: props.announcement.content,
|
content: props.announcement.content,
|
||||||
category: props.announcement.category as any,
|
category: props.announcement.category as any,
|
||||||
@@ -133,7 +135,7 @@ watch(
|
|||||||
is_popup: false,
|
is_popup: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void loadDistributionSites()
|
if (!siteStore.isTenant) void loadDistributionSites()
|
||||||
formRef.value?.clearValidate()
|
formRef.value?.clearValidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,7 +311,7 @@ function escapeMarkdownImageText(text: string) {
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog :model-value="visible" :title="dialogTitle" width="800px" @close="handleClose">
|
<el-dialog :model-value="visible" :title="dialogTitle" width="800px" @close="handleClose">
|
||||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
|
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
|
||||||
<el-form-item label="归属站点">
|
<el-form-item v-if="!siteStore.isTenant" label="归属站点">
|
||||||
<el-select
|
<el-select
|
||||||
v-if="mode === 'create'"
|
v-if="mode === 'create'"
|
||||||
v-model="formData.distribution_site_id"
|
v-model="formData.distribution_site_id"
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ import {
|
|||||||
} from '@/features/admin/api/adminDistribution'
|
} from '@/features/admin/api/adminDistribution'
|
||||||
import type { Announcement } from '@/features/announcement'
|
import type { Announcement } from '@/features/announcement'
|
||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
|
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||||
import AnnouncementDialog from '../components/AnnouncementDialog.vue'
|
import AnnouncementDialog from '../components/AnnouncementDialog.vue'
|
||||||
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const siteStore = useDistributionSiteStore()
|
||||||
const announcements = ref<Announcement[]>([])
|
const announcements = ref<Announcement[]>([])
|
||||||
const currentPage = ref(1)
|
const currentPage = ref(1)
|
||||||
const currentPageSize = ref(20)
|
const currentPageSize = ref(20)
|
||||||
@@ -62,7 +64,7 @@ const statusOptions = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void loadDistributionSites()
|
if (!siteStore.isTenant) void loadDistributionSites()
|
||||||
void loadAnnouncements()
|
void loadAnnouncements()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ async function loadAnnouncements() {
|
|||||||
const result = await fetchAdminAnnouncements({
|
const result = await fetchAdminAnnouncements({
|
||||||
status: statusFilter.value || undefined,
|
status: statusFilter.value || undefined,
|
||||||
category: categoryFilter.value || undefined,
|
category: categoryFilter.value || undefined,
|
||||||
site_id: siteFilter.value === '' ? undefined : Number(siteFilter.value),
|
site_id: siteStore.isTenant || siteFilter.value === '' ? undefined : Number(siteFilter.value),
|
||||||
page: currentPage.value,
|
page: currentPage.value,
|
||||||
page_size: currentPageSize.value,
|
page_size: currentPageSize.value,
|
||||||
})
|
})
|
||||||
@@ -247,6 +249,7 @@ function getStatusType(status: string): '' | 'success' | 'info' | 'warning' {
|
|||||||
|
|
||||||
<div class="filter-bar">
|
<div class="filter-bar">
|
||||||
<el-select
|
<el-select
|
||||||
|
v-if="!siteStore.isTenant"
|
||||||
v-model="siteFilter"
|
v-model="siteFilter"
|
||||||
placeholder="筛选站点"
|
placeholder="筛选站点"
|
||||||
clearable
|
clearable
|
||||||
@@ -315,7 +318,7 @@ function getStatusType(status: string): '' | 'success' | 'info' | 'warning' {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="站点" width="150">
|
<el-table-column v-if="!siteStore.isTenant" label="站点" width="150">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag v-if="row.distribution_site_id" type="success" effect="plain" size="small">
|
<el-tag v-if="row.distribution_site_id" type="success" effect="plain" size="small">
|
||||||
{{ siteLabel(row) }}
|
{{ siteLabel(row) }}
|
||||||
|
|||||||
@@ -312,6 +312,22 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu-item-scope {
|
||||||
|
flex: none;
|
||||||
|
margin-left: auto;
|
||||||
|
padding: 0 5px;
|
||||||
|
border: 1px solid #64748b;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-size: 10px;
|
||||||
|
font-style: normal;
|
||||||
|
line-height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-menu--collapse .menu-item-scope) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
:deep(.el-menu--collapse .menu-item-badge) {
|
:deep(.el-menu--collapse .menu-item-badge) {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 6px;
|
top: 6px;
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ interface NavItem {
|
|||||||
to: string
|
to: string
|
||||||
icon: Component
|
icon: Component
|
||||||
permission?: string
|
permission?: string
|
||||||
|
shared?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavGroup {
|
interface NavGroup {
|
||||||
@@ -107,6 +108,7 @@ const allNavGroups: NavGroup[] = [
|
|||||||
to: adminPath('points-mall'),
|
to: adminPath('points-mall'),
|
||||||
icon: Present,
|
icon: Present,
|
||||||
permission: 'points_mall:view',
|
permission: 'points_mall:view',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
{ label: '订单管理', to: adminPath('orders'), icon: Tickets, permission: 'order:view' },
|
{ label: '订单管理', to: adminPath('orders'), icon: Tickets, permission: 'order:view' },
|
||||||
{
|
{
|
||||||
@@ -120,6 +122,7 @@ const allNavGroups: NavGroup[] = [
|
|||||||
to: adminPath('pickup'),
|
to: adminPath('pickup'),
|
||||||
icon: Switch,
|
icon: Switch,
|
||||||
permission: 'order:pickup',
|
permission: 'order:pickup',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
{ label: '商品管理', to: adminPath('listings'), icon: Shop, permission: 'listing:view' },
|
{ label: '商品管理', to: adminPath('listings'), icon: Shop, permission: 'listing:view' },
|
||||||
{
|
{
|
||||||
@@ -133,24 +136,28 @@ const allNavGroups: NavGroup[] = [
|
|||||||
to: adminPath('crash/categories'),
|
to: adminPath('crash/categories'),
|
||||||
icon: Present,
|
icon: Present,
|
||||||
permission: 'mohong:category',
|
permission: 'mohong:category',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '撞车商品',
|
label: '撞车商品',
|
||||||
to: adminPath('crash/products'),
|
to: adminPath('crash/products'),
|
||||||
icon: Present,
|
icon: Present,
|
||||||
permission: 'mohong:product_view',
|
permission: 'mohong:product_view',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '撞车订单',
|
label: '撞车订单',
|
||||||
to: adminPath('crash/orders'),
|
to: adminPath('crash/orders'),
|
||||||
icon: Tickets,
|
icon: Tickets,
|
||||||
permission: 'mohong:order_view',
|
permission: 'mohong:order_view',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '撞车配置',
|
label: '撞车配置',
|
||||||
to: adminPath('crash/config'),
|
to: adminPath('crash/config'),
|
||||||
icon: Setting,
|
icon: Setting,
|
||||||
permission: 'mohong:config',
|
permission: 'mohong:config',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -238,6 +245,7 @@ const allNavGroups: NavGroup[] = [
|
|||||||
to: adminPath('manual-entries'),
|
to: adminPath('manual-entries'),
|
||||||
icon: EditPen,
|
icon: EditPen,
|
||||||
permission: 'cs_manual_entry:view',
|
permission: 'cs_manual_entry:view',
|
||||||
|
shared: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -567,6 +575,7 @@ async function handleForcedPasswordChange() {
|
|||||||
<el-icon><component :is="item.icon" /></el-icon>
|
<el-icon><component :is="item.icon" /></el-icon>
|
||||||
<template #title>
|
<template #title>
|
||||||
<span class="menu-item-label">{{ item.label }}</span>
|
<span class="menu-item-label">{{ item.label }}</span>
|
||||||
|
<em v-if="siteStore.isTenant && item.shared" class="menu-item-scope">共享</em>
|
||||||
<em
|
<em
|
||||||
v-if="item.to === refundReviewPath && pendingRefundCount > 0"
|
v-if="item.to === refundReviewPath && pendingRefundCount > 0"
|
||||||
class="menu-item-badge"
|
class="menu-item-badge"
|
||||||
|
|||||||
Reference in New Issue
Block a user