Support not sending e-mails on WebAPI token creation

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

Information

Review Board
release-3.0.x
de65698...

Reviewers

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.

Description From Last Updated

F841 local variable 'webapi_token' is assigned to but never used

reviewbotreviewbot

F401 'reviewboard.webapi.signals.webapi_token_created' imported but unused

reviewbotreviewbot

At this point it might be nice to turn this into a table with signal, handler, sender and then iterate …

daviddavid

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

daviddavid

F401 'reviewboard.webapi.managers.WebAPITokenManager' imported but unused

reviewbotreviewbot

F401 'reviewboard.webapi.signals.webapi_token_updated' imported but unused

reviewbotreviewbot

Maybe a list of tuples?

daviddavid

This docstring needs to be updated now.

daviddavid

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

daviddavid

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

daviddavid

This can fit on one line.

chipx86chipx86

"WebAPIToken"

chipx86chipx86
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

brennie
david
  1. 
      
  2. reviewboard/notifications/email/__init__.py (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    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)
     
     
    Show all issues

    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. 
      
brennie
brennie
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

brennie
brennie
david
  1. 
      
  2. Show all issues

    Maybe a list of tuples?

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

    This docstring needs to be updated now.

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

    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)
     
     
    Show all issues

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

  6. 
      
brennie
chipx86
  1. 
      
  2. reviewboard/notifications/email/__init__.py (Diff revision 6)
     
     
     
    Show all issues

    This can fit on one line.

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

    "WebAPIToken"

  4. 
      
brennie
chipx86
  1. Ship It!
  2. 
      
brennie
Review request changed

Status: Closed (submitted)

Change Summary:

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