32 lines
876 B
Python
32 lines
876 B
Python
import pymongo
|
|
from motor.motor_asyncio import AsyncIOMotorDatabase
|
|
|
|
from core.config import settings
|
|
from crud.base import CRUDBase
|
|
from schemas import *
|
|
from utils import *
|
|
|
|
__all__ = 'authority',
|
|
|
|
|
|
class CRUDAuthority(CRUDBase):
|
|
|
|
async def create(self, db: AsyncIOMotorDatabase, *args):
|
|
casbin_model.add_policy(args[0], args[0], args[1:])
|
|
data = {'ptype': args[0],
|
|
'v0': args[1],
|
|
'v1': args[2],
|
|
'v2': args[3],
|
|
}
|
|
await self.update_upsert(db, data, **data)
|
|
|
|
async def create_index(self, db: AsyncIOMotorDatabase):
|
|
await db[self.coll_name].create_index(
|
|
[('ptype', pymongo.DESCENDING), ('v0', pymongo.DESCENDING), ('v1', pymongo.DESCENDING),
|
|
('v2', pymongo.DESCENDING)],
|
|
unique=True)
|
|
|
|
|
|
|
|
authority = CRUDAuthority(settings.CASBIN_COLL)
|