Skip to content

Commit

Permalink
Fix merge confilict
Browse files Browse the repository at this point in the history
  • Loading branch information
mmd-mostafaee committed Oct 27, 2024
2 parents db16600 + 16e62d9 commit af9c39b
Show file tree
Hide file tree
Showing 93 changed files with 2,314 additions and 240 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy to Server

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Disable Host Key Checking
run: |
mkdir -p ~/.ssh
echo "StrictHostKeyChecking no" >> ~/.ssh/config
- name: Push to Server
run: |
git remote add dokku [email protected]:unitap-dev
git fetch --unshallow origin
git push dokku develop -f
1 change: 1 addition & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ jobs:
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
DEPLOYMENT_ENV: "dev"
TELEGRAM_BOT_API_KEY: ${{ secrets.TELEGRAM_BOT_API_KEY }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN pip install -r requirements.txt
COPY . .
RUN mkdir db
RUN mkdir -p static
RUN mkdir media
RUN mkdir media -p
RUN chmod +x start_dev.sh

EXPOSE 5678
Expand Down
13 changes: 13 additions & 0 deletions authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TwitterConnection,
UserProfile,
Wallet,
FarcasterConnection,
)


Expand All @@ -22,6 +23,7 @@ class ProfileAdmin(admin.ModelAdmin):

class WalletAdmin(admin.ModelAdmin):
list_display = ["pk", "wallet_type", "user_profile"]
autocomplete_fields = ["user_profile"]
search_fields = [
"user_profile__initial_context_id",
"wallet_type",
Expand All @@ -33,6 +35,7 @@ class WalletAdmin(admin.ModelAdmin):

class BrightIDConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "context_id", "age"]
autocomplete_fields = ["user_profile"]
search_fields = [
"context_id",
]
Expand All @@ -41,16 +44,25 @@ class BrightIDConnectionAdmin(admin.ModelAdmin):
class GitcoinPassportConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_wallet_address", "user_profile__username"]
autocomplete_fields = ["user_profile"]


class TwitterConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "oauth_token"]
search_fields = ["user_profile__username", "oauth_token"]
autocomplete_fields = ["user_profile"]


class EnsConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_profile__username", "user_wallet_address"]
autocomplete_fields = ["user_profile"]


class FarcasterConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_profile__username", "user_wallet_address"]
autocomplete_fields = ["user_profile"]


admin.site.register(Wallet, WalletAdmin)
Expand All @@ -59,3 +71,4 @@ class EnsConnectionAdmin(admin.ModelAdmin):
admin.site.register(GitcoinPassportConnection, GitcoinPassportConnectionAdmin)
admin.site.register(TwitterConnection, TwitterConnectionAdmin)
admin.site.register(ENSConnection, EnsConnectionAdmin)
admin.site.register(FarcasterConnection, FarcasterConnectionAdmin)
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),
),
]
14 changes: 6 additions & 8 deletions authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ class GitcoinPassportConnection(BaseThirdPartyConnection):

@property
def score(self):
score_tuple = self.driver.get_score(self.user_wallet_address)
return score_tuple[0] if score_tuple else 0.0
_score = self.driver.submit_passport(self.user_wallet_address)
return _score if _score is not None else 0


@receiver(pre_save, sender=GitcoinPassportConnection)
Expand All @@ -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,11 +280,8 @@ def follower_count(self):
def username(self):
return self.driver.get_username(self.access_token, self.access_token_secret)

@property
def twitter_id(self):
return self.driver.get_twitter_id(
self, self.access_token, self.access_token_secret
)
def get_twitter_id(self):
return self.driver.get_twitter_id(self.access_token, self.access_token_secret)

def is_replied(self, self_tweet_id, target_tweet_id):
return self.driver.get_is_replied(
Expand Down
12 changes: 6 additions & 6 deletions authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Meta:
fields = ["pk", "wallet_type", "address", "signature", "message"]

def is_valid(self, raise_exception=False):
super_is_validated = super().is_valid(raise_exception)
super_is_validated = super().is_valid(raise_exception=raise_exception)

address = self.validated_data.get("address")
message = self.validated_data.get("message")
Expand Down Expand Up @@ -208,8 +208,8 @@ class Meta:
]

def is_valid(self, raise_exception=False):
super_is_validated = super().is_valid(raise_exception)
is_address_valid = self.validate_address(raise_exception)
super_is_validated = super().is_valid(raise_exception=raise_exception)
is_address_valid = self.validate_address(raise_exception=raise_exception)

return is_address_valid and super_is_validated

Expand Down Expand Up @@ -237,7 +237,7 @@ class Meta:
]

def is_valid(self, raise_exception=False):
super_is_validated = super().is_valid(raise_exception)
super_is_validated = super().is_valid(raise_exception=raise_exception)
is_address_valid = self.validate_address(raise_exception)

return is_address_valid and super_is_validated
Expand All @@ -255,7 +255,7 @@ class Meta:
]

def is_valid(self, raise_exception=False):
super_is_validated = super().is_valid(raise_exception)
super_is_validated = super().is_valid(raise_exception=raise_exception)
is_address_valid = self.validate_address(raise_exception)

return is_address_valid and super_is_validated
Expand All @@ -273,7 +273,7 @@ class Meta:
]

def is_valid(self, raise_exception=False):
super_is_validated = super().is_valid(raise_exception)
super_is_validated = super().is_valid(raise_exception=raise_exception)
is_address_valid = self.validate_address(raise_exception)

