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.let( { "user": q.match(q.index("unique_User_username"), q.select("username", q.var("input"))) }, q.if_( q.equals( q.select(["data", "account_status"], q.get(q.var("user"))), "ACTIVE"), q.select( "secret", q.login( q.var("user"), { "password": q.select("password", q.var("input")), "ttl": q.time_add(q.now(), 7, 'days') })), q.abort( "Account is not active. Please check email for activation." )))))
def get_function_lambda(self): return q.query( q.lambda_(['data'], q.equals( q.select( 'account_status', q.select( 'data', q.match( q.index( 'unique_User_username', q.select('username', q.var('data')))))), "ACTIVE")))
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_lambda(self, resource_type): lambda_args = ["object_ref"] return q.query( q.lambda_(lambda_args, q.equals(q.var('object_ref'), q.current_identity())))