Skip to content

Commit

Permalink
October update (#635)
Browse files Browse the repository at this point in the history
* chore(deps): bump slack-sdk from 3.16.0 to 3.18.3 (#602)

Bumps [slack-sdk](https://github.com/slackapi/python-slack-sdk) from 3.16.0 to 3.18.3.
- [Release notes](https://github.com/slackapi/python-slack-sdk/releases)
- [Changelog](https://github.com/slackapi/python-slack-sdk/blob/main/docs-v2/changelog.html)
- [Commits](slackapi/python-slack-sdk@v3.16.0...v3.18.3)

---
updated-dependencies:
- dependency-name: slack-sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* ref(epost): Endret e-post (#607)

Co-authored-by: Lea Raknes <[email protected]>

* force sentry sdk version (#615)

* fix(mail): celery mail lock (#619)

* Delete mails instead of setting mail to "sent".

* Lock mail rows that are being sent.

* Fixed formatting

* Remove sent tables before fields.

* Do not use in mail send

* fixed tests :nerd: :feelsgood:

* Added changelog

* Fixed mail migration oopsie 😳

* chore(deps): update django-ordered-model requirement from ~=3.5 to ~=3.6 (#590)

Updates the requirements on [django-ordered-model](https://github.com/django-ordered-model/django-ordered-model) to permit the latest version.
- [Release notes](https://github.com/django-ordered-model/django-ordered-model/releases)
- [Changelog](https://github.com/django-ordered-model/django-ordered-model/blob/master/CHANGES.md)
- [Commits](django-ordered-model/django-ordered-model@3.5...3.6)

---
updated-dependencies:
- dependency-name: django-ordered-model
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tobias Rødahl Thingnes <[email protected]>

* chore(deps): bump django from 4.0.4 to 4.1.2 (#618)

Bumps [django](https://github.com/django/django) from 4.0.4 to 4.1.2.
- [Release notes](https://github.com/django/django/releases)
- [Commits](django/django@4.0.4...4.1.2)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: norgor <[email protected]>

* fix(notification): Avoid Slack as only channel when not connected (#625)

* chore(deps): bump whitenoise from 6.1.0 to 6.2.0 (#592)

Bumps [whitenoise](https://github.com/evansd/whitenoise) from 6.1.0 to 6.2.0.
- [Release notes](https://github.com/evansd/whitenoise/releases)
- [Changelog](https://github.com/evansd/whitenoise/blob/main/docs/changelog.rst)
- [Commits](evansd/whitenoise@6.1.0...6.2.0)

---
updated-dependencies:
- dependency-name: whitenoise
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump django-filter from 21.1 to 22.1 (#595)

Bumps [django-filter](https://github.com/carltongibson/django-filter) from 21.1 to 22.1.
- [Release notes](https://github.com/carltongibson/django-filter/releases)
- [Changelog](https://github.com/carltongibson/django-filter/blob/main/CHANGES.rst)
- [Commits](carltongibson/django-filter@21.1...22.1)

---
updated-dependencies:
- dependency-name: django-filter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* refactor(album): changed primary key from slug to id (#606)

* changed primary key from slug to id

* Update picture.py

* changelog

* reverted migration

* created new migration

* fixed migrations

* fixed migrations

* Delete Makefile.bak

* removed unused import

* Update CHANGELOG.md

* added functions to re-add pictures

* tried to fix

* norbert fix

* norbert fix v2

* norbert fix v3

* norbert fix v4

* adding uuid manually

* new try at fix

* new attempt

* desperate

* ...

* desperation

* removed .bak file

* ...

* might have fixed it

* fix?

* fix?

* alhamdulillah!

* i must have brain tumour

* contemplating unspeakable things

* chore(grammar): Added very important commas. (#629)

* Added very important commas.

* Add changelog entry

* chore(grammar): Even more grammar fixes 🤓 (#631)

* Even more grammar fixes :nerd:

* Added entry to changelog

* chore(readme): Improved readme! 🔧 (#633)

Improved readme.

* fix(django): add required files for Django 4.1

* Revert "fix(django): add required files for Django 4.1"

This reverts commit 3de9965.

* fix(django): django and django-rest-frameworks issues (#634)

fix(django): downgrading Django version from 4.1.2 to 4.0.8

* docs(changelog): iterate changelog version (#636)

Co-authored-by: trthingnes <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: learak <[email protected]>
Co-authored-by: Lea Raknes <[email protected]>
Co-authored-by: norgor <[email protected]>
Co-authored-by: Callum Gran <[email protected]>
Co-authored-by: Martin Clementz <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: trthingnes <[email protected]>
  • Loading branch information
9 people authored Oct 13, 2022
1 parent d4e1f7b commit 8817351
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 67 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ staticfiles
__pycache__

# VS Code
.vscode
/.vscode
/.devcontainer

.idea/
volume/
Expand All @@ -24,4 +25,4 @@ mysite.log
# Coverage
.coverage

celerybeat-schedule
celerybeat-schedule
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
---

## Neste versjon
## Versjon 2022.10.13
- 🦟 **Galleri**. Problem hvor galleri ble duplisert er fikset.
- 🦟 **Notifikasjoner** Fikset noen grammatiske feil i notifikasjonene.
- 🦟 **Mails** Mails *skal* bli sendt kun én gang. 🤞
- 🦟 **Varslinger**. Brukere kan ikke lenger sette Slack som eneste kommunikasjonskanal uten å koble til Slack-konto.

## Versjon 2022.05.12
-**Varsler**. Ny medlemmer og ledere av grupper får nå mer informasjon om hva det innebærer.

Expand Down
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</p>


<h1 align="center">LEPTON</h1>
<h1 align="center">Lepton</h1>

<h4 align="center">
TIHLDEs open source backend for <a href="https://tihlde.org">tihlde.org</a> - the organizations main web site.
Open source backend for <a href="https://tihlde.org">TIHLDE's website.</a>
</h4>

<br/>
Expand Down Expand Up @@ -84,22 +84,20 @@ The tests can be run with pytest by running `make test`.
To run with test coverage, run `make test args="--cov"`.

## ❤ Contributing
The Lepton backend is an open source project build on voluntary work.
We are committed to a fully transparent development process
and highly appreciate any contributions.
Whether you are helping us fixing bugs, proposing new feature, improving our documentation
or spreading the word - **we would love to have you as part of the community**.
The Lepton backend is an open source project built on voluntary work.
We are committed to a fully transparent development process, and highly appreciate any contributions.
Whether you are helping us by fixing bugs, proposing new feature, improving our documentation,
or simply spreading the word - **we would love to have you as part of our community**.

## 🤝 Found a bug? Missing a specific feature?
Feel free to file a new issue with a respective title and description
on the the [tihlde/Lepton](https://github.com/tihlde/Lepton/issues) repository.
If you already found a solution to your problem, we would love to review your pull request!
in the [TIHLDE/Lepton](https://github.com/TIHLDE/Lepton/issues) repository.
If you have already found a solution to your problem, we would love to review your pull request!
We enforce the PEP-8 style guide with isort, black and flake8.
Have a look at `setup.cfg` to find out more about our coding standards.

## 📫 Contact
Feel free to send us a message on our official [slack channel](https://tihlde.slack.com/archives/C01CJ0EQCFM).
Of course you can always reach out to us directly at [email protected].
Feel free to send us a message on our official [slack channel](https://tihlde.slack.com/archives/C01CJ0EQCFM), or email us at [email protected].

## 📘 Licence
The code in this project is licensed under MIT license.
## 📘 License
The code in this repository is licensed under the [MIT license](LICENSE.md).
1 change: 0 additions & 1 deletion app/communication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class MailAdmin(admin.ModelAdmin):
list_filter = (
"sent",
"users__user_id",
"eta",
)
Expand Down
1 change: 0 additions & 1 deletion app/communication/factories/mail_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Meta:

subject = factory.Sequence(lambda n: f"Mail {n}")
body = factory.Faker("paragraph", nb_sentences=10)
sent = False

@factory.post_generation
def users(self, create, extracted, **kwargs):
Expand Down
21 changes: 21 additions & 0 deletions app/communication/migrations/0007_remove_sent_mails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import migrations


def delete_sent(apps, schema_editor):
Mail = apps.get_model("communication", "Mail")
Mail.objects.filter(sent=True).delete()


class Migration(migrations.Migration):

dependencies = [
("communication", "0006_alter_mail_users"),
]

operations = [
migrations.RunPython(delete_sent),
migrations.RemoveField(
model_name="mail",
name="sent",
),
]
5 changes: 2 additions & 3 deletions app/communication/models/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Mail(BaseModel):
subject = models.CharField(max_length=200)
body = models.TextField(default="")
users = models.ManyToManyField(User, related_name="emails", blank=True)
sent = models.BooleanField(default=False)

class Meta:
verbose_name = "Mail"
Expand All @@ -33,8 +32,8 @@ def send(self):
to_mails=emails, html=self.body, subject=self.subject
)
if is_success:
self.sent = True
self.save(update_fields=["sent"])
self.delete()

return is_success

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion app/communication/models/user_notification_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __str__(self):
)

def clean(self):
if not self.email and not self.website and not self.slack:
if not self.email and not self.website and not (self.slack and self.user.slack_user_id):
raise AllChannelsUnselected("Du må velge minst en kommunikasjonsmetode")

@classmethod
Expand Down
22 changes: 12 additions & 10 deletions app/communication/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.db import transaction

from app.celery import app
from app.util.tasks import BaseTask

Expand All @@ -7,14 +9,14 @@ def send_due_mails(self, *args, **kwargs):
from app.communication.models.mail import Mail
from app.util.utils import now

mails_to_send = Mail.objects.filter(sent=False, eta__lt=now())
mails_successfully_sent = 0

for mail in mails_to_send:
is_success = mail.send()
if is_success:
mails_successfully_sent += 1
mails = Mail.objects.select_for_update().filter(eta__lt=now())
total_mails = 0
mails_sent = 0
with transaction.atomic():
for mail in mails:
is_success = mail.send()
if is_success:
mails_sent += 1
total_mails += 1

self.logger.info(
f"Successfully sent: {mails_successfully_sent}/{mails_to_send.count()} mails"
)
self.logger.info(f"Successfully sent: {mails_sent}/{total_mails} mails")
11 changes: 0 additions & 11 deletions app/communication/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ def test_mail_is_sent_when_not_sent_and_due(mock_send_html_email):
assert mock_send_html_email.called


@pytest.mark.django_db
@patch("app.communication.notifier.send_html_email")
def test_mail_is_not_sent_when_already_sent(mock_send_html_email):
"""Mail should be not sent when already sent"""
MailFactory(sent=True)

send_due_mails()

assert not mock_send_html_email.called


@pytest.mark.django_db
@patch("app.communication.notifier.send_html_email")
def test_mail_is_not_sent_when_not_due(mock_send_html_email):
Expand Down
2 changes: 1 addition & 1 deletion app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)
MAIL_INDEX = "[email protected]" if os.environ.get("PROD") else "[email protected]"
MAIL_NOK_LEADER = (
"naeringslivminister@tihlde.org"
"naeringslivsminister@tihlde.org"
if os.environ.get("PROD")
else "[email protected]"
)
Expand Down
6 changes: 3 additions & 3 deletions app/content/models/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def send_notification_and_mail(self):
[self.user],
f'Du har fått plass på "{self.event.title}"',
UserNotificationSettingType.REGISTRATION,
).add_paragraph(f"Hei {self.user.first_name}!").add_paragraph(
).add_paragraph(f"Hei, {self.user.first_name}!").add_paragraph(
f"Arrangementet starter {datetime_format(self.event.start_date)} og vil være på {self.event.location}."
).add_paragraph(
f"Du kan melde deg av innen {datetime_format(self.event.sign_off_deadline)}."
Expand All @@ -174,10 +174,10 @@ def send_notification_and_mail(self):
[self.user],
f'Venteliste for "{self.event.title}"',
UserNotificationSettingType.REGISTRATION,
).add_paragraph(f"Hei {self.user.first_name}!").add_paragraph(
).add_paragraph(f"Hei, {self.user.first_name}!").add_paragraph(
f"På grunn av stor pågang har du blitt satt på venteliste for {self.event.title}."
).add_paragraph(
"Dersom noen melder seg av vil du automatisk bli flyttet opp på listen. Du vil få beskjed dersom du får plass på arrangementet."
"Dersom noen melder seg av, vil du automatisk bli flyttet opp på listen. Du vil få beskjed dersom du får plass på arrangementet."
).add_paragraph(
f"PS. De vanlige reglene for prikker gjelder også for venteliste, husk derfor å melde deg av arrangementet innen {datetime_format(self.event.sign_off_deadline)} dersom du ikke kan møte."
).add_event_link(
Expand Down
2 changes: 1 addition & 1 deletion app/content/models/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def save(self, *args, **kwargs):

Notify(
[self.user], "Du har fått en prikk", UserNotificationSettingType.STRIKE
).add_paragraph(f"Hei {self.user.first_name}!").add_paragraph(
).add_paragraph(f"Hei, {self.user.first_name}!").add_paragraph(
self.description
).add_paragraph(
"Prikken varer i 20 dager. Ta kontakt med arrangøren om du er uenig. Konsekvenser kan sees i arrangementsreglene. Du kan finne dine aktive prikker og mer info om dem i profilen."
Expand Down
2 changes: 1 addition & 1 deletion app/content/tasks/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __post_event_actions(event, *args, **kwargs):
).add_paragraph(
f"Vi i TIHLDE setter stor pris på at du tar deg tid til å svare på denne korte undersøkelsen angående {event.title} den {datetime_format(event.start_date)}"
).add_paragraph(
"Undersøkelsen tar ca 1 minutt å svare på, og er til stor hjelp for fremtidige arrangementer. Takk på forhånd!"
"Undersøkelsen tar ca. ett minutt å svare på, og er til stor hjelp for fremtidige arrangementer. Takk på forhånd!"
).add_paragraph(
"PS: Du kan ikke melde deg på flere arrangementer gjennom TIHLDE.org før du har svart på denne undersøkelsen. Du kan alltid finne alle dine ubesvarte spørreskjemaer i profilen din."
).add_link(
Expand Down
4 changes: 2 additions & 2 deletions app/content/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def makeTIHLDEMember(self, request, *args, **kwargs):
Membership.objects.get_or_create(user=user, group=TIHLDE)
Notify(
[user], "Brukeren din er godkjent", UserNotificationSettingType.OTHER
).add_paragraph(f"Hei {user.first_name}!").add_paragraph(
).add_paragraph(f"Hei, {user.first_name}!").add_paragraph(
"Vi har godkjent brukeren din på TIHLDE.org! Du kan nå logge inn og ta i bruk siden."
).add_link(
"Logg inn", "/logg-inn/"
Expand Down Expand Up @@ -343,7 +343,7 @@ def declineTIHLDEMember(self, request, *args, **kwargs):
user = get_object_or_404(User, user_id=user_id)
Notify(
[user], "Brukeren din ble ikke godkjent", UserNotificationSettingType.OTHER
).add_paragraph(f"Hei {user.first_name}!").add_paragraph(
).add_paragraph(f"Hei, {user.first_name}!").add_paragraph(
"Vi har avslått brukeren din på TIHLDE.org fordi den ikke oppfylte kravene til å ha bruker. Du kan lage en ny bruker der du har rettet feilen hvis du ønsker. Kontakt oss hvis du er uenig i avgjørelsen."
).add_paragraph(
f"Vedlagt begrunnelse: {reason}."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated by Django 4.0.4 on 2022-09-29 17:05

from django.db import migrations, models
import uuid

albums = []

def save_pk(apps, schema_editor):
Picture = apps.get_model('gallery', 'Picture')
Album = apps.get_model('gallery', 'Album')

for album in Album.objects.all():
pic_ids = []
album.id = uuid.uuid4()
album.save()
for picture in Picture.objects.filter(album=album):
pic_ids.append(picture.id)

albums.append({
'album_id': album.id,
'pic_ids': pic_ids,
})

def update_pk(apps, schema_editor):
Picture = apps.get_model('gallery', 'Picture')
Album = apps.get_model('gallery', 'Album')

for album in albums:
for pic_id in album.get('pic_ids'):
pic = Picture.objects.get(id=pic_id)
pic.album = Album.objects.get(id=album.get('album_id'))
pic.save()

class Migration(migrations.Migration):

dependencies = [
('gallery', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='album',
name='id',
field=models.UUIDField(unique=True, null=True, default=None),
),
migrations.RunPython(save_pk),
migrations.RemoveField(
model_name='picture',
name='album',
),
migrations.AlterField(
model_name='album',
name='slug',
field=models.SlugField(),
),
migrations.AlterField(
model_name='album',
name='id',
field=models.UUIDField(default=uuid.uuid4, null=False, editable=False, primary_key=True, serialize=False),
),
migrations.AddField(
model_name='picture',
name='album',
field=models.ForeignKey(to='gallery.album', on_delete=models.SET_NULL, null=True),
),
migrations.RunPython(update_pk),
]
5 changes: 4 additions & 1 deletion app/gallery/models/album.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

from django.db import models
from django.utils.text import slugify

Expand All @@ -9,10 +11,11 @@

class Album(BaseModel, BasePermissionModel, OptionalImage):

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=100)
event = models.ForeignKey(Event, on_delete=models.SET_NULL, null=True)
description = models.TextField(blank=True)
slug = models.SlugField(max_length=50, primary_key=True)
slug = models.SlugField(max_length=50, primary_key=False)
write_access = AdminGroup.all()

def __str__(self):
Expand Down
1 change: 1 addition & 0 deletions app/gallery/serializers/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AlbumSerializer(BaseModelSerializer):
class Meta:
model = Album
fields = [
"id",
"title",
"event",
"image",
Expand Down
4 changes: 2 additions & 2 deletions app/gallery/serializers/picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class ListPictureSerializer(serializers.ListSerializer):
def create(self, validated_data):
album_id = self.context["slug"]
album = Album.objects.get(slug=album_id)
id = self.context["id"]
album = Album.objects.get(id=id)

pictures = [Picture(album=album, **data) for data in validated_data]
return Picture.objects.bulk_create(pictures)
Expand Down
2 changes: 1 addition & 1 deletion app/gallery/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

router = routers.DefaultRouter()
router.register("", AlbumViewSet)
router.register(r"(?P<slug>[^.]+)/pictures", PictureViewSet, basename="pictures")
router.register(r"(?P<id>[^.]+)/pictures", PictureViewSet, basename="pictures")

urlpatterns = [
re_path(r"", include(router.urls)),
Expand Down
2 changes: 1 addition & 1 deletion app/gallery/views/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AlbumViewSet(BaseViewSet):
serializer_class = AlbumSerializer
queryset = Album.objects.all()
permission_classes = [BasicViewPermission]
lookup_field = "slug"
lookup_field = "id"
pagination_class = BasePagination
filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_class = AlbumFilter
Expand Down
8 changes: 4 additions & 4 deletions app/gallery/views/picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class PictureViewSet(BaseViewSet):
pagination_class = BasePagination

def get_queryset(self):
album_id = self.kwargs.get("slug", None)
return Picture.objects.filter(album__slug=album_id)
id = self.kwargs.get("id", None)
return Picture.objects.filter(album__id=id)

def create(self, request, *args, **kwargs):

album_id = self.kwargs.get("slug", None)
album = get_object_or_404(Album, slug=album_id)
id = self.kwargs.get("id", None)
album = get_object_or_404(Album, id=id)

files = request.FILES.getlist("file")
if len(files) < 1:
Expand Down
Loading

0 comments on commit 8817351

Please sign in to comment.