Пример #1
0
    def test_contact(self):

        data = copy.deepcopy(TEST_DATADICT)
        data['private'] = False
        data['contact'][0]['email'] = '*****@*****.**'
        data['id'] = 'test-contact'
        data['name'] = 'test-contact'

        model.User(name="test_sysadmin", sysadmin=True).save()

        organisation = get_action('organization_create')({'user': '******'}, {'name': 'test-organization',
                                                                                     'title': "Test organization"})
        data['owner_org'] = organisation.get('name')
        get_action('package_create')({'user': '******'}, data)

        offset = url_for("/contact/send/test-contact")
        res = self.app.post(offset, params={'recipient': utils.get_package_contacts(data.get('name'))[0].get('id')})
        assert res.status == 302

        offset = url_for("/dataset/test-contact")
        res = self.app.post(offset)
        assert 'Message not sent' in res

        import base64
        import time

        cc = ContactController()
        _time = base64.b64encode(cc.crypto.encrypt(cc._pad(str(int(time.time())))))

        offset = url_for("/contact/send/test-contact")
        params = {
            'recipient': utils.get_package_contacts(data.get('name'))[0].get('id'),
            'check_this_out': _time,
            'accept_logging': 'True'
        }
        self.app.post(offset, params=params, status=302)

        offset = url_for("/dataset/test-contact")
        res = self.app.post(offset)

        assert 'spam bot' in res

        _time = base64.b64encode(cc.crypto.encrypt(cc._pad(str(int(time.time())-21))))
        offset = url_for("/contact/send/test-contact")
        params = {
            'recipient': utils.get_package_contacts(data.get('name'))[0].get('id'),
            'check_this_out': _time,
            'accept_logging': 'True'
        }
        self.app.post(offset, params=params, status=302)
        offset = url_for("/dataset/test-contact")
        res = self.app.post(offset)

        assert 'Message not sent' in res
Пример #2
0
    def render_request_form(self, pkg_id):
        """
        Render the access request contact form if allowed.

        :param pkg_id: package id
        :type pkg_id: string
        """
        c.package = Package.get(pkg_id)

        if asbool(config.get('kata.disable_contact')):
            h.flash_error(_(u"Sending contact emails is prohibited for now. "
                            u"Please try again later or contact customer service."))

            return redirect(h.url_for(controller='package',
                                      action="read",
                                      id=c.package.name))

        if not c.package:
            abort(404, _(u"Dataset not found"))

        contacts = utils.get_package_contacts(c.package.id)
        c.recipient_options = [{'text': contact['name'], 'value': contact['id']} for contact in contacts]
        c.recipient_index = request.params.get('recipient', '')
        c.current_time = base64.b64encode(self.crypto.encrypt(self._pad(str(int(time.time())))))

        return render('contact/dataset_request_form.html')
Пример #3
0
    def render_request_form(self, pkg_id):
        """
        Render the access request contact form if allowed.

        :param pkg_id: package id
        :type pkg_id: string
        """
        c.package = Package.get(pkg_id)

        if not c.package:
            abort(404, _(u"Dataset not found"))

        if asbool(config.get('kata.disable_contact')):
            h.flash_error(_(u"Sending contact emails is prohibited for now. "
                            u"Please try again later or contact customer service."))

            return redirect(h.url_for(controller='package',
                                      action="read",
                                      id=c.package.name))

        contacts = utils.get_package_contacts(c.package.id)
        c.recipient_options = [{'text': contact['name'], 'value': contact['id']} for contact in contacts]
        c.recipient_index = request.params.get('recipient', '')
        c.current_time = base64.b64encode(self.crypto.encrypt(self._pad(str(int(time.time())))))

        return render('contact/dataset_request_form.html')
Пример #4
0
    def _get_contact_email(self, pkg_id, contact_id):
        recipient = None
        if contact_id:
            contacts = utils.get_package_contacts(pkg_id)
            contact = fn.first(filter(lambda c: c.get('id') == contact_id, contacts))

            if contact and 'email' in contact.keys():
                email = contact.get('email')
                name = contact.get('name')
                recipient = {'name': name, 'email': email}

        return recipient
Пример #5
0
    def _get_contact_email(self, pkg_id, contact_id):
        recipient = None
        if contact_id:
            contacts = utils.get_package_contacts(pkg_id)
            contact = fn.first(filter(lambda c: c.get('id') == contact_id, contacts))

            if contact and 'email' in contact.keys():
                email = contact.get('email')
                name = contact.get('name')
                recipient = {'name': name, 'email': email}

        return recipient
Пример #6
0
    def test_contact(self):

        data = copy.deepcopy(TEST_DATADICT)
        data['private'] = False
        data['contact'][0]['email'] = '*****@*****.**'

        model.User(name="test_sysadmin", sysadmin=True).save()

        organisation = get_action('organization_create')(
            {
                'user': '******'
            }, {
                'name': 'test-organization',
                'title': "Test organization"
            })
        data['owner_org'] = organisation.get('name')
        package = get_action('package_create')({'user': '******'}, data)
        name = package['name']
        id = package['id']
        package_contact_id = utils.get_package_contacts(id)[0].get('id')

        send_contact_offset = url_for("/contact/send/{0}".format(id))
        res = self.app.post(send_contact_offset,
                            params={'recipient': package_contact_id})
        assert res.status == 302

        dataset_offset = url_for("/dataset/{0}".format(name))
        res = self.app.post(dataset_offset)
        assert 'Message not sent' in res

        import base64
        import time

        cc = ContactController()
        _time = base64.b64encode(
            cc.crypto.encrypt(cc._pad(str(int(time.time())))))

        params = {'recipient': package_contact_id, 'accept_logging': 'True'}

        self.app.post(send_contact_offset, params=params, status=302)
        res = self.app.post(dataset_offset)
        assert 'spam bot' in res

        _time = base64.b64encode(
            cc.crypto.encrypt(cc._pad(str(int(time.time()) - 21))))
        params = {'recipient': package_contact_id, 'accept_logging': 'True'}
        self.app.post(send_contact_offset, params=params, status=302)
        offset = url_for("/dataset/{0}".format(name))
        res = self.app.post(offset)

        assert 'Message not sent' in res
Пример #7
0
    def render_contact_form(self, pkg_id):
        """
        Render the contact form if allowed.

        :param pkg_id: package id
        :type pkg_id: string
        """

        c.package = Package.get(pkg_id)

        if not c.package:
            abort(404, _(u"Dataset not found"))

        if asbool(config.get('kata.disable_contact')):
            h.flash_error(_(u"Sending contact emails is prohibited for now. "
                            u"Please try again later or contact customer service."))

            return redirect(h.url_for(controller='package',
                                      action="read",
                                      id=c.package.name))

        contacts = utils.get_package_contacts(c.package.id)
        c.recipient_options = []
        for contact in contacts:
            if 'name' in contact:
                text_val = contact['name']
            else:
                at_idx = contact['email'].find('@')
                text_val = contact['email'][0:at_idx]
                text_val = text_val.replace(".", " ").title()
                print(text_val)

            c.recipient_options.append({'text': text_val, 'value': contact['id']})

        c.recipient_index = request.params.get('recipient', '')
        c.current_time = base64.b64encode(self.crypto.encrypt(self._pad(str(int(time.time())))))
        return render('contact/contact_form.html')