Beispiel #1
0
def get_regular_user_context():
    user = factories.User()
    auth_user_obj = CkanUser.get(user['id'])
    return {
        'user': user.get('name'),
        'auth_user_obj': auth_user_obj,
        'model': model,
        'session': model.Session,
        'ignore_auth': True,
    }
def convert_id_to_email(ids):
    ids = ids.split(',')
    emails = []

    for id in ids:
        user = User.get(id)

        if user:
            emails.append(user.email)

    return ','.join(emails)
Beispiel #3
0
    def crawl(self):
        site_url = config.get('ckan.site_url')
        crawl_url_blacklist_regex = re.compile(r'/activity/')
        crawl_content_type_whitelist_regex = re.compile(r'text/html')
        url_regex = re.compile(
            r'href="((http[s]?://|/)(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)"'
        )
        site_map = {}
        to_crawl = [site_url]
        while to_crawl:
            next_crawl = to_crawl.pop(0)
            new_crawl = crawl(next_crawl, site_url, site_map,
                              crawl_url_blacklist_regex,
                              crawl_content_type_whitelist_regex, url_regex)
            to_crawl += new_crawl

        external_urls = get_external_children(site_url, site_map)
        url_errors = {}
        for url in sorted(external_urls):
            try:
                urlopen(url)
            except HTTPError as e:
                referrers = find_referrers(url, site_map)
                url_errors[url] = referrers
            except URLError as e:
                referrers = find_referrers(url, site_map)
                url_errors[url] = referrers

        for url, referrers in url_errors.iteritems():
            result = LinkValidationResult()
            result.type = u'error'
            result.url = url
            result.referrers = []

            for referrer_url in referrers:
                referrer = LinkValidationReferrer()
                referrer.result_id = result.id
                referrer.url = referrer_url
                result.referrers.append(referrer)

            model.Session.add(result)
        model.Session.commit()

        if url_errors:
            from ckan.model.user import User
            admin = User.get('admin')
            mailer.mail_user(
                admin, 'URL errors',
                '\n\n'.join('%s\n%s' % (u, '\n'.join('  - %s' % r for r in rs))
                            for u, rs in url_errors.iteritems()))
Beispiel #4
0
    def policy(self, policy_id):
        if not authz.is_sysadmin(c.user):
            abort(403, _('Unauthorized'))
        c.policy = GDPRPolicy.get(id=policy_id)
        accepted_policy = GDPRAccept.filter(policy_id=c.policy.id)
        c.accepting_users = []
        for policy in accepted_policy:
            c.accepting_users.append(User.get(policy.user_id))

        c.not_accepting_users = [
            item for item in User.all() if item not in c.accepting_users
        ]

        return toolkit.render('gdpr/policy.html')
def request_create(context, data_dict):
    '''Create new request data.

    :param sender_name: The name of the sender who request data.
    :type sender_name: string

    :param organization: The sender's organization.
    :type organization: string

    :param email_address: The sender's email_address.
    :type email_address: string

    :param message_content: The content of the message.
    :type message_content: string

    :param package_id: The id of the package the data belongs to.
    :type package_id: string

    :returns: the newly created request data
    :rtype: dictionary

    '''

    check_access('requestdata_request_create', context, data_dict)

    data, errors = df.validate(data_dict, schema.request_create_schema(),
                               context)

    if errors:
        raise toolkit.ValidationError(errors)

    sender_name = data.get('sender_name')
    organization = data.get('organization')
    email_address = data.get('email_address')
    message_content = data.get('message_content')
    package_id = data.get('package_id')

    package = toolkit.get_action('package_show')(context, {'id': package_id})

    sender_user_id = User.get(context['user']).id

    maintainers = package['maintainer'].split(',')

    data = {
        'sender_name': sender_name,
        'sender_user_id': sender_user_id,
        'organization': organization,
        'email_address': email_address,
        'message_content': message_content,
        'package_id': package_id
    }

    requestdata = ckanextRequestdata(**data)
    requestdata.save()
    maintainers_list = []
    is_hdx = helpers.is_hdx_portal()

    for id in maintainers:
        try:
            if is_hdx:
                main_ids = toolkit.get_action('user_show')(context, {'id': id})
                user = User.get(main_ids['id'])
            else:
                user = User.get(id)
            data = ckanextMaintainers()
            data.maintainer_id = user.id
            data.request_data_id = requestdata.id
            data.email = user.email
            maintainers_list.append(data)
        except NotFound:
            pass

    out = ckanextMaintainers.insert_all(maintainers_list, requestdata.id)

    return out