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

Black test only #153

Merged
merged 7 commits into from
Oct 19, 2023
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
12 changes: 12 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Black

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: '--check --line-length=120 --diff --exclude="dockertest"'
2 changes: 1 addition & 1 deletion django_project_base/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .constants import ACCOUNT_APP_ID
from .middleware import SessionMiddleware

default_app_config = '%s.apps.DjangoProjectBaseAccountsConfig' % ACCOUNT_APP_ID
default_app_config = "%s.apps.DjangoProjectBaseAccountsConfig" % ACCOUNT_APP_ID
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@


class Command(BaseCommand):
help = 'Migrate social login data from allauth to social_core'
help = "Migrate social login data from allauth to social_core"

provider_mapping: dict = {
'google': social_core.backends.google.GoogleOAuth2.name,
'facebook': social_core.backends.facebook.FacebookOAuth2.name,
'azure': social_core.backends.microsoft.MicrosoftOAuth2.name,
"google": social_core.backends.google.GoogleOAuth2.name,
"facebook": social_core.backends.facebook.FacebookOAuth2.name,
"azure": social_core.backends.microsoft.MicrosoftOAuth2.name,
}

def handle(self, *args, **options):

with connection.cursor() as cursor:
cursor.execute('select user_id, provider, extra_data from socialaccount_socialaccount;')
cursor.execute("select user_id, provider, extra_data from socialaccount_socialaccount;")
rows: list = cursor.fetchall()
for row in rows:
user_id: int = row[0]
provider: str = row[1]
extra_data: dict = json.loads(row[2]) if row[2] else {}
user_email: Optional[str] = extra_data.get('email') or extra_data.get('mail')
user_email: Optional[str] = extra_data.get("email") or extra_data.get("mail")
if user_email:
new_provider: str = self.provider_mapping.get(provider)
assert new_provider, 'New social auth provider for %s is not defined' % provider
assert new_provider, "New social auth provider for %s is not defined" % provider
payload = {
'user_id': user_id,
'provider': new_provider,
"user_id": user_id,
"provider": new_provider,
}
social_auth_records_exists: bool = UserSocialAuth.objects.filter(**payload).exists()
if not social_auth_records_exists:
payload['uid'] = user_email
payload['extra_data'] = None
payload["uid"] = user_email
payload["extra_data"] = None
UserSocialAuth.objects.create(**payload)
return 'ok'
return "ok"
44 changes: 22 additions & 22 deletions django_project_base/account/social_auth/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
{
"name": "AUTHENTICATION_BACKENDS",
"default": (
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.microsoft.MicrosoftOAuth2',
'social_core.backends.github.GithubOAuth2',
'social_core.backends.gitlab.GitLabOAuth2',
"social_core.backends.facebook.FacebookOAuth2",
"social_core.backends.google.GoogleOAuth2",
"social_core.backends.twitter.TwitterOAuth",
"social_core.backends.microsoft.MicrosoftOAuth2",
"social_core.backends.github.GithubOAuth2",
"social_core.backends.gitlab.GitLabOAuth2",
# 'social_core.backends.apple.AppleIdAuth', # not fully tested yet
),
"description": "Social login authentication backends. Add desired authentication backends to "
"Django’s AUTHENTICATION_BACKENDS setting.",
"Django’s AUTHENTICATION_BACKENDS setting.",
},
{
"name": "SOCIAL_AUTH_REDIRECT_IS_HTTPS",
"default": False,
"description": "On projects behind a reverse proxy that uses HTTPS, the redirect URIs can have the wrong "
"schema (http:// instead of https://) if the request lacks the appropriate headers, which might "
"cause errors during the auth process. To force HTTPS in the "
"final URIs set this setting to True",
"schema (http:// instead of https://) if the request lacks the appropriate headers, which might "
"cause errors during the auth process. To force HTTPS in the "
"final URIs set this setting to True",
},
{
"name": "SOCIAL_AUTH_LOGIN_REDIRECT_URL",
"default": "/",
"description": "Used to redirect the user once the auth process ended successfully. "
"The value of ?next=/foo is used if it was present",
"The value of ?next=/foo is used if it was present",
},
{
"name": "SOCIAL_AUTH_PIPELINE",
"default": (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.auth_allowed",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.user.get_username",
"social_core.pipeline.social_auth.associate_by_email",
"social_core.pipeline.user.create_user",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
),
"description": "python-social-auth authentication workflow pipeline. The default pipeline is a mechanism "
"that creates user instances and gathers basic data from providers.",
"that creates user instances and gathers basic data from providers.",
},
)
4 changes: 2 additions & 2 deletions django_project_base/account/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from django_project_base.account.router import accounts_router, profile_router

