Exemplo n.º 1
0
def addgroup_req(request):
    mcid = normalize_mcid(request.REQUEST['mcid'])
    user = User.objects.get(mcid=mcid)

    if request.POST:
        form = GroupForm(request.POST)

        if form.is_valid():
            g = create_group(form.clean_data['name'],
                             normalize_mcid(form.clean_data['accid']),
                             'https://' + request.META['SERVER_NAME'])

            g.save()

            return submit_redirect(
                request,
                g,
                create_redirect='addgroup?mcid=%s' % mcid,
                edit_redirect='../groups/edit?id=%(groupinstanceid)s',
                save_redirect='groups?mcid=%s' % mcid)

    else:
        form = GroupForm(initial=dict(accid=pretty_mcid(mcid)))

    return render_to_response('users/addgroup.html',
                              default_context(request, mcuser=user, form=form))
Exemplo n.º 2
0
def addgroup_req(request):
    mcid = normalize_mcid(request.REQUEST["mcid"])
    user = User.objects.get(mcid=mcid)

    if request.POST:
        form = GroupForm(request.POST)

        if form.is_valid():
            g = create_group(
                form.clean_data["name"],
                normalize_mcid(form.clean_data["accid"]),
                "https://" + request.META["SERVER_NAME"],
            )

            g.save()

            return submit_redirect(
                request,
                g,
                create_redirect="addgroup?mcid=%s" % mcid,
                edit_redirect="../groups/edit?id=%(groupinstanceid)s",
                save_redirect="groups?mcid=%s" % mcid,
            )

    else:
        form = GroupForm(initial=dict(accid=pretty_mcid(mcid)))

    return render_to_response("users/addgroup.html", default_context(request, mcuser=user, form=form))
Exemplo n.º 3
0
 def test_remove_group_member(self):
     group = group_model.create_group('*****@*****.**', 'The A team', 1)
     group_model.add_group_member(group['uri'], '*****@*****.**')
     group_model.add_group_member(group['uri'], '*****@*****.**')
     group_model.remove_group_member(group['uri'], '*****@*****.**')
     group = group_model.get_group(group['uri'])
     self.assertEqual(len(group['members']), 1)
     self.assertEqual(group['members'][0], '*****@*****.**')
Exemplo n.º 4
0
 def test_remove_group_member(self):
     group = group_model.create_group('*****@*****.**', 'The A team', 1)
     group_model.add_group_member(group['uri'], '*****@*****.**')
     group_model.add_group_member(group['uri'], '*****@*****.**')
     group_model.remove_group_member(group['uri'], '*****@*****.**')
     group = group_model.get_group(group['uri'])
     self.assertEqual(len(group['members']), 1)
     self.assertEqual(group['members'][0], '*****@*****.**')
Exemplo n.º 5
0
    def test_get_member_groups(self):
        group = group_model.create_group('*****@*****.**', 'The A team', 1)
        group_model.add_group_member(group['uri'], '*****@*****.**')

        group = group_model.get_group(group['uri'])
        groups = group_model.get_member_groups('*****@*****.**')

        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0], group)
Exemplo n.º 6
0
    def test_get_member_groups(self):
        group = group_model.create_group('*****@*****.**', 'The A team', 1)
        group_model.add_group_member(group['uri'], '*****@*****.**')
        
        group = group_model.get_group(group['uri'])
        groups = group_model.get_member_groups('*****@*****.**')

        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0], group)
Exemplo n.º 7
0
def create_groups(groups, sequence, name_prefix="Group"):
    """ Create the groups in the backend """
    for i, group_data in enumerate(groups):
        group_address = "{0}-{1}@{2}".format(name_prefix.lower().replace(' ','-'), i+1, settings.EMAIL_DOMAIN)
        group_name = "{0} {1}: {2} to {3}".format(name_prefix, i+1, group_data[0]['tz_offset'], group_data[-1]['tz_offset'])
        print(group_name)

        group = group_model.create_group(group_address, group_name, sequence)

        for member in group_data:
            group_model.add_group_member(group['uri'], member['email'])
