Exemplo n.º 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()
Exemplo n.º 2
0
def pull_master_app(request, domain, app_id):
    app = get_current_app_doc(domain, app_id)
    master_app = get_app(None, app['master'])
    latest_master_build = get_app(None, app['master'], latest=True)
    if app['domain'] in master_app.linked_whitelist:
        report_map = get_static_report_mapping(master_app.domain,
                                               app['domain'], {})
        try:
            overwrite_app(app, latest_master_build, report_map)
        except AppEditingError:
            messages.error(
                request,
                _('This linked application uses dynamic mobile UCRs '
                  'which are currently not supported. For this application '
                  'to function correctly, you will need to remove those modules '
                  'or revert to a previous version that did not include them.')
            )
        else:
            messages.success(
                request,
                _('Your linked application was successfully updated to the latest version.'
                  ))
    else:
        messages.error(
            request,
            _('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. '
              ))
    return HttpResponseRedirect(
        reverse_util('view_app', params={}, args=[domain, app_id]))
Exemplo n.º 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))
Exemplo n.º 4
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 app.version is None or 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:
            pull_missing_multimedia_for_app(app)
        except RemoteRequestError:
            raise AppLinkError(_(
                'Error fetching multimedia from remote server. Please try again later.'
            ))

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

    # reapply linked application specific data
    app.reapply_overrides()
Exemplo n.º 5
0
    def copy_ucr_reports(self, datasource_map):
        report_map = {}
        reports = get_report_configs_for_domain(self.existing_domain)
        for report in reports:
            old_datasource_id = report.config_id
            try:
                report.config_id = datasource_map[old_datasource_id]
            except KeyError:
                pass  # datasource not found

            old_id, new_id = self.save_couch_copy(report, self.new_domain)
            report_map[old_id] = new_id
        report_map = get_static_report_mapping(self.existing_domain, self.new_domain, report_map)
        return report_map
Exemplo n.º 6
0
    def copy_ucr_reports(self, datasource_map):
        report_map = {}
        reports = get_report_configs_for_domain(self.existing_domain)
        for report in reports:
            old_datasource_id = report.config_id
            try:
                report.config_id = datasource_map[old_datasource_id]
            except KeyError:
                pass  # datasource not found

            old_id, new_id = self.save_couch_copy(report, self.new_domain)
            report_map[old_id] = new_id
        report_map.update(get_static_report_mapping(self.existing_domain, self.new_domain))
        return report_map
Exemplo n.º 7
0
def _convert_reports_permissions(domain_link, master_results):
    """Mutates the master result docs to convert dynamic report permissions.
    """
    report_map = get_static_report_mapping(domain_link.master_domain, domain_link.linked_domain)
    for role_def in master_results:
        new_report_perms = [
            perm for perm in role_def['permissions']['view_report_list']
            if 'DynamicReport' not in perm
        ]

        for master_id, linked_id in report_map.items():
            master_report_perm = get_ucr_class_name(master_id)
            if master_report_perm in role_def['permissions']['view_report_list']:
                new_report_perms.append(get_ucr_class_name(linked_id))

        role_def['permissions']['view_report_list'] = new_report_perms
Exemplo n.º 8
0
def _convert_reports_permissions(domain_link, master_results):
    """Mutates the master result docs to convert dynamic report permissions.
    """
    report_map = get_static_report_mapping(domain_link.master_domain, domain_link.linked_domain)
    for role_def in master_results:
        new_report_perms = [
            perm for perm in role_def['permissions']['view_report_list']
            if 'DynamicReport' not in perm
        ]

        for master_id, linked_id in report_map.items():
            master_report_perm = get_ucr_class_name(master_id)
            if master_report_perm in role_def['permissions']['view_report_list']:
                new_report_perms.append(get_ucr_class_name(linked_id))

        role_def['permissions']['view_report_list'] = new_report_perms
Exemplo n.º 9
0
def pull_master_app(request, domain, app_id):
    app = get_current_app(domain, app_id)
    try:
        master_version = app.get_master_version()
    except RemoteRequestError:
        messages.error(
            request,
            _('Unable to pull latest master from remote CommCare HQ. Please try again later.'
              ))
        return HttpResponseRedirect(
            reverse_util('app_settings', params={}, args=[domain, app_id]))

    if master_version > app.version:
        exception_message = None
        try:
            latest_master_build = app.get_latest_master_release()
        except ActionNotPermitted:
            exception_message = _(
                '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:
            exception_message = _(
                'Authentication failure attempting to pull latest master from remote CommCare HQ.'
                'Please verify your authentication details for the remote link are correct.'
            )
        except RemoteRequestError:
            exception_message = _(
                'Unable to pull latest master from remote CommCare HQ. Please try again later.'
            )

        if exception_message:
            messages.error(request, exception_message)
            return HttpResponseRedirect(
                reverse_util('app_settings', params={}, args=[domain, app_id]))

        report_map = get_static_report_mapping(latest_master_build.domain,
                                               app['domain'], {})
        try:
            overwrite_app(app, latest_master_build, report_map)
        except AppEditingError:
            messages.error(
                request,
                _('This linked application uses dynamic mobile UCRs '
                  'which are currently not supported. For this application '
                  'to function correctly, you will need to remove those modules '
                  'or revert to a previous version that did not include them.')
            )
            return HttpResponseRedirect(
                reverse_util('app_settings', params={}, args=[domain, app_id]))

    if app.master_is_remote:
        try:
            pull_missing_multimedia_from_remote(app)
        except RemoteRequestError:
            messages.error(
                request,
                _('Error fetching multimedia from remote server. Please try again later.'
                  ))
            return HttpResponseRedirect(
                reverse_util('app_settings', params={}, args=[domain, app_id]))

    messages.success(
        request,
        _('Your linked application was successfully updated to the latest version.'
          ))
    return HttpResponseRedirect(
        reverse_util('app_settings', params={}, args=[domain, app_id]))
Exemplo n.º 10
0
 def report_map(self):
     if not self._report_map:
         self._report_map = get_static_report_mapping(self.from_domain, self.to_domain)
     return self._report_map