def get_lambda(self, resource_type): if resource_type == 'write': lambda_args = ["old_object", "new_object", "object_ref"] user_ref = q.select(self.current_user_field, q.select('data', q.var('old_object'))) return q.query( q.lambda_( lambda_args, q.and_( q.equals(user_ref, q.current_identity()), q.equals( q.select(self.current_user_field, q.select('data', q.var('new_object'))), q.current_identity())))) elif resource_type == 'create': lambda_args = ["new_object"] user_ref = q.select(self.current_user_field, q.select('data', q.var('new_object'))) elif resource_type == 'read': lambda_args = ["object_ref"] user_ref = q.select(self.current_user_field, q.select('data', q.get(q.var('object_ref')))) return q.query( q.lambda_(lambda_args, q.equals(user_ref, q.current_identity())))
def get_body(self): return q.query( q.lambda_(["input"], q.if_( q.identify( q.current_identity(), q.select("current_password", q.var("input"))), q.update( q.current_identity(), { "credentials": { "password": q.select("new_password", q.var("input")) } }), q.abort("Wrong current password."))))
def update_password_b(self, current_password, new_password, _token=None): self.client(token=_token).query( q.if_( q.identify(self._get_identity(), current_password), q.update(q.current_identity(), {"credentials": { "password": new_password }}), q.abort("Wrong current password.")))
def get_lambda(self, resource_type): if resource_type == 'write': group_ref = q.select(self.current_group_field, q.select('data', q.var('old_object'))) lambda_args = ["old_object", "new_object", "object_ref"] return q.query( q.lambda_( lambda_args, q.and_( q.exists( # User ID from index q.select( self.through_user_field, q.select( "data", q.get( q.match( q.index(self.relation_index_name), group_ref, q.current_identity()))))), q.equals( q.select(self.current_group_field, q.select('data', q.var('old_object'))), q.select(self.current_group_field, q.select('data', q.var('new_object'))), )))) elif resource_type == 'create': group_ref = q.select(self.current_group_field, q.select('data', q.var('new_object'))) lambda_args = ["new_object"] elif resource_type == 'read': group_ref = q.select(self.current_group_field, q.select('data', q.get(q.var('object_ref')))) lambda_args = ["object_ref"] return q.query( q.lambda_( lambda_args, q.exists( #User ID from index q.select( self.through_user_field, q.select( "data", q.get( q.match(q.index(self.relation_index_name), group_ref, q.current_identity())))))))
def get_current_user(cls, _token=None): c = cls() return cls.get( c.client(_token=_token).query(q.current_identity()).id())
def get_from_id(cls, _token=None): c = cls() ref = c.client(_token=_token).query(q.current_identity()) return cls(_ref=ref, _lazied=True)
def _get_identity(self, _token=None): return self.client(token=_token).query(q.get(q.current_identity()))
def get_lambda(self, resource_type): lambda_args = ["object_ref"] return q.query( q.lambda_(lambda_args, q.equals(q.var('object_ref'), q.current_identity())))