Exemple #1
0
def _group_set_membership_policy(user, group, pol, priv):
    if not group_can_manage(user, group):
        raise AccessError

    if pol is None:
        pol = 'owner'
        
    members = group.get_members()
    perms = members.get_perms()
        
    if pol == 'open':
        perms[2].append(priv)
        perms[1].append(priv)
        perms[0].append(priv)
    elif pol == 'member':
        perms[1].append(priv)
        if priv in perms[2]:
            perms[2].remove(priv)
    elif pol == 'owner':
        perms[0].append(priv)
        if priv in perms[2]:
            perms[2].remove(priv)
        if priv in perms[1]:
            perms[1].remove(priv)
    
    members.set_other_perms(perms[2])
    members.set_group_perms(perms[1])
    members.set_owner_perms(perms[0])
Exemple #2
0
def group_invite_user(user, group, email, inviter):
    """Invite email to join group. May raise smtplib.SMTPRecipientsRefused if server
    rejects email.
    """
    if not group.is_accepted() or not group.get_members().can_manage(user):
        raise AccessError

    group.add_invitation(email, inviter)

    transaction_commit(inviter, 'InviteToGroup')    # moved from group/form.ptl/InviteForm.commit()
    
    try:
        user = get_user_database().get_user_by_email(email)
    except KeyError:
        # e-mail address is not registered, send an e-mail (rather than internal message)
        subject=_(_email_invite_subject) % dict(group_name=group.name)
        body=_(_email_invite_body) % dict(email=email,
            home_url=messages.home_url,
            inviter=qon.ui.blocks.user.display_name_plain(inviter),
            group_name=qon.ui.blocks.group.display_name_plain(group))
            
        sendmail(subject, body, [email])
    else:
        message_send(inviter, user,
            subject=_(_message_invite_subject) % dict(group_name=group.name),
            body=_(_message_invite_body) % dict(
                email=email,
                inviter=qon.ui.blocks.user.display_name_plain(inviter),
                group_name=qon.ui.blocks.group.display_name_plain(group)
                )
            )