53 lines
1.5 KiB
Python
53 lines
1.5 KiB
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, **kwargs):
|
|
data = dict()
|
|
if len(args) > 0:
|
|
data['ptype'] = args[0]
|
|
if len(args) > 1:
|
|
data['v0'] = args[1]
|
|
if len(args) > 2:
|
|
data['v1'] = args[2]
|
|
if len(args) > 3:
|
|
data['v2'] = args[3]
|
|
if len(args) > 4:
|
|
data['v3'] = args[4]
|
|
if len(args) > 5:
|
|
data['v4'] = args[5]
|
|
|
|
data.update(kwargs)
|
|
await self.update_one(db, data, {'$set': data}, upsert=True)
|
|
|
|
async def get_all_dom_role(self, db, dom):
|
|
pass
|
|
|
|
async def get_role_dom_authority(self, db, role, dom):
|
|
data = await self.find_many(db, v0=role, v1=dom)
|
|
res = []
|
|
for item in data:
|
|
res.append({
|
|
'api': item['v2'],
|
|
'api_name': item.get('api_name', item['v2'])
|
|
})
|
|
return res
|
|
|
|
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), ('v3', pymongo.DESCENDING)],
|
|
unique=True)
|
|
|
|
|
|
authority = CRUDAuthority(settings.CASBIN_COLL)
|