完善角色权限与数据隔离
This commit is contained in:
@@ -21,7 +21,7 @@ func (h *CustomerHandler) Export(c *gin.Context) {
|
||||
source := c.Query("source")
|
||||
|
||||
query := model.DB.Where("tenant_id = ?", tenantID)
|
||||
if middleware.GetRole(c) == "agent" {
|
||||
if !middleware.CanAccessAllData(c, "chat_history") {
|
||||
assignedCustomers := model.DB.Model(&model.Session{}).
|
||||
Select("customer_id").
|
||||
Where("tenant_id = ? AND agent_id = ?", tenantID, middleware.GetUserID(c))
|
||||
@@ -76,7 +76,7 @@ func (h *SessionHandler) Export(c *gin.Context) {
|
||||
to := c.Query("to")
|
||||
|
||||
query := model.DB.Model(&model.Session{}).Where("sessions.tenant_id = ?", tenantID)
|
||||
if middleware.GetRole(c) == "agent" {
|
||||
if !middleware.CanAccessAllData(c, "customer") {
|
||||
query = query.Where("sessions.agent_id = ? OR sessions.status = ?", middleware.GetUserID(c), "waiting")
|
||||
}
|
||||
if status != "" {
|
||||
@@ -253,7 +253,8 @@ func (h *StatisticsHandler) Export(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
tenantID := middleware.GetTenantID(c)
|
||||
sessions, messages, err := loadStatisticsData(tenantID, r)
|
||||
allData := middleware.CanAccessAllData(c, "statistics")
|
||||
sessions, messages, err := loadStatisticsData(tenantID, middleware.GetUserID(c), allData, r)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "导出统计失败"})
|
||||
return
|
||||
@@ -282,7 +283,11 @@ func (h *StatisticsHandler) Export(c *gin.Context) {
|
||||
|
||||
// 坐席绩效
|
||||
var agents []model.User
|
||||
model.DB.Where("tenant_id = ? AND role = ?", tenantID, "agent").Find(&agents)
|
||||
agentQuery := model.DB.Where("tenant_id = ?", tenantID)
|
||||
if !allData {
|
||||
agentQuery = agentQuery.Where("id = ?", middleware.GetUserID(c))
|
||||
}
|
||||
agentQuery.Find(&agents)
|
||||
type perf struct {
|
||||
Name string
|
||||
Conversations int
|
||||
|
||||
Reference in New Issue
Block a user