Пример #1
0
def test_get_group_data(client):
    assert helpers.get_group_data(4) == {}
    assert helpers.get_group_data(1, ["not_a_real_field"]) == "Invalid field"
    assert helpers.get_group_data(1) == group
    assert helpers.get_group_data(1, ["group_name"]) == {
        "group_name": "Donut Devteam"
    }
Пример #2
0
def test_create_group(client):
    group_id = helpers.create_group("Page House", "May the work be light",
                                    "House", False, False, True, True)
    assert helpers.get_group_data(group_id, [
        "group_id", "group_name", "group_desc", "type", "anyone_can_send",
        "newsgroups", "visible", "admin_control_members"
    ]) == {
        "group_name": "Page House",
        "group_desc": "May the work be light",
        "type": "House",
        "newsgroups": False,
        "anyone_can_send": False,
        "visible": True,
        "admin_control_members": True,
        "group_id": group_id
    }

    # check that a new position with name "Member" was created
    assert helpers.get_group_positions(group_id) == [{
        "pos_id": 6,
        "pos_name": "Member"
    }]
    helpers.delete_group(group_id)
    assert helpers.get_group_data(group_id) == {}
    assert helpers.get_group_positions(group_id) == []
Пример #3
0
def all_posts(group_id):
    if 'username' not in flask.session:
        return flask.abort(403)
    user_id = auth_utils.get_user_id(flask.session['username'])
    if not groups.is_user_in_group(user_id, group_id):
        return flask.abort(403)
    group_name = groups.get_group_data(group_id, ['group_name'])['group_name']
    return flask.render_template('all_posts.html',
                                 group_id=group_id,
                                 group_name=group_name,
                                 messages=helpers.get_past_messages(
                                     group_id, 50))
Пример #4
0
def view_group(group_id):
    if 'username' not in flask.session:
        return flask.abort(403)
    user_id = auth_utils.get_user_id(flask.session['username'])
    actions = helpers.get_user_actions(user_id, group_id)
    fields = [
        'group_id', 'group_name', 'group_desc', 'anyone_can_send', 'visible'
    ]
    group_info = groups.get_group_data(group_id, fields)
    applications = None
    if actions['control']:
        applications = helpers.get_applications(group_id)
    messages = None
    member = groups.is_user_in_group(user_id, group_id)
    if member:
        messages = helpers.get_past_messages(group_id)
    return flask.render_template('group.html',
                                 group=group_info,
                                 member=member,
                                 actions=actions,
                                 messages=messages,
                                 owners=helpers.get_owners(group_id),
                                 applications=applications)
Пример #5
0
def post_message():
    if 'username' not in flask.session:
        return flask.abort(403)
    user_id = auth_utils.get_user_id(flask.session['username'])
    fields = ['group', 'subject', 'msg', 'poster']
    data = {}
    for field in fields:
        data[field] = flask.request.form.get(field)
    group_id = data['group']
    actions = helpers.get_user_actions(user_id, group_id)
    if not actions['send']:
        return flask.abort(403)
    data['group_name'] = groups.get_group_data(group_id,
                                               ['group_name'])['group_name']
    full_name = get_name_and_email(user_id)['full_name']
    poster = data['poster']
    if poster is None:
        # If not posting from a position, just use the user's name
        data['poster'] = full_name
    else:
        # If positing from a position, ensure the user has that position
        poster = int(poster)
        pos_name = None
        for position in helpers.get_posting_positions(group_id, user_id):
            if position['pos_id'] == poster:
                pos_name = position['pos_name']
                break
        if pos_name is None:
            flask.abort(403)
        data['poster'] = f'{pos_name} ({full_name})'
    data['plain'] = html2plain.handle(data['msg'])
    if helpers.send_email(data):
        flask.flash('Email sent')
        helpers.insert_email(user_id, data)
    else:
        flask.flash('Email failed to send')
    return flask.redirect(flask.url_for('newsgroups.post'))
Пример #6
0
def get_groups(group_id):
    """GET /1/groups/<int:group_id>"""
    return jsonify(helpers.get_group_data(group_id))