Beispiel #1
0
    def write(self, user, coll, _id, data, options={}):
        """write

        :param user:
        :param coll:
        :param _id:
        :param data:
        :param options:
        """
        collection = self.getDbCollection(coll)
        if _id:
            prevInfo = self.getPrevDoc(user, coll, _id, options)
            authUpdate = self.authorize(user, coll, 1, prevInfo, options)
            self.validateSchema(self, coll, prevInfo, data, options)
            rawQuery = options.get('rawDbQuery', False)
            if rawQuery:
                if '$set' in data:
                    data['$set'].update(authUpdate)
                else:
                    data['$set'] = authUpdate
                collection.find_one_and_update({_id: Store.GenId(_id)}, data)
            else:
                data.update(authUpdate)
                collection.find_one_and_update({_id: Store.GenId(_id)},
                                               {'$set': data})
            self.emitDbEvent('update:' + coll, str(_id), cont)
            return 1
        self.validateSchema(self, coll, data, {}, options)
        data.update(self.authorizeCollection(self, user, coll, 1, options))
        newId = collection.insert_one(data).insertedId
        self.emitDbEvent('create:' + coll, str(newId), data)
        return newId
Beispiel #2
0
    def delete(self, user, coll, _id, options):
        """delete

        :param user:
        :param coll:
        :param _id:
        :param options:
        """
        prevInfo = self.getPrevDoc(user, coll, _id, options)
        authUpdate = self.authorize(user, coll, 1, prevInfo, options)
        self.getDbCollection(coll).delete_one({_id: Store.GenId(_id)})
        self.emitDbEvent('delete:' + coll, str(_id), prevInfo)
        return 1