mirror of https://github.com/veops/cmdb.git
acl: resource type api
This commit is contained in:
parent
a1f63b00dd
commit
e5baa5012d
|
@ -43,10 +43,10 @@ class UserCRUD(object):
|
||||||
return User.create(**kwargs)
|
return User.create(**kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update(rid, **kwargs):
|
def update(uid, **kwargs):
|
||||||
user = User.get_by_id(rid) or abort(404, "User <{0}> does not exist".format(rid))
|
user = User.get_by_id(uid) or abort(404, "User <{0}> does not exist".format(uid))
|
||||||
|
|
||||||
UserCache.clean(rid)
|
UserCache.clean(uid)
|
||||||
|
|
||||||
return user.update(**kwargs)
|
return user.update(**kwargs)
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,55 @@ from api.lib.decorator import args_required
|
||||||
from api.lib.perm.acl import validate_app
|
from api.lib.perm.acl import validate_app
|
||||||
from api.lib.perm.acl.resource import ResourceCRUD
|
from api.lib.perm.acl.resource import ResourceCRUD
|
||||||
from api.lib.perm.acl.resource import ResourceGroupCRUD
|
from api.lib.perm.acl.resource import ResourceGroupCRUD
|
||||||
|
from api.lib.perm.acl.resource import ResourceTypeCRUD
|
||||||
from api.lib.utils import get_page
|
from api.lib.utils import get_page
|
||||||
from api.lib.utils import get_page_size
|
from api.lib.utils import get_page_size
|
||||||
from api.lib.utils import handle_arg_list
|
from api.lib.utils import handle_arg_list
|
||||||
from api.resource import APIView
|
from api.resource import APIView
|
||||||
|
|
||||||
|
|
||||||
|
class ResourceTypeView(APIView):
|
||||||
|
url_prefix = ("/resource_types", "/resource_types/<int:type_id>")
|
||||||
|
|
||||||
|
@args_required('app_id')
|
||||||
|
@validate_app
|
||||||
|
def get(self):
|
||||||
|
page = get_page(request.values.get("page", 1))
|
||||||
|
page_size = get_page_size(request.values.get("page_size"))
|
||||||
|
q = request.values.get('q')
|
||||||
|
app_id = request.values.get('app_id')
|
||||||
|
|
||||||
|
numfound, res = ResourceTypeCRUD.search(q, app_id, page, page_size)
|
||||||
|
|
||||||
|
return self.jsonify(numfound=numfound,
|
||||||
|
page=page,
|
||||||
|
page_size=page_size,
|
||||||
|
groups=[i.to_dict() for i in res])
|
||||||
|
|
||||||
|
@args_required('name')
|
||||||
|
@args_required('app_id')
|
||||||
|
@args_required('perms')
|
||||||
|
@validate_app
|
||||||
|
def post(self):
|
||||||
|
name = request.values.get('name')
|
||||||
|
app_id = request.values.get('app_id')
|
||||||
|
perms = request.values.get('perms')
|
||||||
|
|
||||||
|
rt = ResourceTypeCRUD.add(name, app_id, perms)
|
||||||
|
|
||||||
|
return self.jsonify(rt.to_dict())
|
||||||
|
|
||||||
|
def put(self, type_id):
|
||||||
|
rt = ResourceTypeCRUD.update(type_id, **request.values)
|
||||||
|
|
||||||
|
return self.jsonify(rt.to_dict())
|
||||||
|
|
||||||
|
def delete(self, type_id):
|
||||||
|
ResourceTypeCRUD.delete(type_id)
|
||||||
|
|
||||||
|
return self.jsonify(type_id=type_id)
|
||||||
|
|
||||||
|
|
||||||
class ResourceView(APIView):
|
class ResourceView(APIView):
|
||||||
url_prefix = ("/resources", "/resources/<int:resource_id>")
|
url_prefix = ("/resources", "/resources/<int:resource_id>")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue