Пример #1
0
def index(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] not in team['chiefs']:
        return redirect('/')
    ''' ..note::
        1. create campaign (campaign name) / list campaign
        2. write title, content(jinja2, markdown)
        3. pick up receiver
        4. send / send test

    '''

    if request.method == 'GET':
        return render_template('./sender.html')

    elif request.method == 'POST':
        data = request.get_json()

        if 'casename' in data and data['casename'] == 'get':
            return jsonify({
                'campaigns':
                list(SenderCampaign.get_list(pid=team['pid'], tid=team['tid']))
            })

        if 'casename' in data and data['casename'] == 'create':
            r = SenderCampaign.create(name=data['name'],
                                      pid=team['pid'],
                                      tid=team['tid'],
                                      uid=g.user['account']['_id'])

            return jsonify({'cid': r['_id']})
Пример #2
0
def members(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                g.user['account']['_id'] in team['owners'] or \
                g.user['account']['_id'] in project['owners'])

    uids = []
    uids.extend(team['chiefs'])
    uids.extend(team['members'])

    uids = list(set(uids))
    users_info = User.get_info(uids=uids)

    members = []
    for uid in uids:
        if uid in users_info:
            user = users_info[uid]

            user['chat'] = {}
            mid = MattermostTools.find_possible_mid(uid=uid)
            if mid:
                user['chat'] = {'mid': mid, 'name': MattermostTools.find_user_name(mid=mid)}

            members.append(user)

    members = sorted(members, key=lambda u: u['profile']['badge_name'].lower())

    return render_template('./team_members.html', project=project, team=team, is_admin=is_admin, members=members)
Пример #3
0
def index(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    for k in ('desc', 'public_desc'):
        if k not in team:
            team[k] = ''
        else:
            team[k] = re.sub('<a href="javascript:.*"', '<a href="/"', markdown(html.escape(team[k])))

    preview_public = False
    if 'preview' in request.args:
        preview_public = True

    join_able = not (g.user['account']['_id'] in team['members'] or \
                     g.user['account']['_id'] in team['chiefs'] or \
                     g.user['account']['_id'] in team['owners'] or \
                     g.user['account']['_id'] in project['owners'])

    is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                g.user['account']['_id'] in team['owners'] or \
                g.user['account']['_id'] in project['owners'])

    return render_template('./team_index.html', team=team, project=project,
            join_able=join_able, is_admin=is_admin, preview_public=preview_public)
Пример #4
0
def team_form_drink(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_drink.html', project=project, team=team)

    elif request.method == 'POST':
        post_data = request.get_json()
        if post_data['casename'] == 'get':
            data = Form.get_drink(pid=team['pid'], uid=g.user['account']['_id'])
            if not data:
                data = {'data': {'y18': False}}

            return jsonify({'data': data['data']})

        elif post_data['casename'] == 'post':
            if 'y18' in post_data:
                data = {'y18': bool(post_data['y18'])}
                Form.update_drink(pid=team['pid'], uid=g.user['account']['_id'], data=data)

        return jsonify({'data': post_data})
Пример #5
0
def team_form_parking_card(pid, tid):
    ''' Team form parking card '''
    # pylint: disable=too-many-return-statements
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_parking_card.html',
                               project=project,
                               team=team)

    if request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            data = Form.get_parking_card(pid=team['pid'],
                                         uid=g.user['account']['_id'])

            parking_card_options = []
            if 'parking_card' in project:
                parking_card_options = project['parking_card']

            if not data:
                return jsonify({
                    'data': {
                        'carno': '',
                        'dates': []
                    },
                    'parking_card_options': parking_card_options
                })

            return jsonify({
                'data': data['data'],
                'parking_card_options': parking_card_options
            })

        if post_data['casename'] == 'post':
            if 'data' in post_data and post_data['data']:
                carno = post_data['data']['carno'].strip().upper()
                if not carno:
                    return jsonify({})

                dates = post_data['data']['dates']

                Form.update_parking_card(pid=team['pid'],
                                         uid=g.user['account']['_id'],
                                         data={
                                             'carno': carno,
                                             'dates': dates
                                         })

                return jsonify({})

    return jsonify({}), 404
