Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to YaDisk from Google Drive #612

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ae7bc08
fix force push
gsfatakhov Sep 13, 2024
7b32aff
Fix applicant-to-student feature, add possibility to convert to stude…
startsev2000 Feb 20, 2024
41f6ad7
Add opportunity to convert applicant to student as admin, add all dat…
startsev2000 Mar 5, 2024
ae64d0a
Remove unneccessary data, fix issue with university program id
startsev2000 Mar 6, 2024
78ac978
Revert backend files
startsev2000 Mar 6, 2024
22e2907
Add js logic for registration student from applicant
startsev2000 Apr 2, 2024
c4b0a17
Add registration from applicant to backend
startsev2000 Apr 3, 2024
fa42b14
Format code
startsev2000 Apr 3, 2024
ab4edda
Fix issue with student deletion
startsev2000 Sep 6, 2024
a7ab488
Update GitHub workflows
startsev2000 Sep 6, 2024
cf9adc7
Return PersonalDocumentsInfo model
startsev2000 Sep 6, 2024
23a0297
Update back-end.yaml
startsev2000 Sep 6, 2024
6e10812
Update back-end.yaml
startsev2000 Sep 6, 2024
702cdf1
Fix migrations
startsev2000 Sep 6, 2024
18ea09b
Fix
startsev2000 Sep 6, 2024
49484de
Some minor code improvements
startsev2000 Sep 8, 2024
70c8d4d
Add applicant deletion after student deletion
startsev2000 Sep 8, 2024
3b509d1
Format
startsev2000 Sep 8, 2024
3424ef9
Add role when creating student from applicant
startsev2000 Sep 19, 2024
561d421
Format code
startsev2000 Sep 19, 2024
2f619ab
Fix issue with personal docs saving
startsev2000 Sep 19, 2024
d2ef008
Fix issue with serializer, return permission level
startsev2000 Sep 19, 2024
2c00ddb
Fix issue with personal docs info
startsev2000 Sep 19, 2024
96ee38b
Another issue with personal docs info
startsev2000 Sep 19, 2024
6908a0b
Review fixes
startsev2000 Sep 19, 2024
f218b4f
Fix deploy
gsfatakhov Sep 20, 2024
f093271
Make admission year calculation same on backend and frontend
Sep 21, 2024
4da79c8
Fix different row height on applicant page
Sep 21, 2024
548c805
Updating after data changed
Sep 21, 2024
a2cbce4
(May be) fix unintentional education program setting
Sep 21, 2024
6815618
Move to bullseye
Sep 27, 2024
af068e4
Rollback devcontainer Dockerfile
Sep 27, 2024
54a9475
Fix 3.9 python maintenance versions
Sep 27, 2024
b81fcef
Add number to each student in students table
startsev2000 Sep 20, 2024
a9f680c
Add room sorting
startsev2000 Sep 20, 2024
8728569
Fix issue with numbers in the table and rooms sort
startsev2000 Sep 27, 2024
5b7bd10
Fix minor issues
startsev2000 Sep 27, 2024
8a03574
Fix devcontainers
ShishckovA Oct 9, 2024
91a12e5
Deleted extra files + moved back docs
bugovsky Oct 11, 2024
5e0b68c
Add selectable_by_program field for milspec
ShishckovA Oct 9, 2024
584d4a8
Populating Not available to select programs
ShishckovA Oct 9, 2024
66fa46d
Fix formatting
ShishckovA Oct 9, 2024
39940c2
Frontend for denying seleciton and showing error message
ShishckovA Oct 9, 2024
140da3b
Fix typos in milsepcs
ShishckovA Oct 9, 2024
12f42f9
Fix front-end for applicants
ShishckovA Oct 9, 2024
610884c
Back-end tests + checking "selectable by" on applicant submit
ShishckovA Oct 9, 2024
b238c5e
Fix front-end current year
ShishckovA Oct 9, 2024
173c356
Move selectable check to method, rename serializer
ShishckovA Oct 11, 2024
c5b2104
Fix codestyle
ShishckovA Oct 11, 2024
a66f194
Remove many to many class
ShishckovA Oct 12, 2024
84089f5
Move check to recieving signal
ShishckovA Oct 13, 2024
176d069
fix force push
gsfatakhov Sep 13, 2024
1bcaa33
Deleted extra files + moved back docs
bugovsky Oct 11, 2024
b9304a4
Merge branch 'feature/drive-to-yadisk' of https://github.com/hse-mtc/…
gsfatakhov Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Base Python image
FROM python:3.9.1-buster
FROM python:3.10-bullseye

# Update system and install backup utilities
COPY back-end/docker/image/install-postgres-client.sh /
RUN sh install-postgres-client.sh

# Install node 14
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt -y install nodejs
# Install node 16
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
RUN . ~/.nvm/nvm.sh && nvm install 16

