From 39aaa916dce9c45be9d1196b75ba76ca455341cc Mon Sep 17 00:00:00 2001 From: pycook Date: Sun, 24 Nov 2019 16:35:28 +0800 Subject: [PATCH] fix acl api --- api/lib/database.py | 2 +- api/lib/perm/acl/resource.py | 6 +++--- api/lib/perm/acl/user.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/lib/database.py b/api/lib/database.py index 3b402a3..af89b6f 100644 --- a/api/lib/database.py +++ b/api/lib/database.py @@ -69,7 +69,7 @@ class CRUDMixin(FormatMixin): @classmethod def get_by_id(cls, _id): if any((isinstance(_id, six.string_types) and _id.isdigit(), - isinstance(_id, (int, long, float))), ): + isinstance(_id, (six.integer_types, float))), ): return getattr(cls, "query").get(int(_id)) or None @classmethod diff --git a/api/lib/perm/acl/resource.py b/api/lib/perm/acl/resource.py index 90a722e..18fa462 100644 --- a/api/lib/perm/acl/resource.py +++ b/api/lib/perm/acl/resource.py @@ -53,11 +53,11 @@ class ResourceTypeCRUD(object): rt = ResourceType.get_by_id(rt_id) or abort(404, "ResourceType <{0}> is not found".format(rt_id)) if 'name' in kwargs: other = ResourceType.get_by(name=kwargs['name'], app_id=rt.app_id, to_dict=False, first=True) - if other.id != rt_id: + if other and other.id != rt_id: return abort(400, "ResourceType <{0}> is duplicated".format(kwargs['name'])) if 'perms' in kwargs: - cls.update_perms(rt_id, kwargs['perms'], rt.app_id) + cls.update_perms(rt_id, kwargs.pop('perms'), rt.app_id) return rt.update(**kwargs) @@ -160,7 +160,7 @@ class ResourceCRUD(object): resource = Resource.get_by_id(_id) or abort(404, "Resource <{0}> is not found".format(_id)) other = Resource.get_by(name=name, resource_type_id=resource.resource_type_id, to_dict=False, first=True) - if other.id != _id: + if other and other.id != _id: return abort(400, "Resource <{0}> is duplicated".format(name)) return resource.update(name=name) diff --git a/api/lib/perm/acl/user.py b/api/lib/perm/acl/user.py index 78396ff..2a21fa1 100644 --- a/api/lib/perm/acl/user.py +++ b/api/lib/perm/acl/user.py @@ -46,7 +46,7 @@ class UserCRUD(object): def update(uid, **kwargs): user = User.get_by(uid=uid, to_dict=False, first=True) or abort(404, "User <{0}> does not exist".format(uid)) - UserCache.clean(uid) + UserCache.clean(user) return user.update(**kwargs)