示例#1
0
def org_request(request, domain):
    org_name = request.POST.get("org_name", None)
    org = Organization.get_by_name(org_name)
    if org:
        org_request = OrgRequest.get_requests(
            org_name, domain=domain, user_id=request.couch_user.get_id)
        if not org_request:
            org_request = OrgRequest(organization=org_name,
                                     domain=domain,
                                     requested_by=request.couch_user.get_id,
                                     requested_on=datetime.datetime.utcnow())
            org_request.save()
            _send_request_notification_email(request, org, domain)
            messages.success(
                request,
                "Your request was submitted. The admin of organization %s can now choose to manage the project %s"
                % (org_name, domain))
        else:
            messages.error(
                request,
                "You've already submitted a request to this organization")
    else:
        messages.error(request,
                       "The organization '%s' does not exist" % org_name)
    return HttpResponseRedirect(reverse('domain_org_settings', args=[domain]))
示例#2
0
def seen_request(request, org):
    req_id = request.POST.get('request_id', None)
    org_req = OrgRequest.get(req_id)
    if org_req and org_req.organization == org:
        org_req.seen = True
        org_req.save()
    return HttpResponseRedirect(reverse("orgs_landing", args=[org]))
示例#3
0
def seen_request(request, org):
    req_id = request.POST.get('request_id', None)
    org_req = OrgRequest.get(req_id)
    if org_req and org_req.organization == org:
        org_req.seen = True
        org_req.save()
    return HttpResponseRedirect(reverse("orgs_landing", args=[org]))
示例#4
0
def orgs_landing(request, org, template="orgs/orgs_landing.html", form=None, add_form=None, invite_member_form=None,
                 add_team_form=None, update_form=None, tab=None):
    organization = request.organization

    class LandingNotification(Notification):
        doc_type = 'OrgLandingNotification'

        def template(self):
            return 'orgs/partials/landing_notification.html'

    MainNotification.display_if_needed(messages, request, ctxt={"org": organization})
    LandingNotification.display_if_needed(messages, request)

    reg_form_empty = not form
    add_form_empty = not add_form
    invite_member_form_empty = not invite_member_form
    add_team_form_empty = not add_team_form

    reg_form = form or DomainRegistrationForm(initial={'org': organization.name})
    add_form = add_form or AddProjectForm(org)
    invite_member_form = invite_member_form or InviteMemberForm(org)
    add_team_form = add_team_form or AddTeamForm(org)

    ctxt = base_context(request, organization, update_form=update_form)
    user_domains = []
    req_domains = []
    # display a notification for each org request that hasn't previously been seen
    if request.couch_user.is_org_admin(org):
        requests = OrgRequest.get_requests(org)
        for req in requests:
            if req.seen or req.domain in [d.name for d in ctxt["domains"]]:
                continue
            messages.info(request, render_to_string("orgs/partials/org_request_notification.html",
                {"requesting_user": WebUser.get(req.requested_by).username, "org_req": req, "org": organization}),
                extra_tags="html")

        def format_domains(dom_list, extra=None):
            extra = extra or []
            dom_list = list(set(filter(lambda d: d not in ctxt["domains"] + extra, dom_list)))
            return [Domain.get_by_name(d) for d in dom_list]

        # get the existing domains that an org admin would add to the organization
        user_domains = request.couch_user.domains or []
        user_domains = filter(
            lambda x: domain_has_privilege(x, privileges.CROSS_PROJECT_REPORTS),
            user_domains
        )
        req_domains = [req.domain for req in requests]
        user_domains = format_domains(user_domains)
        req_domains = format_domains(req_domains, [d.name for d in user_domains if d])
        filter(
            lambda x: domain_has_privilege(x, privileges.CROSS_PROJECT_REPORTS),
            req_domains
        )

    ctxt.update(dict(reg_form=reg_form, add_form=add_form, reg_form_empty=reg_form_empty, add_form_empty=add_form_empty,
                invite_member_form=invite_member_form, invite_member_form_empty=invite_member_form_empty,
                add_team_form=add_team_form, add_team_form_empty=add_team_form_empty, tab="projects",
                user_domains=user_domains, req_domains=req_domains))
    return render(request, template, ctxt)
