Ejemplo n.º 1
0
def get_app_build(app_dict):
    domain = Domain.get_by_name(app_dict['domain'])
    if domain.use_cloudcare_releases:
        return get_latest_released_app(app_dict['domain'], app_dict['_id'])
    else:
        return get_latest_build_id(app_dict['domain'], app_dict['_id'])
    return None
Ejemplo n.º 2
0
def get_latest_master_app_release(domain_link, app_id):
    master_domain = domain_link.master_domain
    linked_domain = domain_link.linked_domain
    if domain_link.is_remote:
        return get_released_app(master_domain, app_id, linked_domain, domain_link.remote_details)
    else:
        return get_latest_released_app(master_domain, app_id)
Ejemplo n.º 3
0
def _create_linked_app(request, app_id, build_id, from_domain, to_domain, link_app_name):
    # Linked apps can only be created from released versions
    error = None
    if from_domain == to_domain:
        error = _("You may not create a linked app in the same domain as its master app.")
    elif build_id:
        from_app = Application.get(build_id)
        if not from_app.is_released:
            error = _("Make sure the version you are copying from is released.")
    else:
        from_app = get_latest_released_app(from_domain, app_id)
        if not from_app:
            error = _("Unable to get latest released version of your app."
                      " Make sure you have at least one released build.")

    if error:
        messages.error(request, _("Creating linked app failed. {}").format(error))
        return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[from_domain, app_id]))

    linked_app = create_linked_app(from_domain, from_app.master_id, to_domain, link_app_name)
    try:
        update_linked_app(linked_app, from_app, request.couch_user.get_id)
    except AppLinkError as e:
        linked_app.delete()
        messages.error(request, str(e))
        return HttpResponseRedirect(reverse_util('app_settings', params={},
                                                 args=[from_domain, from_app.master_id]))

    messages.success(request, _('Application successfully copied and linked.'))
    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[to_domain, linked_app.get_id]))
Ejemplo n.º 4
0
def get_latest_master_app_release(domain_link, app_id):
    master_domain = domain_link.master_domain
    linked_domain = domain_link.linked_domain
    if domain_link.is_remote:
        return get_released_app(master_domain, app_id, linked_domain, domain_link.remote_details)
    else:
        return get_latest_released_app(master_domain, app_id)
Ejemplo n.º 5
0
def get_latest_released_app_source(request, domain, app_id):
    master_app = get_app(None, app_id)
    if master_app.domain != domain:
        raise Http404

    latest_master_build = get_latest_released_app(domain, app_id)
    if not latest_master_build:
        raise Http404

    return JsonResponse(convert_app_for_remote_linking(latest_master_build))
Ejemplo n.º 6
0
def get_latest_released_app_source(request, domain, app_id):
    master_app = get_app(None, app_id)
    if master_app.domain != domain:
        raise Http404

    latest_master_build = get_latest_released_app(domain, app_id)
    if not latest_master_build:
        raise Http404

    return JsonResponse(convert_app_for_remote_linking(latest_master_build))
Ejemplo n.º 7
0
def get_latest_released_app_source(request, domain, app_id):
    master_app = get_app(None, app_id)
    if master_app.domain != domain:
        raise Http404

    requester = request.GET.get('requester')
    if requester not in master_app.linked_whitelist:
        return HttpResponseForbidden()

    latest_master_build = get_latest_released_app(domain, app_id)
    if not latest_master_build:
        raise Http404

    return JsonResponse(_convert_app_for_remote_linking(latest_master_build))
Ejemplo n.º 8
0
def get_visit_scheduler_forms(domain, timestamp):
    """
    The timestamp is set once at the beginning of each loading
    of the page, so that this result is only calculated once
    per page load.
    """
    result = []
    for app_id in get_app_ids_in_domain(domain):
        app = get_latest_released_app(domain, app_id)
        if app and app.doc_type == 'Application':
            for module in app.get_modules():
                for form in module.get_forms():
                    if isinstance(form, AdvancedForm) and form.schedule and form.schedule.enabled:
                        result.append({
                            'id': get_combined_id(app_id, form.unique_id),
                            'text': form.full_path_name,
                        })
    return result
Ejemplo n.º 9
0
def get_visit_scheduler_forms(domain, timestamp):
    """
    The timestamp is set once at the beginning of each loading
    of the page, so that this result is only calculated once
    per page load.
    """
    result = []
    for app_id in get_app_ids_in_domain(domain):
        app = get_latest_released_app(domain, app_id)
        if app and not app.is_deleted() and not app.is_remote_app():
            for module in app.get_modules():
                for form in module.get_forms():
                    if isinstance(form, AdvancedForm) and form.schedule and form.schedule.enabled:
                        result.append({
                            'id': get_combined_id(app_id, form.unique_id),
                            'text': form.full_path_name,
                        })
    return result
Ejemplo n.º 10
0
    def get_visit_scheduler_module_and_form(cls, domain, app_id,
                                            form_unique_id):
        app = get_latest_released_app(domain, app_id)
        if app is None:
            raise cls.VisitSchedulerIntegrationException("App not found")

        try:
            form = app.get_form(form_unique_id)
        except FormNotFoundException:
            raise cls.VisitSchedulerIntegrationException("Form not found")

        if not isinstance(form, AdvancedForm):
            raise cls.VisitSchedulerIntegrationException(
                "Expected AdvancedForm")

        if not form.schedule:
            raise cls.VisitSchedulerIntegrationException(
                "Expected form.schedule")

        if not form.schedule.enabled:
            raise cls.VisitSchedulerIntegrationException(
                "Expected form.schedule.enabled")

        return form.get_module(), form