Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Sep 23, 2024
1 parent f560242 commit 42a8f84
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions care/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class ExportCsvMixin:
@admin.action(description="Export Selected")
def export_as_csv(self, _, __):
def export_as_csv(self, request, queryset):
queryset = User.objects.filter(is_superuser=False).values(
*User.CSV_MAPPING.keys()
)
Expand Down Expand Up @@ -73,7 +73,7 @@ class UserFlagForm(forms.ModelForm):
)

class Meta:
fields = "__all__" # noqa DJ007
fields = "__all__"

Check failure on line 76 in care/users/admin.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (DJ007)

care/users/admin.py:76:13: DJ007 Do not use `__all__` with `ModelForm`, use `fields` instead
model = UserFlag

form = UserFlagForm
Expand Down
10 changes: 5 additions & 5 deletions care/users/api/viewsets/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UserFilterSet(filters.FilterSet):
district_id = filters.NumberFilter(field_name="district_id", lookup_expr="exact")
home_facility = filters.CharFilter(method="filter_home_facility")

def filter_home_facility(self, queryset, _, value):
def filter_home_facility(self, queryset, name, value):
if value == "NONE":
return queryset.filter(home_facility__isnull=True)
return queryset.filter(home_facility__external_id=value)
Expand All @@ -73,7 +73,7 @@ def filter_home_facility(self, queryset, _, value):
def get_user_type(
self,
queryset,
_,
field_name,
value,
):
if value and value in INVERSE_USER_TYPE:
Expand All @@ -82,7 +82,7 @@ def get_user_type(

user_type = filters.CharFilter(method="get_user_type", field_name="user_type")

def last_active_after(self, queryset, _, value):
def last_active_after(self, queryset, name, value):
if value == "never":
return queryset.filter(last_login__isnull=True)
# convert days to date
Expand Down Expand Up @@ -243,7 +243,7 @@ def check_facility_user_exists(self, user, facility):

@extend_schema(tags=["users"])
@action(detail=True, methods=["GET"], permission_classes=[IsAuthenticated])
def get_facilities(self, _, *__, **kwargs_):
def get_facilities(self, request, *args, **kwargs):
user = self.get_object()
queryset = Facility.objects.filter(users=user).select_related(
"local_body", "district", "state", "ward"
Expand Down Expand Up @@ -366,7 +366,7 @@ def pnconfig(self, request, *args, **kwargs):

@extend_schema(tags=["users"])
@action(methods=["GET"], detail=True)
def check_availability(self, _, username):
def check_availability(self, request, username):
"""
Checks availability of username by getting as query, returns 200 if available, and 409 otherwise.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import migrations


def rename_skill_and_add_new(apps, _):
def rename_skill_and_add_new(apps, schema_editor):
Skill = apps.get_model("users", "Skill")
Skill.objects.filter(name="Genreal Surgeon").update(name="General Surgeon")

Expand Down
4 changes: 2 additions & 2 deletions care/users/migrations/0009_userfacilityallocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db import migrations, models


def fill_user_facility_allocation(apps, _):
def fill_user_facility_allocation(apps, schema_editor):
UserFacilityAllocation = apps.get_model("users", "UserFacilityAllocation")
User = apps.get_model("users", "User")
users = User.objects.filter(home_facility__isnull=False)
Expand All @@ -20,7 +20,7 @@ def fill_user_facility_allocation(apps, _):
UserFacilityAllocation.objects.bulk_create(to_create, batch_size=2000)


def reverse_fill_user_facility_allocation(apps, _):
def reverse_fill_user_facility_allocation(apps, schema_editor):
UserFacilityAllocation = apps.get_model("users", "UserFacilityAllocation")
UserFacilityAllocation.objects.all().delete()

Expand Down
2 changes: 1 addition & 1 deletion care/users/migrations/0010_rename_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import migrations


def fix_skill_name(apps, _):
def fix_skill_name(apps, schema_editor):
Skill = apps.get_model("users", "Skill")

fix = {
Expand Down
4 changes: 2 additions & 2 deletions care/users/migrations/0013_staff_to_nurse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from care.users.models import User


def migrate_staff_to_nurse(_, __):
def migrate_staff_to_nurse(apps, schema_editor):
User.objects.filter(user_type=User.TYPE_VALUE_MAP["Staff"]).update(
user_type=User.TYPE_VALUE_MAP["Nurse"]
)
Expand All @@ -14,7 +14,7 @@ def migrate_staff_to_nurse(_, __):
)


def migrate_nurse_to_staff(_, __):
def migrate_nurse_to_staff(apps, schema_editor):
User.objects.filter(user_type=User.TYPE_VALUE_MAP["Nurse"]).update(
user_type=User.TYPE_VALUE_MAP["Staff"]
)
Expand Down
4 changes: 2 additions & 2 deletions care/users/migrations/0015_age_to_dateofbirth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils.timezone import now


def age_to_date_of_birth(apps, _):
def age_to_date_of_birth(apps, schema_editor):
User = apps.get_model("users", "User")
users_to_update = []
for user in User.objects.all():
Expand All @@ -13,7 +13,7 @@ def age_to_date_of_birth(apps, _):
User.objects.bulk_update(users_to_update, ["date_of_birth"])


def date_of_birth_to_age(apps, _):
def date_of_birth_to_age(apps, schema_editor):
User = apps.get_model("users", "User")
users_to_update = []
for user in User.objects.all():
Expand Down
2 changes: 1 addition & 1 deletion care/users/migrations/0016_upgrade_user_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import migrations


def add_skills(apps, _):
def add_skills(apps, schema_editor):
Skill = apps.get_model("users", "Skill")
if Skill.objects.exists():
skills = [
Expand Down
2 changes: 1 addition & 1 deletion care/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def full_name(self):
return self.get_full_name()

@staticmethod
def has_read_permission(_):
def has_read_permission(request):
return True

def has_object_read_permission(self, request):
Expand Down
8 changes: 5 additions & 3 deletions care/users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


@receiver(reset_password_token_created)
def password_reset_token_created(_, __, reset_password_token, *args, **kwargs):
def password_reset_token_created(
sender, instance, reset_password_token, *args, **kwargs
):
"""
Handles password reset tokens
When a token is created, an e-mail needs to be sent to the user
Expand All @@ -39,7 +41,7 @@ def password_reset_token_created(_, __, reset_password_token, *args, **kwargs):


@receiver(pre_save, sender=settings.AUTH_USER_MODEL)
def save_fields_before_update(_, instance, raw, __, update_fields, **kwargs_):
def save_fields_before_update(sender, instance, raw, using, update_fields, **kwargs):
if raw:
return

Expand All @@ -56,7 +58,7 @@ def save_fields_before_update(_, instance, raw, __, update_fields, **kwargs_):

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def track_user_facility_allocation(
_, instance, created, raw, __, update_fields, **kwargs_
sender, instance, created, raw, using, update_fields, **kwargs
):
if raw or (update_fields and "home_facility" not in update_fields):
return
Expand Down
2 changes: 1 addition & 1 deletion config/auth_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def validate(self, attrs):
return {}

@classmethod
def get_token(cls, _):
def get_token(cls, user):
msg = "Must implement `get_token` method for `TokenObtainSerializer` subclasses"
raise NotImplementedError(msg)

Expand Down
20 changes: 10 additions & 10 deletions config/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def is_authenticated(self):


class CustomJWTAuthentication(JWTAuthentication):
def authenticate_header(self, _):
def authenticate_header(self, request):
return ""

def get_validated_token(self, raw_token):
Expand All @@ -63,7 +63,7 @@ def get_validated_token(self, raw_token):


class CustomBasicAuthentication(BasicAuthentication):
def authenticate_header(self, _):
def authenticate_header(self, request):
return ""


Expand Down Expand Up @@ -91,7 +91,7 @@ def open_id_authenticate(self, url, token):
public_key = jwt.algorithms.RSAAlgorithm.from_jwk(public_key_response)
return jwt.decode(token, key=public_key, algorithms=["RS256"])

def authenticate_header(self, _):
def authenticate_header(self, request):
return f'{self.auth_header_type} realm="{self.www_authenticate_realm}"'

def get_user(self, _: Token, facility: Facility):
Expand Down Expand Up @@ -208,7 +208,7 @@ def open_id_authenticate(self, url, token):
token, key=public_key, audience="account", algorithms=["RS256"]
)

def authenticate_header(self, _):
def authenticate_header(self, request):
return "Bearer"

def authenticate(self, request):
Expand All @@ -233,7 +233,7 @@ def get_validated_token(self, url, token):
err = {"detail": "Invalid Authorization token"}
raise InvalidToken(err) from e

def get_user(self, _):
def get_user(self, validated_token):
user = User.objects.filter(username=settings.ABDM_USERNAME).first()
if not user:
password = User.objects.make_random_password()
Expand All @@ -255,7 +255,7 @@ class CustomJWTAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = "config.authentication.CustomJWTAuthentication"
name = "jwtAuth"

def get_security_definition(self, *args):
def get_security_definition(self, auto_schema):
return build_bearer_security_scheme_object(
header_name="Authorization",
token_prefix="Bearer",
Expand All @@ -267,7 +267,7 @@ class MiddlewareAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = "config.authentication.MiddlewareAuthentication"
name = "middlewareAuth"

def get_security_definition(self, *args):
def get_security_definition(self, auto_schema):
return {
"type": "http",
"scheme": "bearer",
Expand All @@ -286,7 +286,7 @@ class MiddlewareAssetAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = "config.authentication.MiddlewareAssetAuthentication"
name = "middlewareAssetAuth"

def get_security_definition(self, *args):
def get_security_definition(self, auto_schema):
return {
"type": "http",
"scheme": "bearer",
Expand All @@ -305,7 +305,7 @@ class CustomBasicAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = "config.authentication.CustomBasicAuthentication"
name = "basicAuth"

def get_security_definition(self, *args):
def get_security_definition(self, auto_schema):
return {
"type": "http",
"scheme": "basic",
Expand All @@ -317,7 +317,7 @@ class SessionAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = "rest_framework.authentication.SessionAuthentication"
name = "cookieAuth"

def get_security_definition(self, *args):
def get_security_definition(self, auto_schema):
return {
"type": "apiKey",
"in": "cookie",
Expand Down
2 changes: 1 addition & 1 deletion config/ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
VALIDATE_CAPTCHA_REQUEST_TIMEOUT = 5


def get_ratelimit_key(_, __):
def get_ratelimit_key(group, request):
return "ratelimit"


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ select = [
"TID", # flake8-tidy-imports
"TCH", # flake8-todo
"INT", # flake8-gettext
"ARG", # flake8-unused-arguments
# "ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"TD", # flake8-todo
"ERA", # eradicate
Expand Down

0 comments on commit 42a8f84

Please sign in to comment.