Skip to content

Commit

Permalink
Merge pull request #1974 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
RignonNoel authored Jul 5, 2023
2 parents 612e8fe + f18dbe9 commit ddd6e7b
Show file tree
Hide file tree
Showing 14 changed files with 567 additions and 72 deletions.
19 changes: 2 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,16 @@ FROM lambci/lambda:build-python3.8

LABEL maintainer="[email protected]"

# Fancy prompt to remind you are in zappashell
RUN echo 'export PS1="\[\e[36m\]blitz_shell>\[\e[m\] "' >> /root/.bashrc

COPY requirements.txt /requirements.txt
COPY requirements-dev.txt /requirements-dev.txt

# Virtualenv created for zappa
RUN virtualenv ~/ve
RUN source ~/ve/bin/activate \
&& pip install -r /requirements.txt \
&& pip install -r /requirements-dev.txt

RUN pip --timeout=1000 install -r /requirements.txt \
&& pip --timeout=1000 install -r /requirements-dev.txt
RUN pip --timeout=1000 --no-cache-dir install -r /requirements.txt
RUN pip --timeout=1000 --no-cache-dir install -r /requirements-dev.txt

RUN mkdir -p /opt/project

COPY ./docker/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./docker/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

WORKDIR /opt/project

ENTRYPOINT ["/entrypoint"]
10 changes: 5 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pipeline {
agent {
docker {
image 'tmaier/docker-compose'
image 'docker:20.10.24-cli-alpine3.18'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
Expand All @@ -11,22 +11,22 @@ pipeline {
stages {
stage('Debug info') {
steps {
sh 'docker-compose --version'
sh 'docker compose --version'
}
}
stage('Build images') {
steps {
sh 'docker-compose build'
sh 'docker compose build'
}
}
stage('Static code analysis') {
steps {
sh 'docker-compose run --rm api pycodestyle --config=.pycodestylerc .'
sh 'docker compose run --rm api pycodestyle --config=.pycodestylerc .'
}
}
stage('Unit tests') {
steps {
sh 'docker-compose run --rm api python manage.py test'
sh 'docker compose run --rm api python manage.py test'
}
}
stage('deploy QA') {
Expand Down
12 changes: 11 additions & 1 deletion blitz_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from simple_history.admin import SimpleHistoryAdmin

from .models import (AcademicField, AcademicLevel, ActionToken, Domain,
Organization, TemporaryToken, User)
Organization, TemporaryToken, User, ExportMedia)
from .resources import (AcademicFieldResource, AcademicLevelResource,
OrganizationResource, UserResource)

Expand Down Expand Up @@ -132,10 +132,20 @@ class AcademicLevelAdmin(SimpleHistoryAdmin, TranslationAdmin,
resource_class = AcademicLevelResource


class ExportMediaAdmin(admin.ModelAdmin):
list_display = ('name', 'author', 'type',)
search_fields = ('type', 'author__email',)
list_filter = (
'type',
'author',
)


admin.site.register(User, CustomUserAdmin)
admin.site.register(Organization, CustomOrganizationAdmin)
admin.site.register(Domain, SimpleHistoryAdmin)
admin.site.register(ActionToken, ActionTokenAdmin)
admin.site.register(TemporaryToken, TemporaryTokenAdmin)
admin.site.register(AcademicField, AcademicFieldAdmin)
admin.site.register(AcademicLevel, AcademicLevelAdmin)
admin.site.register(ExportMedia, ExportMediaAdmin)
15 changes: 14 additions & 1 deletion blitz_api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import factory.fuzzy
from django.contrib.auth import get_user_model

from blitz_api.models import Organization, AcademicLevel, AcademicField
from blitz_api.models import (
Organization,
AcademicLevel,
AcademicField,
MagicLink,
)
from retirement.models import (
Retreat,
RetreatDate,
Expand Down Expand Up @@ -83,6 +88,14 @@ class Meta:
name = factory.Sequence(lambda n: f'AcademicField {n}')


class MagicLinkFactory(DjangoModelFactory):
class Meta:
model = MagicLink

full_link = 'http://myverylonglink.thatiwantshorten.toamagiclink'
description = 'This is a factory magic link'


class RetreatTypeFactory(DjangoModelFactory):
class Meta:
model = RetreatType
Expand Down
31 changes: 31 additions & 0 deletions blitz_api/migrations/0030_auto_20230627_0926.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.8 on 2023-06-27 13:26

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
('blitz_api', '0029_auto_20230203_1624'),
]

operations = [
migrations.CreateModel(
name='MagicLink',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('full_link', models.TextField(verbose_name='Full link')),
('type', models.CharField(choices=[('DOWNLOAD', 'Download')], default='DOWNLOAD', max_length=255)),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
('nb_uses', models.PositiveIntegerField(default=0, verbose_name='Number of uses')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')),
],
),
migrations.AlterField(
model_name='exportmedia',
name='type',
field=models.CharField(choices=[('ANONYMOUS CHRONO DATA', 'Anonymous Chrono data'), ('OTHER', 'Other'), ('RETREAT SALES', 'Retreat sales'), ('RETREAT PARTICIPATION', 'Retreat participation'), ('RETREAT OPTIONS', 'Retreat options'), ('COUPON USAGE', 'Coupon usage')], default='OTHER', max_length=255),
),
]
67 changes: 66 additions & 1 deletion blitz_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import logging
import calendar
import uuid

from django.conf import settings
from django.db import models
Expand Down Expand Up @@ -689,6 +690,63 @@ class Meta:
abstract = True


class MagicLink(models.Model):
"""
This model stores a full link (for download etc.) and uuid.
The uuid is used publicly (in email etc.) and the model does the
bridge between uuid and the full link
"""
MAGIC_LINK_TYPE_DOWNLOAD = 'DOWNLOAD'

MAGIC_LINK_TYPE_CHOICES = (
(MAGIC_LINK_TYPE_DOWNLOAD, _('Download')),
)

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
full_link = models.TextField(
verbose_name=_("Full link")
)
type = models.CharField(
max_length=255,
choices=MAGIC_LINK_TYPE_CHOICES,
default=MAGIC_LINK_TYPE_DOWNLOAD,
)
description = models.TextField(
blank=True,
null=True,
verbose_name=_("Description"),
)
nb_uses = models.PositiveIntegerField(
verbose_name=_('Number of uses'),
default=0,
)
created_at = models.DateTimeField(
verbose_name=_('Created at'),
auto_now_add=True,
)
updated_at = models.DateTimeField(
verbose_name=_('Updated at'),
auto_now=True
)

@property
def is_used(self):
return self.nb_uses > 0

def use(self):
self.nb_uses += 1
self.save()

def get_url(self):
FRONTEND_SETTINGS = settings.LOCAL_SETTINGS['FRONTEND_INTEGRATION']
BASE_URL = FRONTEND_SETTINGS['SSO_URL']

return BASE_URL + FRONTEND_SETTINGS['MAGIC_LINK_URL'].replace(
"{{token}}",
str(self.id)
)


class ExportMedia(models.Model):
EXPORT_ANONYMOUS_CHRONO_DATA = 'ANONYMOUS CHRONO DATA'
EXPORT_OTHER = 'OTHER'
Expand Down Expand Up @@ -740,12 +798,19 @@ def size(self):

def send_confirmation_email(self):
if self.author:
magic_link = MagicLink.objects.create(
full_link=self.file.url,
type=MagicLink.MAGIC_LINK_TYPE_DOWNLOAD,
description=f'Export {self.type} '
f'for {self.author}'
)

services.send_mail(
[self.author],
{
"USER_FIRST_NAME": self.author.first_name,
"USER_LAST_NAME": self.author.last_name,
"export_link": self.file.url,
"export_link": magic_link.get_url(),
},
"EXPORT_DONE",
)
21 changes: 19 additions & 2 deletions blitz_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
from django.core.exceptions import ValidationError

from .models import (
Domain, Organization, ActionToken, AcademicField, AcademicLevel,
ExportMedia
Domain,
Organization,
ActionToken,
AcademicField,
AcademicLevel,
ExportMedia,
MagicLink,
)
from .services import remove_translation_fields, check_if_translated_field
from . import services, mailchimp
Expand Down Expand Up @@ -726,3 +731,15 @@ def create(self, validated_data):
'non_field_errors': [e.args[0]['detail']]
})
return validated_data


class MagicLinkSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField()

class Meta:
model = MagicLink
fields = [
'id',
'full_link',
'description',
]
5 changes: 5 additions & 0 deletions blitz_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@
cast=bool,
),
'FRONTEND_INTEGRATION': {
'SSO_URL': config(
'SSO_URL',
default='https://login-dev-gcp.thesez-vous.org/',
),
'LINK_TO_BE_PREPARED_FOR_VIRTUAL_RETREAT': config(
'LINK_TO_BE_PREPARED_FOR_VIRTUAL_RETREAT',
default='https://www.thesez-vous.com/sypreparer_retraitevirtuelle.html',
Expand Down Expand Up @@ -453,6 +457,7 @@
'RETREAT_UNSUBSCRIBE_URL',
default='https://example.com/wait_queue/{{wait_queue_id}}/unsubscribe',
),
"MAGIC_LINK_URL": "magic-link/{{token}}",
},
'SELLING_TAX': 0.14975,
'RETREAT_NOTIFICATION_LIFETIME_DAYS': config(
Expand Down
Loading

0 comments on commit ddd6e7b

Please sign in to comment.