fix: one can edit team's memory (#17104)

### Summary

As title
This commit is contained in:
Haruko386
2026-07-20 19:19:06 +08:00
committed by GitHub
parent 0cd06e4013
commit da2b1ce6d6
2 changed files with 32 additions and 0 deletions
+29
View File
@@ -378,3 +378,32 @@ func (dao *MemoryDAO) GetByFilter(userID string, tenantIDs []string, memoryTypes
return memories, total, nil
}
// Accessible check if it is possible for user to access the memory
func (dao *MemoryDAO) Accessible(userID, memoryID string) (bool, error) {
memory, err := dao.GetByID(memoryID)
if err != nil {
return false, err
}
if memory.TenantID == userID {
return true, nil
}
if memory.Permissions != string(entity.TenantPermissionTeam) {
return false, fmt.Errorf("user %s have no access to this memory", userID)
}
var count int64
err = DB.Table("user_tenant").
Where("tenant_id = ? AND user_id = ? AND status = ?", memory.TenantID, userID, "1").
Count(&count).Error
if err != nil {
return false, err
}
if count > 0 {
return true, nil
}
return false, fmt.Errorf("user %s have no access to this memory", userID)
}