Exemplo n.º 8
0
 def test_create_group(self):
     """
     Test group creation
     """
     group = group_model.create_group('*****@*****.**', 'The A team', 1)
     self.assertTrue('address' in group)
     self.assertTrue('description' in group)
     self.assertTrue('members' in group)
     self.assertTrue('sequence' in group)
     group_copy = group_model.get_group(group['uri'])
     self.assertEqual(group, group_copy)
Exemplo n.º 9
0
 def test_create_group(self):
     """
     Test group creation
     """
     group = group_model.create_group('*****@*****.**', 'The A team', 1)
     self.assertTrue('address' in group)
     self.assertTrue('description' in group)
     self.assertTrue('members' in group)
     self.assertTrue('sequence' in group)
     group_copy = group_model.get_group(group['uri'])
     self.assertEqual(group, group_copy)
Exemplo n.º 10
0
    def test_get_sequence_groups(self):
        group = group_model.create_group('*****@*****.**', 'The A team', 1)
        group = group_model.create_group('*****@*****.**', 'The B team', 1)
        group = group_model.create_group('*****@*****.**', 'The C team', 1)
        group = group_model.create_group('*****@*****.**', 'The D team', 1)
        group = group_model.create_group('*****@*****.**', 'The E team', 1)

        group = group_model.create_group('*****@*****.**', 'The A team', 2)
        group = group_model.create_group('*****@*****.**', 'The B team', 2)
        group = group_model.create_group('*****@*****.**', 'The C team', 2)

        s_1_groups = group_model.get_groups('1')
        self.assertIn('*****@*****.**', [group['address'] for group in s_1_groups])
Exemplo n.º 11
0
def wiz_create_req(request):
    id = request.REQUEST.get('id', '')
    action = 'wiz_create?id=%s' % id

    if id:
        g = Group.objects.get(groupinstanceid=id)
    else:
        g = None

    queryset = all_query_set()

    if 'search' in request.POST or 'search.x' in request.POST:
        queryset = search_query_set(request.POST['q'])
        form = CreateForm(initial=request.POST)

    elif request.POST:
        form = CreateForm(request.POST)

        if form.is_valid():
            mcid = normalize_mcid(form.clean_data['owner_mcid'])

            if g:
                p = Practice.objects.get(practiceid=g.parentid)
                p.accid_id = g.accid_id = mcid

                p.save()
            else:
                g = create_group('New Group', mcid,
                                 'https://' + request.META['SERVER_NAME'])

            g.save()

            return HttpResponseRedirect('wiz_name?id=%d' % g.groupinstanceid)
    else:
        initial = dict(id=id)

        if 'mcid' in request.REQUEST:
            initial['owner_mcid'] = pretty_mcid(request.REQUEST['mcid'])
        elif g:
            initial['owner_mcid'] = pretty_mcid(g.accid_id)

        form = CreateForm(initial=initial)

    return object_list(request,
                       queryset=queryset,
                       template_name='groups/wiz_1create.html',
                       paginate_by=20,
                       extra_context=default_context(request,
                                                     form=form,
                                                     action=action))
Exemplo n.º 12
0
def wiz_create_req(request):
    id = request.REQUEST.get('id', '')
    action = 'wiz_create?id=%s' % id

    if id:
        g = Group.objects.get(groupinstanceid = id)
    else:
        g = None

    queryset = all_query_set()

    if 'search' in request.POST or 'search.x' in request.POST:
        queryset = search_query_set(request.POST['q'])
        form = CreateForm(initial = request.POST)

    elif request.POST:
        form = CreateForm(request.POST)

        if form.is_valid():
            mcid = normalize_mcid(form.clean_data['owner_mcid'])

            if g:
                p = Practice.objects.get(practiceid = g.parentid)
                p.accid_id = g.accid_id = mcid

                p.save()
            else:
                g = create_group('New Group', mcid,
                                 'https://' + request.META['SERVER_NAME'])

            g.save()

    	    return HttpResponseRedirect('wiz_name?id=%d' % g.groupinstanceid)
    else:
        initial = dict(id = id)

        if 'mcid' in request.REQUEST:
            initial['owner_mcid'] = pretty_mcid(request.REQUEST['mcid'])
	elif g:
	    initial['owner_mcid'] = pretty_mcid(g.accid_id)

        form = CreateForm(initial = initial)

    return object_list(request, queryset = queryset,
                       template_name = 'groups/wiz_1create.html',
                       paginate_by = 20,
                       extra_context = default_context(request,
                                                       form=form,
                                                       action=action))
