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

bug fixes #1561

Open
wants to merge 27 commits into
base: gad-3-final
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b07ea3f
fix 1. order of files in inbox and outbox 2. order of files is mantai…
theoden42 Feb 19, 2024
402c8c4
fix login required on viewing file
theoden42 Feb 19, 2024
5c6ab07
fix create_file method so that subject and description are also accepted
theoden42 Feb 19, 2024
a4e01b3
add rest api for create file and view file
theoden42 Mar 3, 2024
3760068
add rest api for create, view and delete file
aish0749 Mar 3, 2024
a06d437
add rest api for inbox, outbox, history view
aish0749 Mar 3, 2024
2ab199e
add rest api for draft view, forward file
aish0749 Mar 4, 2024
e824b66
Merge remote-tracking branch 'upstream/gad-4'
theoden42 Mar 5, 2024
79ef20d
prevent student access of the filetracking module
theoden42 Mar 5, 2024
c3f14b7
add dropdown filtering based on reciever username and update notallow…
theoden42 Mar 5, 2024
a97f482
add option to unarchive files
theoden42 Mar 7, 2024
b0109b8
fix template for filetrackingnotallowed page
theoden42 Mar 7, 2024
586775a
fix attachments view in the history of the file
theoden42 Mar 7, 2024
b3c8f54
make the fields in draft view editable
theoden42 Mar 7, 2024
0dfdd3f
update the views
aish0749 Mar 10, 2024
2018781
Merge pull request #1 from aish0749/main
theoden42 Mar 10, 2024
acf82f8
merge updated changes in dashboard into the filetracking module.
theoden42 Mar 19, 2024
7f33e90
fix file sending and forwarding template to include designation autom…
theoden42 Mar 19, 2024
2f8813c
fix forward file view to include designations automatically
theoden42 Mar 19, 2024
808b4cf
support file uploading and other minor fixes
arminpatel Apr 2, 2024
21f4411
change docker and req
arminpatel Apr 2, 2024
4032140
Merge branch 'main' of https://github.com/theoden42/Fusion into gad-3…
arminpatel Apr 2, 2024
2677ecf
fts implementation in api and bug fixes
arminpatel Apr 14, 2024
a8c631f
Merge branch 'gad-3' of https://github.com/FusionIIIT/Fusion into gad…
arminpatel Apr 14, 2024
e41c09d
change requirements.txt
arminpatel Apr 14, 2024
a0ddb2d
add user_type enum
arminpatel Apr 14, 2024
3c601ff
bug fixes
arminpatel Apr 22, 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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ node_modules/
FusionIIIT/static/
package-lock.json


docker-entrypoint.sh


Expand All @@ -86,4 +85,3 @@ postgres_data
!media/Administrator/academic_procedures/sample_student_profile.xlsx

migrations/

15 changes: 14 additions & 1 deletion FusionIIIT/applications/complaint_system/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ class CaretakerSerializers(serializers.ModelSerializer):
class Meta:
model = Caretaker
fields=('__all__')
depth=2

def to_representation(self, instance):
response = super().to_representation(instance)
# get caretaker complaints and filter by status = 0
complaints = StudentComplain.objects.filter(location = instance.area, status = 0)
response['complaints'] = StudentComplainSerializers(complaints, many=True).data
return response

class SupervisorSerializers(serializers.ModelSerializer):
class Meta:
model=Supervisor
fields=('__all__')

def to_representation(self, instance):
response = super().to_representation(instance)
response['name'] = instance.sup_id.user.first_name + ' ' + instance.sup_id.user.last_name
return response

class ExtraInfoSerializers(serializers.ModelSerializer):
class Meta:
model=ExtraInfo
Expand All @@ -34,4 +47,4 @@ class Meta:
class UserSerializers(serializers.ModelSerializer):
class Meta:
model=User
fields=('__all__')
fields=('__all__')
1 change: 1 addition & 0 deletions FusionIIIT/applications/complaint_system/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
url(r'^removesupervisor/(?P<s_id>[0-9]+)',views.edit_supervisor_api,name='supervisor-delete-api'),
url(r'^updatesupervisor/(?P<s_id>[0-9]+)',views.edit_supervisor_api,name='supervisor-put-api'),

