mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 12:44:22 +00:00
feat(clients): enforce unique subId per client like email
Reject creating or editing a client with a subId already owned by a different client, mirroring the email-uniqueness checks against client_records in Create and Update (BulkCreate inherits via Create). The old multi-inbound model duplicated a client across inbounds sharing one subId, so this check was dropped; the first-class multi-client model makes per-client subId uniqueness correct again. Existing duplicates are left untouched; only new/edited duplicates are blocked.
This commit is contained in:
parent
d2058f07dd
commit
88a3677318
1 changed files with 24 additions and 0 deletions
|
|
@ -475,6 +475,18 @@ func (s *ClientService) Create(inboundSvc *InboundService, payload *ClientCreate
|
|||
}
|
||||
}
|
||||
|
||||
if client.SubID != "" {
|
||||
var subTaken int64
|
||||
if err := database.GetDB().Model(&model.ClientRecord{}).
|
||||
Where("sub_id = ? AND email <> ?", client.SubID, client.Email).
|
||||
Count(&subTaken).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
if subTaken > 0 {
|
||||
return false, common.NewError("subId already in use:", client.SubID)
|
||||
}
|
||||
}
|
||||
|
||||
needRestart := false
|
||||
for _, ibId := range payload.InboundIds {
|
||||
inbound, getErr := inboundSvc.GetInbound(ibId)
|
||||
|
|
@ -646,6 +658,18 @@ func (s *ClientService) Update(inboundSvc *InboundService, id int, updated model
|
|||
}
|
||||
}
|
||||
|
||||
if updated.SubID != "" {
|
||||
var subCollision int64
|
||||
if err := database.GetDB().Model(&model.ClientRecord{}).
|
||||
Where("sub_id = ? AND id <> ?", updated.SubID, id).
|
||||
Count(&subCollision).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
if subCollision > 0 {
|
||||
return false, common.NewError("Duplicate subId:", updated.SubID)
|
||||
}
|
||||
}
|
||||
|
||||
needRestart := false
|
||||
for _, ibId := range inboundIds {
|
||||
inbound, getErr := inboundSvc.GetInbound(ibId)
|
||||
|
|
|
|||
Loading…
Reference in a new issue