urlpatterns = [
path('', include(accounts_router.urls)),
path('', include(profile_router.urls)),
path("", include(accounts_router.urls)),
path("", include(profile_router.urls)),
]
4 changes: 2 additions & 2 deletions django_project_base/base/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


def hijack_set_is_hijacked(sender, **kwargs):
cache.set(CACHE_IMPERSONATE_USER % kwargs.get('hijacked').id, True)
cache.set(CACHE_IMPERSONATE_USER % kwargs.get("hijacked").id, True)


def hijack_delete_is_hijacked(sender, **kwargs):
cache.delete(CACHE_IMPERSONATE_USER % kwargs.get('hijacked').id)
cache.delete(CACHE_IMPERSONATE_USER % kwargs.get("hijacked").id)


hijack_started.connect(hijack_set_is_hijacked)
Expand Down
4 changes: 1 addition & 3 deletions django_project_base/licensing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
default_app_config = (
"%s.apps.DjangoProjectBaseLicensingConfig" % "django_project_base.licensing"
)
default_app_config = "%s.apps.DjangoProjectBaseLicensingConfig" % "django_project_base.licensing"
4 changes: 1 addition & 3 deletions django_project_base/licensing/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class Migration(migrations.Migration):
),
(
"date",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="Date"
),
models.DateTimeField(default=django.utils.timezone.now, verbose_name="Date"),
),
(
"type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ class Migration(migrations.Migration):
field=models.IntegerField(
choices=[
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
"Used access",
)
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
verbose_name="Type",
),
),
Expand All @@ -45,21 +41,15 @@ class Migration(migrations.Migration):
field=models.IntegerField(
choices=[
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
"Used access",
),
(
django_project_base.licensing.models.LicenseAccessUse.UseType[
"ADMIN_USE"
],
django_project_base.licensing.models.LicenseAccessUse.UseType["ADMIN_USE"],
"Used access by admin",
),
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType[
"USE"
],
default=django_project_base.licensing.models.LicenseAccessUse.UseType["USE"],
verbose_name="Type",
),
),
Expand Down
2 changes: 1 addition & 1 deletion django_project_base/notifications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django_project_base.notifications.constants import NOTIFICATIONS_APP_ID

default_app_config = '%s.apps.DjangoProjectBaseNotifyConfig' % NOTIFICATIONS_APP_ID
default_app_config = "%s.apps.DjangoProjectBaseNotifyConfig" % NOTIFICATIONS_APP_ID
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Command(BaseCommand):
help = 'Resends notification. Example: python manage.py resend_notification "178a46c2-2aa3-4a33-bad6-9af2d76f6891" 2' # noqa: E501

def add_arguments(self, parser) -> None:
parser.add_argument('notification', type=str, help='Notification identifier (uuid string).')
parser.add_argument('user', type=str, help='User identifier (user sending notification).')
parser.add_argument("notification", type=str, help="Notification identifier (uuid string).")
parser.add_argument("user", type=str, help="User identifier (user sending notification).")

def handle(self, *args, **options):
Notification.resend(get_object_or_404(DjangoProjectBaseNotification, pk=str(options['notification'])),
str(options["user"]))
Notification.resend(
get_object_or_404(DjangoProjectBaseNotification, pk=str(options["notification"])), str(options["user"])
)
return "ok"
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,20 @@ class Migration(migrations.Migration):
models.IntegerField(
choices=[
(
django_project_base.notifications.models.DeliveryReport.Status[
"DELIVERED"
],
django_project_base.notifications.models.DeliveryReport.Status["DELIVERED"],
"Delivered",
),
(
django_project_base.notifications.models.DeliveryReport.Status[
"NOT_DELIVERED"
],
django_project_base.notifications.models.DeliveryReport.Status["NOT_DELIVERED"],
"Not Delivered",
),
(
django_project_base.notifications.models.DeliveryReport.Status[
"PENDING_DELIVERY"
],
django_project_base.notifications.models.DeliveryReport.Status["PENDING_DELIVERY"],
"Pending delivery",
),
],
db_index=True,
default=django_project_base.notifications.models.DeliveryReport.Status[
"PENDING_DELIVERY"
],
default=django_project_base.notifications.models.DeliveryReport.Status["PENDING_DELIVERY"],
),
),
(
Expand Down
7 changes: 3 additions & 4 deletions django_project_base/notifications/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
"name": "TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY",
"default": 900,
"description": "When list maintenance notifications api is called with current=true in query param, "
"maintenance notification within range of now - TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY, "
"now + TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY is returned. Maintenance notification "
"cannot be created if it overlaps with annother maintenance notification in buffer.",
"maintenance notification within range of now - TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY, "
"now + TIME_BUFFER_FOR_CURRENT_MAINTENANCE_API_QUERY is returned. Maintenance notification "
"cannot be created if it overlaps with annother maintenance notification in buffer.",
},

)
Loading
Loading