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

Feature/addopenforotherpostions #1654

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions backend/root/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@
samfundet__recruitment_applications_for_position_detail = 'samfundet:recruitment_applications_for_position-detail'
samfundet__interview_list = 'samfundet:interview-list'
samfundet__interview_detail = 'samfundet:interview-detail'
samfundet__api_root = 'samfundet:api-root'
samfundet__api_root = 'samfundet:api-root'
samfundet__schema = 'samfundet:schema'
samfundet__swagger_ui = 'samfundet:swagger_ui'
samfundet__redoc = 'samfundet:redoc'
Expand Down Expand Up @@ -605,6 +603,7 @@
samfundet__applicants_without_three_interview_criteria = 'samfundet:applicants_without_three_interview_criteria'
samfundet__recruitment_recruiter_dashboard = 'samfundet:recruitment_recruiter_dashboard'
samfundet__recruitment_download_gang_application_csv = 'samfundet:recruitment_download_gang_application_csv'
samfundet__recruitment_toggle_open_for_other_positions = 'samfundet:recruitment_toggle_open_for_other_positions'
samfundet__occupied_timeslots = 'samfundet:occupied_timeslots'
samfundet__recruitment_interview_availability = 'samfundet:recruitment_interview_availability'
samfundet__recruitment_availability = 'samfundet:recruitment_availability'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.1 on 2024-12-22 16:08

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("samfundet", "0011_recruitmentposition_file_description_en_and_more"),
]

operations = [
migrations.AddField(
model_name="user",
name="recruitment_is_open_to_other_positions",
field=models.BooleanField(
blank=True,
default=False,
verbose_name="Is open to other positions in recruitment",
),
),
]
2 changes: 2 additions & 0 deletions backend/samfundet/models/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class User(AbstractUser):
on_delete=models.PROTECT,
)

recruitment_is_open_to_other_positions = models.BooleanField(default=False, blank=True, verbose_name='Is open to other positions in recruitment')

