Exemple #1
0
    def post(self):
        # This is checked for in a before_request hook.
        submitter = request.environ.get('REMOTE_USER')
        # We need copies of all the forms to reprint the page if there's any
        # errors. The form that was actually submitted will get overridden with
        # data later on.
        forms = {
            'fennecForm': FennecReleaseForm(formdata=None),
            'firefoxForm': FirefoxReleaseForm(formdata=None),
            'thunderbirdForm': ThunderbirdReleaseForm(formdata=None)
        }

        for field, value in request.form.items():
            if field.endswith('product'):
                product = value
                break

        try:
            form = getReleaseForm(product)()
        except ValueError:
            cef_event('User Input Failed', CEF_ALERT, ProductName=product)
            return Response(status=400,
                            response="Unknown product name '%s'" % product)
        errors = []
        if not form.validate():
            cef_event('User Input Failed', CEF_INFO, **form.errors)
            for error in form.errors.values():
                errors.extend(error)

        table = getReleaseTable(form.product.data)
        release = table.createFromForm(submitter, form)

        if db.session.query(table).filter(table.name == release.name).first():
            msg = 'Release "%s" already exists' % release.name
            cef_event('User Input Failed', CEF_INFO, ReleaseName=release.name)
            errors.append(msg)
        if errors:
            forms['%sForm' % product] = getReleaseForm(product)()
            return make_response(
                render_template('submit_release.html',
                                errors=errors,
                                selectedProduct=product,
                                **forms), 400)

        db.session.add(release)
        db.session.commit()
        log.debug('%s added to the database', release.name)
        return redirect('releases.html')
Exemple #2
0
    def post(self):
        # This is checked for in a before_request hook.
        submitter = request.environ.get('REMOTE_USER')
        # We need copies of all the forms to reprint the page if there's any
        # errors. The form that was actually submitted will get overridden with
        # data later on.
        forms = {
            'fennecForm': FennecReleaseForm(formdata=None),
            'firefoxForm': FirefoxReleaseForm(formdata=None),
            'deveditionForm': DeveditionReleaseForm(formdata=None),
            'thunderbirdForm': ThunderbirdReleaseForm(formdata=None)
        }

        for field, value in request.form.items():
            if field.endswith('product'):
                product = value
                break

        try:
            form = getReleaseForm(product)()
        except ValueError:
            cef_event('User Input Failed', CEF_ALERT, ProductName=product)
            return Response(status=400,
                            response="Unknown product name '%s'" % product)
        errors = []
        if not form.validate():
            cef_event('User Input Failed', CEF_INFO, **form.errors)
            for error in form.errors.values():
                errors.extend(error)

        table = getReleaseTable(form.product.data)
        release = table.createFromForm(submitter, form)

        if db.session.query(table).filter(table.name == release.name).first():
            msg = 'Release "%s" already exists' % release.name
            cef_event('User Input Failed', CEF_INFO, ReleaseName=release.name)
            errors.append(msg)
        if errors:
            forms['%sForm' % product] = getReleaseForm(product)()
            return make_response(
                render_template('submit_release.html', errors=errors,
                                selectedProduct=product, **forms), 400
            )

        db.session.add(release)
        db.session.commit()
        log.debug('%s added to the database', release.name)
        return redirect('releases.html')
Exemple #3
0
    def post(self):
        name = request.args.get('name')
        form = getReleaseForm(name)()
        release = getReleaseTable(name).query.filter_by(name=name).first()
        if not release:
            abort(404)
        # Similar to the above, don't allow edits to ready or completed
        # releases. Unless someone has constructed a POST by hand, this code
        # should never be hit.
        if release.ready or release.complete:
            errors = [
                "Cannot update a release that's been marked as ready or is complete"
            ]
            return make_response(
                render_template('release.html',
                                errors=errors,
                                form=form,
                                release=name), 403)

        if not form.validate():
            return make_response(
                render_template('release.html',
                                errors=form.errors.values(),
                                form=form,
                                release=name), 400)

        release.updateFromForm(form)
        db.session.add(release)
        db.session.commit()
        log.debug('%s has been edited', name)
        return redirect('releases.html')
Exemple #4
0
    def get(self):
        name = request.args.get('name')
        form = getReleaseForm(name)()
        release = getReleaseTable(name).query.filter_by(name=name).first()
        if not release:
            abort(404)
        # If this release is already ready or complete, edits aren't allowed.
        # It would be best to display an error here, but considering that there
        # aren't even links to this page for these releases, redirecting back
        # to the list of release seems OK.
        if release.ready or release.complete:
            return redirect('releases.html')

        # If the release is editable, prepopulate the form with the current
        # values from the database.
        form.updateFromRow(release)
        return render_template('release.html', form=form, release=name)
Exemple #5
0
    def get(self):
        name = request.args.get('name')
        form = getReleaseForm(name)()
        release = getReleaseTable(name).query.filter_by(name=name).first()
        if not release:
            abort(404)
        # If this release is already ready or complete, edits aren't allowed.
        # It would be best to display an error here, but considering that there
        # aren't even links to this page for these releases, redirecting back
        # to the list of release seems OK.
        if release.ready or release.complete:
            return redirect('releases.html')

        # If the release is editable, prepopulate the form with the current
        # values from the database.
        form.updateFromRow(release)
        return render_template('release.html', form=form, release=name)
Exemple #6
0
    def post(self):
        name = request.args.get('name')
        form = getReleaseForm(name)()
        release = getReleaseTable(name).query.filter_by(name=name).first()
        if not release:
            abort(404)
        # Similar to the above, don't allow edits to ready or completed
        # releases. Unless someone has constructed a POST by hand, this code
        # should never be hit.
        if release.ready or release.complete:
            errors = ["Cannot update a release that's been marked as ready or is complete"]
            return make_response(render_template('release.html', errors=errors, form=form, release=name), 403)

        if not form.validate():
            return make_response(render_template('release.html', errors=form.errors.values(), form=form, release=name), 400)

        release.updateFromForm(form)
        db.session.add(release)
        db.session.commit()
        log.debug('%s has been edited', name)
        return redirect('releases.html')