Skip to content

Commit

Permalink
Issue 1295. Added revert action for migration (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurasavin committed Sep 15, 2023
1 parent e4b06eb commit 85bd366
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ Víðir Valberg Guðmundsson
Will Beaufoy
pySilver
Łukasz Skarżyński
Yuri Savin
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### WARNING
* If you are going to revert migration 0006 make note that previously hashed client_secret cannot be reverted

### Added
* #1185 Add middleware for adding access token to request
* #1273 Add caching of loading of OIDC private key.
Expand All @@ -24,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- ### Fixed
* #1284 Allow to logout whith no id_token_hint even if the browser session already expired
* #1296 Added reverse function in migration 0006_alter_application_client_secret

## [2.3.0] 2023-05-31

Expand Down
17 changes: 15 additions & 2 deletions oauth2_provider/migrations/0006_alter_application_client_secret.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import logging

from django.db import migrations
from oauth2_provider import settings

import oauth2_provider.generators
import oauth2_provider.models
from oauth2_provider import settings


logger = logging.getLogger()


def forwards_func(apps, schema_editor):
Expand All @@ -14,6 +20,13 @@ def forwards_func(apps, schema_editor):
application.save(update_fields=['client_secret'])


def reverse_func(apps, schema_editor):
warning_color_code = "\033[93m"
end_color_code = "\033[0m"
msg = f"\n{warning_color_code}The previously hashed client_secret cannot be reverted, and it remains hashed{end_color_code}"
logger.warning(msg)


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -26,5 +39,5 @@ class Migration(migrations.Migration):
name='client_secret',
field=oauth2_provider.models.ClientSecretField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, help_text='Hashed on Save. Copy it now if this is a new secret.', max_length=255),
),
migrations.RunPython(forwards_func),
migrations.RunPython(forwards_func, reverse_func),
]

0 comments on commit 85bd366

Please sign in to comment.