Merge pull request #6 from pycook/master

fix acl api
This commit is contained in:
kdyq007 2019-11-24 16:43:53 +08:00 committed by GitHub
commit bc63548dd8
3 changed files with 5 additions and 5 deletions

View File

@ -69,7 +69,7 @@ class CRUDMixin(FormatMixin):
@classmethod @classmethod
def get_by_id(cls, _id): def get_by_id(cls, _id):
if any((isinstance(_id, six.string_types) and _id.isdigit(), 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 return getattr(cls, "query").get(int(_id)) or None
@classmethod @classmethod

View File

@ -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)) rt = ResourceType.get_by_id(rt_id) or abort(404, "ResourceType <{0}> is not found".format(rt_id))
if 'name' in kwargs: if 'name' in kwargs:
other = ResourceType.get_by(name=kwargs['name'], app_id=rt.app_id, to_dict=False, first=True) 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'])) return abort(400, "ResourceType <{0}> is duplicated".format(kwargs['name']))
if 'perms' in kwargs: 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) 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)) 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) 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 abort(400, "Resource <{0}> is duplicated".format(name))
return resource.update(name=name) return resource.update(name=name)

View File

@ -46,7 +46,7 @@ class UserCRUD(object):
def update(uid, **kwargs): 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)) 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) return user.update(**kwargs)