-
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (39 loc) · 1.72 KB
/
utils.py
File metadata and controls
48 lines (39 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
from django.core.exceptions import ObjectDoesNotExist
from swapper import load_model
from .. import settings as app_settings
logger = logging.getLogger(__name__)
Organization = load_model("openwisp_users", "Organization")
OrganizationRadiusSettings = load_model("openwisp_radius", "OrganizationRadiusSettings")
RegisteredUser = load_model("openwisp_radius", "RegisteredUser")
class ErrorDictMixin(object):
def _get_error_dict(self, error):
dict_ = error.message_dict.copy()
if "__all__" in dict_:
dict_["non_field_errors"] = dict_.pop("__all__")
return dict_
class IDVerificationHelper(object):
def _needs_identity_verification(self, organization_filter_kwargs={}, org=None):
try:
if not org:
org = Organization.objects.select_related("radius_settings").get(
**organization_filter_kwargs
)
return org.radius_settings.needs_identity_verification
except ObjectDoesNotExist:
return app_settings.NEEDS_IDENTITY_VERIFICATION
def is_identity_verified_strong(self, user, organization=None):
reg_user = None
global_reg_user = None
# We use all() to utilize the prefetch cache, otherwise
# it would cause an additional query to fetch the registered user
for ru in user.registered_users.all():
if organization and ru.organization_id == organization.pk:
reg_user = ru
break
elif ru.organization_id is None:
global_reg_user = ru
reg_user = reg_user or global_reg_user
if reg_user is None:
return False
return reg_user.is_identity_verified_strong