示例#5
0
def org_request(request, domain):
    org_name = request.POST.get("org_name", None)
    org = Organization.get_by_name(org_name)
    if org:
        org_request = OrgRequest.get_requests(org_name, domain=domain, user_id=request.couch_user.get_id)
        if not org_request:
            org_request = OrgRequest(organization=org_name, domain=domain,
                requested_by=request.couch_user.get_id, requested_on=datetime.datetime.utcnow())
            org_request.save()
            messages.success(request,
                "Your request was submitted. The admin of organization %s can now choose to manage the project %s" %
                (org_name, domain))
        else:
            messages.error(request, "You've already submitted a request to this organization")
    else:
        messages.error(request, "The organization '%s' does not exist" % org_name)
    return HttpResponseRedirect(reverse('domain_org_settings', args=[domain]))
示例#6
0
    def clean_domain_name(self):
        data = self.cleaned_data['domain_name'].strip().lower()
        project = Domain.get_by_name(data)
        if not project:
            raise forms.ValidationError('This project does not exist.')

        if not self.user.is_domain_admin(data):
            org_requests = filter(lambda r: r.domain == data, OrgRequest.get_requests(self.org_name))
            if not org_requests:
                raise forms.ValidationError('You must be an admin of this project in order to add it to your organization')

        return data
示例#7
0
def orgs_landing(request, org, template="orgs/orgs_landing.html", form=None, add_form=None, invite_member_form=None,
                 add_team_form=None, update_form=None, tab=None):
    organization = request.organization

    class LandingNotification(Notification):
        doc_type = 'OrgLandingNotification'

        def template(self):
            return 'orgs/partials/landing_notification.html'

    MainNotification.display_if_needed(messages, request, ctxt={"org": organization})
    LandingNotification.display_if_needed(messages, request)

    reg_form_empty = not form
    add_form_empty = not add_form
    invite_member_form_empty = not invite_member_form
    add_team_form_empty = not add_team_form

    reg_form = form or DomainRegistrationForm(initial={'org': organization.name})
    add_form = add_form or AddProjectForm(org)
    invite_member_form = invite_member_form or InviteMemberForm(org)
    add_team_form = add_team_form or AddTeamForm(org)

    ctxt = base_context(request, organization, update_form=update_form)
    user_domains = []
    req_domains = []
    # display a notification for each org request that hasn't previously been seen
    if request.couch_user.is_org_admin(org):
        requests = OrgRequest.get_requests(org)
        for req in requests:
            if req.seen or req.domain in [d.name for d in ctxt["domains"]]:
                continue
            messages.info(request, render_to_string("orgs/partials/org_request_notification.html",
                {"requesting_user": WebUser.get(req.requested_by).username, "org_req": req, "org": organization}),
                extra_tags="html")

        def format_domains(dom_list, extra=None):
            extra = extra or []
            dom_list = list(set(filter(lambda d: d not in ctxt["domains"] + extra, dom_list)))
            return [Domain.get_by_name(d) for d in dom_list]

        # get the existing domains that an org admin would add to the organization
        user_domains = request.couch_user.domains or []
        req_domains = [req.domain for req in requests]
        user_domains = format_domains(user_domains)
        req_domains = format_domains(req_domains, [d.name for d in user_domains if d])

    ctxt.update(dict(reg_form=reg_form, add_form=add_form, reg_form_empty=reg_form_empty, add_form_empty=add_form_empty,
                invite_member_form=invite_member_form, invite_member_form_empty=invite_member_form_empty,
                add_team_form=add_team_form, add_team_form_empty=add_team_form_empty, tab="projects",
                user_domains=user_domains, req_domains=req_domains))
    return render(request, template, ctxt)
