Ejemplo n.º 1
0
        def wrapped(request, *args, **kwargs):
            try:
                if (hasattr(request, 'subscription')
                    and request.subscription is not None
                    and request.subscription.is_trial
                    and request.subscription.date_end is not None
                ):
                    edition_req = DefaultProductPlan.get_lowest_edition_by_domain(
                        request.domain, [slug]
                    )
                    plan_name = request.subscription.plan_version.user_facing_description['name']
                    feature_name = privileges.Titles.get_name_from_privilege(slug)
                    request.show_trial_notice = True
                    request.trial_info = {
                        'current_plan': plan_name,
                        'feature_name': feature_name,
                        'required_plan': edition_req,
                        'date_end': request.subscription.date_end.strftime(USER_DATE_FORMAT)
                    }
                    request.is_billing_admin = (hasattr(request, 'couch_user')
                                                and BillingAccountAdmin.get_admin_status_and_account(
                                                    request.couch_user, request.domain
                                                )[0])

                return requires_privilege(slug, **assignment)(fn)(
                    request, *args, **kwargs
                )
            except PermissionDenied:
                request.show_trial_notice = False
                from corehq.apps.domain.views import SubscriptionUpgradeRequiredView
                return SubscriptionUpgradeRequiredView().get(
                    request, request.domain, slug
                )
Ejemplo n.º 2
0
 def wrapped(request, *args, **kwargs):
     if not hasattr(request, "couch_user") or not hasattr(request, "domain"):
         raise Http404()
     is_billing_admin = BillingAccountAdmin.get_admin_status_and_account(request.couch_user, request.domain)[0]
     request.is_billing_admin = is_billing_admin
     if not (is_billing_admin or request.couch_user.is_superuser):
         raise Http404()
     return fn(request, *args, **kwargs)
Ejemplo n.º 3
0
    def sidebar_items(self):
        items = []
        user_is_admin = self.couch_user.is_domain_admin(self.domain)

        project_info = []

        if user_is_admin:
            from corehq.apps.domain.views import EditBasicProjectInfoView, EditDeploymentProjectInfoView

            project_info.extend([
                {
                    'title': _(EditBasicProjectInfoView.page_title),
                    'url': reverse(EditBasicProjectInfoView.urlname, args=[self.domain])
                },
                {
                    'title': _(EditDeploymentProjectInfoView.page_title),
                    'url': reverse(EditDeploymentProjectInfoView.urlname, args=[self.domain])
                }
            ])

        from corehq.apps.domain.views import EditMyProjectSettingsView
        project_info.append({
            'title': _(EditMyProjectSettingsView.page_title),
            'url': reverse(EditMyProjectSettingsView.urlname, args=[self.domain])
        })

        can_view_orgs = (user_is_admin
                         and self.project and self.project.organization)
        if can_view_orgs:
            try:
                ensure_request_has_privilege(self._request, privileges.CROSS_PROJECT_REPORTS)
            except PermissionDenied:
                can_view_orgs = False

        if can_view_orgs:
            from corehq.apps.domain.views import OrgSettingsView
            project_info.append({
                'title': _(OrgSettingsView.page_title),
                'url': reverse(OrgSettingsView.urlname, args=[self.domain])
            })

        items.append((_('Project Information'), project_info))

        if user_is_admin:
            from corehq.apps.domain.views import CommTrackSettingsView

            if self.project.commtrack_enabled:
                commtrack_settings = [
                    {
                        'title': _(CommTrackSettingsView.page_title),
                        'url': reverse(CommTrackSettingsView.urlname, args=[self.domain])
                    },
                ]
                items.append((_('CommTrack'), commtrack_settings))

            administration = [
                {
                    'title': _('CommCare Exchange'),
                    'url': reverse('domain_snapshot_settings', args=[self.domain])
                },
                {
                    'title': _('Multimedia Sharing'),
                    'url': reverse('domain_manage_multimedia', args=[self.domain])
                }
            ]

            def forward_name(repeater_type=None, **context):
                if repeater_type == 'FormRepeater':
                    return _("Forward Forms")
                elif repeater_type == 'ShortFormRepeater':
                    return _("Forward Form Stubs")
                elif repeater_type == 'CaseRepeater':
                    return _("Forward Cases")

            administration.extend([
                {'title': _('Data Forwarding'),
                 'url': reverse('domain_forwarding', args=[self.domain]),
                 'subpages': [
                     {'title': forward_name,
                      'urlname': 'add_repeater'}
                 ]}
            ])

            administration.append({
                    'title': _('Feature Previews'),
                    'url': reverse('feature_previews', args=[self.domain])
            })
            items.append((_('Project Administration'), administration))

        from corehq.apps.users.models import WebUser
        if isinstance(self.couch_user, WebUser):
            user_is_billing_admin, billing_account = BillingAccountAdmin.get_admin_status_and_account(
                self.couch_user, self.domain)
            if user_is_billing_admin or self.couch_user.is_superuser:
                from corehq.apps.domain.views import (
                    DomainSubscriptionView, EditExistingBillingAccountView,
                    DomainBillingStatementsView, ConfirmSubscriptionRenewalView,
                )
                subscription = [
                    {
                        'title': DomainSubscriptionView.page_title,
                        'url': reverse(DomainSubscriptionView.urlname, args=[self.domain]),
                        'subpages': [
                            {
                                'title': ConfirmSubscriptionRenewalView.page_title,
                                'urlname': ConfirmSubscriptionRenewalView.urlname,
                                'url': reverse(ConfirmSubscriptionRenewalView.urlname, args=[self.domain]),
                            }
                        ]
                    },
                ]
                if billing_account is not None:
                    subscription.append(
                        {
                            'title':  EditExistingBillingAccountView.page_title,
                            'url': reverse(EditExistingBillingAccountView.urlname, args=[self.domain]),
                        },
                    )
                if (billing_account is not None
                    and Invoice.exists_for_domain(self.domain)
                ):
                    subscription.append(
                        {
                            'title': DomainBillingStatementsView.page_title,
                            'url': reverse(DomainBillingStatementsView.urlname, args=[self.domain]),
                        }
                    )
                items.append((_('Subscription'), subscription))

        if self.couch_user.is_superuser:
            from corehq.apps.domain.views import EditInternalDomainInfoView, EditInternalCalculationsView
            internal_admin = [{
                'title': _(EditInternalDomainInfoView.page_title),
                'url': reverse(EditInternalDomainInfoView.urlname, args=[self.domain])
            },
            {
                'title': _(EditInternalCalculationsView.page_title),
                'url': reverse(EditInternalCalculationsView.urlname, args=[self.domain])
            }]
            items.append((_('Internal Data (Dimagi Only)'), internal_admin))



        return items
