mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 22:04:04 +08:00
fix acl api
This commit is contained in:
@@ -1,11 +1,37 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
from api.extensions import cache
|
||||
from api.models.acl import App
|
||||
from api.models.acl import Permission
|
||||
from api.models.acl import Role
|
||||
from api.models.acl import User
|
||||
|
||||
|
||||
class AppCache(object):
|
||||
PREFIX_ID = "App::id::{0}"
|
||||
PREFIX_NAME = "App::name::{0}"
|
||||
|
||||
@classmethod
|
||||
def get(cls, key):
|
||||
app = cache.get(cls.PREFIX_ID.format(key)) or cache.get(cls.PREFIX_NAME.format(key))
|
||||
if app is None:
|
||||
app = App.get_by_id(key) or App.get_by(name=key, to_dict=False, first=True)
|
||||
if app is not None:
|
||||
cls.set(app)
|
||||
|
||||
return app
|
||||
|
||||
@classmethod
|
||||
def set(cls, app):
|
||||
cache.set(cls.PREFIX_ID.format(app.id), app)
|
||||
cache.set(cls.PREFIX_NAME.format(app.name), app)
|
||||
|
||||
@classmethod
|
||||
def clean(cls, app):
|
||||
cache.delete(cls.PREFIX_ID.format(app.id))
|
||||
cache.delete(cls.PREFIX_NAME.format(app.name))
|
||||
|
||||
|
||||
class UserCache(object):
|
||||
PREFIX_ID = "User::uid::{0}"
|
||||
PREFIX_NAME = "User::username::{0}"
|
||||
|
Reference in New Issue
Block a user