示例#8
0
    def clean_domain_name(self):
        data = self.cleaned_data['domain_name'].strip().lower()
        project = Domain.get_by_name(data)
        if not project:
            raise forms.ValidationError('This project does not exist.')

        if not self.user.is_domain_admin(data):
            org_requests = filter(lambda r: r.domain == data,
                                  OrgRequest.get_requests(self.org_name))
            if not org_requests:
                raise forms.ValidationError(
                    'You must be an admin of this project in order to add it to your organization'
                )

        return data
示例#9
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data["domain_name"]

        if not request.couch_user.is_domain_admin(domain_name):
            org_requests = filter(lambda r: r.domain == domain_name, OrgRequest.get_requests(org))
            if not org_requests:
                messages.error(request, "You must be an admin of this project in order to add it to your organization")
                return orgs_landing(request, org, add_form=form)

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data["domain_hrname"]
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse("orgs_landing", args=[org]))
示例#10
0
def orgs_add_project(request, org):
    form = AddProjectForm(org, request.POST)
    if form.is_valid():
        domain_name = form.cleaned_data['domain_name']

        if not request.couch_user.is_domain_admin(domain_name):
            org_requests = filter(lambda r: r.domain == domain_name, OrgRequest.get_requests(org))
            if not org_requests:
                messages.error(request, 'You must be an admin of this project in order to add it to your organization')
                return orgs_landing(request, org, add_form=form)

        dom = Domain.get_by_name(domain_name)
        dom.organization = org
        dom.hr_name = form.cleaned_data['domain_hrname']
        dom.save()
        messages.success(request, "Project Added!")
    else:
        messages.error(request, "Unable to add project")
        return orgs_landing(request, org, add_form=form)
    return HttpResponseRedirect(reverse('orgs_landing', args=[org]))
示例#11
0
def orgs_landing(
    request,
    org,
    template="orgs/orgs_landing.html",
    form=None,
    add_form=None,
    invite_member_form=None,
    add_team_form=None,
    update_form=None,
    tab=None,
):
    organization = Organization.get_by_name(org, strict=True)

    reg_form_empty = not form
    add_form_empty = not add_form
    invite_member_form_empty = not invite_member_form
    add_team_form_empty = not add_team_form

    reg_form = form or DomainRegistrationForm(initial={"org": organization.name})
    add_form = add_form or AddProjectForm(org)
    invite_member_form = invite_member_form or InviteMemberForm(org)
    add_team_form = add_team_form or AddTeamForm(org)

    ctxt = base_context(request, organization, update_form=update_form)
    potential_domains = []

    # display a notification for each org request that hasn't previously been seen
    if request.couch_user.is_org_admin(org):
        requests = OrgRequest.get_requests(org)
        for req in requests:
            if req.seen or req.domain in [d.name for d in ctxt["domains"]]:
                continue
            messages.info(
                request,
                render_to_string(
                    "orgs/partials/org_request_notification.html",
                    {"requesting_user": WebUser.get(req.requested_by).username, "org_req": req, "org": organization},
                ),
                extra_tags="html",
            )

        # get the existing domains that an org admin would add to the organization
        potential_domains = request.couch_user.domains
        potential_domains.extend([req.domain for req in requests])
        potential_domains = list(set(filter(lambda d: d not in ctxt["domains"], potential_domains)))

    ctxt.update(
        dict(
            reg_form=reg_form,
            add_form=add_form,
            reg_form_empty=reg_form_empty,
            add_form_empty=add_form_empty,
            invite_member_form=invite_member_form,
            invite_member_form_empty=invite_member_form_empty,
            add_team_form=add_team_form,
            add_team_form_empty=add_team_form_empty,
            tab="projects",
            potential_domains=potential_domains,
        )
    )
    return render(request, template, ctxt)