36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from exceptions.exception import PermissionException
|
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
|
from module_business.dao.access_dao import AccessDao
|
|
|
|
|
|
class AccessService:
|
|
"""仓库与客户现场数据权限服务层。"""
|
|
|
|
@classmethod
|
|
async def assert_warehouse_access(
|
|
cls,
|
|
db: AsyncSession,
|
|
current_user: CurrentUserModel,
|
|
warehouse_id: int,
|
|
) -> None:
|
|
"""校验当前用户是否有权访问指定仓库。"""
|
|
if current_user.user.admin:
|
|
return
|
|
if not await AccessDao.user_has_warehouse(db, current_user.user.user_id, warehouse_id):
|
|
raise PermissionException(data='', message='无权访问该仓库')
|
|
|
|
@classmethod
|
|
async def assert_site_access(
|
|
cls,
|
|
db: AsyncSession,
|
|
current_user: CurrentUserModel,
|
|
site_id: int,
|
|
) -> None:
|
|
"""校验当前用户是否有权访问指定客户现场。"""
|
|
if current_user.user.admin:
|
|
return
|
|
if not await AccessDao.user_has_site(db, current_user.user.user_id, site_id):
|
|
raise PermissionException(data='', message='无权访问该客户现场')
|