# Setup fish
RUN apt -y install fish; chsh -s /usr/bin/fish; mkdir /root/.config; mkdir /root/.config/fish
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ services:
- ../back-end/.env
volumes:
# Forwards the local Docker socket to the container.
- /var/run/docker.sock:/var/run/docker-host.sock
- ~/.ssh:/root/.ssh
- /var/run/docker.sock:/var/run/docker.sock
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspace:cached

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/back-end.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
- run: cp back-end/.env.example back-end/.env
- run: cp tgbot/.env.example tgbot/.env
- run: cp watchdoc/.env.example watchdoc/.env
- name: "Build back-end container"
run: docker-compose build back-end
- name: "Run Postgres in background"
run: docker-compose up -d postgres
run: docker compose up -d postgres
- name: "Build back-end container"
run: docker compose build back-end
- name: "Run tests"
run: docker-compose run back-end scripts/test.sh
run: docker compose run back-end scripts/test.sh
- name: "Check code style"
run: docker-compose run back-end scripts/format.sh --check
run: docker compose run back-end scripts/format.sh --check
# - name: "Lint code"
# run: docker-compose run back-end scripts/lint.sh
- name: "Stop all containers"
run: docker-compose down
run: docker compose down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
sudo chmod 777 vpn.log
sudo killall openvpn
- name: Upload VPN logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: always()
with:
name: VPN logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/front-end.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: "Check code style"
run: cd front-end && npm run lint .
- name: "Build front end container"
run: docker-compose build front-end
run: docker compose build front-end
2 changes: 1 addition & 1 deletion back-end/docker/image/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base Python image
FROM python:3.10-buster
FROM python:3.10-bullseye

# Update system and install backup utilities
COPY back-end/docker/image/install-postgres-client.sh /
Expand Down
2 changes: 1 addition & 1 deletion back-end/docker/image/prod.dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base Python image
FROM python:3.10-buster
FROM python:3.10-bullseye

# Update system and install backup utilities
COPY back-end/docker/image/install-postgres-client.sh /
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/ams/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

def get_current_admission_year():
now = datetime.now()
if (now.month, now.day) > (9, 1):
if (now.month, now.day) >= (9, 1):
return now.year + 1
return now.year
24 changes: 24 additions & 0 deletions back-end/src/ams/views/applicants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

from ams.models.applicants import Applicant

from common.models.universities import Program

from ams.serializers.applicants import (
ApplicantSerializer,
ApplicantMutateSerializer,
Expand Down Expand Up @@ -147,6 +149,15 @@ def create(self, request, *args, **kwargs):
request.data["user"] = self.request.user.id
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
if not self.milspecialty_is_selectable(
request.data["milspecialty"], request.data["university_info"]["program"]
):
return Response(
{
"detail": "You can't select this milspecialty with your educational program"
},
status=status.HTTP_400_BAD_REQUEST,
)
self.request.user.campuses = [self.request.data["university_info"]["campus"]]
self.request.user.save()
if self.is_creation_allowed_by_scope(request.data):
Expand Down Expand Up @@ -177,6 +188,15 @@ def update(self, request, *args, **kwargs):
{"detail": "Bad request"},
status=status.HTTP_400_BAD_REQUEST,
)
if not self.milspecialty_is_selectable(
request.data["milspecialty"], request.data["university_info"]["program"]
):
return Response(
{
"detail": "You can't select this milspecialty with your educational program"
},
status=status.HTTP_400_BAD_REQUEST,
)
result = super(ApplicantViewSet, self).update(request, **kwargs)
applicant.user.campuses = [request.data["university_info"]["campus"]]
applicant.user.save()
Expand All @@ -187,6 +207,10 @@ def update(self, request, *args, **kwargs):
generate_documents_for_applicant(updated_applicant)
return result

def milspecialty_is_selectable(self, milspecialty_id: int, program_id: int):
milspecialty = Milspecialty.objects.filter(pk=milspecialty_id).first()
return milspecialty.is_selectable_by_program(program_id)

@transaction.atomic
def perform_create(self, serializer):
return serializer.save()
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
admin.site.register(Program)
admin.site.register(Faculty)

# Milspeciality
# Milspecialty
admin.site.register(Milspecialty)
6 changes: 6 additions & 0 deletions back-end/src/common/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
create_faculties,
create_programs,
)
from common.populate.milspecialities_selectable_by_programs import (
create_milspecialities_selectable_by_programs,
)

from common.utils.date import get_date_range

Expand Down Expand Up @@ -169,6 +172,9 @@ def handle(self, *args, **options):
subjects = create_subjects(milspecialties)
faculties = create_faculties()
programs = create_programs(faculties)
create_milspecialities_selectable_by_programs(
milspecialties=milspecialties, programs=programs
)

print(" OK")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.20 on 2024-10-12 16:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0004_add_personal_documents_info'),
]

operations = [
migrations.AddField(
model_name='milspecialty',
name='selectable_by',
field=models.ManyToManyField(to='common.Program'),
),
migrations.AddField(
model_name='milspecialty',
name='selectable_by_every_program',
field=models.BooleanField(default=True),
),
]
40 changes: 38 additions & 2 deletions back-end/src/common/models/milspecialties.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import Union

