Skip to content

Commit

Permalink
Merge pull request #141 from YogeshUpdhyay/main
Browse files Browse the repository at this point in the history
update jobs query set and auth
  • Loading branch information
YogeshUpdhyay authored Dec 30, 2024
2 parents d6126a6 + 9a9f515 commit 6da4f98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/jobs/utils/user_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def is_user_employer(user_id):

# check if the user_id belongs to any user
user_data = User.objects.filter(
user_id=user_id, user_type__iexact=values.EMPLOYER
id=user_id, user_type__iexact=values.EMPLOYER
)
return True if user_data.exists() else False
8 changes: 4 additions & 4 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from apps.userprofile.models import UserProfile
from apps.applicants.models import Applicants
from apps.jobs.models import Company, ContactMessage, Job
from apps.accounts.permissions import IsEmployer
from apps.accounts.permissions import IsEmployer, IsJobSeeker
from apps.jobs.serializers import CompanySerializer, ContactUsSerializer, JobSerializer, JobsCountByCategoriesSerializer, CompanyStatsResponseSerializer
from apps.jobs.utils.validators import validationClass
from apps.utils.responses import InternalServerError
Expand Down Expand Up @@ -56,7 +56,7 @@ class JobViewSets(viewsets.ModelViewSet):
def get_queryset(self):
queryset = super().get_queryset()

if self.request.user.is_authenticated:
if self.request.user.is_authenticated and self.request.user.user_type != "Employer":
queryset = queryset.annotate(
has_applied=Case(
When(applicants__user=UserProfile.objects.get(user=self.request.user), then=Value(True)),
Expand Down Expand Up @@ -104,15 +104,15 @@ def update(self, request, *args, **kwargs):

# check if the user_id present in the request belongs to Employer or Moderator
if not (
UserTypeCheck.is_user_employer(request.user_id)
UserTypeCheck.is_user_employer(request.user.id)
or Moderator().has_permission(request)
):
return response.create_response(
response.PERMISSION_DENIED
+ " You don't have permissions to update a job",
status.HTTP_401_UNAUTHORIZED,
)

return super().update(request, *args, **kwargs)

def destroy(self, request, pk, *args, **kwargs):
Expand Down

0 comments on commit 6da4f98

Please sign in to comment.