Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model.Session.add(self.otherUser)
model.Session.commit()
self.dataset = model.Package.get('annakarenina')
# test fixture
self.context = {
'model': model,
'auth_user_obj': self.user,
'user': self.user.name
}
# fixture issue
self.issue = logic.get_action('issue_create')(self.context, {
'title': 'General test issue',
'description': 'Abc\n\n## Section',
'dataset_id': self.dataset.id
})
self.issue2 = logic.get_action('issue_create')(self.context, {
'title': 'General test issue 2',
'description': '',
'dataset_id': self.dataset.id
})
def test_issue_comment_new_post(self):
ourissue = logic.get_action('issue_create')(self.context, {
'title': 'General test issue',
'description': 'Abc\n\n## Section',
'dataset_id': self.dataset.id
})
offset = url_for('issues_comments', package_id=self.dataset.name,
id=ourissue['id'])
data = {
'comment': ''
}
res = self.app.post(offset,
params=data,
status=[302],
extra_environ=self.extra_environ_tester
)
issueUpdate = logic.get_action('issue_show')(self.context, {
'id': ourissue['id']
@click_config_option
@click.option(u'--dryrun', is_flag=True)
@click.option(u'--force', is_flag=True)
@click.option(u'--all-harvesters', is_flag=True)
@click.pass_context
def send_harvester_status_emails(ctx, config, dryrun, force, all_harvesters):
load_config(config or ctx.obj['config'])
email_notification_recipients = t.aslist(t.config.get('ckanext.apicatalog.harvester_status_recipients', ''))
if not email_notification_recipients and not dryrun:
print 'No recipients configured'
return
status_opts = {} if not all_harvesters else {'include_manual': True, 'include_never_run': True}
status = get_action('harvester_status')({}, status_opts)
errored_runs = any(item.get('errors') != 0 for item in status.values())
running = (item.get('started') for item in status.values() if item.get('status') == 'running')
stuck_runs = any(_elapsed_since(started).days > 1 for started in running)
if not (errored_runs or stuck_runs) and not force:
print 'Nothing to report'
return
if len(status) == 0:
print 'No harvesters matching criteria found'
return
site_title = t.config.get('ckan.site_title', '')
today = datetime.now().date().isoformat()
def get_group(id):
context = {'ignore_auth': True,
'limits': {'packages': 2},
'for_view': True}
data_dict = {'id': id,
'include_datasets': True}
try:
out = logic.get_action('organization_show')(context, data_dict)
except logic.NotFound:
return None
return out
def _before_dataset(self, dataset_id):
'''Returns the dataset dict and checks issues are enabled for it.'''
self.context = {'for_view': True}
try:
pkg = logic.get_action('package_show')(self.context,
{'id': dataset_id})
# need this as some templates in core explicitly reference
# c.pkg_dict
c.pkg = pkg
c.pkg_dict = c.pkg
# keep the above lines to keep current code working till it's all
# refactored out, otherwise, we should pass pkg as an extra_var
# directly that's returned from this function
if not issues_helpers.issues_enabled(pkg):
abort(404, _('Issues have not been enabled for this dataset'))
return pkg
except logic.NotFound:
abort(404, _('Dataset not found'))
except p.toolkit.NotAuthorized:
p.toolkit.abort(401,
import ckan
import ckan.lib.base as base
import ckan.logic as logic
import ckan.plugins as plugins
from ckan.common import c, _
import logging
import json
get_action = logic.get_action
log = logging.getLogger(__name__)
class PahaPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IRoutes, inherit=True)
plugins.implements(plugins.IAuthFunctions)
plugins.implements(plugins.IActions)
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.key_whitelist = []
# IConfigurer
def update_config(self, config_):
@return: package
"""
# Merge package params with default params
params = dict(chain(self.default_package_params.iteritems(), self.package.iteritems()))
try:
# Try and load the KE EMu package
package = logic.get_action('package_show')(context, {'id': params['name']})
except logic.NotFound:
# KE EMu package not found; create it
# Error adds dataset_show to __auth_audit: remove it
context['__auth_audit'] = []
package = logic.get_action('package_create')(context, params)
return package
def get_random_groups(random_count, excluded_ids):
''' Return random valid groups up to random_count where id is not in excluded '''
chunk_size = 2 * random_count
package_search = logic.get_action('package_search')
def get_orgs_with_visible_packages(ids):
id_chunks = (ids[i:i+chunk_size] for i in range(0, len(ids), chunk_size))
for chunk_ids in id_chunks:
query = "organization:(%s)+shared_resource:yes" % " OR ".join(chunk_ids)
packages = package_search({}, {"q": query}).get('results', [])
valid_ids = {p['organization']['name'] for p in packages}
for id in (id for id in ids if id in valid_ids):
yield id
all_items = logic.get_action('organization_list')({}, {})
items = list(set(i for i in all_items if i not in excluded_ids))
random.shuffle(items)
result_ids = itertools.islice(get_orgs_with_visible_packages(items), random_count)
result = [get_group(id) for id in result_ids]
return result
Adds example vocabularies to the database if they don't already exist.
'''
user = get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
context = {'model': model, 'session': model.Session, 'user': user['name']}
try:
data = {'id': forms.GENRE_VOCAB}
get_action('vocabulary_show')(context, data)
log.info("Example genre vocabulary already exists, skipping.")
except NotFound:
log.info("Creating vocab %s" % forms.GENRE_VOCAB)
data = {'name': forms.GENRE_VOCAB}
vocab = get_action('vocabulary_create')(context, data)
log.info("Adding tag %s to vocab %s" % ('jazz', forms.GENRE_VOCAB))
data = {'name': 'jazz', 'vocabulary_id': vocab['id']}
get_action('tag_create')(context, data)
log.info("Adding tag %s to vocab %s" % ('soul', forms.GENRE_VOCAB))
data = {'name': 'soul', 'vocabulary_id': vocab['id']}
get_action('tag_create')(context, data)
try:
data = {'id': forms.COMPOSER_VOCAB}
get_action('vocabulary_show')(context, data)
log.info("Example composer vocabulary already exists, skipping.")
except NotFound:
log.info("Creating vocab %s" % forms.COMPOSER_VOCAB)
data = {'name': forms.COMPOSER_VOCAB}
vocab = get_action('vocabulary_create')(context, data)
log.info("Adding tag %s to vocab %s" % ('Bob Mintzer', forms.COMPOSER_VOCAB))
data = {'name': 'Bob Mintzer', 'vocabulary_id': vocab['id']}
get_action('tag_create')(context, data)
log.info("Adding tag %s to vocab %s" % ('Steve Lewis', forms.COMPOSER_VOCAB))