Пример #1
0
 def get(cls, name, create=False):
     name = name.lower()
     result = cls.query.filter_by(name=name).one_or_none()
     if not result and create:
         result = cls(name=name, is_webmail=is_public_email_domain(name, default=False))
         db.session.add(result)
     return result
Пример #2
0
 def get(cls, name, create=False):
     name = name.lower()
     result = cls.query.filter_by(name=name).one_or_none()
     if not result and create:
         result = cls(name=name,
                      is_webmail=is_public_email_domain(name,
                                                        default=False))
         db.session.add(result)
     return result
Пример #3
0
    def url_for(self, action='view', _external=False, **kwargs):
        if self.state.UNPUBLISHED and action in ('view', 'edit'):
            domain = None
        else:
            domain = self.email_domain

        # A/B test flag for permalinks
        if 'b' in kwargs:
            if kwargs['b'] is not None:
                kwargs['b'] = unicode(int(kwargs['b']))
            else:
                kwargs.pop('b')

        if action == 'view':
            return url_for('jobdetail', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'reveal':
            return url_for('revealjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'apply':
            return url_for('applyjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'edit':
            return url_for('editjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'withdraw':
            return url_for('withdraw', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'close':
            return url_for('close', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'viewstats':
            return url_for('job_viewstats', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'related_posts':
            return url_for('job_related_posts', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'reopen':
            return url_for('reopen', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'moderate':
            return url_for('moderatejob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'pin':
            return url_for('pinnedjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'reject':
            return url_for('rejectjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'confirm':
            return url_for('confirm', hashid=self.hashid, _external=_external, **kwargs)
        elif action == 'logo':
            return url_for('logoimage', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'confirm-link':
            return url_for('confirm_email', hashid=self.hashid, domain=domain,
                key=self.email_verify_key, _external=True, **kwargs)
        elif action == 'star':
            return url_for('starjob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'manage':
            return url_for('managejob', hashid=self.hashid, domain=domain, _external=_external, **kwargs)
        elif action == 'browse':
            if is_public_email_domain(self.email_domain, default=False):
                return url_for('browse_by_email', md5sum=self.md5sum, _external=_external, **kwargs)
            else:
                return url_for('browse_by_domain', domain=self.email_domain, _external=_external, **kwargs)
Пример #4
0
    def validate_auto_domains(self, field):
        relist = []
        for item in field.data:
            item = item.strip()
            if u',' in item:
                relist.extend([x.strip() for x in item.split(',')])
            elif u' ' in item:
                relist.extend([x.strip() for x in item.split(' ')])
            else:
                relist.append(item)

        domains = set()
        for item in relist:
            if item:
                # FIXME: This will break domains where the subdomain handles email
                r = tldextract.extract(item.lower())
                d = u'.'.join([r.domain, r.suffix])
                if not is_public_email_domain(d, default=False):
                    domains.add(d)
        field.data = list(domains)
Пример #5
0
    def validate_auto_domains(self, field):
        relist = []
        for item in field.data:
            item = item.strip()
            if u',' in item:
                relist.extend([x.strip() for x in item.split(',')])
            elif u' ' in item:
                relist.extend([x.strip() for x in item.split(' ')])
            else:
                relist.append(item)

        domains = set()
        for item in relist:
            if item:
                # FIXME: This will break domains where the subdomain handles email
                r = tldextract.extract(item.lower())
                d = u'.'.join([r.domain, r.suffix])
                if not is_public_email_domain(d, default=False):
                    domains.add(d)
        field.data = list(domains)
Пример #6
0
    def test_public_email_domain_helper(self):
        with self.app.test_request_context('/'):
            assert is_public_email_domain('gmail.com', default=False)
            assert not is_public_email_domain('google.com', default=False)

            # Intentionally trigger a DNS lookup failure using an invalid domain name.
            # Since no default is provided, we will receive an exception.
            with self.assertRaises(MXLookupException):
                is_public_email_domain(
                    'www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijks.com'
                )

            # If default value is provided, it'll return default is case of DNS lookup failure.
            assert not is_public_email_domain(
                'www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijks.com',
                default=False,
            )
            assert is_public_email_domain(
                'www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijks.com',
                default=True,
            )
Пример #7
0
 def from_webmail_domain(self):
     return is_public_email_domain(self.email_domain, default=False)
Пример #8
0
    def url_for(self, action='view', _external=False, **kwargs):
        if self.state.UNPUBLISHED and action in ('view', 'edit'):
            domain = None
        else:
            domain = self.email_domain

        # A/B test flag for permalinks
        if 'b' in kwargs:
            if kwargs['b'] is not None:
                kwargs['b'] = unicode(int(kwargs['b']))
            else:
                kwargs.pop('b')

        if action == 'view':
            return url_for('jobdetail',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'reveal':
            return url_for('revealjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'apply':
            return url_for('applyjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'edit':
            return url_for('editjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'withdraw':
            return url_for('withdraw',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'close':
            return url_for('close',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'viewstats':
            return url_for('job_viewstats',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'related_posts':
            return url_for('job_related_posts',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'reopen':
            return url_for('reopen',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'moderate':
            return url_for('moderatejob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'pin':
            return url_for('pinnedjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'reject':
            return url_for('rejectjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'confirm':
            return url_for('confirm',
                           hashid=self.hashid,
                           _external=_external,
                           **kwargs)
        elif action == 'logo':
            return url_for('logoimage',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'confirm-link':
            return url_for('confirm_email',
                           hashid=self.hashid,
                           domain=domain,
                           key=self.email_verify_key,
                           _external=True,
                           **kwargs)
        elif action == 'star':
            return url_for('starjob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'manage':
            return url_for('managejob',
                           hashid=self.hashid,
                           domain=domain,
                           _external=_external,
                           **kwargs)
        elif action == 'browse':
            if is_public_email_domain(self.email_domain, default=False):
                return url_for('browse_by_email',
                               md5sum=self.md5sum,
                               _external=_external,
                               **kwargs)
            else:
                return url_for('browse_by_domain',
                               domain=self.email_domain,
                               _external=_external,
                               **kwargs)
Пример #9
0
    def validate(self):
        success = super(ListingForm, self).validate(send_signals=False)
        if success:
            if (
                not self.job_type_ob.nopay_allowed
            ) and self.job_pay_type.data == PAY_TYPE.NOCASH:
                self.job_pay_type.errors.append(
                    _("“%s” cannot pay nothing") % self.job_type_ob.title
                )
                success = False

            domain_name = get_email_domain(self.poster_email.data)
            domain = Domain.get(domain_name)
            if domain and domain.is_banned:
                self.poster_email.errors.append(
                    _("%s is banned from posting jobs on Hasjob") % domain_name
                )
                success = False
            elif (not self.job_type_ob.webmail_allowed) and is_public_email_domain(
                domain_name, default=False
            ):
                self.poster_email.errors.append(
                    _(
                        "Public webmail accounts like Gmail are not accepted. Please use your corporate email address"
                    )
                )
                success = False

            # Check for cash pay range
            if self.job_pay_type.data in (PAY_TYPE.ONETIME, PAY_TYPE.RECURRING):
                if self.job_pay_cash_min.data == 0:
                    if self.job_pay_cash_max.data == 10000000:
                        self.job_pay_cash_max.errors.append(_("Please select a range"))
                        success = False
                    else:
                        self.job_pay_cash_min.errors.append(
                            _("Please specify a minimum non-zero pay")
                        )
                        success = False
                else:
                    if self.job_pay_cash_max.data == 10000000:
                        if self.job_pay_currency.data == 'INR':
                            figure = _("1 crore")
                        else:
                            figure = _("10 million")
                        self.job_pay_cash_max.errors.append(
                            _(
                                "You’ve selected an upper limit of {figure}. That can’t be right"
                            ).format(figure=figure)
                        )
                        success = False
                    elif (
                        self.job_pay_type.data == PAY_TYPE.RECURRING
                        and self.job_pay_currency.data == 'INR'
                        and self.job_pay_cash_min.data < 60000
                    ):
                        self.job_pay_cash_min.errors.append(
                            _(
                                "That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12"
                            )
                        )
                        success = False
                    elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4:
                        self.job_pay_cash_max.errors.append(
                            _(
                                "Please select a narrower range, with maximum within 4× minimum"
                            )
                        )
                        success = False
            if self.job_pay_equity.data:
                if self.job_pay_equity_min.data == 0:
                    if self.job_pay_equity_max.data == 100:
                        self.job_pay_equity_max.errors.append(
                            _("Please select a range")
                        )
                        success = False
                else:
                    if self.job_pay_equity_min.data <= Decimal('1.0'):
                        multiplier = 10
                    elif self.job_pay_equity_min.data <= Decimal('2.0'):
                        multiplier = 8
                    elif self.job_pay_equity_min.data <= Decimal('3.0'):
                        multiplier = 6
                    else:
                        multiplier = 4

                    if (
                        self.job_pay_equity_max.data
                        > self.job_pay_equity_min.data * multiplier
                    ):
                        self.job_pay_equity_max.errors.append(
                            _(
                                "Please select a narrower range, with maximum within %d× minimum"
                            )
                            % multiplier
                        )
                        success = False
        self.send_signals()
        return success
Пример #10
0
 def from_webmail_domain(self):
     return (self.domain.is_webmail if self.domain else
             is_public_email_domain(self.email_domain, default=False))
Пример #11
0
 def from_webmail_domain(self):
     return is_public_email_domain(self.email_domain, default=False)
Пример #12
0
    def validate(self):
        success = super(ListingForm, self).validate(send_signals=False)
        if success:
            if (not self.job_type_ob.nopay_allowed) and self.job_pay_type.data == PAY_TYPE.NOCASH:
                self.job_pay_type.errors.append(_(u"“%%s” cannot pay nothing") % self.job_type_ob.title)
                success = False

            domain_name = get_email_domain(self.poster_email.data)
            domain = Domain.get(domain_name)
            if domain and domain.is_banned:
                self.poster_email.errors.append(_(u"%%s is banned from posting jobs on Hasjob") % domain_name)
                success = False
            elif (not self.job_type_ob.webmail_allowed) and is_public_email_domain(domain_name, default=False):
                self.poster_email.errors.append(
                    _(u"Public webmail accounts like Gmail are not accepted. Please use your corporate email address"))
                success = False

            # Check for cash pay range
            if self.job_pay_type.data in (PAY_TYPE.ONETIME, PAY_TYPE.RECURRING):
                if self.job_pay_cash_min.data == 0:
                    if self.job_pay_cash_max.data == 10000000:
                        self.job_pay_cash_max.errors.append(_(u"Please select a range"))
                        success = False
                    else:
                        self.job_pay_cash_min.errors.append(_(u"Please specify a minimum non-zero pay"))
                        success = False
                else:
                    if self.job_pay_cash_max.data == 10000000:
                        if self.job_pay_currency.data == 'INR':
                            figure = _(u"1 crore")
                        else:
                            figure = _(u"10 million")
                        self.job_pay_cash_max.errors.append(
                            _(u"You’ve selected an upper limit of {figure}. That can’t be right").format(figure=figure))
                        success = False
                    elif (self.job_pay_type.data == PAY_TYPE.RECURRING
                            and self.job_pay_currency.data == 'INR'
                            and self.job_pay_cash_min.data < 60000):
                        self.job_pay_cash_min.errors.append(
                            _(u"That’s rather low. Did you specify monthly pay instead of annual pay? Multiply by 12"))
                        success = False
                    elif self.job_pay_cash_max.data > self.job_pay_cash_min.data * 4:
                        self.job_pay_cash_max.errors.append(_(u"Please select a narrower range, with maximum within 4× minimum"))
                        success = False
            if self.job_pay_equity.data:
                if self.job_pay_equity_min.data == 0:
                    if self.job_pay_equity_max.data == 100:
                        self.job_pay_equity_max.errors.append(_(u"Please select a range"))
                        success = False
                else:
                    if self.job_pay_equity_min.data <= Decimal('1.0'):
                        multiplier = 10
                    elif self.job_pay_equity_min.data <= Decimal('2.0'):
                        multiplier = 8
                    elif self.job_pay_equity_min.data <= Decimal('3.0'):
                        multiplier = 6
                    else:
                        multiplier = 4

                    if self.job_pay_equity_max.data > self.job_pay_equity_min.data * multiplier:
                        self.job_pay_equity_max.errors.append(
                            _(u"Please select a narrower range, with maximum within %%d× minimum") % multiplier)
                        success = False
        self.send_signals()
        return success