refactor platform domain states and permissions
This commit is contained in:
31
backend/api/internal/logic/common/organization.go
Normal file
31
backend/api/internal/logic/common/organization.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
)
|
||||
|
||||
// ValidateOrganizationIDs verifies that an optional delivery point and staff
|
||||
// member belong to the requested gas organization.
|
||||
func ValidateOrganizationIDs(gasID, deliveryID, staffID uint64) bool {
|
||||
var delivery models.DeliveryBasic
|
||||
if deliveryID != 0 {
|
||||
if err := impl.DBService.First(&delivery, deliveryID).Error; err != nil {
|
||||
return false
|
||||
}
|
||||
if gasID != 0 && delivery.GasBasicID != 0 && delivery.GasBasicID != gasID {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if staffID == 0 {
|
||||
return true
|
||||
}
|
||||
var staff models.StaffAccount
|
||||
if err := impl.DBService.First(&staff, staffID).Error; err != nil {
|
||||
return false
|
||||
}
|
||||
if deliveryID != 0 && staff.DeliveryBasicID != deliveryID {
|
||||
return false
|
||||
}
|
||||
return gasID == 0 || staff.GasBasicID == 0 || staff.GasBasicID == gasID
|
||||
}
|
||||
Reference in New Issue
Block a user