diff --git a/src/account/serializers.py b/src/account/serializers.py index fd5f20fa1dff87dc6b67f05513a9ef5560b94a08..1ceaf2d2f0f3a08782238c014653b5af899b19d4 100644 --- a/src/account/serializers.py +++ b/src/account/serializers.py @@ -31,17 +31,28 @@ class ProfileSerializer(serializers.ModelSerializer): 'role', ) - def validate(self, data): + def validate_updated_at(self, value): deadline = models.Deadline.get_solo().deadline - if data['signed'] is False: - raise serializers.ValidationError("You cannot join without signed") - if deadline is not None and data['updated_at'] > deadline: + if deadline is not None and value > deadline: raise serializers.ValidationError("You cannot join after the deadline") + return value + + def validate_role(self, value): modifier_role = CurrentUserMiddleware.get_current_user_profile().role - role = data['role'] - if role is not None and modifier_role != 'Staff': - raise serializers.ValidationError("You don't have permission to change role") - return data + if value != modifier_role and modifier_role != "Staff": + raise serializers.ValidationError("You don't have permission change role") + return value + + def validate_signed(self, value): + if value is False: + raise serializers.ValidationError("You cannot join without signed") + return value + + def validate_id(self, value): + modifier= CurrentUserMiddleware.get_current_user_profile() + if value != modifier.id and modifier.role != "Staff": + raise serializers.ValidationError("You don't have permission") + return value def get_full_name(self, obj): return obj.full_name diff --git a/src/common/email.py b/src/common/email.py index 67ca7d6939d97113b1cfbe13790c7856dd520bbe..1c4151ebb776e983001a6f4a7690b904e66148ad 100644 --- a/src/common/email.py +++ b/src/common/email.py @@ -19,11 +19,11 @@ def denied(email): send_mail(subject, message, 'noreply@devteam.sch.bme.hu', [email, ]) -def new_homework(email): +def new_homework(emails): subject = "NEW HOMEWORK TEST" message = "Szia!\nEgy Ăşj hĂĄzi lett kiadva, ha tĂz percen belĂźl megoldod akkor fasza gyerek vagy," \ " ha nem ĂŠleted vĂŠgĂŠig bĂĄnnifogod..." - send_mail(subject, message, 'noreply@devteam.sch.bme.hu', [email, ]) + send_mail(subject, message, 'noreply@devteam.sch.bme.hu', emails) def homework_corrected(email): diff --git a/src/document/migrations/0002_auto_20190121_1332.py b/src/document/migrations/0002_auto_20190121_1332.py new file mode 100644 index 0000000000000000000000000000000000000000..5cf755b92259e186c711bd5be422791f17294858 --- /dev/null +++ b/src/document/migrations/0002_auto_20190121_1332.py @@ -0,0 +1,20 @@ +# Generated by Django 2.0.1 on 2019-01-21 12:32 + +import common.validators +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('document', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='file', + field=models.FileField(blank=True, default='', upload_to='', validators=[django.core.validators.FileExtensionValidator(['png', 'jpeg', 'jpg', 'zip']), common.validators.FileSizeValidator(size_limit=52428800)]), + ), + ] diff --git a/src/document/migrations/0003_auto_20190121_1335.py b/src/document/migrations/0003_auto_20190121_1335.py new file mode 100644 index 0000000000000000000000000000000000000000..fa4d1c22ae825d615e093126a69d4a0a76132ad0 --- /dev/null +++ b/src/document/migrations/0003_auto_20190121_1335.py @@ -0,0 +1,20 @@ +# Generated by Django 2.0.1 on 2019-01-21 12:35 + +import common.validators +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('document', '0002_auto_20190121_1332'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='file', + field=models.FileField(blank=True, upload_to='', validators=[django.core.validators.FileExtensionValidator(['png', 'jpeg', 'jpg', 'zip']), common.validators.FileSizeValidator(size_limit=52428800)]), + ), + ] diff --git a/src/document/models.py b/src/document/models.py index 3401e64aeb507e9f452e4a8733b4a1199cef9cbe..d86febb2d868fea16983aa4ced5dfe6a1bfd9ede 100644 --- a/src/document/models.py +++ b/src/document/models.py @@ -20,7 +20,8 @@ class Document(models.Model): 'zip', ]), FileSizeValidator(size_limit=52428800), # 52428800 - 50MiB - ] + ], + blank=True, ) solution = models.ForeignKey(Solution, related_name='files', on_delete=models.DO_NOTHING, blank=True, null=True) diff --git a/src/homework/serializers.py b/src/homework/serializers.py index cb9ff5b9cf25f98a28c6121f2a3df35799822d15..c6acde3b00cbcdeaaf52624ef5031455a2eff8e4 100755 --- a/src/homework/serializers.py +++ b/src/homework/serializers.py @@ -1,7 +1,8 @@ from rest_framework import serializers from django.utils import timezone - +from account.models import Profile from . import models +from common.email import new_homework from common.middleware import CurrentUserMiddleware @@ -16,6 +17,11 @@ class TaskSerializer(serializers.ModelSerializer): raise serializers.ValidationError('Please, enter appropriate deadline.') return data + def create(self, validated_data): + emails = Profile.objects.filter(role="Student").exclude(user__email='').values_list('user__email', flat=True) + new_homework(emails) + return self.Meta.model.objects.create(**validated_data) + class SolutionSerializer(serializers.ModelSerializer): class Meta: diff --git a/src/kszkepzes/settings/local.py b/src/kszkepzes/settings/local.py index 2cb6909eb82d4a0c961584326c805653a9a322c0..53eb49a1bd60f3f66631867f420381d3070b85a1 100644 --- a/src/kszkepzes/settings/local.py +++ b/src/kszkepzes/settings/local.py @@ -5,5 +5,5 @@ EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_USE_TLS = True EMAIL_PORT = 587 -EMAIL_HOST_USER = 'bmate711kamu@gmail.com' -EMAIL_HOST_PASSWORD = '1IronxDog' +EMAIL_HOST_USER = os.getenv('EMAIL') +EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD')