Skip to content

Commit 47756c0

Browse files
authored
Merge pull request #224 from PROCOLLAB-github/feature/force-verify
Add /force_verify/ route
2 parents 7e02008 + 1439a84 commit 47756c0

5 files changed

Lines changed: 77 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 4.2.3 on 2023-10-27 06:48
2+
3+
from django.db import migrations, models
4+
import mailing.constants
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("mailing", "0006_alter_mailingschema_schema_and_more"),
11+
]
12+
13+
operations = [
14+
migrations.AlterModelOptions(
15+
name="mailingschema",
16+
options={
17+
"verbose_name": "Схема шаблона письма",
18+
"verbose_name_plural": "Схемы шаблонов писем",
19+
},
20+
),
21+
migrations.AlterField(
22+
model_name="mailingschema",
23+
name="schema",
24+
field=models.JSONField(
25+
blank=True,
26+
default=mailing.constants.get_default_mailing_schema,
27+
null=True,
28+
),
29+
),
30+
]

users/helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ def update_links(links, pk):
8787
for link in links
8888
]
8989
)
90+
91+
92+
def force_verify_user(user: User) -> None:
93+
if user.is_active:
94+
return
95+
96+
# todo: send email
97+
user.is_active = True
98+
user.save()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 4.2.3 on 2023-10-27 06:48
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("users", "0040_alter_customuser_user_type_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name="customuser",
15+
options={
16+
"ordering": ["-ordering_score", "id"],
17+
"verbose_name": "Пользователь",
18+
"verbose_name_plural": "Пользователи",
19+
},
20+
),
21+
]

users/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ResendVerifyEmail,
1919
CurrentUserPrograms,
2020
CurrentUserProgramsTags,
21+
ForceVerifyView,
2122
)
2223

2324
app_name = "users"
@@ -33,6 +34,7 @@
3334
path("users/types/", UserTypesView.as_view()),
3435
path("users/<int:pk>/", UserDetail.as_view()),
3536
path("users/<int:pk>/set_onboarding_stage/", SetUserOnboardingStage.as_view()),
37+
path("users/<int:pk>/force_verify/", ForceVerifyView.as_view()),
3638
path("users/current/", CurrentUser.as_view()),
3739
# todo: change password view
3840
path("users/current/programs/", CurrentUserPrograms.as_view()),

users/views.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.db.models import Q
77
from django.shortcuts import redirect
88
from django_filters import rest_framework as filters
9-
from rest_framework import status
9+
from rest_framework import status, permissions
1010
from rest_framework.generics import (
1111
GenericAPIView,
1212
ListAPIView,
@@ -32,6 +32,7 @@
3232
from users.helpers import (
3333
verify_email,
3434
check_related_fields_update,
35+
force_verify_user,
3536
)
3637
from users.constants import (
3738
VERBOSE_ROLE_TYPES,
@@ -348,3 +349,16 @@ def post(self, request, *args, **kwargs):
348349
)
349350
except Exception:
350351
return Response(status=status.HTTP_400_BAD_REQUEST)
352+
353+
354+
class ForceVerifyView(APIView):
355+
queryset = User.objects.get_users_for_detail_view()
356+
permission_classes = [permissions.IsAdminUser]
357+
358+
def post(self, request, *args, **kwargs):
359+
try:
360+
user = User.objects.get(pk=kwargs["pk"])
361+
force_verify_user(user)
362+
return Response(status=status.HTTP_200_OK)
363+
except User.DoesNotExist:
364+
return Response(status=status.HTTP_404_NOT_FOUND)

0 commit comments

Comments
 (0)