Support not sending e-mails on WebAPI token creation

Review Request #9258 - Created Oct. 10, 2017 and submitted

Barret Rennie
Review Board
release-3.0.x
9275
9259
de65698...
reviewboard

Currently when a WebAPI token is created, we always send an e-mail
notifying the user of its creation. However, this is not always ideal.
Some extensions and/or integrations require a WebAPI token in order to
communicate with Review Board from some external service (such as
CircleCI). In this case, we do not need to bother the user with a
notification that the token was created.

Djblets now has support for token update and create signals (via
/r/9275). We use these signals to determine if the token generated was
auto-generated. The notifications module has been modified to listen
to the new signals (instead of the generic post_save signal it was
listening to before) and not send e-mails when the token in question
is auto-generated.

Ran unit tests.

  • 0
  • 0
  • 12
  • 0
  • 12
Description From Last Updated
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

Barret Rennie
David Trowbridge
  1. 
      
  2. reviewboard/notifications/email/__init__.py (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    At this point it might be nice to turn this into a table with signal, handler, sender and then iterate that to do all the connections.

  3. reviewboard/webapi/managers.py (Diff revision 2)
     
     

    We could just have a signal for this in djblets. It's definitely possible that other consumers of djblets.webapi will have similar wants.

    1. I feel like the wanting email or not is kinda specific to RB itself?

    2. I mean the created signal, not the handler.

    3. Yeah but we are adding the signal basically only for this reason. We have to have the args the signal will accept ahead of time, and having send_email be one of those is weird. Perhaps it would be better to rename this to autogenerated? I would be comfortable with that in djblets.

  4. 
      
Barret Rennie
Barret Rennie
Review request changed

Change Summary:

Move signals into /r/9275/

Description:

   

Currently when a WebAPI token is created, we always send an e-mail

    notifying the user of its creation. However, this is not always ideal.
    Some extensions and/or integrations require a WebAPI token in order to
    communicate with Review Board from some external service (such as
    CircleCI). In this case, we do not need to bother the user with a
    notification that the token was created.

   
~  

To accomplish this, we now have specific WebAPI creation/update signals,

~   as well as a more specialized manager for the WebAPIToken class so
~   that we may specify at creation time whether or not an e-mail will be
~   sent. Currently the only way to not send an e-mail is via this manager.

~  
~  

The notifications module has been modified to listen to these new

  ~

Djblets now has support for token update and create signals (via

  ~ /r/9275). We use these signals to determine if the token generated was
  ~ auto-generated. The notifications module has been modified to listen
  ~ to the new signals (instead of the generic post_save signal it was
  ~ listening to before) and not send e-mails when the token in question
  ~ is auto-generated.

-   signals (instead of the generic post_save signal it was listening to
-   before) and conditionally not send e-mails when requested.

-  
-  

Testing done:

-   Ran unit tests.

Commit:

-5be1a7f85d2dcfc9176275ce31195acb8f272eac
+23b1d7a8157d2c7c4840d9506fe3b52286a7729a

Diff:

Revision 4 (+56 -23)

Show changes

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

Barret Rennie
Barret Rennie
David Trowbridge
  1. 
      
  2. Maybe a list of tuples?

  3. reviewboard/notifications/tests.py (Diff revision 5)
     
     

    This docstring needs to be updated now.

  4. reviewboard/notifications/tests.py (Diff revision 5)
     
     

    The outbox should default to [] at the beginning of every test. I think you can get rid of this line.

  5. reviewboard/notifications/tests.py (Diff revision 5)
     
     

    I think other things assertEqual(len(mail.outbox), 0)

  6. 
      
Barret Rennie
Christian Hammond
  1. 
      
  2. reviewboard/notifications/email/__init__.py (Diff revision 6)
     
     
     

    This can fit on one line.

  3. reviewboard/notifications/tests.py (Diff revision 6)
     
     

    "WebAPIToken"

  4. 
      
Barret Rennie
Christian Hammond
  1. Ship It!
  2. 
      
Barret Rennie
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.0.x (4c22dec)
Loading...