from django.db import models
from django.contrib.postgres.fields import ArrayField


from common.models.universities import Campus
from common.models.universities import Campus, Program
from rest_framework.exceptions import ValidationError
from django.db.models.signals import m2m_changed
from django.dispatch import receiver


class Milspecialty(models.Model):
Expand All @@ -18,9 +22,41 @@ class Milspecialty(models.Model):
)
)

selectable_by = models.ManyToManyField(to=Program, blank=True)

selectable_by_every_program = models.BooleanField(default=True)

class Meta:
verbose_name = "Military Specialty"
verbose_name_plural = "Military Specialties"

def __str__(self) -> str:
return self.title

def is_selectable_by_program(self, program_: Union[Program, int]):
if isinstance(program_, Program):
program = program_.pk
else:
program = program_
return (
self.selectable_by.filter(pk=program).exists()
or self.selectable_by_every_program
)


@receiver(m2m_changed, sender=Milspecialty.selectable_by.through)
def validate_b_titles(
sender, instance: Milspecialty, action, reverse, model, pk_set, **kwargs
):
if action in ["post_add", "post_remove", "post_clear"]:
mismatched_progs = instance.selectable_by.exclude(
faculty__campus__in=instance.available_for
)
if mismatched_progs.exists():
program: Program = mismatched_progs.first()
raise ValidationError(
{
"selectable_by": f"Can't make milspecialty {instance} be selectable by program {program}: "
f"program's campus ({program.faculty.campus}) is not available for this program"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from common.models.milspecialties import Milspecialty

from common.models.universities import (
Program,
)


def create_milspecialities_selectable_by_programs(
milspecialties: dict[str, Milspecialty], programs: dict[str, Milspecialty]
):
milspecialties["453000"].selectable_by.add(
programs["Информационная безопасность"],
programs["Информатика и вычислительная техника"],
programs["Программная инженерия"],
)
milspecialties["453100"].selectable_by.add(
programs["Информационная безопасность"],
programs["Информатика и вычислительная техника"],
programs["Программная инженерия"],
)
2 changes: 2 additions & 0 deletions back-end/src/common/populate/milspecialties.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def create_milspecialties() -> dict[str, Milspecialty]:
"code": "453000",
"title": "Организация эксплуатации и ремонта автоматизированных систем управления и вычислительных комплексов ракетно-космической обороны",
"available_for": [Campus.MOSCOW.value],
"selectable_by_every_program": False,
},
{
"code": "453100",
"title": "Математическое и программное обеспечение функционирования вычислительных комплексов ракетно-космической обороны",
"available_for": [Campus.MOSCOW.value],
"selectable_by_every_program": False,
},
{
"code": "461300",
Expand Down
13 changes: 12 additions & 1 deletion back-end/src/common/serializers/milspecialties.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@
class MilspecialtySerializer(serializers.ModelSerializer):
class Meta:
model = Milspecialty
fields = "__all__"
exclude = ["selectable_by", "selectable_by_every_program"]


class WithSelectableByProgramMilspecialtySerializer(MilspecialtySerializer):
selectable_by_program = serializers.SerializerMethodField()

def get_selectable_by_program(self, milspecialty: Milspecialty):
request = self.context["request"]
program = request.query_params.get("program")
if program is not None:
return milspecialty.is_selectable_by_program(program)
return False
48 changes: 44 additions & 4 deletions back-end/src/common/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
from auth.models import User
from common.models.milspecialties import Milspecialty
from common.models.subjects import Subject
from common.models.universities import Program, Faculty
from typing import Optional


@pytest.fixture
def create_milspeciality():
def call_me(title: str, code: str, available_for=None):
def create_milspecialty():
def call_me(
title: str,
code: str,
available_for: Optional[list[str]] = None,
selectable_by_every_program: bool = True,
):
if available_for is None:
available_for = ["MO"]
milspeciality, _ = Milspecialty.objects.get_or_create(
milspecialty, _ = Milspecialty.objects.get_or_create(
title=title,
code=code,
available_for=available_for,
selectable_by_every_program=selectable_by_every_program,
)
return milspeciality
return milspecialty

return call_me

Expand Down Expand Up @@ -71,3 +79,35 @@ def call_me(
return data

return call_me


@pytest.fixture
def create_faculty():
def call_me(title: str, abbreviation: str, campus: str = "MO"):
faculty, _ = Faculty.objects.get_or_create(
title=title,
abbreviation=abbreviation,
campus=campus,
)
return faculty

return call_me


@pytest.fixture
def create_program():
def call_me(
title: str,
code: str,
faculty: Faculty,
available_to_choose_for_applicants: bool = True,
):
program, _ = Program.objects.get_or_create(
title=title,
code=code,
faculty=faculty,
available_to_choose_for_applicants=available_to_choose_for_applicants,
)
return program

return call_me
Loading