mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FIX/BE-US] adjustment sso-location
This commit is contained in:
@@ -178,8 +178,6 @@ func uniqueUint(ids []uint) []uint {
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
|
||||
func ApplyScopeFilter(db *gorm.DB, scope ScopeFilter, column string) *gorm.DB {
|
||||
if db == nil || !scope.Restrict {
|
||||
return db
|
||||
@@ -190,6 +188,30 @@ func ApplyScopeFilter(db *gorm.DB, scope ScopeFilter, column string) *gorm.DB {
|
||||
return db.Where(column+" IN ?", scope.IDs)
|
||||
}
|
||||
|
||||
func ApplyLocationScope(c *fiber.Ctx, db *gorm.DB, column string) (*gorm.DB, error) {
|
||||
scopeDB := db
|
||||
if db != nil {
|
||||
scopeDB = db.Session(&gorm.Session{NewDB: true})
|
||||
}
|
||||
scope, err := ResolveLocationScope(c, scopeDB)
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
return ApplyScopeFilter(db, scope, column), nil
|
||||
}
|
||||
|
||||
func ApplyAreaScope(c *fiber.Ctx, db *gorm.DB, column string) (*gorm.DB, error) {
|
||||
scopeDB := db
|
||||
if db != nil {
|
||||
scopeDB = db.Session(&gorm.Session{NewDB: true})
|
||||
}
|
||||
scope, err := ResolveAreaScope(c, scopeDB)
|
||||
if err != nil {
|
||||
return db, err
|
||||
}
|
||||
return ApplyScopeFilter(db, scope, column), nil
|
||||
}
|
||||
|
||||
func EnsureWarehouseAccess(c *fiber.Ctx, db *gorm.DB, warehouseID uint) error {
|
||||
if warehouseID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid warehouse id")
|
||||
|
||||
Reference in New Issue
Block a user