return is_address_valid and super_is_validated
5 changes: 4 additions & 1 deletion authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,13 @@ def test_api_verify_login_signature_with_deleted_wallet(self):

class TestGitcoinPassportThirdPartyConnection(APITestCase):
def setUp(self) -> None:
self.address = "0x0cE49AF5d8c5A70Edacd7115084B2b3041fE4fF6"
self.address = "0x05204E317D25eb172115546297b056965bE2C74d"
self.user_profile = create_new_user()
create_new_wallet(
user_profile=self.user_profile, _address=self.address, wallet_type="EVM"
)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_gitcoin_passport_connection_successful(self):
self.client.force_authenticate(user=self.user_profile.user)
response = self.client.post(
Expand All @@ -697,6 +698,7 @@ def test_gitcoin_passport_connection_successful(self):
1,
)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_gitcoin_passport_not_exists(self):
address_does_not_have_gitcoin_passport = (
"0x0cE49AF5d8c5A70Edacd7115084B2b3041fE4fF5"
Expand All @@ -713,6 +715,7 @@ def test_gitcoin_passport_not_exists(self):
)
self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_address_not_owned_by_user(self):
self.client.force_authenticate(user=self.user_profile.user)
response = self.client.post(
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"""
)
return Response({}, HTTP_200_OK)
60 changes: 53 additions & 7 deletions brightIDfaucet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dotenv import load_dotenv
from sentry_sdk.integrations.django import DjangoIntegration

from corsheaders.defaults import default_headers

from faucet.faucet_manager.bright_id_interface import BrightIDInterface

load_dotenv()
Expand Down Expand Up @@ -72,6 +74,19 @@ def str2bool(v):
MEMCACHED_PASSWORD = os.environ.get("MEMCACHEDCLOUD_PASSWORD")
DEPLOYMENT_ENV = os.environ.get("DEPLOYMENT_ENV")


TELEGRAM_BOT_API_KEY = os.environ.get("TELEGRAM_BOT_API_KEY")
TELEGRAM_BOT_USERNAME = os.environ.get("TELEGRAM_BOT_USERNAME")
TELEGRAM_BOT_API_SECRET = os.environ.get("TELEGRAM_BOT_API_SECRET")
TELEGRAM_BUG_REPORTER_CHANNEL_ID = os.environ.get("TELEGRAM_BUG_REPORTER_CHANNEL_ID")

CLOUDFLARE_IMAGES_ACCOUNT_ID = os.environ.get("CLOUDFLARE_ACCOUNT_ID")
CLOUDFLARE_IMAGES_API_TOKEN = os.environ.get("CLOUDFLARE_API_TOKEN")
CLOUDFLARE_IMAGES_ACCOUNT_HASH = os.environ.get("CLOUDFLARE_ACCOUNT_HASH")

CLOUDFLARE_TURNSTILE_SECRET_KEY = os.environ.get("CLOUDFLARE_TURNSTILE_SECRET_KEY")
H_CAPTCHA_SECRET = os.environ.get("H_CAPTCHA_SECRET")

assert DEPLOYMENT_ENV in ["dev", "main"]


Expand Down Expand Up @@ -126,6 +141,7 @@ def before_send(event, hint):
"corsheaders",
"django_filters",
"safedelete",
"telegram.apps.TelegramConfig",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -161,6 +177,15 @@ def before_send(event, hint):

WSGI_APPLICATION = "brightIDfaucet.wsgi.application"

STORAGES = {
"default": {
"BACKEND": "cloudflare_images.storage.CloudflareImagesStorage",
},
"staticfiles": { # default
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

# Database
DATABASES = {"default": dj_database_url.config(conn_max_age=600)}

Expand All @@ -173,19 +198,32 @@ def before_send(event, hint):
# }
# }

CACHES = {
"default": {
"BACKEND": "django_bmemcached.memcached.BMemcached",
"LOCATION": MEMCACHED_URL
if MEMCACHED_URL and ',' in MEMCACHED_URL:
CACHES = {
"default": {
"BACKEND": "django_bmemcached.memcached.BMemcached",
"LOCATION": MEMCACHED_URL.split(","),
"OPTIONS": {
"username": MEMCACHED_USERNAME,
"password": MEMCACHED_PASSWORD,
},
}
}
}
else:
CACHES = {
"default": {
"BACKEND": "django_bmemcached.memcached.BMemcached",
"LOCATION": MEMCACHED_URL
}
}

# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.Us"
"erAttributeSimilarityValidator",
"erAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
Expand Down Expand Up @@ -223,6 +261,14 @@ def before_send(event, hint):
else:
CORS_ALLOW_ALL_ORIGINS = True

# Add Turnstile response headers for CORS
# These headers are required for Cloudflare and HCaptcha Turnstile anti-bot service

CORS_ALLOW_HEADERS = list(default_headers) + [
"cf-turnstile-response",
"hc-turnstile-response",
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

Expand Down Expand Up @@ -255,4 +301,4 @@ def before_send(event, hint):
"djangorestframework_camel_case.parser.CamelCaseJSONParser",
),
}
CELERY_BROKER_URL = REDIS_URL
CELERY_BROKER_URL = REDIS_URL
2 changes: 2 additions & 0 deletions brightIDfaucet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import include, path

Expand All @@ -31,4 +32,5 @@
path("api/prizetap/", include("prizetap.urls")),
path("api/quiztap/", include("quiztap.urls")),
path("api/analytics/", include("analytics.urls")),
path("api/telegram/", include("telegram.urls")),
]
Loading

0 comments on commit af9c39b

Please sign in to comment.