Exemple #1
0
def update_linked_app(app, user_id):
    if not app.domain_link:
        raise AppLinkError(_(
            'This project is not authorized to update from the master application. '
            'Please contact the maintainer of the master app if you believe this is a mistake. '
        ))
    try:
        master_version = app.get_master_version()
    except RemoteRequestError:
        raise AppLinkError(_(
            'Unable to pull latest master from remote CommCare HQ. Please try again later.'
        ))

    if master_version > app.version:
        try:
            latest_master_build = app.get_latest_master_release()
        except ActionNotPermitted:
            raise AppLinkError(_(
                'This project is not authorized to update from the master application. '
                'Please contact the maintainer of the master app if you believe this is a mistake. '
            ))
        except RemoteAuthError:
            raise AppLinkError(_(
                'Authentication failure attempting to pull latest master from remote CommCare HQ.'
                'Please verify your authentication details for the remote link are correct.'
            ))
        except RemoteRequestError:
            raise AppLinkError(_(
                'Unable to pull latest master from remote CommCare HQ. Please try again later.'
            ))

        report_map = get_static_report_mapping(latest_master_build.domain, app['domain'])

        try:
            app = overwrite_app(app, latest_master_build, report_map)
        except AppEditingError as e:
            raise AppLinkError(
                _(
                    'This application uses mobile UCRs '
                    'which are not available in the linked domain: {ucr_id}'
                ).format(ucr_id=str(e))
            )

    if app.master_is_remote:
        try:
            missing_mm_populated = pull_missing_multimedia_for_app(app)
        except RemoteRequestError:
            raise AppLinkError(_(
                'Error fetching multimedia from remote server. Please try again later.'
            ))
        if not missing_mm_populated:
            raise MultimediaMissingError(_(
                'Application has missing multimedia even after an attempt to pull them. '
                'An email has been sent with details. Please try again. If persists, report an issue.'
            ))

    app.domain_link.update_last_pull('app', user_id, model_details=AppLinkDetail(app_id=app._id))

    # reapply linked application specific data
    app.reapply_overrides()
def link_app(linked_app, master_domain, master_id, remote_details=None):
    DomainLink.link_domains(linked_app.domain, master_domain, remote_details)

    linked_app.family_id = master_id
    linked_app.doc_type = 'LinkedApplication'
    linked_app.save()

    if linked_app.master_is_remote:
        try:
            pull_missing_multimedia_for_app(linked_app)
        except RemoteRequestError:
            raise AppLinkError('Error fetching multimedia from remote server. Please try again later.')

    return linked_app
Exemple #3
0
def update_linked_app(app, master_app_id_or_build, user_id):
    if not app.domain_link:
        raise AppLinkError(_(
            'This project is not authorized to update from the master application. '
            'Please contact the maintainer of the master app if you believe this is a mistake. '
        ))

    if isinstance(master_app_id_or_build, str):
        try:
            master_build = app.get_latest_master_release(master_app_id_or_build)
        except ActionNotPermitted:
            raise AppLinkError(_(
                'This project is not authorized to update from the master application. '
                'Please contact the maintainer of the master app if you believe this is a mistake. '
            ))
        except RemoteAuthError:
            raise AppLinkError(_(
                'Authentication failure attempting to pull latest master from remote CommCare HQ.'
                'Please verify your authentication details for the remote link are correct.'
            ))
        except RemoteRequestError:
            raise AppLinkError(_(
                'Unable to pull latest master from remote CommCare HQ. Please try again later.'
            ))
    else:
        master_build = master_app_id_or_build
    master_app_id = master_build.master_id

    previous = app.get_latest_build_from_upstream(master_app_id)
    if previous is None or master_build.version > previous.upstream_version:
        old_multimedia_ids = set([media_info.multimedia_id for path, media_info in app.multimedia_map.items()])
        report_map = get_static_report_mapping(master_build.domain, app['domain'])

        try:
            app = overwrite_app(app, master_build, report_map)
        except AppEditingError as e:
            raise AppLinkError(
                _(
                    'This application uses mobile UCRs '
                    'which are not available in the linked domain: {ucr_id}'
                ).format(ucr_id=str(e))
            )

        if app.master_is_remote:
            try:
                pull_missing_multimedia_for_app(app, old_multimedia_ids)
            except RemoteRequestError:
                raise AppLinkError(_(
                    'Error fetching multimedia from remote server. Please try again later.'
                ))

        # reapply linked application specific data
        app.reapply_overrides()
        app.save()

    app.domain_link.update_last_pull('app', user_id, model_details=AppLinkDetail(app_id=app._id))