Esempio n. 1
0
    def put(self, id):
        permission = auth.UpdatePatchPermission(id)
        if not permission.can():
            raise auth.PermissionDenied(permission)
        try:
            patch = patching.from_text(request.data)
            affected_entities = patching.validate(patch, database.get_dataset())
        except patching.InvalidPatchError as e:
            if str(e) != 'Could not apply JSON patch to dataset.':
                return {'status': 400, 'message': str(e)}, 400

        db = database.get_db()
        curs = db.cursor()
        curs.execute('''
UPDATE patch_request SET
original_patch = ?,
updated_entities = ?,
removed_entities = ?,
updated_by = ?
WHERE id = ?
        ''', (patch.to_string(),
              json.dumps(sorted(affected_entities['updated'])),
              json.dumps(sorted(affected_entities['removed'])),
              g.identity.id, id)
        )
        db.commit()
Esempio n. 2
0
 def patch(self):
     try:
         patch_request_id = patching.create_request(
             patching.from_text(request.data), g.identity.id)
         database.commit()
         return None, 202, {
             'Location': api.url_for(PatchRequest, id=patch_request_id)
         }
     except patching.InvalidPatchError as e:
         return {'status': 400, 'message': str(e)}, 400