Beispiel #1
0
    def _put(self, release, changed_by, transaction):
        form = ReadOnlyForm()
        data_version = form.data_version.data

        if not form.validate():
            self.log.warning("Bad input: %s", form.errors)
            return Response(status=400, response=json.dumps(form.errors))
        is_release_read_only = dbo.releases.isReadOnly(release)

        if form.read_only.data:
            if not is_release_read_only:
                dbo.releases.update(where={"name": release},
                                    what={"read_only": True},
                                    changed_by=changed_by,
                                    old_data_version=data_version,
                                    transaction=transaction)
                data_version += 1
        else:
            dbo.releases.update(where={"name": release},
                                what={"read_only": False},
                                changed_by=changed_by,
                                old_data_version=data_version,
                                transaction=transaction)
            data_version += 1
        return Response(status=201,
                        response=json.dumps(
                            dict(new_data_version=data_version)))
Beispiel #2
0
    def _put(self, release, changed_by, transaction):
        form = ReadOnlyForm()
        data_version = form.data_version.data

        if not form.validate():
            self.log.warning("Bad input: %s", form.errors)
            return Response(status=400, response=json.dumps(form.errors))
        is_release_read_only = dbo.releases.isReadOnly(release)

        if form.read_only.data:
            if not is_release_read_only:
                dbo.releases.update(where={"name": release}, what={"read_only": True}, changed_by=changed_by, old_data_version=data_version,
                                    transaction=transaction)
                data_version += 1
        else:
            dbo.releases.update(where={"name": release}, what={"read_only": False}, changed_by=changed_by, old_data_version=data_version,
                                transaction=transaction)
            data_version += 1
        return Response(status=201, response=json.dumps(dict(new_data_version=data_version)))
Beispiel #3
0
    def _put(self, release, changed_by, transaction):
        form = ReadOnlyForm()
        data_version = form.data_version.data

        if not form.validate():
            self.log.warning("Bad input: %s", form.errors)
            return Response(status=400, response=json.dumps(form.errors))
        is_release_read_only = dbo.releases.isReadOnly(release)

        if form.read_only.data:
            if not is_release_read_only:
                dbo.releases.updateRelease(release,
                                           changed_by,
                                           data_version,
                                           read_only=True,
                                           transaction=transaction)
                data_version += 1
        else:
            if is_release_read_only:
                # Only an admin user can unset the read_only field once it's set to True
                if dbo.permissions.hasUrlPermission(changed_by, 'admin',
                                                    'PUT'):
                    dbo.releases.updateRelease(release,
                                               changed_by,
                                               data_version,
                                               read_only=False,
                                               transaction=transaction)
                    data_version += 1
                else:
                    msg = "%s is not allowed to set releases as read-write" % changed_by
                    self.log.warning(
                        "Unauthorized attempt to mark release as read-write: %s",
                        msg)
                    return Response(status=403, response=msg)
        return Response(status=201,
                        response=json.dumps(
                            dict(new_data_version=data_version)))
Beispiel #4
0
    def _put(self, release, changed_by, transaction):
        form = ReadOnlyForm()
        data_version = form.data_version.data

        if not form.validate():
            self.log.warning("Bad input: %s", form.errors)
            return Response(status=400, response=json.dumps(form.errors))
        is_release_read_only = dbo.releases.isReadOnly(release)

        if form.read_only.data:
            if not is_release_read_only:
                dbo.releases.updateRelease(release, changed_by, data_version, read_only=True, transaction=transaction)
                data_version += 1
        else:
            if is_release_read_only:
                # Only an admin user can unset the read_only field once it's set to True
                if dbo.permissions.hasUrlPermission(changed_by, 'admin', 'PUT'):
                    dbo.releases.updateRelease(release, changed_by, data_version, read_only=False, transaction=transaction)
                    data_version += 1
                else:
                    msg = "%s is not allowed to set releases as read-write" % changed_by
                    self.log.warning("Unauthorized attempt to mark release as read-write: %s", msg)
                    return Response(status=403, response=msg)
        return Response(status=201, response=json.dumps(dict(new_data_version=data_version)))