예제 #1
0
def issue_comment_create(context, data_dict):
    '''Add a new issue comment.

    You must provide your API key in the Authorization header.

    :param comment: the comment text
    :type comment: string
    :param issue_number: the number of the issue the comment belongs to
    :type issue_number: integer
    :param dataset_id: the dataset name or id of the issue the comment belongs to
    :type dataset_id: unicode

    :returns: the newly created issue comment
    :rtype: dictionary
    '''
    p.toolkit.check_access('issue_comment_create', context, data_dict)
    user = context['user']
    user_obj = model.User.get(user)

    issue = issuemodel.Issue.get_by_name_or_id_and_number(
        dataset_name_or_id=data_dict['dataset_id'],
        issue_number=data_dict['issue_number'],
        session=context['session'])

    comment_dict = data_dict.copy()
    del comment_dict['dataset_id']
    del comment_dict['issue_number']
    comment_dict.update({
        'user_id': user_obj.id,
        'issue_id': issue.id,
    })

    issue_comment = issuemodel.IssueComment(**comment_dict)
    model.Session.add(issue_comment)
    model.Session.commit()

    notifications = p.toolkit.asbool(
        config.get('ckanext.issues.send_email_notifications'))

    if notifications:
        dataset = model.Package.get(data_dict['dataset_id'])
        recipients = _get_recipients(context, dataset)
        subject = get_issue_subject(issue.as_dict())

        for recipient in recipients:
            body = _get_comment_email_body(issue_comment, subject, user_obj,
                                           recipient)

            user_obj = model.User.get(recipient['user_id'])
            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 comment %s' % (issue.id))
    return issue_comment.as_dict()
예제 #2
0
def issue_comment_create(context, data_dict):
    '''Add a new issue comment.

    You must provide your API key in the Authorization header.

    :param comment: the comment text
    :type comment: string
    :param issue_number: the number of the issue the comment belongs to
    :type issue_number: integer
    :param dataset_id: the dataset name or id of the issue the comment belongs to
    :type dataset_id: unicode

    :returns: the newly created issue comment
    :rtype: dictionary
    '''
    p.toolkit.check_access('issue_comment_create', context, data_dict)
    user = context['user']
    user_obj = model.User.get(user)

    issue = issuemodel.Issue.get_by_name_or_id_and_number(
        dataset_name_or_id=data_dict['dataset_id'],
        issue_number=data_dict['issue_number'],
        session=context['session']
    )

    comment_dict = data_dict.copy()
    del comment_dict['dataset_id']
    del comment_dict['issue_number']
    comment_dict.update({
        'user_id': user_obj.id,
        'issue_id': issue.id,
    })

    issue_comment = issuemodel.IssueComment(**comment_dict)
    model.Session.add(issue_comment)
    model.Session.commit()

    notifications = p.toolkit.asbool(
        config.get('ckanext.issues.send_email_notifications')
    )

    if notifications:
        dataset = model.Package.get(data_dict['dataset_id'])
        recipients = _get_recipients(context, dataset)
        subject = get_issue_subject(issue.as_dict())

        for recipient in recipients:
            body = _get_comment_email_body(
                issue_comment, subject, user_obj, recipient)

            user_obj = model.User.get(recipient['user_id'])
            try:
                mailer.mail_user(user_obj, subject, body)
            except (mailer.MailerException, TypeError), e:
                # TypeError occurs when we're running command from ckanapi
                log.debug(e.message)
예제 #3
0
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()
예제 #4
0
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), e:
                # TypeError occurs when we're running command from ckanapi
                log.debug(e.message)
