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

Fix/user verify #479

Merged
merged 4 commits into from
Nov 1, 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
4 changes: 2 additions & 2 deletions chats/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class IsChatMember(BasePermission):
Allows access only to authenticated users.
"""

def has_permission(self, request, view):
def has_permission(self, request, view) -> bool:
kwargs = request.parser_context.get("kwargs")

chat_id: str = kwargs["id"]

return str(request.user.id) in chat_id
return str(request.user.id) in chat_id.split("_")
Empty file.
64 changes: 0 additions & 64 deletions core/management/commands/migrate_education.py

This file was deleted.

51 changes: 0 additions & 51 deletions core/management/commands/reverse_migrate_education.py

This file was deleted.

14 changes: 0 additions & 14 deletions log/migrated_users.json

This file was deleted.

44 changes: 22 additions & 22 deletions procollab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,31 +321,31 @@

SESSION_COOKIE_SECURE = False

# EMAIL_BACKEND = "anymail.backends.unisender_go.EmailBackend"
#
# UNISENDER_GO_API_KEY = config("UNISENDER_GO_API_KEY", default="", cast=str)
# ANYMAIL = {
# "UNISENDER_GO_API_KEY": UNISENDER_GO_API_KEY,
# "UNISENDER_GO_API_URL": "https://go1.unisender.ru/ru/transactional/api/v1/",
# "UNISENDER_GO_SEND_DEFAULTS": {
# "esp_extra": {
# "global_language": "ru",
# }
# },
# }

# EMAIL_USE_TLS = True
#
# EMAIL_PORT = config("EMAIL_PORT", default=587, cast=int)
# EMAIL_USER = config("EMAIL_USER", cast=str, default="[email protected]")
EMAIL_BACKEND = "anymail.backends.unisender_go.EmailBackend"

UNISENDER_GO_API_KEY = config("UNISENDER_GO_API_KEY", default="", cast=str)
ANYMAIL = {
"UNISENDER_GO_API_KEY": UNISENDER_GO_API_KEY,
"UNISENDER_GO_API_URL": "https://go1.unisender.ru/ru/transactional/api/v1/",
"UNISENDER_GO_SEND_DEFAULTS": {
"esp_extra": {
"global_language": "ru",
}
},
}

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_USE_TLS = True
EMAIL_HOST = config("EMAIL_HOST", default="smtp.gmail.com", cast=str)

EMAIL_PORT = config("EMAIL_PORT", default=587, cast=int)
EMAIL_HOST_USER = config("EMAIL_USER", cast=str, default="[email protected]")
EMAIL_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = config("EMAIL_PASSWORD", cast=str, default="password")
EMAIL_USER = config("EMAIL_USER", cast=str, default="[email protected]")

# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
# EMAIL_USE_TLS = True
# EMAIL_HOST = config("EMAIL_HOST", default="smtp.gmail.com", cast=str)
# EMAIL_PORT = config("EMAIL_PORT", default=587, cast=int)
# EMAIL_HOST_USER = config("EMAIL_USER", cast=str, default="[email protected]")
# EMAIL_USER = EMAIL_HOST_USER
# EMAIL_HOST_PASSWORD = config("EMAIL_PASSWORD", cast=str, default="password")

SELECTEL_ACCOUNT_ID = config("SELECTEL_ACCOUNT_ID", cast=str, default="123456")
SELECTEL_CONTAINER_NAME = config(
Expand Down
22 changes: 17 additions & 5 deletions users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class UserLanguagesInline(admin.TabularInline):
verbose_name_plural = "Знание языков"


@admin.action(description="Сделать выбранных пользователей подтверждёнными")
def make_active(modeladmin, request, queryset):
queryset.update(is_active=True)


@admin.register(CustomUser)
class CustomUserAdmin(admin.ModelAdmin):
fieldsets = (
Expand Down Expand Up @@ -94,7 +99,6 @@ class CustomUserAdmin(admin.ModelAdmin):
"status",
"city",
"region",
"organization", # TODO need to be removed in future.
"speciality",
"v2_speciality",
"key_skills",
Expand Down Expand Up @@ -127,6 +131,7 @@ class CustomUserAdmin(admin.ModelAdmin):
"is_active",
"dataset_migration_applied",
"v2_speciality",
"datetime_created",
)
list_display_links = (
"id",
Expand Down Expand Up @@ -154,6 +159,7 @@ class CustomUserAdmin(admin.ModelAdmin):
UserWorkExperienceInline,
UserLanguagesInline,
]
actions = [make_active]

readonly_fields = ("ordering_score",)
change_form_template = "users/admin/users_change_form.html"
Expand Down Expand Up @@ -264,6 +270,7 @@ def get_export_users_emails(self, users):
"collaborations__project",
"collaborations__project__industry",
"skills__skill",
"education",
)
)
little_mans = users.filter(birthday__lte=date_limit_18)
Expand All @@ -290,7 +297,7 @@ def get_export_users_emails(self, users):
baby.first_name + " " + baby.last_name,
today.year - baby.birthday.year,
", ".join(interests),
baby.organization,
"; ".join(baby.education.values_list("organization_name", flat=True)),
baby.v2_speciality if baby.v2_speciality else baby.speciality,
baby.email,
]
Expand All @@ -306,7 +313,7 @@ def get_export_users_emails(self, users):
big_man.first_name + " " + big_man.last_name,
today.year - big_man.birthday.year,
", ".join(industry_names),
big_man.organization,
"; ".join(big_man.education.values_list("organization_name", flat=True)),
big_man.v2_speciality
if big_man.v2_speciality
else big_man.speciality,
Expand Down Expand Up @@ -370,7 +377,11 @@ class UserLanguagesAdmin(admin.ModelAdmin):
@admin.register(UserSkillConfirmation)
class UserSkillConfirmationAdmin(admin.ModelAdmin):
list_display = ("id", "get_user_and_skill", "confirmed_by", "confirmed_at")
search_fields = ("skill_to_object__skill__name", "confirmed_by__first_name", "confirmed_by__last_name")
search_fields = (
"skill_to_object__skill__name",
"confirmed_by__first_name",
"confirmed_by__last_name",
)
raw_id_fields = ("skill_to_object", "confirmed_by")
readonly_fields = ("confirmed_at",)

Expand All @@ -382,4 +393,5 @@ def get_user_and_skill(self, obj):
# Possible contingencies with attributes.
except Exception:
return ""
get_user_and_skill.short_description = 'User and Skill'

get_user_and_skill.short_description = "User and Skill"
3 changes: 1 addition & 2 deletions users/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UserFilter(filters.FilterSet):

Parameters to filter by:
first_name (str), last_name (str), patronymic (str),
city (str), region (str), organization (str), about_me__contains (str),
city (str), region (str), about_me__contains (str),
useful_to_project__contains (str)

Examples:
Expand Down Expand Up @@ -121,7 +121,6 @@ class Meta:
"patronymic",
"city",
"region",
"organization", # TODO need to be removed in future.
"user_type",
"speciality",
)
Expand Down
17 changes: 17 additions & 0 deletions users/migrations/0052_remove_customuser_organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.11 on 2024-10-25 09:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("users", "0051_alter_usereducation_options_customuser_phone_number_and_more"),
]

operations = [
migrations.RemoveField(
model_name="customuser",
name="organization",
),
]
10 changes: 1 addition & 9 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class CustomUser(AbstractUser):
status: CharField instance notifies about the user's status.
region: CharField instance the user's name region.
city: CharField instance the user's name city.
organization: CharField instance the user's place of study or work.
speciality: CharField instance the user's specialty.
datetime_updated: A DateTimeField indicating date of update.
datetime_created: A DateTimeField indicating date of creation.
Expand Down Expand Up @@ -104,13 +103,6 @@ class CustomUser(AbstractUser):
verbose_name="Номер телефона",
help_text="Пример: +7 XXX XX-XX-XX | +7XXXXXXXXX | +7 (XXX) XX-XX-XX"
)
# TODO need to be removed in future `organization` -> `education`.
organization = models.CharField(
max_length=255,
null=True,
blank=True,
help_text="Устаревшее поле -> UserEducation",
)
v2_speciality = models.ForeignKey(
on_delete=models.SET_NULL,
null=True,
Expand Down Expand Up @@ -179,7 +171,7 @@ def calculate_ordering_score(self) -> int:
if self.city:
score += 4
# TODO need to be removed in future.
if self.organization or self.education.all().exists():
if self.education.all().exists():
score += 6
if self.speciality:
score += 7
Expand Down
1 change: 0 additions & 1 deletion users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ class Meta:
"speciality",
"v2_speciality",
"v2_speciality_id",
"organization", # TODO need to be removed in future.
"education",
"work_experience",
"user_languages",
Expand Down
7 changes: 2 additions & 5 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,6 @@ def post(self, request, *args, **kwargs):
return Response(
"User with given email does not exists!", status=status.HTTP_404_NOT_FOUND
)
except Exception:
return Response(status=status.HTTP_400_BAD_REQUEST)


class ForceVerifyView(APIView):
Expand Down Expand Up @@ -614,9 +612,7 @@ def get(self, request, *args, **kwargs) -> HttpResponse:
data_preparer = UserCVDataPreparerV2(request.user.pk)
user_cv_data: UserCVDataV2 = data_preparer.get_prepared_data()

html_string: str = render_to_string(
data_preparer.TEMPLATE_PATH, user_cv_data
)
html_string: str = render_to_string(data_preparer.TEMPLATE_PATH, user_cv_data)
binary_pdf_file: bytes | None = HTML(string=html_string).write_pdf()

encoded_filename: str = urllib.parse.quote(
Expand All @@ -635,6 +631,7 @@ class UserCVMailing(APIView):
Full-fledged work `UserCVDownload`.
The user can send a letter once per minute.
"""

permission_classes = [IsAuthenticated]

def get(self, request, *args, **kwargs):
Expand Down
Loading