Skip to content
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

Add twitter_id filed to TwitterConnection #612

Merged
merged 1 commit into from
Aug 30, 2024
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
18 changes: 18 additions & 0 deletions authentication/migrations/0042_twitterconnection_twitter_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2024-08-30 15:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authentication', '0041_alter_brightidconnection_user_profile_and_more'),
]

operations = [
migrations.AddField(
model_name='twitterconnection',
name='twitter_id',
field=models.CharField(max_length=255, null=True, unique=True),
),
]
6 changes: 3 additions & 3 deletions authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ class TwitterConnection(BaseThirdPartyConnection):
access_token_secret = models.CharField(
max_length=255, unique=True, blank=True, null=True
)
twitter_id = models.CharField(max_length=255, unique=True, null=True)
driver = TwitterDriver()

def is_connected(self):
return bool(self.access_token and self.access_token_secret)
return bool(self.twitter_id)

@property
def tweet_count(self):
Expand All @@ -279,8 +280,7 @@ def follower_count(self):
def username(self):
return self.driver.get_username(self.access_token, self.access_token_secret)

@property
def twitter_id(self):
def get_twitter_id(self):
return self.driver.get_twitter_id(
self, self.access_token, self.access_token_secret
)
Expand Down
12 changes: 10 additions & 2 deletions authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,15 @@ def get(self, request, *args, **kwargs):

twitter_connection.access_token = access_token
twitter_connection.access_token_secret = access_token_secret
twitter_connection.twitter_id = twitter_connection.get_twitter_id()

twitter_connection.save(update_fields=("access_token", "access_token_secret"))

try:
twitter_connection.save(
update_fields=("access_token", "access_token_secret", "twitter_id")
)
except IntegrityError:
raise ValidationError(
"""We can not connect you twitter account,
may be your account is connected before"""
Comment on lines +748 to +750
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Improve the error message for better user experience

Consider rephrasing the error message to be more user-friendly and fixing the typo. Also, ensure proper indentation for multiline strings.

            raise ValidationError(
                "Unable to connect your Twitter account. "
                "This account may have been connected previously."
            )

)
return Response({}, HTTP_200_OK)
Loading