Skip to content

Commit

Permalink
Remove code that added role to tokens
Browse files Browse the repository at this point in the history
The role should now be added when the token is generated in our frontend apps, so we can remove that step from here.
  • Loading branch information
MuriloDalRi committed Nov 1, 2017
1 parent 6949e17 commit bc9539a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@

Records breaking changes from major version bumps

## 30.0.0

PR: [#341](https://github.com/alphagov/digitalmarketplace-utils/pull/341)

### What changed

We don't need to add the user role to tokens when decoding them since now we're using the "send_user_account_email" function to create tokens and the user role should be passed in to that function.

### Example app changes

Old token creation:
```
token = generate_token(
{
"role": "supplier",
"supplier_id": 1234,
"supplier_name": "Supplier Name",
"email_address": "[email protected]"
},
current_app.config['SHARED_EMAIL_KEY'],
current_app.config['INVITE_EMAIL_SALT']
)
```
New token creation:
```
send_user_account_email(
'supplier',
"[email protected]",
current_app.config['NOTIFY_TEMPLATES']['invite_contributor'],
extra_token_data={
'supplier_id': 1234,
'supplier_name': "Supplier Name"
},
personalisation={
'user': "Name",
'supplier': "Supplier Name"
}
)
```

## 29.0.0

PR: [#339](https://github.com/alphagov/digitalmarketplace-utils/pull/339)
Expand Down
2 changes: 1 addition & 1 deletion dmutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import flask_featureflags # noqa


__version__ = '29.0.0'
__version__ = '30.0.0'
4 changes: 0 additions & 4 deletions dmutils/email/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ def decode_invitation_token(encoded_token):
current_app.config['INVITE_EMAIL_SALT'],
SEVEN_DAYS_IN_SECONDS
)
if 'role' not in token:
token.update({
'role': 'supplier' if token.get('supplier_id') else 'buyer'
})
return token

except fernet.InvalidToken as error:
Expand Down
28 changes: 0 additions & 28 deletions tests/email/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,34 +189,6 @@ def test_decode_invitation_token_returns_an_error_and_role_if_token_expired(emai
assert decode_invitation_token(token) == {'error': 'token_expired', 'role': 'supplier'}


def test_decode_invitation_token_adds_the_role_key_to_old_style_buyer_tokens(email_app):
data = {'email_address': '[email protected]'}
token = generate_token(data, 'Key', 'Salt')

with email_app.app_context():
assert decode_invitation_token(token) == {
'email_address': '[email protected]',
'role': 'buyer'
}


def test_decode_invitation_token_adds_the_role_key_to_old_style_supplier_tokens(email_app):
data = {
'email_address': '[email protected]',
'supplier_id': 1234,
'supplier_name': 'A. Supplier',
}
token = generate_token(data, 'Key', 'Salt')

with email_app.app_context():
assert decode_invitation_token(token) == {
'email_address': '[email protected]',
'supplier_id': 1234,
'supplier_name': 'A. Supplier',
'role': 'supplier'
}


def test_decode_invitation_token_adds_the_role_key_to_expired_old_style_buyer_tokens(email_app):
with freeze_time('2015-01-02 03:04:05'):
data = {'email_address': '[email protected]'}
Expand Down

0 comments on commit bc9539a

Please sign in to comment.