Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tigaserver_app/migrations/0087_alter_tigauser_password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2025-10-28 14:49

from django.db import migrations, models
import tigaserver_app.models


class Migration(migrations.Migration):

dependencies = [
('tigaserver_app', '0086_auto_20251016_1353'),
]

operations = [
migrations.AlterField(
model_name='tigauser',
name='password',
field=models.CharField(default=tigaserver_app.models.get_default_password_hash, max_length=128, verbose_name='password'),
),
]
6 changes: 5 additions & 1 deletion tigaserver_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
from django.contrib.gis.db import models
from django.contrib.gis.db.models.functions import Distance as DistanceFunction
Expand Down Expand Up @@ -170,14 +171,17 @@ class RankingData(models.Model):
score_v2 = models.IntegerField()
last_update = models.DateTimeField(help_text="Last time ranking data was updated", null=True, blank=True)

def get_default_password_hash():
return make_password(settings.DEFAULT_TIGAUSER_PASSWORD)
Comment on lines +174 to +175
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called every time a TigaUser instance is created, hashing the same password repeatedly. Since the default password is static, consider caching the hash result to avoid unnecessary computation on each user creation.

Copilot uses AI. Check for mistakes.

class TigaUser(UserRolePermissionMixin, AbstractBaseUser, AnonymousUser):
AVAILABLE_LANGUAGES = [
(standarize_language_tag(code), Language.get(code).autonym().title()) for code, _ in settings.LANGUAGES
]

USERNAME_FIELD = 'pk'

password = models.CharField(_('password'), max_length=128, null=True, blank=True)
password = models.CharField(_('password'), max_length=128, default=get_default_password_hash)
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing null=True and blank=True from the password field may cause issues for existing TigaUser records that have NULL passwords. Consider adding a data migration to populate existing NULL passwords before applying this schema change.

Copilot uses AI. Check for mistakes.

user_UUID = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4, editable=False, help_text='UUID randomly generated on '
'phone to identify each unique user. Must be exactly 36 '
Expand Down
5 changes: 5 additions & 0 deletions tigaserver_app/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,9 @@ def setUp(self):
self.global_topic = NotificationTopic.objects.create(topic_code='global')
self.language_topic = NotificationTopic.objects.create(topic_code='en')

@override_settings(
DEFAULT_TIGAUSER_PASSWORD='DEFAULT_PASSWORD_FOR_TESTS'
)
def test_POST_new_user(self):
self.client.force_authenticate(user=self.mobile_user)
new_user_uuid = uuid.uuid4()
Expand All @@ -2482,6 +2485,8 @@ def test_POST_new_user(self):

user = TigaUser.objects.get(pk=str(new_user_uuid))

self.assertTrue(user.check_password('DEFAULT_PASSWORD_FOR_TESTS'))

# Check if the user is subscribed to the global topic
self.assertTrue(UserSubscription.objects.filter(user=user, topic=self.global_topic).exists())

Expand Down
3 changes: 3 additions & 0 deletions tigaserver_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

SECRET_KEY = 'h0v(25z3u9yquh+01+#%tj@7iyk*raq!-6)jwz+0ac^h2grd0@'

# Change this in prod
DEFAULT_TIGAUSER_PASSWORD = 'TEST_PASSWORD'
Comment on lines +35 to +36
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding a default password in settings is a security risk, especially with DEBUG=False in production. Consider using environment variables or Django's secrets management to configure this value securely, and ensure it's overridden in production environments.

Suggested change
# Change this in prod
DEFAULT_TIGAUSER_PASSWORD = 'TEST_PASSWORD'
# Set this via environment variable in production
DEFAULT_TIGAUSER_PASSWORD = os.environ.get('DEFAULT_TIGAUSER_PASSWORD')

Copilot uses AI. Check for mistakes.

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

Expand Down
Loading