Пример #6
0
def team_form_parking_card(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_parking_card.html', project=project, team=team)

    elif request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            data = Form.get_parking_card(pid=team['pid'], uid=g.user['account']['_id'])
            if not data:
                return jsonify({'data': {'carno': '', 'dates': []}})

            return jsonify({'data': data['data']})

        elif post_data['casename'] == 'post':
            if 'data' in post_data and post_data['data']:
                carno = post_data['data']['carno'].strip().upper()
                if not carno:
                    return jsonify({})

                dates = post_data['data']['dates']

                Form.update_parking_card(pid=team['pid'], uid=g.user['account']['_id'],
                        data={'carno': carno, 'dates': dates})

                return jsonify({})
Пример #7
0
def team_edit(pid, tid):
    ''' Team edit '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        return render_template('./team_edit_setting.html',
                               project=project,
                               team=team)

    if request.method == 'POST':
        data = {
            'name': request.form['name'].strip(),
            'public_desc': request.form['public_desc'].strip(),
            'desc': request.form['desc'].strip(),
        }
        Team.update_setting(pid=team['pid'], tid=team['tid'], data=data)
        return redirect(
            url_for('team.team_edit',
                    pid=team['pid'],
                    tid=team['tid'],
                    _scheme='https',
                    _external=True))

    return '', 404
Пример #8
0
def team_form_clothes(pid, tid):
    ''' Team form clothes '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        return render_template('./form_clothes.html',
                               project=project,
                               team=team)

    if request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            data = Form.get_clothes(pid=team['pid'],
                                    uid=g.user['account']['_id'])

            in_action = False
            htg = ''
            if not data:
                data = {
                    'data': {
                        'clothes': '',
                        'htg': htg,
                        'in_action': in_action
                    }
                }

            if project['action_date'] + 86400 * 10 >= arrow.now().timestamp():
                in_action = True

            if 'htg' in data['data']:
                htg = data['data']['htg']

            return jsonify({
                'clothes': data['data']['clothes'],
                'htg': htg,
                'in_action': in_action,
            })

        if post_data['casename'] == 'post':
            if 'clothes' in post_data and post_data['clothes']:
                Form.update_clothes(pid=team['pid'],
                                    uid=g.user['account']['_id'],
                                    data={
                                        'clothes': post_data['clothes'],
                                        'htg': post_data['htg'],
                                    })
                return jsonify({})

    return jsonify({})
