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

Hide deleted units from view

parent ea0ea869
No related branches found
No related tags found
1 merge request!384Hide deleted units from view
Pipeline #179445 passed
......@@ -643,7 +643,7 @@ class Sponsor(BaseModel):
models.UniqueConstraint(name="unique_feide_id", fields=["feide_id"])
]
def get_allowed_units(self) -> set[OrganizationalUnit]:
def get_allowed_units(self) -> list[OrganizationalUnit]:
"""
Fetch every unit the sponsor has access to.
......@@ -659,7 +659,10 @@ class Sponsor(BaseModel):
# Add units accessible through direct access
units = units.union({i.organizational_unit for i in connections})
return units
# Remove units that are deleted
units_filtered = [unit for unit in units if not unit.deleted]
return units_filtered
class SponsorOrganizationalUnit(BaseModel):
......
......@@ -41,7 +41,7 @@ def notify_sponsors_roles_ending() -> list[str]:
# Map sponsors with email to units
sponsors = Sponsor.objects.filter(work_email__isnull=False)
sp2unit = {s.id: list(s.get_allowed_units()) for s in sponsors}
sp2unit = {s.id: s.get_allowed_units() for s in sponsors}
# Map sponsors to ending roles
# Make sure only the sponsor(s) closest to the role is notified
......
......@@ -81,9 +81,20 @@ def test_get_allowed(sponsor_foo, unit1, unit2):
unit2.save()
# Without hier access only get unit connected to
assert sponsor_foo.get_allowed_units() == {unit1}
assert sponsor_foo.get_allowed_units() == [unit1]
# With hier access also get units below
spu.hierarchical_access = True
spu.save()
assert sponsor_foo.get_allowed_units() == {unit1, unit2}
assert sponsor_foo.get_allowed_units() == [unit1, unit2]
# Don't get deleted units
unit2.deleted = True
unit2.save()
assert sponsor_foo.get_allowed_units() == [unit1]
unit2.deleted = False
unit1.deleted = True
unit2.save()
unit1.save()
assert sponsor_foo.get_allowed_units() == [unit2]
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