Example #1
0
    def delete(self, username, reponame):
        # Check whether the key exists and if maybe the last change already is
        # a delete, else insert a `CSet.DELETE` entry without any blob data.

        key = self.get_query_argument("key")
        update = self.get_query_argument("update", "false") == "true"
        repo = revision_logic.get_repo(username, reponame)
        commit_message = self.get_query_argument("m", None)

        if username != self.current_user.name:
            raise HTTPError(reason="Unauthorized update: third party repo.", status_code=403)
        if not key:
            raise HTTPError(reason="Missing argument 'key'.", status_code=400)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        datestr = self.get_query_argument("datetime", None)
        ts = datestr and date(datestr, QSDATEFMT) or now()

        if update:
            # When update-param is set and the ts is the exact one of an existing cset (ts does not need to be increasing)
            if revision_logic.get_cset_at_ts(repo, key, ts):
                revision_logic.remove_revision(repo, key, ts)
                self.finish()
                return
            else:
                raise HTTPError(reason="No memento exists for given timestamp, when 'update' is set this must apply.", status_code=400)
        else:
            try:
                revision_logic.save_revision_delete(repo, key, ts)
            except LookupError:
                raise HTTPError(reason="Resource does not exist at given time.", status_code=404)
            else:
                if commit_message:
                    revision_logic.add_commit_message(repo, key, ts, commit_message.replace('\n', '. ').replace('\r', '. '))
Example #2
0
    def delete(self, username, reponame):
        if username != self.current_user.name:
            raise HTTPError(reason="Unauthorized: Not your Repo", status_code=403)

        key = self.get_query_argument("key")
        update = self.get_query_argument("update", "false") == "true"
        repo = revision_logic.get_repo(username, reponame)

        if not key:
            raise HTTPError(reason="Missing argument 'key'.", status_code=400)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        datestr = self.get_query_argument("datetime", None)
        ts = date(datestr, QSDATEFMT) or now()

        if update:
            # When update-param is set and the ts is the exact one of an existing cset (ts does not need to be increasing)
            if revision_logic.get_cset_at_ts(repo, key, ts):
                revision_logic.remove_revision(repo, key, ts)
                self.finish()
                return
            else:
                raise HTTPError(
                    reason="No memento exists for given timestamp. When 'update' is set this must apply",
                    status_code=400,
                )