class Meta:
permissions = [
('debug', 'Can view debug mode'),
Expand Down
2 changes: 1 addition & 1 deletion backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ def get_interview_time(self, instance: RecruitmentApplication) -> str | None:
class RecruitmentBasicUserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['id', 'first_name', 'last_name', 'email', 'phone_number']
fields = ['id', 'first_name', 'last_name', 'email', 'phone_number', ' recruitment_is_open_to_other_positions']


class RecruitmentRecruitmentPositionSerializer(serializers.ModelSerializer):
Expand Down
26 changes: 26 additions & 0 deletions backend/samfundet/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,32 @@ def test_post_application_overflow(
assert RecruitmentApplication.TOO_MANY_APPLICATIONS_ERROR in response2.data['recruitment']


def test_toggle_recruitment_open_for_other_positions(
fixture_rest_client: APIClient,
fixture_user: User,
):
### Arrange ###
fixture_rest_client.force_authenticate(user=fixture_user)
assert fixture_user.recruitment_is_open_to_other_positions is False
url = reverse(routes.samfundet__recruitment_toggle_open_for_other_positions)

### Update
response: Response = fixture_rest_client.post(path=url)

### Assert ###
assert response.data is True
updated_user = User.objects.get(id=fixture_user.id)
assert updated_user.recruitment_is_open_to_other_positions == response.data

### Update
response: Response = fixture_rest_client.post(path=url)

### Assert ###
assert response.data is False
updated_user = User.objects.get(id=fixture_user.id)
assert updated_user.recruitment_is_open_to_other_positions == response.data


def test_post_recruitment_reapply_overflow(
fixture_rest_client: APIClient,
fixture_user: User,
Expand Down
5 changes: 5 additions & 0 deletions backend/samfundet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
views.DownloadRecruitmentApplicationGangCSV.as_view(),
name='recruitment_download_gang_application_csv',
),
path(
'recruitment-toggle-open-for-other-positions/',
views.RecruitmentToggleOpenForOtherPosition.as_view(),
name='recruitment_toggle_open_for_other_positions',
),
path('occupiedtimeslot/', views.OccupiedTimeslotView.as_view(), name='occupied_timeslots'),
path('recruitment-interview-availability/', views.RecruitmentInterviewAvailabilityView.as_view(), name='recruitment_interview_availability'),
path('recruitment/<int:id>/availability/', views.RecruitmentAvailabilityView.as_view(), name='recruitment_availability'),
Expand Down
10 changes: 10 additions & 0 deletions backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,16 @@ def get(self, request: Request, **kwargs: int) -> Response:
)


class RecruitmentToggleOpenForOtherPosition(APIView):
permission_classes = [IsAuthenticated]

def post(self, request: Request) -> Response:
user = request.user
user.recruitment_is_open_to_other_positions = not user.recruitment_is_open_to_other_positions
user.save()
return Response(data=user.recruitment_is_open_to_other_positions)


class OccupiedTimeslotView(ListCreateAPIView):
model = OccupiedTimeslot
serializer_class = OccupiedTimeslotSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function AppletContainer({ recruitmentId }: Props) {
title={t(KEY.recruitment_applet_open_to_other_positions)}
description={t(KEY.recruitment_applicants_open_to_other_positions)}
url={reverse({
pattern: ROUTES.frontend.admin_recruitment_open_to_other_positions,
pattern: ROUTES.frontend.admin_recruitment_is_open_to_other_positions,
urlParams: { recruitmentId: recruitmentId },
})}
/>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ export async function postOccupiedTimeslots(
return response;
}

export async function postRecruitmentToggleOpenForOtherPositions(
timeslots: OccupiedTimeslotDto,
): Promise<AxiosResponse<OccupiedTimeslotDto>> {
const url = BACKEND_DOMAIN + ROUTES.backend.samfundet__recruitment_toggle_open_for_other_positions;
const response = await axios.post(url, timeslots, { withCredentials: true });
return response;
}

export async function getRecruitmentPositionForApplicant(
positionId: string,
): Promise<AxiosResponse<RecruitmentPositionDto>> {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type RecruitmentUserDto = {
email: string;
phone_number?: string;
campus?: CampusDto;
recruitment_is_open_to_other_positions?: boolean;
recruitment_application_ids?: string[];
applications: RecruitmentApplicationDto[];
applications_without_interview: RecruitmentApplicationDto[];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export const router = createBrowserRouter(
}}
/>
<Route
path={ROUTES.frontend.admin_recruitment_open_to_other_positions}
path={ROUTES.frontend.admin_recruitment_is_open_to_other_positions}
element={
<PermissionRoute
required={[PERM.SAMFUNDET_VIEW_RECRUITMENT]}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ export const ROUTES_BACKEND = {
samfundet__recruitment_applications_for_position_detail: '/api/recruitment-applications-for-position/:pk/',
samfundet__interview_list: '/api/interview/',
samfundet__interview_detail: '/api/interview/:pk/',
samfundet__api_root: '/api/',
samfundet__schema: '/schema/',
samfundet__swagger_ui: '/schema/swagger-ui/',
samfundet__redoc: '/schema/redoc/',
Expand Down Expand Up @@ -603,6 +602,7 @@ export const ROUTES_BACKEND = {
samfundet__applicants_without_three_interview_criteria: '/recruitment-applicants-without-three-interview-criteria/:pk/',
samfundet__recruitment_recruiter_dashboard: '/recruitment-recruiter-dashboard/:pk/',
samfundet__recruitment_download_gang_application_csv: '/recruitment-download-gang-application-csv/:recruitmentId/:gangId',
samfundet__recruitment_toggle_open_for_other_positions: '/recruitment-toggle-open-for-other-positions/',
samfundet__occupied_timeslots: '/occupiedtimeslot/',
samfundet__recruitment_interview_availability: '/recruitment-interview-availability/',
samfundet__recruitment_availability: '/recruitment/:id/availability/',
Expand All @@ -611,4 +611,4 @@ export const ROUTES_BACKEND = {
samfundet__gang_application_stats: '/recruitment/:recruitmentId/gang/:gangId/stats/',
static__path: '/static/:path',
media__path: '/media/:path',
} as const;
} as const;
3 changes: 2 additions & 1 deletion frontend/src/routes/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const ROUTES_FRONTEND = {
admin_recruitment_users_three_interview_criteria:
'/control-panel/recruitment/:recruitmentId/users-without-three-interviews/',
admin_recruitment_users_without_interview: '/control-panel/recruitment/:recruitmentId/users-without-applications/',
admin_recruitment_open_to_other_positions: '/control-panel/recruitment/:recruitmentId/users-open-to-other-positions/',
admin_recruitment_is_open_to_other_positions:
'/control-panel/recruitment/:recruitmentId/users-open-to-other-positions/',
admin_recruitment_overview: '/control-panel/recruitment/:recruitmentId/recruitment-overview/',
admin_recruitment_gang_overview: '/control-panel/recruitment/:recruitmentId/gang-overview/',
admin_recruitment_gang_overview_rejection_email:
Expand Down
Loading