Example #1
0
    def get(self, request, *args, **kwargs):
        job_offer = self.get_object()
        user = request.user

        # Only platform administrators and company
        # administrators can view a job offer from
        # an inactive or hidden company.
        if job_offer.venture.is_inactive or job_offer.venture.is_hidden:
            if user:
                if (not user.is_staff
                        and not EntrepreneurPermissions.can_manage_company(
                            self.request.user,
                            job_offer.venture,
                        )):
                    raise Http404

        # Closed or hidden job offers are visible only
        # for platform administrators or company administrators.
        if job_offer.is_closed or job_offer.is_hidden:
            if user:
                if (not user.is_staff
                        and not EntrepreneurPermissions.can_manage_company(
                            self.request.user,
                            job_offer.venture,
                        )):
                    raise Http404

        return super().get(request, *args, **kwargs)
Example #2
0
    def get(self, request, *args, **kwargs):
        company = self.get_object()
        user = request.user

        # Only platform administrators and company
        # administrators can view an inactive or
        # hidden company.
        if company.is_inactive or company.is_hidden:
            if user:
                if (not user.is_staff
                        and not EntrepreneurPermissions.can_manage_company(
                            self.request.user,
                            company,
                        )):
                    raise Http404

        return super().get(request, *args, **kwargs)
Example #3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        company = self.get_object()

        # Score form. It is displayed in the company detail.
        context['score_form'] = CompanyScoreForm()

        context['company'] = company

        # True if authenticated user has a membership as
        # company administrator.
        context['can_manage'] = EntrepreneurPermissions.can_manage_company(
            self.request.user,
            company,
        )

        # True if authenticated user does not have a membership
        # as company administrator and if the company has not been
        # added to the address book.
        context[
            'can_add_to_address_book'] = AddressBookPermissions.can_add_company(
                self.request.user,
                company,
            )

        # True if the company is in the address book of the
        # authenticated user.
        context[
            'can_remove_from_address_book'] = AddressBookPermissions.can_remove_company(
                self.request.user,
                company,
            )

        # True if the authenticated user does not have a membership
        # as company administrator and if there is not a previous
        # score from the user.
        context['can_add_score'] = CompanyScorePermissions.can_add_score(
            self.request.user,
            company,
        )

        return context
Example #4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        job_offer = self.get_object()

        # Users can apply to job offers from the detail page.
        # If users have applied previosuly, this functionality
        # will be disbled.
        has_applied = False
        if self.request.user.is_authenticated:
            if Applicant.objects.filter(
                    job_offer=job_offer,
                    applicant=self.request.user.professionalprofile):
                has_applied = True

        context['job_offer'] = job_offer

        # Company administrators can manage job offers.
        context['can_manage'] = EntrepreneurPermissions.can_manage_company(
            self.request.user,
            job_offer.venture,
        )

        # Company administrators can edit job offers.
        context['can_edit'] = JobOfferPermissions.can_edit(
            self.request.user,
            job_offer,
        )

        # Job offer apply permission.
        context['can_apply'] = JobOfferPermissions.can_apply(
            self.request.user,
            job_offer,
        )
        context['has_applied'] = has_applied

        return context
Example #5
0
 def test_func(self):
     return EntrepreneurPermissions.can_manage_company(
         user=self.request.user,
         company=self.get_object(),
     )