Repository: svthalia/concrexit

Issue:
Handle re-registrations after data minimisation
In GitLab by @se-bastiaan on Sep 19, 2018, 16:21

### One-sentence description

Handle re-registrations after data minimisation

### Why?

Because we need to minimise data and this might cause issues with renewals in ~registrations 

### Current implementation

None

### Desired implementation

Handle renewals of members of whom data was minimised by allowing them to re-enter the data.


Discussion:
In GitLab by @thomwiggers on Sep 19, 2018, 20:36

We should probably also add some 'are you trying to register while you already exist'-detection based on email addresses.
In GitLab by @se-bastiaan on Sep 19, 2018, 21:14

You mean like this? https://gitlab.science.ru.nl/thalia/concrexit/blob/master/website/registrations/models.py#L248
In GitLab by @thomwiggers on Sep 20, 2018, 10:45

Exactly, great that we already have that. Maybe we can extend it...
In GitLab by @se-bastiaan on Mar 26, 2019, 22:34

Since renewal is already possible for existing user accounts we could just add the user's information to the renewal in the admin. The responsibility of checking if the information is available is then with the board. This way we prevent over engineering this, since I do not think this will happen that often.
In GitLab by @se-bastiaan on Sep 17, 2019, 09:58

We have our first case here. User id 1073.
In GitLab by @pingiun on Dec 19, 2019, 15:03

There have been 7 cases since
In GitLab by @se-bastiaan on Feb 4, 2020, 16:15

Another 2 today. We  need to either block these renewals  or  allow them to re-enter their information
In GitLab by @se-bastiaan on Feb 4, 2020, 16:22

assigned to @se-bastiaan
@se-bastiaan is this issue still relevant? And if so is there any way to replicate it in a way to try and solve it?
> 
> 
> @se-bastiaan is this issue still relevant? And if so is there any way to replicate it in a way to try and solve it?

Yes. You can try this by:
1. Create a member via the registration route
2. Now end the membership and manually minimise the data
3. Request renewal using the account

The result should be a user that has a membership but the profile is empty.
This doesn't happen very often so I moved this to medium priority

Resolving patch:
diff --git a/website/members/models/profile.py b/website/members/models/profile.py
--- a/website/members/models/profile.py
+++ b/website/members/models/profile.py
@@ -265,6 +265,10 @@ class Profile(models.Model):
         default=False,
     )
 
+    @property
+    def is_minimised(self):
+        return self.address_city == "<removed>"
+
     def display_name(self):
         # pylint: disable=too-many-return-statements
         pref = self.display_name_preference
diff --git a/website/registrations/views.py b/website/registrations/views.py
--- a/website/registrations/views.py
+++ b/website/registrations/views.py
@@ -230,6 +230,17 @@ def get_context_data(self, **kwargs):
         context["was_member"] = Membership.objects.filter(
             user=self.request.member, type=Membership.MEMBER
         ).exists()
+
+        if (
+            self.request.member.latest_membership
+            and not self.request.member.latest_membership.is_active()
+        ) and self.request.member.profile.is_minimised:
+            messages.warning(
+                self.request,
+                _(
+                    "You seem to have been a member in the past, but your profile data has been deleted. Please contact the board to renew your membership."
+                ),
+            )
         context["benefactor_type"] = Membership.BENEFACTOR
         return context
 


Test patch:
diff --git a/website/registrations/tests/test_views.py b/website/registrations/tests/test_views.py
--- a/website/registrations/tests/test_views.py
+++ b/website/registrations/tests/test_views.py
@@ -651,6 +651,25 @@ def test_get_context_data(self):
                     context = self.view.get_context_data(form=MagicMock())
                     self.assertEqual(context["latest_renewal"], renewal)
 
+                with self.subTest("With minimised data"):
+                    with mock.patch("members.models.Profile.is_minimised") as minimised:
+                        with mock.patch(
+                            "django.contrib.messages.warning"
+                        ) as mock_messages:
+                            minimised.return_value = True
+
+                            self.view.request.member.latest_membership = MagicMock()
+                            self.view.request.member.latest_membership.is_active = (
+                                MagicMock()
+                            )
+                            self.view.request.member.latest_membership.is_active.return_value = (
+                                False
+                            )
+
+                            _ = self.view.get_context_data(form=MagicMock())
+
+                            mock_messages.assert_called_once()
+
     def test_get_form(self):
         self.view.request = self.rf.get("/")