Beispiel #1
0
def get_users(user_dao, request_dict):
    """View the maintainers, organizers, and campaign coordinators"""

    org_dao = OrganizerDAO(user_dao)
    user_list = org_dao.get_user_list()

    return {'data': user_list}
Beispiel #2
0
def add_coordinator(user_dao, campaign_id, request_dict):
    """
    Summary: -
        Add a new coordinator identified by Wikimedia username to a campaign
        identified by campaign ID

    Request mode:
        username

    Response model:
        username
        last_active_date
        campaign_id

    Errors:
       403: User does not have permission to add coordinators

    """
    org_dao = OrganizerDAO(user_dao)
    new_user_name = request_dict.get('username')
    new_coord = org_dao.add_coordinator(campaign_id, new_user_name)
    data = {
        'username': new_coord.username,
        'campaign_id': campaign_id,
        'last_active_date': format_date(new_coord.last_active_date)
    }
    return {'data': data}
Beispiel #3
0
def add_series(user_dao, request_dict):
    org_dao = OrganizerDAO(user_dao)

    name = request_dict['name']
    description = request_dict['description']
    url = request_dict['url']
    status = request_dict.get('status')

    new_series = org_dao.create_series(name, description, url, status)
    return {'data': new_series}
Beispiel #4
0
def remove_coordinator(user_dao, campaign_id, request_dict):
    org_dao = OrganizerDAO(user_dao)
    username = request_dict.get('username')
    old_coord = org_dao.remove_coordinator(campaign_id, username)
    data = {
        'username': username,
        'campaign_id': campaign_id,
        'last_active_date': format_date(old_coord.last_active_date)
    }
    return {'data': data}
Beispiel #5
0
def create_campaign(user_dao, request_dict):
    """
    Summary: Post a new campaign

    Request model:
        campaign_name:
            type: string

    Response model: AdminCampaignDetails
    """
    org_dao = OrganizerDAO(user_dao)

    name = request_dict.get('name')

    if not name:
        raise InvalidAction('name is required to create a campaign, got %r' %
                            name)
    now = datetime.datetime.utcnow().isoformat()
    open_date = request_dict.get('open_date', now)

    if open_date:
        open_date = js_isoparse(open_date)

    close_date = request_dict.get('close_date')

    if close_date:
        close_date = js_isoparse(close_date)

    url = request_dict['url']

    series_id = request_dict.get('series_id', 1)

    coord_names = request_dict.get('coordinators')

    coords = [user_dao.user
              ]  # Organizer is included as a coordinator by default
    for coord_name in coord_names:
        coord = org_dao.get_or_create_user(coord_name, 'coordinator')
        coords.append(coord)

    campaign = org_dao.create_campaign(name=name,
                                       open_date=open_date,
                                       close_date=close_date,
                                       series_id=series_id,
                                       url=url,
                                       coords=set(coords))
    # TODO: need completion info for each round
    data = campaign.to_details_dict()

    return {'data': data}
Beispiel #6
0
def edit_series(user_dao, series_id, request_dict):
    org_dao = OrganizerDAO(user_dao)
    series_dict = {}
    name = request_dict.get('name')
    if name:
        series_dict['name'] = name
    description = request_dict.get('description')
    if description:
        series_dict['description'] = description
    url = request_dict.get('url')
    if url:
        series_dict['url'] = url
    status = request_dict.get('status')
    if status:
        series_dict['status'] = status

    new_series = org_dao.edit_series(series_id, series_dict)
    return {'data': new_series}