diff --git a/greg/models.py b/greg/models.py index 1f3b6c4fb9ee2938067d992fda2cbb87f311e72f..a7ad8f959b8e1fc1607419c7f7ac241db868abc7 100644 --- a/greg/models.py +++ b/greg/models.py @@ -80,7 +80,8 @@ class Person(BaseModel): @property def passport(self) -> Optional["Identity"]: """The person's passport if they have one registered. - This property was introduced to make updating of passport easier when the guest registers himself.""" + This property was introduced to make updating of passport easier when the guest registers himself. + """ return self.identities.filter( type=Identity.IdentityType.PASSPORT_NUMBER ).first() diff --git a/greg/tests/api/test_person.py b/greg/tests/api/test_person.py index 6d38d206532e70bc84ed27ccf92716f1829eae15..1259654948d9203ac4d9bb7eaf460b10d7796d74 100644 --- a/greg/tests/api/test_person.py +++ b/greg/tests/api/test_person.py @@ -544,7 +544,6 @@ def test_filter_role_type( sponsor_guy: Sponsor, unit_foo: OrganizationalUnit, ): - date_today = datetime.date.today() best_test_guest = RoleType.objects.create( diff --git a/greg/utils.py b/greg/utils.py index fa61a818f4ddfd303c34f85df281607b15ad4384..bc108f354af6f8aefe306b0022f2a46345e9b92a 100644 --- a/greg/utils.py +++ b/greg/utils.py @@ -171,9 +171,7 @@ def create_objects_for_invitation( role_data: dict, sponsor: typing.Union[Sponsor, str], ) -> Person: - with transaction.atomic(): - # If only sponsor's feide_id is provided create the sponsor if isinstance(sponsor, str): sponsor = Sponsor.objects.create(feide_id=sponsor) diff --git a/gregui/api/serializers/guest.py b/gregui/api/serializers/guest.py index ca63e30dc54bc0067a454cf3a84ca7818990ab87..851adcf6045ca564d1453c372d311baa525b9e7e 100644 --- a/gregui/api/serializers/guest.py +++ b/gregui/api/serializers/guest.py @@ -331,7 +331,6 @@ class FrontPageGuestSerializer(serializers.ModelSerializer): def get_invitation_status( self, obj: Person ) -> Literal["active", "expired", "invalidEmail", "none"]: - private_email = next( iter( [ diff --git a/gregui/api/views/identity.py b/gregui/api/views/identity.py index 1d9bf805fcae967cf19d732724b5d370fd80950f..e9593e82249da8927468f42ddf43c7fa36c1fd67 100644 --- a/gregui/api/views/identity.py +++ b/gregui/api/views/identity.py @@ -36,7 +36,6 @@ class IdentityViewSet( class IdentityCheckView(APIView): - authentication_classes = [SessionAuthentication, BasicAuthentication] permission_classes = [IsAuthenticated, IsSponsor] diff --git a/gregui/authentication/auth_backends.py b/gregui/authentication/auth_backends.py index ac0942ccee7e8e57042c9f9d5faae7c090ae1fbb..f23e4b640b5d6964ddf7e50e0d91a8639e363672 100644 --- a/gregui/authentication/auth_backends.py +++ b/gregui/authentication/auth_backends.py @@ -83,7 +83,6 @@ ID_REGEX = re.compile(r"^(?P<id_type>[^:]+):(?P<id_value>.+)$") def extract_userinfo(claims: dict) -> dict: - ids = [x.split(":")[0] for x in claims["dataporten-userid_sec"] if ":" in x] if len(ids) == 1 and "nin" in ids: # IDPorten login @@ -481,7 +480,6 @@ class GregOIDCBackend(ValidatingOIDCBackend): def _update_person_name( self, person: Person, first_name: str, last_name: str ) -> None: - new_combined_name = f"{first_name} {last_name}" existing_combined_name = f"{person.first_name} {person.last_name}" @@ -533,7 +531,6 @@ class GregOIDCBackend(ValidatingOIDCBackend): def _update_user_profile( self, userinfo: dict, user_profile: GregUserProfile, person: Person ) -> GregUserProfile: - sponsor = self._get_sponsor_from_userinfo(userinfo) self._update_sponsor_from_userinfo(userinfo, sponsor) @@ -554,7 +551,6 @@ class GregOIDCBackend(ValidatingOIDCBackend): def _create_user_profile( self, userinfo: dict, user: UserModel, person: Person ) -> GregUserProfile: - sponsor = self._get_sponsor_from_userinfo(userinfo) self._update_sponsor_from_userinfo(userinfo, sponsor) diff --git a/gregui/migrations/0001_initial.py b/gregui/migrations/0001_initial.py index 71c6ce2c6726236ccbae48a8ac159789e5433802..8b922888d1ed0a06d11346b1794384dbb70e0fc4 100644 --- a/gregui/migrations/0001_initial.py +++ b/gregui/migrations/0001_initial.py @@ -7,7 +7,6 @@ import django.db.models.deletion class Migration(migrations.Migration): - initial = True dependencies = [ diff --git a/gregui/migrations/0002_emailtemplate.py b/gregui/migrations/0002_emailtemplate.py index 15c4b7b6a3c3b1fe58631cb3b613f54d40eb736e..568fe1534fb584e2e8b9dad0cbf416d45540c75a 100644 --- a/gregui/migrations/0002_emailtemplate.py +++ b/gregui/migrations/0002_emailtemplate.py @@ -5,7 +5,6 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ ("gregui", "0001_initial"), ] diff --git a/gregui/migrations/0003_add_email_template_type.py b/gregui/migrations/0003_add_email_template_type.py index 77800099eaf10265dbe61fcc9dadcc01b5bc9669..efe5078c2351019e7127df6d144e7cb3898a9843 100644 --- a/gregui/migrations/0003_add_email_template_type.py +++ b/gregui/migrations/0003_add_email_template_type.py @@ -4,7 +4,6 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ ("gregui", "0002_emailtemplate"), ] diff --git a/gregui/migrations/0004_add_email_template_type.py b/gregui/migrations/0004_add_email_template_type.py index 4c3c0fce2fb94fc5a91010b5cef2e41496aa38ca..ec99d25fcb661618d89e02b476ffede6ac62ec2d 100644 --- a/gregui/migrations/0004_add_email_template_type.py +++ b/gregui/migrations/0004_add_email_template_type.py @@ -4,7 +4,6 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ ("gregui", "0003_add_email_template_type"), ] diff --git a/gregui/tests/conftest.py b/gregui/tests/conftest.py index 9ab9da81169ef3c4df5e22b5a9c1c3840da3f828..0ba81984fc7e000e747b88c3d7edf85cb48cc711 100644 --- a/gregui/tests/conftest.py +++ b/gregui/tests/conftest.py @@ -252,9 +252,9 @@ def user_person(person_foo: Sponsor, create_user) -> User: @pytest.fixture -def create_greg_user_profile() -> Callable[ - [UserModel, Optional[Person], Optional[Sponsor]], GregUserProfile -]: +def create_greg_user_profile() -> ( + Callable[[UserModel, Optional[Person], Optional[Sponsor]], GregUserProfile] +): user_model = get_user_model() def create_greg_user_profile( @@ -364,9 +364,20 @@ def invitation_link_expired( @pytest.fixture -def create_person() -> Callable[ - [str, str, str, Optional[str], Optional[str], Optional[str], Optional[datetime.date]], Person -]: +def create_person() -> ( + Callable[ + [ + str, + str, + str, + Optional[str], + Optional[str], + Optional[str], + Optional[datetime.date], + ], + Person, + ] +): # TODO fix the typing... def create_person( first_name: str, diff --git a/iga/tests/test_uib.py b/iga/tests/test_uib.py index d6c57f347c86ce994aaf7b628bcbc58fb453d918..a666aa540663194f6cd466a04e54a937ca98bf89 100644 --- a/iga/tests/test_uib.py +++ b/iga/tests/test_uib.py @@ -5,55 +5,40 @@ from ..iga import IgaPerson from ..uib import UibRiScim UIB_SEARCH = { - "schemas": [ - "urn:ietf:params:scim:api:messages:2.0:ListResponse" - ], - "totalResults": 1, - "startIndex": 1, - "itemsPerPage": 1, - "Resources": [ - { - "schemas": [ - "urn:ietf:params:scim:schemas:core:2.0:User", - "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", - "no:edu:scim:user" - ], - "id": "", - "externalId": "", - "userName": "", - "displayName": "Ruth Pedersen", - "profileUrl": "", - "title": "", - "userType": "Employee", - "preferredLanguage": None, - "active": True, - "emails": [ + "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], + "totalResults": 1, + "startIndex": 1, + "itemsPerPage": 1, + "Resources": [ { - "value": "", - "type": "work" + "schemas": [ + "urn:ietf:params:scim:schemas:core:2.0:User", + "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", + "no:edu:scim:user", + ], + "id": "", + "externalId": "", + "userName": "", + "displayName": "Ruth Pedersen", + "profileUrl": "", + "title": "", + "userType": "Employee", + "preferredLanguage": None, + "active": True, + "emails": [{"value": "", "type": "work"}], + "phoneNumbers": [], + "roles": [{"value": "iam:employee"}, {"value": "iam:operation"}], + "no:edu:scim:user": { + "accountType": "primary", + "employeeNumber": "102160", + "eduPersonPrincipalName": "ruped001@uib.no", + "userPrincipalName": "Ruth.Pedersen@uibtest.no", + }, } - ], - "phoneNumbers": [], - "roles": [ - { - "value": "iam:employee" - }, - { - "value": "iam:operation" - } - ], - "no:edu:scim:user": { - "accountType": "primary", - "employeeNumber": "102160", - "eduPersonPrincipalName": "ruped001@uib.no", - "userPrincipalName": "Ruth.Pedersen@uibtest.no", - }, - } - ] + ], } - def test_uib_search(requests_mock): """Regular search works as expected""" uib_search_wname = copy.deepcopy(UIB_SEARCH) diff --git a/iga/uib.py b/iga/uib.py index 2e923e8f33b5897e23e3614b5a8a583b5b320357..a4cebe394a785138c1f5a0fa01e125486318a6c9 100644 --- a/iga/uib.py +++ b/iga/uib.py @@ -15,15 +15,19 @@ class UibRiScim(IgaImplementation): self.client: IgaClient = IgaAbstract.get_iga_client( "scim-ri@uib", endpoints={"base_url": config["url"]}, - headers=config["headers"]) + headers=config["headers"], + ) self.idtype_methodmap = { Identity.IdentityType.NORWEGIAN_NATIONAL_ID_NUMBER: lambda nor_edu_person_nin: self.client.client( - user_query_request(extra_parameters={"norEduPersonNIN": nor_edu_person_nin})).payload, + user_query_request( + extra_parameters={"norEduPersonNIN": nor_edu_person_nin} + ) + ).payload, Identity.IdentityType.PASSPORT_NUMBER: None, # not supported by uib scim } def extid_search( - self, id_type: Identity.IdentityType, extid: str + self, id_type: Identity.IdentityType, extid: str ) -> Optional[IgaPerson]: search = self.idtype_methodmap.get(id_type) @@ -35,12 +39,16 @@ class UibRiScim(IgaImplementation): if len(user.resources) > 1: # Not expected that this should happen - logger.warning("Multiple hits found when searching in RI SCIM for {}".format(extid)) + logger.warning( + "Multiple hits found when searching in RI SCIM for {}".format(extid) + ) # Return the first user found return IgaPerson( - first=user.resources[0].name.given_name if user.resources[0].name and user.resources[ - 0].name.given_name else None, - last=user.resources[0].name.family_name if user.resources[0].name and user.resources[ - 0].name.family_name else None, + first=user.resources[0].name.given_name + if user.resources[0].name and user.resources[0].name.given_name + else None, + last=user.resources[0].name.family_name + if user.resources[0].name and user.resources[0].name.family_name + else None, )