Repository: svthalia/concrexit

Issue:
Hyperlink of "display [event] on website" button always refers to thalia.nu (also on staging)
In GitLab by @JobDoesburg on Dec 4, 2019, 19:26

### One-sentence description

Hyperlink of "display [event] on website" button 
is hardcoded
 always refers to thalia.nu (also on staging)
### Current behaviour / Reproducing the bug

<!-- Please write what is happening and how we could reproduce it, if relevant -->

At staging.thalia.nu, the action button "display on website" (in the events admin) refers to thalia.nu


### Expected behaviour

Be a relative url (to staging.thalia.nu)


Discussion:
In GitLab by @se-bastiaan on Dec 4, 2019, 20:10

Could you change the issue to reflect that this is not really hardcoded (at)jdoesburg? Since you apparently already found that out.
In GitLab by @se-bastiaan on Dec 4, 2019, 20:11

This is the actual response of one such buttons:
```
GET - https://staging.thalia.nu/admin/r/43/42/

HTTP/2.0 302 Found
server: nginx/1.14.0 (Ubuntu)
date: Wed, 04 Dec 2019 18:52:25 GMT
content-type: text/html; charset=utf-8
content-length: 0
location: https://thalia.nu/events/42/
expires: Wed, 04 Dec 2019 18:52:25 GMT
cache-control: max-age=0, no-cache, no-store, must-revalidate
vary: Accept-Language, Cookie
content-language: en
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
strict-transport-security: max-age=63072000; includeSubDomains; preload
feature-policy: camera 'none'; vr 'none'; camera 'none'; accelerometer 'none'; gyroscope 'none'
referrer-policy: strict-origin
expect-ct: max-age=604800
```
In GitLab by @JobDoesburg on Dec 4, 2019, 20:11

You did, I didn't
In GitLab by @se-bastiaan on Jan 25, 2020, 21:48

This is also the case for localhost

```
GET - http://localhost:8000/admin/r/57/2/

HTTP/1.1 302 Found
Date: Sat, 25 Jan 2020 20:48:16 GMT
Server: WSGIServer/0.2 CPython/3.7.1
Content-Type: text/html; charset=utf-8
Location: http://thalia.nu/education/courses/2/
Expires: Sat, 25 Jan 2020 20:48:16 GMT
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
Vary: Accept-Language, Cookie
Content-Language: en
Content-Length: 0
X-Content-Type-Options: nosniff
```
In GitLab by @se-bastiaan on Jan 25, 2020, 22:05

So the actual reason is the Django sites framework. https://docs.djangoproject.com/en/3.0/ref/contrib/sites/
Since we insert the default site in [a migration](https://gitlab.science.ru.nl/thalia/concrexit/blob/master/website%2Fthaliawebsite%2Fmigrations%2F0001_initial.py) and define `SITE_ID` in settings the url is set for every environment.
In GitLab by @se-bastiaan on Jan 25, 2020, 22:36

We could remove the database model and content type. Then migrate `thaliawebsite` to `zero` so that we can remove the complete app from `INSTALLED_APPS`. Which has my preference over setting the domain to a different value for every  environment or just keeping it like it is now. Especially since we do not use this functionality. What do you think?

Resolving patch:
diff --git a/website/thaliawebsite/migrations/0001_initial.py b/website/thaliawebsite/migrations/0001_initial.py
deleted file mode 100644
--- a/website/thaliawebsite/migrations/0001_initial.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by Django 1.10 on 2016-08-17 18:15
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-def insert_sites(apps, schema_editor):
-    """Populate the sites model"""
-    Site = apps.get_model('sites', 'Site')
-
-    Site.objects.create(domain='thalia.nu', name='thalia')
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('sites', '0001_initial'),
-    ]
-
-    operations = [
-        migrations.RunPython(insert_sites)
-    ]
diff --git a/website/thaliawebsite/migrations/__init__.py b/website/thaliawebsite/migrations/__init__.py
deleted file mode 100644
diff --git a/website/thaliawebsite/settings/settings.py b/website/thaliawebsite/settings/settings.py
--- a/website/thaliawebsite/settings/settings.py
+++ b/website/thaliawebsite/settings/settings.py
@@ -37,7 +37,6 @@
 if not DEBUG:  # Django 1.10.3 security release changed behaviour
     ALLOWED_HOSTS = ["*"]
 
-SITE_ID = 1
 SITE_DOMAIN = os.environ.get("SITE_DOMAIN", "thalia.localhost")
 BASE_URL = f"https://{SITE_DOMAIN}"
 
@@ -52,7 +51,6 @@
     "django.contrib.sessions",
     "django.contrib.messages",
     "django.contrib.staticfiles",
-    "django.contrib.sites",
     "django.contrib.sitemaps",
     # Dependencies
     "bootstrap4",


Test patch: