def delete(cls, rt_id): rt = ResourceType.get_by_id(rt_id) or abort( 404, "ResourceType <{0}> is not found".format(rt_id)) if Resource.get_by(resource_type_id=rt_id): return abort( 400, "At least one instance of this type exists and cannot be deleted" ) cls.update_perms(rt_id, [], rt.app_id) rt.soft_delete()
def update(cls, rt_id, **kwargs): kwargs.pop('app_id', None) 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 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.pop('perms'), rt.app_id) return rt.update(**kwargs)
def delete(cls, rt_id): rt = ResourceType.get_by_id(rt_id) or abort(404, "ResourceType <{0}> is not found".format(rt_id)) cls.update_perms(rt_id, [], rt.app_id) rt.soft_delete()