aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/home/apps.py
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-10-18 12:34:09 +0200
committerGravatar Sebastiaan Zeeff <[email protected]>2019-10-18 12:34:09 +0200
commit6670a3ba48dad0b2e6e79d77d780c5ee77773e3e (patch)
tree30fdc507353e902f194fa84bfcb7516ea72903fd /pydis_site/apps/home/apps.py
parentPrevent double active infractions with constraint (diff)
parentAdd Code of Conduct to navbar submenu (diff)
Merge branch 'master' into active-infractions-validation
Diffstat (limited to 'pydis_site/apps/home/apps.py')
-rw-r--r--pydis_site/apps/home/apps.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/pydis_site/apps/home/apps.py b/pydis_site/apps/home/apps.py
index 9a3d213c..55a393a9 100644
--- a/pydis_site/apps/home/apps.py
+++ b/pydis_site/apps/home/apps.py
@@ -1,7 +1,38 @@
+from typing import Any, Dict
+
from django.apps import AppConfig
class HomeConfig(AppConfig):
"""Django AppConfig for the home app."""
- name = 'home'
+ name = 'pydis_site.apps.home'
+ signal_listener = None
+
+ def ready(self) -> None:
+ """Run when the app has been loaded and is ready to serve requests."""
+ from pydis_site.apps.home.signals import AllauthSignalListener
+
+ self.signal_listener = AllauthSignalListener()
+ self.patch_allauth()
+
+ def patch_allauth(self) -> None:
+ """Monkey-patches Allauth classes so we never collect email addresses."""
+ # Imported here because we can't import it before our apps are loaded up
+ from allauth.socialaccount.providers.base import Provider
+
+ def extract_extra_data(_: Provider, data: Dict[str, Any]) -> Dict[str, Any]:
+ """
+ Extracts extra data for a SocialAccount provided by Allauth.
+
+ This is our version of this function that strips the email address from incoming extra
+ data. We do this so that we never have to store it.
+
+ This is monkey-patched because most OAuth providers - or at least the ones we care
+ about - all use the function from the base Provider class. This means we don't have
+ to make a new Django app for each one we want to work with.
+ """
+ data["email"] = ""
+ return data
+
+ Provider.extract_extra_data = extract_extra_data