-
-
Notifications
You must be signed in to change notification settings - Fork 177
feat: Add social media username validation #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nourzakhama2003
wants to merge
6
commits into
alphaonelabs:main
from
nourzakhama2003:feat/add-social-media-validation
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ed5d31
feat: Add social media username validation
nourzakhama2003 e00d4a1
fix: Address CodeRabbit review feedback on social media validators
nourzakhama2003 7f346a6
fix: address CodeRabbit review feedback round2
nourzakhama2003 eb34ef4
fix: add data migration and update GitHub error message
nourzakhama2003 b06a618
refactor: add type hints and clean up validator functions
nourzakhama2003 f0d8a82
Merge branch 'main' into feat/add-social-media-validation
A1L13N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Generated migration to clean up social media usernames before enforcing new length constraints | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| def cleanup_social_media_usernames(apps, schema_editor): | ||
| """ | ||
| Clean up social media usernames that exceed new length limits: | ||
| - discord_username: 37 chars (down from 50) | ||
| - slack_username: 21 chars (down from 50) | ||
| - github_username: 39 chars (down from 50) | ||
|
|
||
| This migration truncates over-limit usernames to fit the new constraints. | ||
| """ | ||
| Profile = apps.get_model("web", "Profile") | ||
| updated_count = 0 | ||
|
|
||
| for profile in Profile.objects.all(): | ||
| modified = False | ||
|
|
||
| # Truncate discord_username to 37 chars | ||
| if profile.discord_username and len(profile.discord_username) > 37: | ||
| profile.discord_username = profile.discord_username[:37] | ||
| modified = True | ||
|
|
||
| # Truncate slack_username to 21 chars | ||
| if profile.slack_username and len(profile.slack_username) > 21: | ||
| profile.slack_username = profile.slack_username[:21] | ||
| modified = True | ||
|
|
||
| # Truncate github_username to 39 chars | ||
| if profile.github_username and len(profile.github_username) > 39: | ||
| profile.github_username = profile.github_username[:39] | ||
| modified = True | ||
|
|
||
| if modified: | ||
| # Use update() to bypass validators and Profile.save() with full_clean() | ||
| Profile.objects.filter(pk=profile.pk).update( | ||
| discord_username=profile.discord_username, | ||
| slack_username=profile.slack_username, | ||
| github_username=profile.github_username, | ||
| ) | ||
| updated_count += 1 | ||
|
|
||
| if updated_count > 0: | ||
| print(f"✓ Cleaned up {updated_count} profiles with over-limit usernames") | ||
|
|
||
|
|
||
| def reverse_cleanup(apps, schema_editor): | ||
| """ | ||
| Reverse migration - no action needed as truncation is one-way. | ||
| Original usernames are lost, so we cannot restore them. | ||
| """ | ||
| pass | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("web", "0063_virtualclassroom_virtualclassroomcustomization_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(cleanup_social_media_usernames, reverse_cleanup), | ||
| ] |
44 changes: 44 additions & 0 deletions
44
web/migrations/0065_alter_profile_social_username_fields.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Schema migration to enforce new field length constraints on social media usernames | ||
|
|
||
| from django.db import migrations, models | ||
| import web.validators | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("web", "0064_cleanup_social_media_usernames"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name="profile", | ||
| name="discord_username", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text="Your Discord username (e.g., User#1234)", | ||
| max_length=37, | ||
| validators=[web.validators.validate_discord_username], | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="profile", | ||
| name="slack_username", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text="Your Slack username", | ||
| max_length=21, | ||
| validators=[web.validators.validate_slack_username], | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="profile", | ||
| name="github_username", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text="Your GitHub username (without @)", | ||
| max_length=39, | ||
| validators=[web.validators.validate_github_username], | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.