Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
bb073734
Commit
bb073734
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-130: Allowing D-number in national ID-field
parent
a5fe0678
No related branches found
No related tags found
1 merge request
!187
GREG-130: Allow dnumber
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
greg/models.py
+1
-1
1 addition, 1 deletion
greg/models.py
greg/utils.py
+9
-1
9 additions, 1 deletion
greg/utils.py
gregui/tests/api/views/test_invitation.py
+26
-0
26 additions, 0 deletions
gregui/tests/api/views/test_invitation.py
gregui/validation.py
+6
-5
6 additions, 5 deletions
gregui/validation.py
with
42 additions
and
7 deletions
greg/models.py
+
1
−
1
View file @
bb073734
...
...
@@ -270,7 +270,7 @@ class Identity(BaseModel):
FEIDE_ID
=
"
feide_id
"
FEIDE_EMAIL
=
"
feide_email
"
PASSPORT_NUMBER
=
"
passport_number
"
# Norwegian national ID - "fødselsnummer"
# Norwegian national ID - "fødselsnummer"
or D-number
NORWEGIAN_NATIONAL_ID_NUMBER
=
"
norwegian_national_id_number
"
PRIVATE_EMAIL
=
"
private_email
"
PRIVATE_MOBILE_NUMBER
=
"
private_mobile
"
...
...
This diff is collapsed.
Click to expand it.
greg/utils.py
+
9
−
1
View file @
bb073734
...
...
@@ -9,9 +9,17 @@ def camel_to_snake(s: str) -> str:
return
re
.
sub
(
"
([A-Z])
"
,
"
_
\\
1
"
,
s
).
lower
().
lstrip
(
"
_
"
)
def
is_valid_id_number
(
input_digits
:
str
)
->
bool
:
"""
Checks whether the input represents a valid national ID number (fødselsnummer) or a valid D-number.
"""
is_dnumber
=
int
(
input_digits
[
0
:
1
])
>=
4
return
is_valid_norwegian_national_id_number
(
input_digits
,
is_dnumber
)
def
is_valid_norwegian_national_id_number
(
input_digits
:
str
,
is_dnumber
:
bool
)
->
bool
:
"""
Checks whether input_digits is a valid national ID number o
f
D-number.
Checks whether input_digits is a valid national ID number o
r
D-number.
It is based on the code found here:
https://github.com/navikt/fnrvalidator/blob/master/src/validator.js
...
...
This diff is collapsed.
Click to expand it.
gregui/tests/api/views/test_invitation.py
+
26
−
0
View file @
bb073734
...
...
@@ -467,3 +467,29 @@ def test_saves_consents(client, invited_person, consent_type_foo, consent_type_b
type
=
consent_type_bar
,
choice
=
consent_type_bar
.
choices
.
filter
(
value
=
"
yes
"
).
first
(),
).
exists
()
@pytest.mark.django_db
def
test_post_invited_info_valid_dnumber
(
client
,
invited_person
):
person
,
invitation_link
=
invited_person
d_number
=
"
53097248016
"
data
=
{
"
person
"
:
{
"
mobile_phone
"
:
"
+4797543992
"
,
"
email
"
:
"
test@example.com
"
,
"
fnr
"
:
d_number
,
}
}
url
=
reverse
(
"
gregui-v1:invited-info
"
)
assert
person
.
fnr
is
None
session
=
client
.
session
session
[
"
invite_id
"
]
=
str
(
invitation_link
.
uuid
)
session
.
save
()
response
=
client
.
post
(
url
,
data
,
format
=
"
json
"
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
,
response
.
data
person
.
refresh_from_db
()
assert
person
.
fnr
.
value
==
d_number
This diff is collapsed.
Click to expand it.
gregui/validation.py
+
6
−
5
View file @
bb073734
...
...
@@ -3,16 +3,17 @@ from typing import Optional
import
phonenumbers
from
rest_framework
import
serializers
from
greg.utils
import
is_valid_
norwegian_national_
id_number
from
greg.utils
import
is_valid_id_number
_valid_email_regex
=
r
"
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
"
def
validate_norwegian_national_id_number
(
value
):
# Not excepted that D-numbers will be entered through the form, so only
# accept national ID numbers
if
not
is_valid_norwegian_national_id_number
(
value
,
False
):
raise
serializers
.
ValidationError
(
"
Not a valid Norwegian national ID number
"
)
"""
Both fødselsnummer and D-nummer are accepted
"""
if
not
is_valid_id_number
(
value
):
raise
serializers
.
ValidationError
(
"
Not a valid ID number
"
)
def
validate_phone_number
(
value
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment