コード例 #1
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def report(id):
    review = Review.query.get_or_404(str(id))
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    if review.user == current_user:
        flash.error(gettext("You cannot report your own review."))
        return redirect(url_for('.entity', id=id))

    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to report this review because "
                    "your account has been blocked by a moderator."))
        return redirect(url_for('.entity', id=id))

    last_revision_id = review.last_revision.id
    report = db_spam_report.get(current_user.id, last_revision_id)
    if report:
        flash.error(gettext("You have already reported this review."))
        return redirect(url_for('.entity', id=id))

    form = ReviewReportForm()
    if form.validate_on_submit():
        db_spam_report.create(last_revision_id, current_user.id,
                              form.reason.data)
        flash.success(gettext("Review has been reported."))
        return redirect(url_for('.entity', id=id))

    return render_template('review/report.html', review=review, form=form)
コード例 #2
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def vote_submit(review_id):
    review_id = str(review_id)
    if 'yes' in request.form:
        vote = True
    elif 'no' in request.form:
        vote = False
    else:
        vote = None

    review = Review.query.get_or_404(review_id)
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    if review.user == current_user:
        flash.error(gettext("You cannot rate your own review."))
        return redirect(url_for('.entity', id=review_id))
    if current_user.is_vote_limit_exceeded is True and current_user.has_voted(
            review) is False:
        flash.error(gettext("You have exceeded your limit of votes per day."))
        return redirect(url_for('.entity', id=review_id))
    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to rate this review because "
                    "your account has been blocked by a moderator."))
        return redirect(url_for('.entity', id=review_id))

    db_vote.submit(
        user_id=current_user.id,
        revision_id=review.last_revision.id,
        vote=vote,  # overwrites an existing vote, if needed
    )

    flash.success(gettext("You have rated this review!"))
    return redirect(url_for('.entity', id=review_id))
コード例 #3
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def delete(id):
    review = Review.query.get_or_404(str(id))
    if review.user != current_user and not current_user.is_admin():
        raise Unauthorized(
            gettext("Only the author or an admin can delete this review."))
    if request.method == 'POST':
        review.delete()
        flash.success(gettext("Review has been deleted."))
        return redirect(url_for('user.reviews', user_id=current_user.id))
    return render_template('review/delete.html', review=review)
コード例 #4
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def vote_delete(id):
    review = Review.query.get_or_404(str(id))
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    try:
        vote = db_vote.get(user_id=current_user.id,
                           revision_id=review.last_revision.id)
        flash.success(gettext("You have deleted your vote for this review!"))
        db_vote.delete(user_id=vote["user_id"],
                       revision_id=vote["revision_id"])
    except db_exceptions.NoDataFoundException:
        flash.error(gettext("This review is not rated yet."))
    return redirect(url_for('.entity', id=id))
コード例 #5
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def edit(id):
    review = Review.query.get_or_404(str(id))
    if review.is_draft and current_user != review.user:
        raise NotFound(gettext("Can't find a review with the specified ID."))
    if review.user != current_user:
        raise Unauthorized(gettext("Only author can edit this review."))
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))

    form = ReviewEditForm(default_license_id=review.license_id,
                          default_language=review.language)
    if not review.is_draft:
        # Can't change license if review is published.
        del form.license_choice

    if form.validate_on_submit():
        if review.is_draft:
            license_choice = form.license_choice.data
        else:
            license_choice = None
        review.update(text=form.text.data,
                      is_draft=(form.state.data == 'draft'),
                      license_id=license_choice,
                      language=form.language.data)
        flash.success(gettext("Review has been updated."))
        return redirect(url_for('.entity', id=review.id))
    else:
        form.text.data = review.text
    if review.entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(review.entity_id)
        soundcloud_url = soundcloud.get_url(review.entity_id)
        return render_template('review/modify/edit.html',
                               form=form,
                               review=review,
                               entity_type=review.entity_type,
                               entity=entity,
                               spotify_mappings=spotify_mappings,
                               soundcloud_url=soundcloud_url)
    return render_template('review/modify/edit.html',
                           form=form,
                           review=review,
                           entity_type=review.entity_type)
コード例 #6
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def hide(id):
    review = Review.query.get_or_404(str(id))

    if review.is_hidden:
        flash.info(gettext("Review is already hidden."))
        return redirect(url_for('.entity', id=review.id))

    form = AdminActionForm()
    if form.validate_on_submit():
        review.hide()
        ModerationLog.create(admin_id=current_user.id,
                             action=ACTION_HIDE_REVIEW,
                             reason=form.reason.data,
                             review_id=review.id)
        for report in db_spam_report.list_reports(review_id=review.id):
            db_spam_report.archive(report["user_id"], report["revision_id"])
        flash.success(gettext("Review has been hidden."))
        return redirect(url_for('.entity', id=review.id))

    return render_template('log/action.html',
                           review=review,
                           form=form,
                           action=ACTION_HIDE_REVIEW)
コード例 #7
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def unhide(id):
    review = Review.query.get_or_404(str(id))
    review.unhide()
    flash.success(gettext("Review is not hidden anymore."))
    return redirect(request.referrer
                    or url_for('user.reviews', user_id=current_user.id))
コード例 #8
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def create():
    for entity_type in ENTITY_TYPES:
        entity_id = request.args.get(entity_type)
        if entity_id:
            break

    if not entity_id:
        flash.info(gettext("Please choose an entity to review."))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if current_user.is_blocked:
        flash.error(
            gettext("You are not allowed to write new reviews because your "
                    "account has been blocked by a moderator."))
        return redirect(url_for('user.reviews', user_id=current_user.id))

    # Checking if the user already wrote a review for this entity
    review = Review.query.filter_by(user_id=current_user.id,
                                    entity_id=entity_id).first()
    if review:
        flash.error(
            gettext("You have already published a review for this entity!"))
        return redirect(url_for('review.entity', id=review.id))

    form = ReviewCreateForm(default_language=get_locale())

    if form.validate_on_submit():
        if current_user.is_review_limit_exceeded:
            flash.error(
                gettext("You have exceeded your limit of reviews per day."))
            return redirect(url_for('user.reviews', user_id=current_user.id))

        is_draft = form.state.data == 'draft'
        review = Review.create(user_id=current_user.id,
                               entity_id=entity_id,
                               entity_type=entity_type,
                               text=form.text.data,
                               license_id=form.license_choice.data,
                               language=form.language.data,
                               is_draft=is_draft)
        if is_draft:
            flash.success(gettext("Review has been saved!"))
        else:
            flash.success(gettext("Review has been published!"))
        return redirect(url_for('.entity', id=review.id))

    entity = musicbrainz.get_entity_by_id(entity_id, entity_type)
    if not entity:
        flash.error(
            gettext(
                "You can only write a review for an entity that exists on MusicBrainz!"
            ))
        return redirect(url_for('search.selector', next=url_for('.create')))

    if entity_type == 'release_group':
        spotify_mappings = mbspotify.mappings(entity_id)
        soundcloud_url = soundcloud.get_url(entity_id)
        return render_template('review/modify/write.html',
                               form=form,
                               entity_type=entity_type,
                               entity=entity,
                               spotify_mappings=spotify_mappings,
                               soundcloud_url=soundcloud_url)
    return render_template('review/modify/write.html',
                           form=form,
                           entity_type=entity_type,
                           entity=entity)