Ejemplo n.º 4
0
 def is_billing_admin(self):
     return (BillingAccountAdmin.get_admin_status_and_account(self.couch_user, self.domain)[0]
             or self.couch_user.is_superuser)
Ejemplo n.º 5
0
    def sidebar_items(self):
        items = []
        user_is_admin = self.couch_user.is_domain_admin(self.domain)

        project_info = []

        if user_is_admin:
            from corehq.apps.domain.views import EditBasicProjectInfoView, EditDeploymentProjectInfoView

            project_info.extend([
                {
                    'title': _(EditBasicProjectInfoView.page_title),
                    'url': reverse(EditBasicProjectInfoView.urlname, args=[self.domain])
                },
                {
                    'title': _(EditDeploymentProjectInfoView.page_title),
                    'url': reverse(EditDeploymentProjectInfoView.urlname, args=[self.domain])
                }
            ])

        from corehq.apps.domain.views import EditMyProjectSettingsView
        project_info.append({
            'title': _(EditMyProjectSettingsView.page_title),
            'url': reverse(EditMyProjectSettingsView.urlname, args=[self.domain])
        })

        if user_is_admin:
            from corehq.apps.domain.views import OrgSettingsView
            project_info.append({
                'title': _(OrgSettingsView.page_title),
                'url': reverse(OrgSettingsView.urlname, args=[self.domain])
            })

        items.append((_('Project Information'), project_info))

        if user_is_admin:
            from corehq.apps.domain.views import (
                BasicCommTrackSettingsView,
                AdvancedCommTrackSettingsView,
            )

            if self.project.commtrack_enabled:
                commtrack_settings = [
                    {
                        'title': _(BasicCommTrackSettingsView.page_title),
                        'url': reverse(BasicCommTrackSettingsView.urlname, args=[self.domain])
                    },
                    {
                        'title': _(AdvancedCommTrackSettingsView.page_title),
                        'url': reverse(AdvancedCommTrackSettingsView.urlname, args=[self.domain])
                    },
                ]
                items.append((_('CommTrack'), commtrack_settings))

            administration = [
                {
                    'title': _('CommCare Exchange'),
                    'url': reverse('domain_snapshot_settings', args=[self.domain])
                },
                {
                    'title': _('Multimedia Sharing'),
                    'url': reverse('domain_manage_multimedia', args=[self.domain])
                }
            ]

            def forward_name(repeater_type=None, **context):
                if repeater_type == 'FormRepeater':
                    return _("Forward Forms")
                elif repeater_type == 'ShortFormRepeater':
                    return _("Forward Form Stubs")
                elif repeater_type == 'CaseRepeater':
                    return _("Forward Cases")

            administration.extend([
                {'title': _('Data Forwarding'),
                 'url': reverse('domain_forwarding', args=[self.domain]),
                 'subpages': [
                     {'title': forward_name,
                      'urlname': 'add_repeater'}
                 ]}
            ])
            items.append((_('Project Administration'), administration))

        user_is_billing_admin, billing_account = BillingAccountAdmin.get_admin_status_and_account(
            self.couch_user, self.domain)
        if user_is_billing_admin or self.couch_user.is_superuser:
            from corehq.apps.domain.views import DomainSubscriptionView, EditExistingBillingAccountView
            subscription = [
                {
                    'title': DomainSubscriptionView.page_title,
                    'url': reverse(DomainSubscriptionView.urlname, args=[self.domain]),
                },
            ]
            if billing_account is not None:
                subscription.append(
                    {
                        'title':  EditExistingBillingAccountView.page_title,
                        'url': reverse(EditExistingBillingAccountView.urlname, args=[self.domain]),
                    },
                )
            if toggle.shortcuts.toggle_enabled(toggles.ACCOUNTING_PREVIEW, self.couch_user.username):
                items.append((_('Subscription'), subscription))

        if self.couch_user.is_superuser:
            from corehq.apps.domain.views import EditInternalDomainInfoView, EditInternalCalculationsView
            internal_admin = [{
                'title': _(EditInternalDomainInfoView.page_title),
                'url': reverse(EditInternalDomainInfoView.urlname, args=[self.domain])
            },
            {
                'title': _(EditInternalCalculationsView.page_title),
                'url': reverse(EditInternalCalculationsView.urlname, args=[self.domain])
            }]
            items.append((_('Internal Data (Dimagi Only)'), internal_admin))



        return items