Exemple #1
0
    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())))
Exemple #2
0
 def get_body(self):
     return q.query(
         q.lambda_(["input"],
                   q.map_(
                       q.lambda_(['ref'], q.get(q.var('ref'))),
                       q.paginate(
                           q.match(q.index(
                               self.collection.all_index_name())),
                           q.select('size', q.var('input'))))))
Exemple #3
0
 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."
                     )))))
Exemple #4
0
 def get_body(self):
     return q.query(
         q.lambda_(
             ["input"],
             q.delete(
                 q.ref(q.collection(self.collection.get_collection_name()),
                       q.select('id', q.var("input"))))))
Exemple #5
0
 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())))))))
Exemple #6
0
 def get_body(self):
     data_dict = {
         "data": self.get_fields(),
     }
     return q.query(
         q.lambda_(["input"],
                   q.create(
                       q.collection(self.collection.get_collection_name()),
                       data_dict)))
Exemple #7
0
    def get_body(self):

        data_dict = {
            "data": self.collection.get_fields(),
            "credentials": {
                self.collection._credential_field:
                q.select(self.collection._credential_field, q.var("input"))
            }
        }
        return q.query(
            q.lambda_(
                ["input"],
                q.let(
                    {
                        'result':
                        q.create(
                            q.collection(
                                self.collection.get_collection_name()),
                            data_dict),
                        'input':
                        q.var('input')
                    },
                    # If 'groups' key is an array
                    q.if_(
                        q.is_array(q.select('groups', q.var('input'))),
                        q.foreach(
                            q.lambda_(
                                'group',
                                q.create(
                                    q.collection(
                                        self.collection._base_properties.get(
                                            'groups').relation_name),
                                    {
                                        'data': {
                                            'userID':
                                            q.select('ref', q.var('result')),
                                            'groupID':
                                            q.var('group')
                                        }
                                    })), q.select('groups', q.var('input'))),
                        q.abort('Groups not defined.')))))
Exemple #8
0
 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."))))
Exemple #9
0
 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")))
Exemple #10
0
 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())))