Exemplo n.º 1
0
def org_management(request):
    """Management of all organizations for the given user"""

    # get a list of all the organizations this user helps administer
    organizations = get_or_create_user_profile(request.user).get_organizations()

    # add invitation forms to each of the organizations
    for org in organizations.values():
        org.form = OrganizationInvitationForm(initial={"invited_by": request.user})

    # handle a submitted invitation form
    if request.method == "POST":
        form = OrganizationInvitationForm(data=request.POST)
        if form.is_valid():
            # ensure that the current user is a member of the organization to which someone is being invited
            if not form.instance.organization.is_member(request.user):
                raise PermissionDenied("Unfortunately for you, you do not have permission to do that.")
            # send the invitation email, and save the invitation record
            form.instance.send(request)
            form.save()
            return HttpResponseRedirect(reverse("org_management"))
        else: # we need to inject the form into the correct organization, so errors are displayed inline
            for pk,org in organizations.items():
                if org.pk == int(request.POST.get("organization")):
                    org.form = form

    return {
        "title": _("Account administration"),
        "organizations": organizations,
        "HEADLESS_ORG_NAME": Organization.HEADLESS_ORG_NAME,
        "invitations": OrganizationInvitation.objects.filter(email_to_invite=request.user.email)
    }
Exemplo n.º 2
0
def org_management(request, org_id=None):
    """Management of all organizations for the given user"""

    # get a list of all the organizations this user helps administer
    organizations = get_or_create_user_profile(request.user).get_organizations()

    # add invitation forms to each of the organizations
    for org in organizations.values():
        org.form = OrganizationInvitationForm(initial={"invited_by": request.user})

    # handle a submitted invitation form
    if request.method == "POST":
        form = OrganizationInvitationForm(data=request.POST)
        if form.is_valid():
            # ensure that the current user is a member of the organization to which someone is being invited
            if not form.instance.organization.is_member(request.user):
                raise PermissionDenied(_("Unfortunately for you, you do not have permission to do that."))
            # send the invitation email, and save the invitation record
            form.instance.send(request)
            form.save()
            return HttpResponseRedirect(reverse("org_management"))
        else: # we need to inject the form into the correct organization, so errors are displayed inline
            for pk,org in organizations.items():
                if org.pk == int(request.POST.get("organization")):
                    org.form = form

    zones = {}
    for org in organizations.values():
        zones[org.pk] = []
        for zone in list(org.get_zones()):
            zones[org.pk].append({
                "id": zone.id,
                "name": zone.name,
                "is_deletable": not zone.has_dependencies(passable_classes=["Organization"]),
            })
    return {
        "title": _("Account administration"),
        "organizations": organizations,
        "zones": zones,
        "HEADLESS_ORG_NAME": Organization.HEADLESS_ORG_NAME,
        "my_invitations": list(OrganizationInvitation.objects \
            .filter(email_to_invite=request.user.email)
            .order_by("organization__name")),
        "download_url": reverse("install"),
    }
Exemplo n.º 3
0
def homepage(request):
    
    # show the static landing page to users that aren't logged in
    if not request.user.is_authenticated():
        return landing_page(request)
    
    # get a list of all the organizations this user helps administer    
    organizations = get_or_create_user_profile(request.user).get_organizations()
    
    # add invitation forms to each of the organizations
    for org in organizations:
        org.form = OrganizationInvitationForm(initial={"invited_by": request.user})
    
    # handle a submitted invitation form
    if request.method == "POST":
        form = OrganizationInvitationForm(data=request.POST)
        if form.is_valid():
            # ensure that the current user is a member of the organization to which someone is being invited
            if not form.instance.organization.is_member(request.user):
                return HttpResponseNotAllowed("Unfortunately for you, you do not have permission to do that.")
            # send the invitation email, and save the invitation record
            form.instance.send(request)
            form.save()
            return HttpResponseRedirect(reverse("homepage"))
        else: # we need to inject the form into the correct organization, so errors are displayed inline
            for org in organizations:
                if org.pk == int(request.POST.get("organization")):
                    org.form = form
                    
    return {
        "organizations": organizations,
        "invitations": OrganizationInvitation.objects.filter(email_to_invite=request.user.email)
    }
Exemplo n.º 4
0
def org_management(request, org_id=None):
    """Management of all organizations for the given user"""

    # get a list of all the organizations this user helps administer
    organizations = get_or_create_user_profile(
        request.user).get_organizations()

    # add invitation forms to each of the organizations
    for org in organizations.values():
        org.form = OrganizationInvitationForm(
            initial={"invited_by": request.user})

    # handle a submitted invitation form
    if request.method == "POST":
        form = OrganizationInvitationForm(data=request.POST)
        if form.is_valid():
            # ensure that the current user is a member of the organization to which someone is being invited
            if not form.instance.organization.is_member(request.user):
                raise PermissionDenied(
                    "Unfortunately for you, you do not have permission to do that."
                )
            # send the invitation email, and save the invitation record
            form.instance.send(request)
            form.save()
            return HttpResponseRedirect(reverse("org_management"))
        else:  # we need to inject the form into the correct organization, so errors are displayed inline
            for pk, org in organizations.items():
                if org.pk == int(request.POST.get("organization")):
                    org.form = form

    zones = {}
    for org in organizations.values():
        zones[org.pk] = []
        for zone in org.get_zones():
            zones[org.pk].append({
                "id":
                zone.id,
                "name":
                zone.name,
                "is_deletable":
                not zone.has_dependencies(passable_classes=["Organization"]),
            })
    return {
        "title":
        _("Account administration"),
        "organizations":
        organizations,
        "zones":
        zones,
        "HEADLESS_ORG_NAME":
        Organization.HEADLESS_ORG_NAME,
        "invitations":
        OrganizationInvitation.objects.filter(
            email_to_invite=request.user.email)
    }