Skip to content
Snippets Groups Projects
Commit 14627379 authored by Marte Fossum's avatar Marte Fossum
Browse files

Merge branch 'GREG-296-handle-so-number' into 'master'

Add support for SO numbers

See merge request !351
parents 82141a96 1fdfee85
No related branches found
No related tags found
1 merge request!351Add support for SO numbers
Pipeline #161518 passed
......@@ -587,7 +587,7 @@ const GuestRegisterStep = forwardRef(
rules={{
// It is not required that the Norwegian national ID number be filled in, the guest may not have
// one, so allow empty values for the validation to pass. Note that both "fødselsnummer" and
// D-number are allowed as input
// D-number are allowed as input, and in some cases SO-number
validate: (value) => isValidFnr(value, true),
}}
render={({ field }) => (
......
from django.conf import settings
from greg.utils import is_valid_id_number, is_valid_so_number
def test_so_number():
so_number = "25529312345"
settings.ALLOW_SO_NUMBERS = True
assert is_valid_id_number(so_number)
assert is_valid_so_number(so_number)
def test_not_allow_so_number():
so_number = "25529312345"
settings.ALLOW_SO_NUMBERS = False
assert not is_valid_id_number(so_number)
assert not is_valid_so_number(so_number)
def test_not_valid_so_number():
so_number = "25529322345"
settings.ALLOW_SO_NUMBERS = True
assert not is_valid_id_number(so_number)
assert not is_valid_so_number(so_number)
......@@ -14,10 +14,35 @@ def camel_to_snake(s: str) -> str:
def is_valid_id_number(input_digits: str) -> bool:
"""
Checks whether the input represents a valid Norwegian national ID number (fødselsnummer) or a valid D-number.
Checks whether the input represents a valid national ID number (fødselsnummer), a valid D-number
or a valid SO-number.
"""
is_dnumber = int(input_digits[0:1]) >= 4
return is_valid_norwegian_national_id_number(input_digits, is_dnumber)
return is_valid_norwegian_national_id_number(
input_digits, is_dnumber
) or is_valid_so_number(input_digits)
def is_valid_so_number(input_digits: str) -> bool:
"""
Checks if SO numbers are allowed and if so, check that it is valid.
"""
if not settings.ALLOW_SO_NUMBERS:
return False
SO_NUMBER = False
day, month, year, pnr = (
input_digits[0:2],
int(input_digits[2:4]),
input_digits[4:6],
input_digits[6:],
)
if pnr[0] != "1":
return False
if month > 50:
SO_NUMBER = True
month_str = _check_month(month)
input_digits = day + month_str + year + pnr
return SO_NUMBER and _check_birthdate(input_digits, is_dnumber=False)
def is_valid_norwegian_national_id_number(input_digits: str, is_dnumber: bool) -> bool:
......@@ -63,6 +88,13 @@ def _check_birthdate(digits: str, is_dnumber: bool) -> bool:
return True
def _check_month(month: int) -> str:
month -= 50
if month < 10:
return "0" + str(month)
return str(month)
def _compute_checksum(input_digits: str) -> bool:
d = [int(s) for s in input_digits]
k1 = 11 - (
......
......@@ -352,3 +352,5 @@ IGA_CLIENT = {
"url": "http://example.com/cerebrum/",
"headers": {"X-Gravitee-Api-Key": "<KEY>"},
}
ALLOW_SO_NUMBERS = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment