完善角色权限与数据隔离
This commit is contained in:
@@ -131,6 +131,10 @@ func durationLabel(duration string) string {
|
||||
|
||||
// Create 创建黑名单(支持从会话拉黑 IP 或设备)。
|
||||
func (h *BlacklistHandler) Create(c *gin.Context) {
|
||||
if !middleware.HasPermission(c, "blacklist.create") {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": 403, "message": "仅主管或管理员可管理黑名单"})
|
||||
return
|
||||
}
|
||||
tenantID := middleware.GetTenantID(c)
|
||||
var req CreateBlacklistReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -163,13 +167,6 @@ func (h *BlacklistHandler) Create(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
// 管理员/主管,或当前接待坐席可拉黑
|
||||
if !isTenantManager(c) {
|
||||
if s.AgentID == nil || *s.AgentID != middleware.GetUserID(c) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": 403, "message": "仅接待坐席或管理员可拉黑该访客"})
|
||||
return
|
||||
}
|
||||
}
|
||||
session = s
|
||||
sid := s.ID
|
||||
sessionID = &sid
|
||||
@@ -305,6 +302,10 @@ func maskBlacklistValue(kind, value string) string {
|
||||
|
||||
// List 黑名单列表(有效 + 可选含已过期)。
|
||||
func (h *BlacklistHandler) List(c *gin.Context) {
|
||||
if !middleware.HasPermission(c, "blacklist.view") {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": 403, "message": "仅主管或管理员可查看黑名单"})
|
||||
return
|
||||
}
|
||||
tenantID := middleware.GetTenantID(c)
|
||||
q := model.DB.Where("tenant_id = ?", tenantID)
|
||||
if c.Query("active") != "0" {
|
||||
@@ -323,6 +324,10 @@ func (h *BlacklistHandler) List(c *gin.Context) {
|
||||
|
||||
// Delete 解除黑名单。
|
||||
func (h *BlacklistHandler) Delete(c *gin.Context) {
|
||||
if !middleware.HasPermission(c, "blacklist.delete") {
|
||||
c.JSON(http.StatusForbidden, gin.H{"code": 403, "message": "仅主管或管理员可解除黑名单"})
|
||||
return
|
||||
}
|
||||
tenantID := middleware.GetTenantID(c)
|
||||
id := c.Param("id")
|
||||
var entry model.BlacklistEntry
|
||||
|
||||
Reference in New Issue
Block a user