def issue_create(context, data_dict): '''Add a new issue. You must provide your API key in the Authorization header. :param title: the title of the issue :type title: string :param description: the description of the issue item (optional) :type description: string :param dataset_id: the name or id of the dataset that the issue item belongs to (optional) :type dataset_id: string :returns: the newly created issue item :rtype: dictionary ''' p.toolkit.check_access('issue_create', context, data_dict) user = context['user'] user_obj = model.User.get(user) data_dict['user_id'] = user_obj.id dataset = model.Package.get(data_dict['dataset_id']) del data_dict['dataset_id'] issue = issuemodel.Issue(**data_dict) issue.dataset_id = dataset.id session = context['session'] issue.number = _get_next_issue_number(session, dataset.id) session.add(issue) session.commit() notifications = p.toolkit.asbool( config.get('ckanext.issues.send_email_notifications')) if notifications: recipients = _get_recipients(context, dataset) subject = get_issue_subject(issue.as_dict()) for i, recipient in enumerate(recipients): body = _get_issue_email_body(issue, subject, user_obj, recipient) user_obj = model.User.get(recipient['user_id']) if i == 0: log.debug('Mailing to %s (and %s others):\n%s', user_obj.email, len(recipients) - 1, body) try: mailer.mail_user(user_obj, subject, body) except (mailer.MailerException, TypeError) as e: # TypeError occurs when we're running command from ckanapi log.debug(e) log.debug('Created issue %s (%s)' % (issue.title, issue.id)) return issue.as_dict()
def issue_create(context, data_dict): '''Add a new issue. You must provide your API key in the Authorization header. :param title: the title of the issue :type title: string :param description: the description of the issue item (optional) :type description: string :param dataset_id: the name or id of the dataset that the issue item belongs to (optional) :type dataset_id: string :returns: the newly created issue item :rtype: dictionary ''' p.toolkit.check_access('issue_create', context, data_dict) user = context['user'] user_obj = model.User.get(user) data_dict['user_id'] = user_obj.id dataset_id = data_dict['dataset_id'] dataset = model.Package.get(dataset_id) del data_dict['dataset_id'] issue = issuemodel.Issue(**data_dict) issue.dataset = dataset model.Session.add(issue) model.Session.commit() review_system.issue_created_in_dataset(data_dict={'dataset_id':dataset_id}) notification.notify_create_reopen(context,issue) log.debug('Created issue %s (%s)' % (issue.title, issue.id)) return issue.as_dict()