url(r'^forward', views.forward_complaint_api, name='forward-complaint-api'),
]
81 changes: 63 additions & 18 deletions FusionIIIT/applications/complaint_system/api/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from applications.globals.models import (HoldsDesignation,Designation)
from django.shortcuts import get_object_or_404
from django.forms.models import model_to_dict
from django.shortcuts import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.authentication import TokenAuthentication
from rest_framework import status
Expand All @@ -11,6 +10,7 @@
from rest_framework.response import Response
from applications.globals.models import User,ExtraInfo
from applications.complaint_system.models import Caretaker, StudentComplain, Supervisor, Workers
from applications.complaint_system.models import USER_TYPE
from . import serializers


Expand Down Expand Up @@ -43,29 +43,51 @@ def complaint_details_api(request,detailcomp_id1):
def student_complain_api(request):
user = get_object_or_404(User,username = request.user.username)
user = ExtraInfo.objects.all().filter(user = user).first()
if user.user_type == 'student':
complain = StudentComplain.objects.filter(complainer = user)
elif user.user_type == 'staff':
staff = ExtraInfo.objects.get(id=user.id)
staff = Caretaker.objects.get(staff_id=staff)
complain = StudentComplain.objects.filter(location = staff.area)
elif user.user_type == 'faculty':
faculty = ExtraInfo.objects.get(id=user.id)
faculty = Supervisor.objects.get(sup_id=faculty)
complain = StudentComplain.objects.filter(location = faculty.area)
complains = serializers.StudentComplainSerializers(complain,many=True).data

user_type = USER_TYPE.student.value
extra_info_id = ExtraInfo.objects.get(id=user.id)
caretaker = Caretaker.objects.filter(staff_id=extra_info_id)
supervisor = Supervisor.objects.filter(sup_id=extra_info_id)
if caretaker.exists():
complaints = StudentComplain.get_complaints_by_user(user, USER_TYPE.caretaker)
user_type = USER_TYPE.caretaker.value
elif supervisor.exists():
complaints = StudentComplain.get_complaints_by_user(user, USER_TYPE.supervisor)
user_type = USER_TYPE.supervisor.value
else:
complaints = StudentComplain.get_complaints_by_user(user, USER_TYPE.student)

complaints = serializers.StudentComplainSerializers(complaints,many=True).data

if user_type == USER_TYPE.caretaker.value or user_type == USER_TYPE.supervisor.value:
for complaint in complaints:
last_forwarded = StudentComplain.get_complaint_owner(complaint['id'])
if last_forwarded.username != request.user.username:
complaint['last_forwarded'] = {
'name': last_forwarded.first_name + ' ' + last_forwarded.last_name,
'username': last_forwarded.username,
}

resp = {
'student_complain' : complains,
'student_complain' : complaints,
'user_type': user_type,
}
return Response(data=resp,status=status.HTTP_200_OK)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def create_complain_api(request):
serializer = serializers.StudentComplainSerializers(data=request.data)
try:
request_user_extrainfo = ExtraInfo.objects.get(user=request.user);
except ExtraInfo.DoesNotExist:
return Response({'message' : 'No such user'}, status=status.HTTP_404_NOT_FOUND)
data = request.data.copy()
data.update({'complainer': request_user_extrainfo.id})
serializer = serializers.StudentComplainSerializers(data=data)
if serializer.is_valid():
serializer.save()
StudentComplain.create_file_for_complaint(serializer.instance)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand All @@ -84,7 +106,7 @@ def edit_complain_api(request,c_id):
serializer = serializers.StudentComplainSerializers(complain,data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data,status=status.HTTP_200_OK)
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

@api_view(['GET','POST'])
Expand Down Expand Up @@ -141,9 +163,16 @@ def edit_worker_api(request,w_id):
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def caretaker_api(request):

if request.method == 'GET':
caretaker = Caretaker.objects.all()
caretakers = None
user = get_object_or_404(User,username = request.user.username)
user = ExtraInfo.objects.get(user = user)
extra_info_id = ExtraInfo.objects.get(id=user.id)
supervisor = Supervisor.objects.filter(sup_id=extra_info_id)
if supervisor.exists():
caretaker = Caretaker.objects.filter(area = supervisor.first().area)
else:
caretaker = Caretaker.objects.all()
caretakers = serializers.CaretakerSerializers(caretaker,many=True).data
resp = {
'caretakers' : caretakers,
Expand Down Expand Up @@ -231,3 +260,19 @@ def edit_supervisor_api(request,s_id):
return Response(serializer.data,status=status.HTTP_200_OK)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)


