Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/armada-ths/ais into ferra…
Browse files Browse the repository at this point in the history
…n/f/redisign-register-armada-nu
  • Loading branch information
ferran98campos committed Jul 11, 2023
2 parents e469789 + d6059bf commit 4f0e010
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 182 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/pr-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ jobs:
with:
options: "--check"
src: "."
validate_title:
name: Title should have valid prefix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Slashgear/[email protected]
with:
regexp: "^(feat|fix|chore|refactor|doc|pipeline): .*$"
helpMessage: "Example: 'feat: example of title'"
check_pull_requests:
name: Require one linked issue
runs-on: ubuntu-latest
Expand Down
48 changes: 48 additions & 0 deletions ais/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"journal",
"markupfield",
"testpage",
"kth_login",
"raven.contrib.django.raven_compat",
)

MIDDLEWARE = [
Expand All @@ -76,6 +78,17 @@

AUTHENTICATION_BACKENDS = ("django.contrib.auth.backends.ModelBackend",)

DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": os.environ.get("DB_NAME", "ais_dev"),
"USER": os.environ.get("DB_USER", "ais_dev"),
"PASSWORD": os.environ.get("DB_PASSWORD", "ais_dev"),
"HOST": os.environ.get("DB_HOST", "127.0.0.1"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
Expand Down Expand Up @@ -119,3 +132,38 @@
USE_L10N = False
DATE_FORMAT = "M j, Y"
DATETIME_FORMAT = "M j, Y, H:i"

# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_TO_EMAIL = "[email protected]"
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = os.environ.get("DUMMY", "dummy")
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

SALES_HOOK_URL = (
"https://hooks.slack.com/services/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"
)
RECRUITMENT_HOOK_URL = (
"https://hooks.slack.com/services/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"
)

# This is for AUTHLIB package for interacting with KTH OpenID Connect
# APPLICATION_ID is given from the 'secrets.py' file.
# CLIENT_SECRET is given from the 'secrets.py' file.
AUTHLIB_OAUTH_CLIENTS = {
"kth": {
"client_id": os.environ.get("APPLICATION_ID"),
"client_secret": os.environ.get("CLIENT_SECRET"),
"api_base_url": "https://login.ug.kth.se/adfs/oauth2/",
}
}
LOGOUT_REDIRECT_URL = "/"

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
AWS_STORAGE_BUCKET_NAME = "armada-ais-files"
58 changes: 2 additions & 56 deletions ais/local/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
and is generally easier to work with.
"""

import os
from ais.common.settings import *

# Debug mode gives us helpful error messages when a server error
Expand All @@ -17,69 +16,16 @@
ALLOWED_HOSTS = ["*"]
CORS_ORIGIN_ALLOW_ALL = True

# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_TO_EMAIL = "[email protected]"
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = os.environ.get("DUMMY", "dummy")
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

ROOT_URLCONF = "ais.local.urls"

# Use KTH OpenID Connect for authentication
INSTALLED_APPS += (
"kth_login",
"raven.contrib.django.raven_compat",
)

# Stripe test keys
STRIPE_SECRET = "sk_test_l4sPsGIoc2f8sD5N4D2fZkBY"
STRIPE_PUBLISHABLE = "pk_test_IzgUj9oJhednbt4EIf78esBE"

# We don't need performance here so use SQLite for ease of setup.
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": os.environ.get("DB_NAME", "ais_dev"),
"USER": os.environ.get("DB_USER", "ais_dev"),
"PASSWORD": os.environ.get("DB_PASSWORD", "ais_dev"),
"HOST": os.environ.get("DB_HOST", "127.0.0.1"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}

SALES_HOOK_URL = (
"https://hooks.slack.com/services/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"
)
RECRUITMENT_HOOK_URL = (
"https://hooks.slack.com/services/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"
)

# Always use the same secret key so we can resume sessions after
# restarting the server. Again, this is a serious security flaw
# if used in production!
SECRET_KEY = "..............¯\_(ツ)_/¯..............."


# This is for AUTHLIB package for interacting with KTH OpenID Connect
# APPLICATION_ID is given from the 'secrets.py' file.
# CLIENT_SECRET is given from the 'secrets.py' file.
AUTHLIB_OAUTH_CLIENTS = {
"kth": {
"client_id": os.environ.get("APPLICATION_ID"),
"client_secret": os.environ.get("CLIENT_SECRET"),
"api_base_url": "https://login.ug.kth.se/adfs/oauth2/",
}
}
LOGOUT_REDIRECT_URL = "/"

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
AWS_STORAGE_BUCKET_NAME = "armada-ais-files"
# todo: Remove after setting production environment in production (2023)
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
97 changes: 10 additions & 87 deletions ais/production/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,102 +8,25 @@
from ais.common.settings import *

SECRET_KEY = os.environ.get("SECRET_KEY")
# This is important so other people can't set their own domains
# to point to AIS (which would be a security concern).
ALLOWED_HOSTS = [".armada.nu", "localhost", "armada.nu"]

ALLOWED_HOSTS = ["*"]
CORS_ALLOWED_ORIGINS = [
"https://armada.nu",
"https://www.armada.nu",
"http://armada.nu",
"http://www.armada.nu",
"http://localhost:8000",
]

DEBUG = False

# The URL scheme is slightly different in a production environment
# since we need to accomodate the KTH OpenID Connect integration.
ROOT_URLCONF = "ais.production.urls"

# Use KTH OpenID Connect for authentication
INSTALLED_APPS += (
"kth_login",
"raven.contrib.django.raven_compat",
)

# Use a full-fledged database instead of SQLite.
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": os.environ.get("DB_NAME", "ais_dev"),
"USER": os.environ.get("DB_USERNAME", "ais_dev"),
"PASSWORD": os.environ.get("DB_PASSWORD", "ais_dev"),
"HOST": os.environ.get("DB_HOST", "127.0.0.1"),
"PORT": os.environ.get("DB_PORT", "5432"),
}
}

# SENTRY
RAVEN_CONFIG = {
"dsn": "https://%s:%[email protected]/%s"
% (
os.environ.get("SENTRY_USERNAME"),
os.environ.get("SENTRY_PASSWORD"),
os.environ.get("SENTRY_APPID"),
),
"processors": ("raven.processors.Processor",),
}

CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}

LOGGING = {
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
},
},
"handlers": {
"sentry": {
"level": "ERROR", # To capture more than ERROR, change to WARNING, INFO, etc.
"class": "raven.contrib.django.raven_compat.handlers.SentryHandler",
"tags": {"custom-tag": "x"},
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"loggers": {
"root": {
"level": "WARNING",
"handlers": ["sentry"],
},
"django.db.backends": {
"level": "ERROR",
"handlers": ["console"],
"propagate": False,
},
"raven": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": False,
},
"sentry.errors": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": False,
},
},
}
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

# The system sends out system-related emails to these addresses.
ADMINS = MANAGERS = (("System", "[email protected]"),)

# This is for AUTHLIB package for interacting with KTH OpenID Connect
# APPLICATION_ID is given from the 'secrets.py' file.
# CLIENT_SECRET is given from the 'secrets.py' file.
AUTHLIB_OAUTH_CLIENTS = {
"kth": {
"client_id": os.environ.get("APPLICATION_ID"),
"client_secret": os.environ.get("CLIENT_SECRET"),
"api_base_url": "https://login.ug.kth.se/adfs/oauth2/",
}
}
LOGOUT_REDIRECT_URL = "/"
55 changes: 51 additions & 4 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ def absolute_url(request, path):
return "{}{}/{}".format(protocol, url, path)


def image_url_or_missing_relative(image, missing=MISSING_IMAGE):
return image.url if image else missing


# This function does not handle trailing slashes
# A common response is "http://localhost:3000//static/images/no-image.png"
#
# Another problem is the usage of ais buckets
# A common response is "https://ais.armada.nu/https://armada-ais-files.s3.amazonaws.com/profiles/picture_original/3d867d2a75f84e3eb32..."
#
# Please use `image_url_or_missing_relative`
def image_url_or_missing(request, image, missing=MISSING_IMAGE):
if image:
return absolute_url(request, image.url)
else:
return absolute_url(request, missing)
return absolute_url(request, image.url if image else missing)


def obj_name(obj):
Expand Down Expand Up @@ -197,6 +205,45 @@ def partner(request, partner):
)


def person_v2(user):
# Check that there is a profile for the user
try:
profile = user.profile

try:
programme = profile.programme.name
except AttributeError:
programme = None

return OrderedDict(
[
("id", profile.user.pk),
("name", profile.user.get_full_name()),
(
"picture",
image_url_or_missing_relative(
profile.picture_original, MISSING_PERSON
),
),
("linkedin_url", profile.linkedin_url),
("programme", programme),
("role", user.delegated_role.__str__()),
]
)
except Profile.DoesNotExist: # There is no profile for this user
return OrderedDict(
[
("id", user.pk),
("name", user.user.get_full_name()),
(
"role",
user.delegated_role.__str__() if user.delegated_role else None,
),
]
)


# Todo: Deprecate the usage of this serializer (used by armada.nu)
def person(request, person, role):
# Check that there are a profile for the user
try:
Expand Down
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
url(r"^fair/", include("fair.api_urls")),
url(r"^catalogueselections/", views.catalogueselections),
url(r"^news/", views.news),
url(r"^organization/v2", views.organization_v2),
url(r"^organization/", views.organization),
url(r"^partners/", views.partners),
url(r"^questions/?$", views.questions),
url(r"^recruitment/$", views.recruitment),
url(r"^recruitment_data/$", views.recruitment_data),
url(r"^status/$", views.status),
url(r"^dates/$", views.dates),
url(r"^student_profile$", views.student_profile),
url(r"^matching/$", views.matching),
url(r"^matching/choices$", views.matching_choices),
Expand Down
Loading

0 comments on commit 4f0e010

Please sign in to comment.