Пример #9
0
def team_form_appreciation(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        names = {
            'oauth': g.user['data']['name'],
        }

        if 'profile' in g.user['account'] and \
           'badge_name' in g.user['account']['profile'] and \
           g.user['account']['profile']['badge_name']:
            names['badge_name'] = g.user['account']['profile']['badge_name']

        if 'profile_real' in g.user['account'] and \
           'name' in g.user['account']['profile_real'] and \
           g.user['account']['profile_real']['name']:
            names['real_name'] = g.user['account']['profile_real']['name']

        select_value = 'no'
        form_data = Form.get_appreciation(pid=pid, uid=g.user['account']['_id'])
        if form_data and 'data' in form_data and 'key' in form_data['data']:
            if 'available' in form_data['data'] and form_data['data']['available']:
                select_value = form_data['data']['key']

        return render_template('./form_appreciation.html',
            project=project, team=team, names=names.items(), select_value=select_value)

    elif request.method == 'POST':
        if request.form['appreciation'] not in ('oauth', 'badge_name', 'real_name', 'no'):
            return u'', 406

        if request.form['appreciation'] == 'no':
            data = {'available': False}

        else:
            if request.form['appreciation'] == 'oauth':
                name = g.user['data']['name']
            elif request.form['appreciation'] == 'badge_name':
                name = g.user['account']['profile']['badge_name']
            elif request.form['appreciation'] == 'real_name':
                name = g.user['account']['profile_real']['name']

            data = {
                'available': True,
                'key': request.form['appreciation'],
                'value': name,
            }

        Form().update_appreciation(pid=team['pid'], uid=g.user['account']['_id'], data=data)
        return redirect(url_for('team.team_form_appreciation', pid=team['pid'], tid=team['tid'], _scheme='https', _external=True))
Пример #10
0
def team_form_volunteer_certificate(pid, tid):
    ''' Team form volunteer certificate '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    is_ok_submit = False
    user = g.user['account']
    if 'profile_real' in user:
        _check = []
        for k in ('name', 'roc_id', 'birthday', 'company'):
            if k in user['profile_real'] and user['profile_real'][k]:
                _check.append(True)
            else:
                _check.append(False)

        is_ok_submit = all(_check)

    if request.method == 'GET':
        form_data = Form.get_volunteer_certificate(
            pid=pid, uid=g.user['account']['_id'])
        if form_data and 'data' in form_data and 'value' in form_data['data']:
            select_value = 'yes' if form_data['data']['value'] else 'no'
        else:
            select_value = 'no'

        return render_template('./form_volunteer_certificate.html',
                               project=project,
                               team=team,
                               is_ok_submit=is_ok_submit,
                               select_value=select_value)

    if request.method == 'POST':
        if not is_ok_submit:
            return '', 406

        data = {'value': request.form['volunteer_certificate'] == 'yes'}
        Form.update_volunteer_certificate(pid=team['pid'],
                                          uid=g.user['account']['_id'],
                                          data=data)

        return redirect(
            url_for('team.team_form_volunteer_certificate',
                    pid=team['pid'],
                    tid=team['tid'],
                    _scheme='https',
                    _external=True))

    return jsonify({}), 404
Пример #11
0
def team_expense_index(pid, tid):
    ''' Team expense index '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'POST':
        data = request.get_json()

        if data['casename'] == 'get':
            teams = []
            for _team in Team.list_by_pid(pid=project['_id']):
                teams.append({'name': _team['name'], 'tid': _team['tid']})

            select_team = data['select_team']
            if select_team == '':
                select_team = team['tid']

            items = []
            for item in Budget.get_by_tid(pid=pid,
                                          tid=select_team,
                                          only_enable=True):
                items.append(item)

            bank = User.get_bank(uid=g.user['account']['_id'])

            return jsonify({
                'teams': teams,
                'items': items,
                'select_team': select_team,
                'bank': bank
            })

        if data['casename'] == 'add_expense':
            # create expense and send notification.
            expense = Expense.process_and_add(pid=project['_id'],
                                              tid=team['tid'],
                                              uid=g.user['account']['_id'],
                                              data=data)
            expense_create.apply_async(kwargs={'expense': expense})
            return jsonify(data)

        if data['casename'] == 'get_has_sent':
            data = Expense.get_has_sent(pid=project['_id'],
                                        budget_id=data['buid'])
            return jsonify({'data': list(data)})

    return jsonify({}), 404
Пример #12
0
def calendar(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if 'calendar' in project and project['calendar']:
        is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                    g.user['account']['_id'] in team['owners'] or \
                    g.user['account']['_id'] in project['owners'])

        return render_template('./team_calendar.html', project=project, team=team, is_admin=is_admin)

    return redirect(url_for('team.index', pid=team['pid'], tid=team['tid'], _scheme='https', _external=True))
Пример #13
0
def team_form_traffic_fee(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    is_ok_submit = False
    user = g.user['account']
    feemapping = FormTrafficFeeMapping.get(pid=pid)

    if 'traffic_fee_doc' in project and project['traffic_fee_doc'] and feemapping and 'data' in feemapping and feemapping['data']:
        if 'profile_real' in user and 'bank' in user['profile_real']:
            _short_check = []
            for k in ('name', 'branch', 'no', 'code'):
                if k in user['profile_real']['bank'] and user['profile_real']['bank'][k]:
                    _short_check.append(True)
                else:
                    _short_check.append(False)

            if all(_short_check):
                is_ok_submit = True

    if request.method == 'GET':
        form_data = Form.get_traffic_fee(pid=pid, uid=g.user['account']['_id'])
        data = ''
        if form_data:
            data = json.dumps({
                'apply': 'yes' if form_data['data']['apply'] else 'no',
                'fromwhere': form_data['data']['fromwhere'],
                'howto': form_data['data']['howto'],
                'fee': form_data['data']['fee'],
            })
        return render_template('./form_traffic_fee.html', project=project, team=team,
                data=data, is_ok_submit=is_ok_submit)

    elif request.method == 'POST':
        if is_ok_submit and request.form['fromwhere'] in feemapping['data']:
            data = {
                'fee': int(request.form['fee']),
                'howto': request.form['howto'].strip(),
                'apply': True if request.form['apply'].strip() == 'yes' else False,
                'fromwhere': request.form['fromwhere'],
            }
            Form.update_traffic_fee(pid=pid, uid=g.user['account']['_id'], data=data)
            return redirect(url_for('team.team_form_traffic_fee',
                    pid=team['pid'], tid=team['tid'], _scheme='https', _external=True))

        return u'', 406
Пример #14
0
def team_form_api(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        if request.args['case'] == 'traffic_fee':
            return jsonify({'locations': list(FormTrafficFeeMapping.get(pid=pid)['data'].items())})

        return jsonify(request.args)
Пример #15
0
def campaign(pid, tid, cid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] not in team['chiefs']:
        return redirect('/')

    campaign_data = SenderCampaign.get(cid=cid, pid=pid, tid=tid)

    return render_template('./sender_campaign_index.html',
                           campaign=campaign_data,
                           team=team)
Пример #16
0
def index(pid, tid):
    ''' Index page '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    # ..note::
    # 1. create campaign (campaign name) / list campaign
    # 2. write title, content(jinja2, markdown)
    # 3. pick up receiver
    # 4. send / send test

    if request.method == 'GET':
        return render_template('./sender.html')

    if request.method == 'POST':
        data = request.get_json()

        if 'casename' in data and data['casename'] == 'get':
            campaigns = list(
                SenderCampaign.get_list(pid=team['pid'], tid=team['tid']))
            raw_users_info = User.get_info(
                uids=[c['created']['uid'] for c in campaigns])
            users_info = {}
            for uid, value in raw_users_info.items():
                users_info[uid] = {
                    'uid': uid,
                    'name': value['profile']['badge_name']
                }

            return jsonify({'campaigns': campaigns, 'users_info': users_info})

        if 'casename' in data and data['casename'] == 'create':
            resp = SenderCampaign.create(name=data['name'],
                                         pid=team['pid'],
                                         tid=team['tid'],
                                         uid=g.user['account']['_id'])

            return jsonify({'cid': resp['_id']})

    return jsonify({})
Пример #17
0
def team_join_to(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] in team['members'] or g.user['account']['_id'] in team['chiefs']:
        return redirect(url_for('team.index', pid=pid, tid=tid))

    if request.method == 'GET':
        is_in_wait = WaitList.is_in_wait(pid=team['pid'], tid=team['tid'], uid=g.user['account']['_id'])
        return render_template('./team_join_to.html', project=project, team=team, is_in_wait=is_in_wait)

    elif request.method == 'POST':
        WaitList.join_to(pid=pid, tid=tid, uid=g.user['account']['_id'], note=request.form['note'].strip())
        TeamMemberChangedDB().make_record(pid=pid, tid=tid, waiting_uids=(g.user['account']['_id'], ))

        return redirect('/project/%s/' % pid)
Пример #18
0
def team_edit_user_api(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                g.user['account']['_id'] in team['owners'] or \
                g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        user = User(uid=request.args['uid']).get()
        user_waitting = WaitList.list_by_team(pid=pid, tid=tid, uid=user['_id'])
        if not user_waitting:
            return jsonify({})

        users_info = User.get_info([user['_id'], ])

        user_data = {
            'badge_name': users_info[user['_id']]['profile']['badge_name'],
            'picture': users_info[user['_id']]['oauth']['picture'],
            'uid': user['_id'],
            'note': user_waitting['note'],
            'wid': u'%(_id)s' % user_waitting,
        }

        return jsonify(user_data)

    elif request.method == 'POST':
        all_members = len(team['members']) + len(team['chiefs'])
        if 'headcount' in team and team['headcount'] and all_members >= team['headcount']:
            return jsonify({'status': 'fail', 'message': 'over headcount.'}), 406

        data = request.json
        w = WaitList.make_result(wid=data['wid'], pid=pid, uid=data['uid'], result=data['result'])
        if w and 'result' in w:
            if w['result'] == 'approval':
                Team.update_members(pid=pid, tid=tid, add_uids=[data['uid'], ])
            elif w['result'] == 'deny':
                TeamMemberChangedDB().make_record(pid=pid, tid=tid, deny_uids=(data['uid'], ))

        return jsonify({'status': 'ok'})
Пример #19
0
def campaign_content(pid, tid, cid):
    ''' Campaign content '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        campaign_data = SenderCampaign.get(cid=cid,
                                           pid=team['pid'],
                                           tid=team['tid'])

        return render_template('./sender_campaign_content.html',
                               campaign=campaign_data,
                               team=team)

    if request.method == 'POST':
        data = request.get_json()

        if 'casename' in data and data['casename'] == 'get':
            campaign_data = SenderCampaign.get(cid=cid,
                                               pid=team['pid'],
                                               tid=team['tid'])
            return jsonify({'mail': campaign_data['mail']})

        if 'casename' in data and data['casename'] == 'save':
            resp = SenderCampaign.save_mail(
                cid=cid,
                subject=data['data']['subject'].strip(),
                content=data['data']['content'].strip(),
                preheader=data['data']['preheader'].strip(),
                layout=data['data']['layout'].strip(),
            )
            return jsonify({'mail': resp['mail']})

    return jsonify({}), 404
Пример #20
0
def team_expense_lists(pid, tid):
    ''' Team expense lists '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members']
            or g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    if request.method == 'GET':
        budget_admin = Budget.is_admin(pid=pid, uid=g.user['account']['_id'])
        return render_template('./expense_lists.html',
                               project=project,
                               team=team,
                               budget_menu=budget_admin)

    return '', 404
Пример #21
0
def campaign(pid, tid, cid):
    ''' campaign '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    campaign_data = SenderCampaign.get(cid=cid, pid=pid, tid=tid)

    return render_template('./sender_campaign_index.html',
                           campaign=campaign_data,
                           team=team)
Пример #22
0
def team_join_to(pid, tid):
    ''' Team join to '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] in team['members'] or g.user['account'][
            '_id'] in team['chiefs']:
        return redirect(url_for('team.index', pid=pid, tid=tid))

    if request.method == 'GET':
        is_in_wait = WaitList.is_in_wait(pid=team['pid'],
                                         tid=team['tid'],
                                         uid=g.user['account']['_id'])

        if not is_in_wait and 'public_desc' in team:
            team['public_desc'] = re.sub(
                '<a href="javascript:.*"', '<a href="/"',
                markdown(html.escape(team['public_desc'])))

        return render_template('./team_join_to.html',
                               project=project,
                               team=team,
                               is_in_wait=is_in_wait)

    if request.method == 'POST':
        WaitList.join_to(pid=pid,
                         tid=tid,
                         uid=g.user['account']['_id'],
                         note=request.form['note'].strip())
        TeamMemberChangedDB().make_record(
            pid=pid, tid=tid, action={'waiting': (g.user['account']['_id'], )})

        return redirect(f'/team/{pid}/{tid}/join_to')

    return '', 404
Пример #23
0
def team_plan_edit(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                g.user['account']['_id'] in team['owners'] or \
                g.user['account']['_id'] in project['owners'])

    if request.method == 'GET':
        return render_template('./team_plan_edit.html', project=project, team=team, is_admin=is_admin)

    elif request.method == 'POST':
        data = request.get_json()
        today = arrow.now().format('YYYY-MM-DD')
        default = {'title': '', 'desc': '', 'start': today, 'end': '', 'tid': tid, 'team_name': team['name'], 'start_timestamp': 0}

        team_plan_db = TeamPlanDB()
        if 'case' in data and data['case'] == 'get':
            plan_data = team_plan_db.find_one({'pid': pid, 'tid': tid})
            if not plan_data:
                plan_data = {'data': [default, ]}

            if not plan_data['data']:
                plan_data['data'] = [default, ]

            for raw in plan_data['data']:
                raw['tid'] = tid
                raw['team_name'] = team['name']

            others = []
            if 'import_others' in data and data['import_others']:
                for team_plan in team_plan_db.find({'pid': pid, 'tid': {'$nin': [tid, ]}}):
                    team_info = Team.get(pid=pid, tid=team_plan['tid'])

                    for raw in team_plan['data']:
                        raw['tid'] = tid
                        raw['team_name'] = team_info['name']

                        others.append(raw)

            return jsonify({'data': plan_data['data'], 'default': default, 'others': others})

        elif 'case' in data and data['case'] == 'get_schedular':
            query = {'pid': pid}
            if not data['import_others']:
                query['tid'] = tid

            dates = {}
            team_plan = list(team_plan_db.find(query))
            for raw in team_plan:
                for plan in raw['data']:
                    if not plan['end']:
                        if plan['start'] not in dates:
                            dates[plan['start']] = []

                        dates[plan['start']].append(plan)
                    else:
                        for d in arrow.Arrow.range('day', arrow.get(plan['start']), arrow.get(plan['end'])):
                            d_format = d.format('YYYY-MM-DD')
                            if d_format not in dates:
                                dates[d_format] = []
                            dates[d_format].append(plan)

            return jsonify({'data': list(dates.items())})

        elif 'case' in data and data['case'] == 'post':
            if 'data' in data:
                _data = []
                for raw in data['data']:
                    if raw['title'] and raw['start']:
                        try:
                            arrow.get(raw['start'])
                            _raw = {}
                            for k in ('title', 'start', 'end', 'desc'):
                                _raw[k] = raw[k]
                            _data.append(_raw)
                        except arrow.parser.ParserError:
                            continue

                _data = sorted(_data, key=lambda d: arrow.get(d['start']))
                result = team_plan_db.save(pid=pid, tid=tid, data=_data)

                for raw in result['data']:
                    raw['tid'] = tid
                    raw['team_name'] = team['name']
                    raw['start_timestamp'] = arrow.get(raw['start']).timestamp

                if not result['data']:
                    result['data'] = [default, ]

                others = []
                if 'import_others' in data and data['import_others']:
                    for team_plan in team_plan_db.find({'pid': pid, 'tid': {'$nin': [tid, ]}}):
                        team_info = Team.get(pid=pid, tid=team_plan['tid'])

                        for raw in team_plan['data']:
                            raw['tid'] = tid
                            raw['team_name'] = team_info['name']
                            raw['start_timestamp'] = arrow.get(raw['start']).timestamp

                            others.append(raw)

                return jsonify({'data': result['data'], 'default': default, 'others': others})

        return jsonify({'data': [], 'default': default})
Пример #24
0
def team_edit_user(pid, tid):
    ''' Team edit user '''
    # pylint: disable=too-many-locals,too-many-return-statements,too-many-branches,too-many-statements
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        waitting_list = list(WaitList.list_by_team(pid=pid, tid=tid))
        uids = [u['uid'] for u in waitting_list]
        users_info = User.get_info(uids)

        for user in waitting_list:
            user['_info'] = users_info[user['uid']]
            user['_history'] = []
            for wait_info in WaitList.find_history(pid=pid, uid=user['uid']):
                if 'result' not in wait_info:
                    wait_info['result'] = 'waitting'

                user['_history'].append(wait_info)

            user['_mail'] = User(uid=user['uid']).get()['mail']

        return render_template('./team_edit_user.html',
                               project=project,
                               team=team,
                               waitting_list=waitting_list)

    if request.method == 'POST':
        data = request.json

        if data['case'] == 'deluser':
            Team.update_members(pid=pid, tid=tid, del_uids=[
                data['uid'],
            ])
        elif data['case'] == 'history':
            history = []
            for raw in WaitList.find_history_in_team(uid=data['uid'],
                                                     pid=pid,
                                                     tid=tid):
                raw['_id'] = str(raw['_id'])
                history.append(raw)

            return jsonify({'history': history})
        elif data['case'] == 'members':
            result_members = []
            if team['members'] or team['chiefs']:
                _all_uids = set(team['chiefs']) | set(team['members'])
                users_info = User.get_info(list(_all_uids))
                for uid in _all_uids:
                    result_members.append(users_info[uid])

                for user in result_members:
                    user['chat'] = {}
                    mid = MattermostTools.find_possible_mid(uid=user['_id'])
                    if mid:
                        user['chat'] = {
                            'mid': mid,
                            'name': MattermostTools.find_user_name(mid=mid)
                        }

                    user['phone'] = {'country_code': '', 'phone': ''}
                    if 'phone' in user['profile_real'] and user[
                            'profile_real']['phone']:
                        phone = phonenumbers.parse(
                            user['profile_real']['phone'])
                        user['phone']['country_code'] = phonenumbers.COUNTRY_CODE_TO_REGION_CODE[phone.country_code][0]  # pylint: disable=line-too-long
                        user['phone']['phone'] = phonenumbers.format_number(
                            phone, phonenumbers.PhoneNumberFormat.NATIONAL)

                result_members = sorted(
                    result_members, key=lambda u: u['profile']['badge_name'])

                return jsonify({
                    'members':
                    result_members,
                    'tags':
                    team.get('tag_members', []),
                    'members_tags':
                    Team.get_members_tags(pid=pid, tid=tid),
                })

        elif data['case'] == 'add_tag':
            result = Team.add_tag_member(pid=pid,
                                         tid=tid,
                                         tag_name=data['tag_name'])
            return jsonify({'tag': result})

        elif data['case'] == 'update_member_tags':
            team_tags = [i['id'] for i in team.get('tag_members', [])]
            team_members = set(team['members'] + team['chiefs'])

            tag_datas = {}
            for uid in team_members:
                if uid in data['data']:
                    tag_datas[uid] = {
                        'tags': list(set(team_tags) & set(data['data'][uid]))
                    }

            if tag_datas:
                Team.add_tags_to_members(pid=pid, tid=tid, data=tag_datas)

            return jsonify({'data': tag_datas})

        elif data['case'] == 'del_tag':
            Team.del_tag(pid=pid, tid=tid, tag_id=data['tag']['id'])

            return jsonify({})

        return jsonify(data)

    return jsonify({})
Пример #25
0
def members(pid, tid):
    ''' members '''
    # pylint: disable=too-many-locals
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if request.method == 'GET':
        return render_template('./team_members.html',
                               project=project,
                               team=team,
                               is_admin=is_admin)

    if request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            list_teams = []
            if 'tid' in post_data and post_data['tid'] != tid:
                team = Team.get(pid=pid, tid=post_data['tid'])

            else:
                for lteam in Team.list_by_pid(pid=pid):
                    list_teams.append({
                        '_id': lteam['tid'],
                        'name': lteam['name']
                    })

            uids = []
            uids.extend(team['chiefs'])
            uids.extend(team['members'])

            uids = list(set(uids))
            users_info = User.get_info(uids=uids)

            result_members = []
            for uid in uids:
                if uid in users_info:
                    user = {
                        '_id': uid,
                        'profile': {
                            'badge_name':
                            users_info[uid]['profile']['badge_name']
                        },
                        'oauth': {
                            'picture': users_info[uid]['oauth']['picture']
                        }
                    }

                    user['is_chief'] = False
                    if uid in team['chiefs']:
                        user['is_chief'] = True

                    user['chat'] = {}
                    mid = MattermostTools.find_possible_mid(uid=uid)
                    if mid:
                        user['chat'] = {
                            'mid': mid,
                            'name': MattermostTools.find_user_name(mid=mid)
                        }

                    result_members.append(user)

            result_members = sorted(
                result_members,
                key=lambda u: u['profile']['badge_name'].lower())

            tags = []
            if 'tag_members' in team and team['tag_members']:
                tags = team['tag_members']

            members_tags = Team.get_members_tags(pid=team['pid'],
                                                 tid=team['tid'])

        return jsonify({
            'members': result_members,
            'teams': list_teams,
            'tags': tags,
            'members_tags': members_tags
        })

    return jsonify({}), 404
Пример #26
0
def recurit_list(pid, tid):
    ''' List page '''
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs']
                or g.user['account']['_id'] in team['owners']
                or g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        return render_template('./recruit_list.html',
                               project=project,
                               team=team,
                               is_admin=is_admin)

    if request.method == 'POST':
        post_data = request.get_json()

        if post_data['casename'] == 'get':
            return jsonify({
                'team_enum': {
                    key: item.value
                    for key, item in TeamsEnum.__members__.items()
                },
                'team_enum_desc': {
                    key: item.value
                    for key, item in TeamsEnumDesc.__members__.items()
                },
                'skill_enum': {
                    key: item.value
                    for key, item in SkillEnum.__members__.items()
                },
                'skill_enum_desc': {
                    key: item.value
                    for key, item in SkillEnumDesc.__members__.items()
                },
                'status_enum': {
                    key: item.value
                    for key, item in StatusEnum.__members__.items()
                },
                'status_enum_desc': {
                    key: item.value
                    for key, item in StatusEnumDesc.__members__.items()
                },
            })

        if post_data['casename'] == 'query':
            query = RecruitQuery.parse_obj(post_data['query']).dict()
            data = list(TobeVolunteer.query(query))

            users_info = User.get_info(uids=[user['uid'] for user in data])

            for member in data:
                member.update({
                    'profile': {
                        'badge_name':
                        users_info[member['uid']]['profile']['badge_name']
                    },
                    'oauth': {
                        'picture':
                        users_info[member['uid']]['oauth']['picture']
                    }
                })

            return jsonify({'members': data})

    return jsonify({})
Пример #27
0
def campaign_receiver(pid, tid, cid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] not in team['chiefs']:
        return redirect('/')

    campaign_data = SenderCampaign.get(cid=cid,
                                       pid=team['pid'],
                                       tid=team['tid'])
    if request.method == 'GET':
        return render_template('./sender_campaign_receiver.html',
                               campaign=campaign_data,
                               team=team)

    if request.method == 'POST':
        data = request.get_json()

        if data and 'casename' in data and data['casename'] == 'getinit':
            teams = []
            for team in Team.list_by_pid(pid=team['pid']):
                teams.append({'tid': team['tid'], 'name': team['name']})

            sender_receiver = SenderReceiver.get(pid=team['pid'], cid=cid)

            return jsonify({
                'teams': teams,
                'pickteams': campaign_data['receiver']['teams'],
                'filedata': sender_receiver,
            })

        if data and 'casename' in data and data['casename'] == 'save':
            tids = [team['tid'] for team in Team.list_by_pid(pid=team['pid'])]

            _result = []
            for tid in tids:
                if tid in data['pickteams']:
                    _result.append(tid)

            return jsonify(
                SenderCampaign.save_receiver(cid=cid,
                                             teams=_result)['receiver'])

        if request.form['uploadtype'] == 'remove':
            SenderReceiver.remove(pid=team['pid'], cid=cid)

            return jsonify({
                'file': [],
                'uploadtype': request.form['uploadtype'],
            })

        if request.files and 'file' in request.files:
            csv_file = list(
                csv.DictReader(
                    io.StringIO(request.files['file'].read().decode('utf8'))))
            if request.form['uploadtype'] == 'replace':
                SenderReceiver.replace(pid=team['pid'],
                                       cid=cid,
                                       datas=csv_file)
            elif request.form['uploadtype'] == 'update':
                SenderReceiver.update(pid=team['pid'], cid=cid, datas=csv_file)

            return jsonify({
                'file': csv_file,
                'uploadtype': request.form['uploadtype'],
            })
Пример #28
0
def team_form_accommodation(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    if not (g.user['account']['_id'] in team['members'] or \
            g.user['account']['_id'] in team['chiefs']):
        return redirect('/')

    is_ok_submit = False
    user = g.user['account']
    if 'profile_real' in user and 'name' in user['profile_real'] and 'roc_id' in user['profile_real'] and 'phone' in user['profile_real']:
        if user['profile_real']['name'] and user['profile_real']['roc_id'] and user['profile_real']['phone']:
            is_ok_submit = True

    if request.method == 'GET':
        return render_template('./form_accommodation.html',
                project=project, team=team, is_ok_submit=is_ok_submit)

    elif request.method == 'POST':
        if not is_ok_submit:
            return u'', 406

        post_data = request.get_json()

        if post_data['casename'] == 'get':
            raw = {'selected': 'no'}
            room = {}

            form_data = Form.get_accommodation(pid=pid, uid=g.user['account']['_id'])
            if form_data:
                raw['selected'] = form_data['data']['key']

                if 'room' in form_data['data'] and form_data['data']['room']:
                    room['no'] = form_data['data']['room']
                    room['key'] = form_data['data']['room_key']
                    room['exkey'] = form_data['data'].get('room_exkey', '')

                    room['mate'] = {}
                    _user_room, mate_room = FormAccommodation.get_room_mate(pid=pid, uid=g.user['account']['_id'])
                    if mate_room:
                        user_info = User.get_info(uids=[mate_room['uid'], ])[mate_room['uid']]
                        room['mate'] = {
                            'uid': mate_room['uid'],
                            'name': user_info['profile']['badge_name'],
                            'tid': '',
                            'picture': user_info['oauth']['picture'],
                        }

            return jsonify({'data': raw, 'room': room})

        elif post_data['casename'] == 'update':
            if post_data['selected'] not in ('no', 'yes', 'yes-longtraffic'):
                return u'', 406

            data = {
                'status': True if post_data['selected'] in ('yes', 'yes-longtraffic') else False,
                'key': post_data['selected'],
            }

            Form.update_accommodation(pid=pid, uid=g.user['account']['_id'], data=data)

            return jsonify({'data': {'selected': post_data['selected']}})

        elif post_data['casename'] == 'makechange':
            msg = FormAccommodation.make_exchange(pid=pid, uid=g.user['account']['_id'], exkey=post_data['key'].strip())
            return jsonify({'data': post_data, 'msg': msg})
Пример #29
0
def campaign_schedule(pid, tid, cid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid,
                                                                      tid=tid)
    if _redirect:
        return _redirect

    if g.user['account']['_id'] not in team['chiefs']:
        return redirect('/')

    campaign_data = SenderCampaign.get(cid=cid,
                                       pid=team['pid'],
                                       tid=team['tid'])
    if request.method == 'GET':
        return render_template('./sender_campaign_schedule.html',
                               campaign=campaign_data,
                               team=team)

    if request.method == 'POST':
        data = request.get_json()

        if 'casename' in data and data['casename'] == 'getlogs':
            logs = []
            for log in SenderLogs.get(cid=cid):
                logs.append({
                    'time':
                    arrow.get(log['create_at']).to('Asia/Taipei').format(
                        'YYYY-MM-DD HH:mm:ss'),
                    'cid':
                    log['cid'],
                    'count':
                    len(log['receivers']),
                    'layout':
                    log['layout'],
                    'desc':
                    log['desc'],
                })

            return jsonify({'logs': logs})

        if 'casename' in data and data['casename'] == 'send':
            user_datas = []

            fields, raws = SenderReceiver.get_from_user(
                pid=team['pid'], tids=campaign_data['receiver']['teams'])
            for raw in raws:
                user_datas.append(dict(zip(fields, raw)))

            fields, raws = SenderReceiver.get(pid=team['pid'], cid=cid)
            for raw in raws:
                user_datas.append(dict(zip(fields, raw)))

            SenderLogs.save(cid=cid,
                            layout=campaign_data['mail']['layout'],
                            desc=u'Send',
                            receivers=user_datas)

            source = None
            if campaign_data['mail']['layout'] == '2':
                if 'mailling' in team and team['mailling']:
                    source = {'name': team['name'], 'mail': team['mailling']}
                    if not (source['name'].startswith('COSCUP')
                            or source['name'].startswith('coscup')):
                        source['name'] = 'COSCUP %s' % source['name']
                else:
                    source = {
                        'name': 'COSCUP Attendee',
                        'mail': '*****@*****.**'
                    }

            sender_mailer_start.apply_async(
                kwargs={
                    'campaign_data': campaign_data,
                    'team_name': team['name'],
                    'source': source,
                    'user_datas': user_datas,
                    'layout': campaign_data['mail']['layout']
                })

            return jsonify(data)

        if 'casename' in data and data['casename'] == 'sendtest':
            # layout, campaign_data, team, uids
            user_datas = []

            fields, raws = SenderReceiver.get_from_user(
                pid=team['pid'], tids=campaign_data['receiver']['teams'])
            if raws:
                user_datas.append(dict(zip(fields, random.choice(raws))))

            fields, raws = SenderReceiver.get(pid=team['pid'], cid=cid)
            if raws:
                user_datas.append(dict(zip(fields, random.choice(raws))))

            uid = g.user['account']['_id']
            users = User.get_info(uids=[
                uid,
            ])

            for user_data in user_datas:
                user_data.update({
                    'mail': users[uid]['oauth']['email'],
                })

            SenderLogs.save(cid=cid,
                            layout=campaign_data['mail']['layout'],
                            desc=u'Test Send',
                            receivers=user_datas)

            source = None
            if campaign_data['mail']['layout'] == '2':
                if 'mailling' in team and team['mailling']:
                    source = {'name': team['name'], 'mail': team['mailling']}
                    if not (source['name'].startswith('COSCUP')
                            or source['name'].startswith('coscup')):
                        source['name'] = 'COSCUP %s' % source['name']
                else:
                    source = {
                        'name': 'COSCUP Attendee',
                        'mail': '*****@*****.**'
                    }

            sender_mailer_start.apply_async(
                kwargs={
                    'campaign_data': campaign_data,
                    'team_name': team['name'],
                    'source': source,
                    'user_datas': user_datas,
                    'layout': campaign_data['mail']['layout']
                })

            return jsonify(data)
Пример #30
0
def team_edit_user(pid, tid):
    team, project, _redirect = check_the_team_and_project_are_existed(pid=pid, tid=tid)
    if _redirect:
        return _redirect

    is_admin = (g.user['account']['_id'] in team['chiefs'] or \
                g.user['account']['_id'] in team['owners'] or \
                g.user['account']['_id'] in project['owners'])

    if not is_admin:
        return redirect('/')

    if request.method == 'GET':
        waitting_list = list(WaitList.list_by_team(pid=pid, tid=tid))
        uids = [u['uid'] for u in waitting_list]
        users_info = User.get_info(uids)

        for u in waitting_list:
            u['_info'] = users_info[u['uid']]
            u['_history'] = []
            for w in WaitList.find_history(pid=pid, uid=u['uid']):
                if 'result' not in w:
                    w['result'] = 'waitting'

                u['_history'].append(w)

            u['_mail'] = User(uid=u['uid']).get()['mail']

        members = []
        if team['members'] or team['chiefs']:
            _all_uids = set(team['chiefs']) | set(team['members'])
            users_info = User.get_info(list(_all_uids))
            for uid in _all_uids:
                members.append(users_info[uid])

            for u in members:
                u['chat'] = {}
                mid = MattermostTools.find_possible_mid(uid=u['_id'])
                if mid:
                    u['chat'] = {'mid': mid, 'name': MattermostTools.find_user_name(mid=mid)}

                u['phone'] = {'country_code': '', 'phone': ''}
                if 'phone' in u['profile_real'] and u['profile_real']['phone']:
                    phone = phonenumbers.parse(u['profile_real']['phone'])
                    u['phone']['country_code'] = phonenumbers.COUNTRY_CODE_TO_REGION_CODE[phone.country_code][0]
                    u['phone']['phone'] = phonenumbers.format_number(phone, phonenumbers.PhoneNumberFormat.NATIONAL)

            members = sorted(members, key=lambda u: u['profile']['badge_name'])

        return render_template('./team_edit_user.html',
                project=project, team=team, waitting_list=waitting_list, members=members)

    elif request.method == 'POST':
        data = request.json

        if data['case'] == 'deluser':
            Team.update_members(pid=pid, tid=tid, del_uids=[data['uid'], ])
        elif data['case'] == 'history':
            history = []
            for raw in WaitList.find_history_in_team(uid=data['uid'], pid=pid, tid=tid):
                raw['_id'] = str(raw['_id'])
                history.append(raw)

            return jsonify({'history': history})

        return jsonify(data)