Skip to content
Snippets Groups Projects
Commit 96248962 authored by Bodor Máté's avatar Bodor Máté
Browse files

Refactor profile validation

parent 394bc284
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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):
......
# 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)]),
),
]
# 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)]),
),
]
......@@ -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)
......
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:
......
......@@ -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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment