Example #1
0
def test_get_public_contacts():
    agenda = {}
    assert get_public_contacts(agenda) == []

    agenda['event'] = {}
    assert get_public_contacts(agenda) == []

    agenda['event']['event_contact_info'] = [{
        '_created': '2018-05-16T11:24:20+0000',
        'honorific': 'Professor',
        '_id': '5afc14e41d41c89668850f67',
        'first_name': 'Tom',
        'is_active': True,
        'organisation': 'AAP',
        'contact_email': ['*****@*****.**'],
        '_updated': '2018-05-16T11:24:20+0000',
        'mobile': [],
        'contact_phone': [],
        'last_name': 'Jones',
        'public': True
    }]
    assert get_public_contacts(agenda) == [{
        'name': 'Tom Jones',
        'organisation': 'AAP',
        'phone': '',
        'email': '*****@*****.**',
        'mobile': ''
    }]
Example #2
0
def send_agenda_notification_email(user, agenda, message, subject,
                                   original_agenda, coverage_updates,
                                   related_planning_removed, coverage_updated,
                                   time_updated):
    if agenda and user.get('receive_email'):
        kwargs = dict(
            message=message,
            agenda=agenda,
            dateString=get_agenda_dates(
                agenda if agenda.get('dates') else original_agenda,
                date_paranthesis=True),
            location=get_location_string(agenda),
            contacts=get_public_contacts(agenda),
            links=get_links(agenda),
            is_admin=is_admin_or_internal(user),
            original_agenda=original_agenda,
            coverage_updates=coverage_updates,
            related_planning_removed=related_planning_removed,
            coverage_updated=coverage_updated,
            time_updated=time_updated,
        )
        send_email(to=[user['email']],
                   subject=subject,
                   text_body=render_template('agenda_updated_email.txt',
                                             **kwargs),
                   html_body=render_template('agenda_updated_email.html',
                                             **kwargs))
Example #3
0
def share():
    current_user = get_user(required=True)
    item_type = get_type()
    data = get_json_or_400()
    assert data.get('users')
    assert data.get('items')
    items = get_items_for_user_action(data.get('items'), item_type)
    for user_id in data['users']:
        user = superdesk.get_resource_service('users').find_one(req=None,
                                                                _id=user_id)
        subject = items[0].get('headline')

        # If it's an event, 'name' is the subject
        if items[0].get('event'):
            subject = items[0]['name']

        if not user or not user.get('email'):
            continue
        template_kwargs = {
            'recipient': user,
            'sender': current_user,
            'items': items,
            'message': data.get('message'),
            'section': request.args.get('type', 'wire')
        }
        if item_type == 'agenda':
            template_kwargs['maps'] = data.get('maps')
            template_kwargs['dateStrings'] = [
                get_agenda_dates(item) for item in items
            ]
            template_kwargs['locations'] = [
                get_location_string(item) for item in items
            ]
            template_kwargs['contactList'] = [
                get_public_contacts(item) for item in items
            ]
            template_kwargs['linkList'] = [get_links(item) for item in items]
            template_kwargs['is_admin'] = is_admin_or_internal(user)

        send_email(
            [user['email']],
            gettext('From %s: %s' % (app.config['SITE_NAME'], subject)),
            text_body=flask.render_template('share_{}.txt'.format(item_type),
                                            **template_kwargs),
            html_body=flask.render_template('share_{}.html'.format(item_type),
                                            **template_kwargs),
        )
    update_action_list(data.get('items'), 'shares', item_type=item_type)
    get_resource_service('history').create_history_record(
        items, 'share', current_user, request.args.get('type', 'wire'))
    return flask.jsonify(), 201
Example #4
0
def send_agenda_notification_email(user, agenda, message, subject):
    if agenda and user.get('receive_email'):
        kwargs = dict(
            message=message,
            item=agenda,
            dateString=get_agenda_dates(agenda),
            location=get_location_string(agenda),
            contacts=get_public_contacts(agenda),
            links=get_links(agenda),
            is_admin=is_admin_or_internal(user),
        )
        send_email(to=[user['email']],
                   subject=subject,
                   text_body=render_template('agenda_updated_email.txt',
                                             **kwargs),
                   html_body=render_template('agenda_updated_email.html',
                                             **kwargs))
Example #5
0
def item(_id):
    item = get_entity_or_404(_id, 'agenda')

    user = get_user()
    company = get_user_company(user)
    if not is_admin_or_internal(user):
        item.get('event', {}).pop('files', None)
        planning_items = item.get('planning_items', [])
        [item.pop('internal_note', None) for item in planning_items]
        coverages = item.get('coverages', [])
        [c.get('planning', {}).pop('internal_note', None) for c in coverages]
        item.get('event', {}).pop('internal_note', None)

    if company and not is_admin(user) and company.get('events_only', False):
        # if the company has permission events only permission then
        # remove planning items and coverages.
        if not item.get('event'):
            # for adhoc planning items abort the request
            flask.abort(403)

        item.pop('planning_items', None)
        item.pop('coverages', None)

    if is_json_request(flask.request):
        return flask.jsonify(item)

    if 'print' in flask.request.args:
        map = flask.request.args.get('map')
        template = 'agenda_item_print.html'
        update_action_list([_id], 'prints', force_insert=True)
        return flask.render_template(
            template,
            item=item,
            map=map,
            dateString=get_agenda_dates(item),
            location=get_location_string(item),
            contacts=get_public_contacts(item),
            links=get_links(item),
            is_admin=is_admin_or_internal(user)
        )

    data = get_view_data()
    data['item'] = item
    return flask.render_template('agenda_index.html', data=data, title=item.get('name', item.get('headline')))
Example #6
0
def _send_history_match_agenda_notification_email(user, item):
    app_name = current_app.config['SITE_NAME']
    url = url_for_agenda(item, _external=True)
    recipients = [user['email']]
    subject = gettext(
        'New update for your previously accessed agenda: {}'.format(
            item['name']))
    text_body = render_template('new_item_notification.txt',
                                app_name=app_name,
                                is_topic=False,
                                name=user.get('first_name'),
                                item=item,
                                url=url,
                                type='agenda',
                                dateString=get_agenda_dates(item),
                                location=get_location_string(item),
                                contacts=get_public_contacts(item),
                                links=get_links(item),
                                is_admin=is_admin_or_internal(user),
                                section='agenda')

    send_email(to=recipients, subject=subject, text_body=text_body)
Example #7
0
def _send_new_agenda_notification_email(user, topic_name, item):
    url = url_for_agenda(item, _external=True)
    recipients = [user['email']]
    subject = gettext('New update for followed agenda: {}'.format(topic_name))
    kwargs = dict(app_name=current_app.config['SITE_NAME'],
                  is_topic=True,
                  topic_name=topic_name,
                  name=user.get('first_name'),
                  item=item,
                  url=url,
                  type='agenda',
                  dateString=get_agenda_dates(item),
                  location=get_location_string(item),
                  contacts=get_public_contacts(item),
                  links=get_links(item),
                  is_admin=is_admin_or_internal(user),
                  section='agenda')
    text_body = render_template('new_item_notification.txt', **kwargs)
    html_body = render_template('new_item_notification.html', **kwargs)
    send_email(to=recipients,
               subject=subject,
               text_body=text_body,
               html_body=html_body)