@api_view(['POST'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def forward_complaint_api(request):
user = get_object_or_404(User, username=request.user.username)
user = ExtraInfo.objects.get(user=user)
supervisor = Supervisor.objects.filter(sup_id=user)
caretaker = Caretaker.objects.filter(staff_id=user)

if supervisor.exists() or caretaker.exists():
forward_supervisor = Supervisor.objects.get(id=request.data['forward_id'])
StudentComplain.forward_complaint(forward_supervisor.sup_id, request.data['complaint_id'])
return Response({'message':'Complaint forwarded'},status=status.HTTP_200_OK)
else:
return Response({'message':'Logged in user does not have permission'},status=status.HTTP_403_FORBIDDEN)
83 changes: 80 additions & 3 deletions FusionIIIT/applications/complaint_system/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
from django.db import models
from django.utils import timezone

from applications.globals.models import ExtraInfo
from applications.globals.models import ExtraInfo, HoldsDesignation
from applications.filetracking.sdk import methods as fts
from applications.filetracking.models import File
from django.contrib.auth.models import User

from enum import Enum

# Class definations:


class Constants:
AREA = (
('hall-1', 'hall-1'),
AREA = ( ('hall-1', 'hall-1'),
('hall-3', 'hall-3'),
('hall-4', 'hall-4'),
('library', 'CC1'),
Expand All @@ -35,6 +39,10 @@ class Constants:
('other', 'other'),
)

class USER_TYPE(Enum):
student = 'student'
caretaker = 'caretaker'
supervisor = 'supervisor'

class Caretaker(models.Model):
staff_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE)
Expand Down Expand Up @@ -88,6 +96,75 @@ class StudentComplain(models.Model):
def __str__(self):
return str(self.complainer.user.username)

@staticmethod
def get_complaints_by_user(user: ExtraInfo, role: USER_TYPE):
"""
user: ExtraInfo
role: student, caretaker or supervisor
"""
if role == USER_TYPE.student:
return StudentComplain.objects.filter(complainer=user)
elif role == USER_TYPE.caretaker or role == USER_TYPE.supervisor:
designation = HoldsDesignation.objects.get(user=user.user).designation.name
complaints = fts.view_inbox(
username=user.user.username,
designation=designation,
src_module='complaint'
)
complaint_queryset = StudentComplain.objects.none()
for complaint in complaints:
complaint_queryset |= StudentComplain.objects.filter(id=complaint['src_object_id'])

complaint_queryset = complaint_queryset | StudentComplain.objects.filter(complainer=user)
return complaint_queryset

@staticmethod
def create_file_for_complaint(complaint):
"""
complaint: StudentComplain
"""

caretaker = Caretaker.objects.get(area=complaint.location)
caretaker_designation = HoldsDesignation.objects.get(user=caretaker.staff_id.user).designation.name
user_designation = HoldsDesignation.objects.get(user=complaint.complainer.user).designation.name
fts.create_file(
uploader=complaint.complainer.user.username,
uploader_designation=user_designation,
receiver=caretaker.staff_id.user.username,
receiver_designation=caretaker_designation,
src_module='complaint',
src_object_id=complaint.id
)

return complaint

@staticmethod
def forward_complaint(user: ExtraInfo, complaint_id: int):
"""
user: ExtraInfo
complaint_id: int
"""
file = File.objects.get(src_object_id=complaint_id, src_module='complaint')
user_designation = HoldsDesignation.objects.get(user=user.user)
try:
fts.forward_file(
file_id=file.id,
receiver=user.user.username,
receiver_designation=user_designation.designation.name,
file_extra_JSON={},
)
return True, 'Complaint forwarded successfully'
except Exception as e:
return False, str(e)


# owner refers to whom it was last forwarded not the complainer
@staticmethod
def get_complaint_owner(complaint_id: int) -> User:
file = File.objects.get(src_object_id=complaint_id, src_module='complaint')
owner_id = fts.get_current_file_owner(file.id)
return User.objects.get(username=owner_id)


class Supervisor(models.Model):
sup_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: postgres:13-alpine
restart: always
volumes:
- ~/private/var/lib/postgresql:/var/lib/postgresql/data
- /usr/var/lib/postgresql:/var/lib/postgresql/data
environment:
- PGDATA=/var/lib/postgresql/data/some_name/
- POSTGRES_DB=fusionlab
Expand Down
Loading