예제 #5
0
def assign(dataset_id, issue_number):
    dataset = _before_dataset(dataset_id)
    if request.method == 'POST':
        try:
            assignee_id = request.form.get('assignee')
            assignee = toolkit.get_action('user_show')(data_dict={
                'id': assignee_id
            })
        except toolkit.ObjectNotFound:
            h.flash_error(_('User {0} does not exist'.format(assignee_id)))
            return p.toolkit.redirect_to('issues.show_issue',
                                         issue_number=issue_number,
                                         dataset_id=dataset_id)

        try:
            issue = toolkit.get_action('issue_update')(
                data_dict={
                    'issue_number': issue_number,
                    'assignee_id': assignee['id'],
                    'dataset_id': dataset_id,
                    'assignee': assignee_id
                })

            notifications = p.toolkit.asbool(
                config.get('ckanext.issues.send_email_notifications'))

            if notifications:
                subject = get_issue_subject(issue)
                body = u'Доделено на {user}.\n\n---\nCaktuar për {user}.\n\n---\nAssigned to {user}.'.format(
                    user=assignee['display_name'])

                user_obj = model.User.get(assignee_id)
                try:
                    mailer.mail_user(user_obj, subject, body)
                except mailer.MailerException as e:
                    log.debug(e.message)

        except toolkit.NotAuthorized:
            msg = _(
                'Unauthorized to assign users to issue'.format(issue_number))
            toolkit.abort(401, msg)
        except toolkit.ObjectNotFound as e:
            toolkit.abort(404)
        except toolkit.ValidationError as e:
            toolkit.abort(404)

        return p.toolkit.redirect_to('issues.show_issue',
                                     issue_number=issue_number,
                                     dataset_id=dataset_id)
예제 #6
0
    def assign(self, dataset_id, issue_number):
        dataset = self._before_dataset(dataset_id)
        if request.method == 'POST':
            try:
                assignee_id = request.POST.get('assignee')
                assignee = toolkit.get_action('user_show')(
                    data_dict={'id': assignee_id})
            except toolkit.ObjectNotFound:
                h.flash_error(_('User {0} does not exist'.format(assignee_id)))
                return p.toolkit.redirect_to('issues_show',
                                             issue_number=issue_number,
                                             dataset_id=dataset_id)

            try:
                issue = toolkit.get_action('issue_update')(
                    data_dict={
                        'issue_number': issue_number,
                        'assignee_id': assignee['id'],
                        'dataset_id': dataset_id
                    }
                )

                notifications = p.toolkit.asbool(
                    config.get('ckanext.issues.send_email_notifications')
                )

                if notifications:
                    subject = get_issue_subject(issue)
                    body = toolkit._('Assigned to {user}'.format(
                        user=assignee['display_name']))

                    user_obj = model.User.get(assignee_id)
                    try:
                        mailer.mail_user(user_obj, subject, body)
                    except mailer.MailerException, e:
                        log.debug(e.message)

            except toolkit.NotAuthorized:
                msg = _('Unauthorized to assign users to issue'.format(
                    issue_number))
                toolkit.abort(401, msg)
            except toolkit.ValidationError, e:
                toolkit.abort(404)
예제 #7
0
    def assign(self, dataset_id, issue_number):
        dataset = self._before_dataset(dataset_id)
        if request.method == 'POST':
            try:
                assignee_id = request.POST.get('assignee')
                assignee = toolkit.get_action('user_show')(data_dict={
                    'id': assignee_id
                })
            except toolkit.ObjectNotFound:
                h.flash_error(
                    _(u'User {0} does not exist').format(assignee_id))
                return p.toolkit.redirect_to('issues_show',
                                             issue_number=issue_number,
                                             dataset_id=dataset_id)

            try:
                issue = toolkit.get_action('issue_update')(
                    data_dict={
                        'issue_number': issue_number,
                        'assignee_id': assignee['id'],
                        'dataset_id': dataset_id
                    })

                notifications = p.toolkit.asbool(
                    config.get('ckanext.issues.send_email_notifications'))

                if notifications:
                    subject = get_issue_subject(issue)
                    msg = toolkit._("Assigned to %s")
                    body = msg % assignee['display_name']

                    user_obj = model.User.get(assignee_id)
                    try:
                        mailer.mail_user(user_obj, subject, body)
                    except mailer.MailerException, e:
                        log.debug(e.message)

            except toolkit.NotAuthorized:
                msg = _(u'Unauthorized to assign users to issue')
                toolkit.abort(401, msg)
            except toolkit.ValidationError, e:
                toolkit.abort(404)