Exemplo n.º 13
0
def create_groups(groups, sequence, name_prefix="Group"):
    """ Create the groups in the backend """
    for i, group_data in enumerate(groups):
        group_address = "{0}-{1}@{2}".format(
            name_prefix.lower().replace(' ', '-'), i + 1,
            settings.EMAIL_DOMAIN)
        group_name = "{0} {1}: {2} to {3}".format(name_prefix, i + 1,
                                                  group_data[0]['tz_offset'],
                                                  group_data[-1]['tz_offset'])
        print(group_name)

        group = group_model.create_group(group_address, group_name, sequence)

        for member in group_data:
            group_model.add_group_member(group['uri'], member['email'])
Exemplo n.º 14
0
    def test_get_sequence_groups(self):
        group = group_model.create_group('*****@*****.**',
                                         'The A team', 1)
        group = group_model.create_group('*****@*****.**',
                                         'The B team', 1)
        group = group_model.create_group('*****@*****.**',
                                         'The C team', 1)
        group = group_model.create_group('*****@*****.**',
                                         'The D team', 1)
        group = group_model.create_group('*****@*****.**',
                                         'The E team', 1)

        group = group_model.create_group('*****@*****.**',
                                         'The A team', 2)
        group = group_model.create_group('*****@*****.**',
                                         'The B team', 2)
        group = group_model.create_group('*****@*****.**',
                                         'The C team', 2)

        s_1_groups = group_model.get_groups('1')
        self.assertIn('*****@*****.**',
                      [group['address'] for group in s_1_groups])
Exemplo n.º 15
0
def do_grouping(sequence):
    groups = prepare_groups(sequence)
    create_groups(groups, sequence, 'Group {0}'.format(sequence))

    # handle singups not in group
    signups = signup_model.get_signups(sequence)
    filter_group_preference = lambda su: su['questions']['groupRadios'] == False
    signups = filter(filter_group_preference, signups)
    group_address = 'ungrouped-s-{0}@{1}'.format(sequence, settings.EMAIL_DOMAIN)
    group_name = 'Ungrouped S{0}'.format(sequence, settings.EMAIL_DOMAIN)
    ungroup = group_model.create_group(group_address, group_name, sequence)

    for signup in signups:
        group_model.add_group_member(ungroup['uri'], signup['email'])

    # sync groups with mailgun
    for group in group_model.get_groups(sequence):
        group_model.add_group_member(group['uri'], settings.DEFAULT_FROM_EMAIL)
        group_model.sync_group_with_mailgun(group['uri'])

    # update access to group for ungrouped users
    mailgun_api.update_list(ungroup['address'], access_level='readonly')
Exemplo n.º 16
0
def do_grouping(sequence):
    groups = prepare_groups(sequence)
    create_groups(groups, sequence, 'Group {0}'.format(sequence))

    # handle singups not in group
    signups = signup_model.get_signups(sequence)
    filter_group_preference = lambda su: su['questions']['groupRadios'
                                                         ] == False
    signups = filter(filter_group_preference, signups)
    group_address = 'ungrouped-s-{0}@{1}'.format(sequence,
                                                 settings.EMAIL_DOMAIN)
    group_name = 'Ungrouped S{0}'.format(sequence, settings.EMAIL_DOMAIN)
    ungroup = group_model.create_group(group_address, group_name, sequence)

    for signup in signups:
        group_model.add_group_member(ungroup['uri'], signup['email'])

    # sync groups with mailgun
    for group in group_model.get_groups(sequence):
        group_model.add_group_member(group['uri'], settings.DEFAULT_FROM_EMAIL)
        group_model.sync_group_with_mailgun(group['uri'])

    # update access to group for ungrouped users
    mailgun_api.update_list(ungroup['address'], access_level='readonly')