summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/tests.py29
-rw-r--r--ishtar_common/forms_common.py1
-rw-r--r--ishtar_common/models.py3
-rw-r--r--ishtar_common/wizards.py6
4 files changed, 38 insertions, 1 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index bfd2a162b..18d927d06 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -3767,6 +3767,20 @@ class OperationPermissionTest(TestCase, TestPermissionRequest, OperationInitTest
)
# nosec: hard coded password for test purposes
+ asso_date_username, asso_date_password, asso_date_user = create_user( # nosec
+ username="darth", password="maul"
+ )
+ self.profile_date = UserProfile.objects.create(
+ profile_type=self.profile_types["ope_associated_items"],
+ person=asso_date_user.ishtaruser.person,
+ expiration_date=datetime.date.today(),
+ current=True,
+ )
+ self.users["asso_date"] = (
+ asso_date_username, asso_date_password, asso_date_user
+ )
+
+ # nosec: hard coded password for test purposes
areas_username, areas_password, areas_user = create_user( # nosec
username="luke", password="iamyourfather"
)
@@ -3882,6 +3896,21 @@ class OperationPermissionTest(TestCase, TestPermissionRequest, OperationInitTest
)
self.assertEqual(json.loads(response.content.decode())["recordsTotal"], 1)
+ asso_date_username, asso_date_password, asso_date_user = self.users["asso_date"]
+ self.operations[1].ishtar_users.add(asso_date_user.ishtaruser)
+ asso_date_user.ishtaruser.generate_permission()
+ c = Client()
+ c.login(username=asso_date_username, password=asso_date_password)
+ response = c.get(reverse("get-operation"), {"year": "2010"})
+ self.assertTrue(json.loads(response.content.decode()))
+ self.assertEqual(json.loads(response.content.decode())["recordsTotal"], 1)
+
+ self.profile_date.expiration_date = datetime.date.today() - datetime.timedelta(days=1)
+ self.profile_date.save()
+ asso_date_user.ishtaruser.generate_permission()
+ response = c.get(reverse("get-operation"), {"year": "2010"})
+ self.assertFalse(json.loads(response.content.decode()))
+
def test_own_modify(self):
operation_pk1 = self.operations[0].pk
operation_pk2 = self.operations[1].pk
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 22e23f3ca..734707419 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1576,6 +1576,7 @@ class ProfileForm(ManageOldType):
profile_type = forms.ChoiceField(label=_("Type"), choices=[])
area = widgets.Select2MultipleField(label=_("Areas"), required=False)
name = forms.CharField(label=_("Name"), required=False)
+ expiration_date = DateField(label=_("Expiration date"), required=False)
pk = forms.IntegerField(label=" ", widget=forms.HiddenInput, required=False)
TYPES = [
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index e1bf3bd33..bf2cd666a 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3611,6 +3611,9 @@ class UserProfile(models.Model):
def generate_permission(self, content_type, permission_type):
ishtar_user = self.person.ishtaruser
+ if self.expiration_date and self.expiration_date < datetime.date.today():
+ return
+
# add base permissions
for group in self.profile_type.groups.all():
for perm in group.permissions.filter(
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 1da9b9f4d..697c51156 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -2120,13 +2120,17 @@ class AccountWizard(Wizard):
if not name:
name = profile_type.label
+ expiration_date = data.get("expiration_date", None)
+
if profile:
profile.name = name
profile.profile_type = profile_type
+ profile.expiration_date = expiration_date
profile.save()
else:
profile, __ = models.UserProfile.objects.get_or_create(
- profile_type=profile_type, person=person, name=name
+ profile_type=profile_type, person=person, name=name,
+ expiration_date=expiration_date
)
area_pks = data.get("area", None)
areas = []