Skip to content

Commit 85bd366

Browse files
authored
Issue 1295. Added revert action for migration (#1296)
1 parent e4b06eb commit 85bd366

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ Víðir Valberg Guðmundsson
9797
Will Beaufoy
9898
pySilver
9999
Łukasz Skarżyński
100+
Yuri Savin

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
## [unreleased]
1818

19+
### WARNING
20+
* If you are going to revert migration 0006 make note that previously hashed client_secret cannot be reverted
21+
1922
### Added
2023
* #1185 Add middleware for adding access token to request
2124
* #1273 Add caching of loading of OIDC private key.
@@ -24,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2427

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

2832
## [2.3.0] 2023-05-31
2933

oauth2_provider/migrations/0006_alter_application_client_secret.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import logging
2+
13
from django.db import migrations
2-
from oauth2_provider import settings
4+
35
import oauth2_provider.generators
46
import oauth2_provider.models
7+
from oauth2_provider import settings
8+
9+
10+
logger = logging.getLogger()
511

612

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

1622

23+
def reverse_func(apps, schema_editor):
24+
warning_color_code = "\033[93m"
25+
end_color_code = "\033[0m"
26+
msg = f"\n{warning_color_code}The previously hashed client_secret cannot be reverted, and it remains hashed{end_color_code}"
27+
logger.warning(msg)
28+
29+
1730
class Migration(migrations.Migration):
1831

1932
dependencies = [
@@ -26,5 +39,5 @@ class Migration(migrations.Migration):
2639
name='client_secret',
2740
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),
2841
),
29-
migrations.RunPython(forwards_func),
42+
migrations.RunPython(forwards_func, reverse_func),
3043
]

0 commit comments

Comments
 (0)