Hi,

If what you're trying to do is mark the review request as "not approved" if
it has not been reviewed by someone other than the author, I think what you
want to do is loop over all the public reviews associated with the review
request. which is not done by the original submitter of the change. That
would look something like this:

def is_approved(self, review_request, prev_approved, prev_failure):
    if not prev_approved:
        return prev_approved, prev_failure

    for review in review_request.reviews.filter(public=True, ship_it=True):
        if review.user_id != review_request.submitter_id:
            return True

    return False


If you want to trigger an e-mail when a review is published by the original
author which includes a ship-it, then the ReviewRequestApprovalHook isn't
the right place to do that. That hook gets run whenever the API is accessed
(to compute and return the "approved" state therein). To send an e-mail,
you'd want to attach a listener to
reviewboard.reviews.signals.review_published and send your email from there.

With all of this, if people are trying to commit code without code review,
you really have a cultural problem rather than a technical one, and you'll
be better served by addressing that rather than trying to build technical
roadblocks.

-David

On Tue, Sep 6, 2016 at 8:33 PM Dave Ca <iamnewt...@gmail.com> wrote:

> how to get the username of the reviewer who clicked ship it? I need to
> validate certain condition and send out a mail if the submitter and
> reviewer is same.
>
> Here is the code:
>
> from __future__ import unicode_literals
>
> from django.conf import settings
> from django.conf.urls import patterns, include
> from reviewboard.extensions.base import Extension
> from reviewboard.extensions.hooks import ReviewRequestApprovalHook
> import io
> import os
> import requests
> import time
>
>
> class SampleApprovalHook(ReviewRequestApprovalHook):
>     def is_approved(self, review_request, prev_approved, prev_failure):
>         if not prev_approved:
>             return prev_approved, prev_failure
>         elif (review_request.shipit_count < 3):
>                 file = open(os.path.join('/tmp',"approvedTest.txt"), "w")
>                 file.write("SUBMITTED BY:")
>                 file.write(review_request.submitter.username)
>                 file.write("REVIEWED BY:")
>                 file.write(review_request.approved.username)
>                 file.close()
>         return True;
>
> class TestHook(Extension):
>     metadata = {
>         'Name': 'Test',
>         'Summary': 'Describe your extension here.',
>     }
>     is_configurable = True
>
>     def initialize(self):
>         # Your extension initialization is done here.
>         SampleApprovalHook(self)
>         pass
>
> --
> Supercharge your Review Board with Power Pack:
> https://www.reviewboard.org/powerpack/
> Want us to host Review Board for you? Check out RBCommons:
> https://rbcommons.com/
> Happy user? Let us know! https://www.reviewboard.org/users/
> ---
> You received this message because you are subscribed to the Google Groups
> "reviewboard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to reviewboard+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Supercharge your Review Board with Power Pack: 
https://www.reviewboard.org/powerpack/
Want us to host Review Board for you? Check out RBCommons: 
https://rbcommons.com/
Happy user? Let us know! https://www.reviewboard.org/users/
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to