Beispiel #1
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:
        try:
            overwrite_app(app, latest_master_build)
        except AppEditingError:
            messages.error(
                request,
                _('This linked application uses 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]))
Beispiel #2
0
 def test_report_mapping(self):
     report_map = {'master_report_id': 'mapped_id'}
     overwrite_app(self.linked_app, self.master_app_with_report_modules,
                   report_map)
     linked_app = Application.get(self.linked_app._id)
     self.assertEqual(linked_app.modules[0].report_configs[0].report_id,
                      'mapped_id')
Beispiel #3
0
 def handle(self, from_domain, from_app_id, to_domain, to_app_id, *args,
            **options):
     self.from_domain = from_domain
     self.to_domain = to_domain
     app = get_current_app(self.to_domain, to_app_id)
     latest_master_build = get_app(None, from_app_id, latest=True)
     overwrite_app(app, latest_master_build, self.report_map)
    def test_overwrite_app_override_form_unique_ids(self):
        module = self.master1.add_module(Module.new_module('M1', None))
        master_form = module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        add_xform_resource_overrides(self.linked_domain, self.linked_app.get_id, {master_form.unique_id: '123'})
        overwrite_app(self.linked_app, self.master1)

        self.assertEqual(
            {master_form.xmlns: '123'},
            self._get_form_ids_by_xmlns(LinkedApplication.get(self.linked_app._id))
        )

        ResourceOverride.objects.filter(domain=self.linked_domain, app_id=self.linked_app.get_id).delete()
Beispiel #5
0
    def test_overwrite_app_override_form_unique_ids(self):
        master_form = list(self.master1.get_forms(bare=True))[0]

        add_xform_resource_overrides(self.linked_domain,
                                     self.linked_app.get_id,
                                     {master_form.unique_id: '123'})
        overwrite_app(self.linked_app, self.master1)

        self.assertEqual({master_form.xmlns: '123'},
                         self._get_form_ids_by_xmlns(
                             LinkedApplication.get(self.linked_app._id)))

        ResourceOverride.objects.filter(
            domain=self.linked_domain, app_id=self.linked_app.get_id).delete()
Beispiel #6
0
    def test_overwrite_app_maintain_form_unique_ids(self):
        module = self.master1.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        module = self.linked_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        id_map_before = _get_form_ids_by_xmlns(self.linked_app)

        overwrite_app(self.linked_app, self.master1, {})
        self.assertEqual(
            id_map_before,
            _get_form_ids_by_xmlns(LinkedApplication.get(self.linked_app._id))
        )
Beispiel #7
0
    def test_overwrite_app_maintain_ids(self):
        module = self.plain_master_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        module = self.linked_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form').decode('utf-8'))

        id_map_before = _get_form_id_map(self.linked_app)

        overwrite_app(self.linked_app, self.plain_master_app, {})
        self.assertEqual(
            id_map_before,
            _get_form_id_map(LinkedApplication.get(self.linked_app._id))
        )
Beispiel #8
0
    def test_overwrite_app_maintain_ids(self):
        module = self.plain_master_app.add_module(Module.new_module(
            'M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form'))

        module = self.linked_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None, self.get_xml('very_simple_form'))

        id_map_before = _get_form_id_map(self.linked_app)

        overwrite_app(self.linked_app, self.plain_master_app, {})
        self.assertEqual(
            id_map_before,
            _get_form_id_map(LinkedApplication.get(self.linked_app._id)))
Beispiel #9
0
    def test_overwrite_app_with_shadow_forms(self):
        upstream_app = self._make_app_with_shadow_forms()
        linked_app = self._make_linked_app(upstream_app.domain)

        linked_app = overwrite_app(linked_app, upstream_app, {})
        original_forms = sorted(linked_app.get_forms(), key=lambda form: form.name['en'])

        linked_app = overwrite_app(linked_app, upstream_app, {})
        updated_forms = sorted(linked_app.get_forms(), key=lambda form: form.name['en'])

        for original, updated in zip(original_forms, updated_forms):
            self.assertEqual(original.name, updated.name)
            self.assertEqual(original.xmlns, updated.xmlns)
            if original.form_type != 'shadow_form':
                self.assertEqual(original.unique_id, updated.unique_id)
    def test_overwrite_app_update_form_unique_ids(self):
        module = self.master1.add_module(Module.new_module('M1', None))
        module.new_form('f1', None,
                        self.get_xml('very_simple_form').decode('utf-8'))

        module = self.linked_app.add_module(Module.new_module('M1', None))
        module.new_form('f1', None,
                        self.get_xml('very_simple_form').decode('utf-8'))

        linked_app = overwrite_app(self.linked_app, self.master1)
        self.assertEqual(self._get_form_ids_by_xmlns(self.master1),
                         self._get_form_ids_by_xmlns(linked_app))
Beispiel #11
0
    def handle(self, from_domain, from_app_id, to_domain, *args, **options):
        self.from_domain = from_domain
        self.to_domain = to_domain
        to_app_id = options.get('to-app-id')
        version = options.get('version')
        if to_app_id:
            app = get_current_app(self.to_domain, to_app_id)
            print('Overwriting application: {}'.format(app.name))
        else:
            print('Creating new application')
            app = Application()

        if version:
            from_app_doc = get_build_doc_by_version(self.from_domain, from_app_id, version)
        else:
            from_app_doc = get_latest_released_app_doc(self.from_domain, from_app_id)

        if not from_app_doc:
            raise CommandError("From app not found")

        from_app = wrap_app(from_app_doc)
        print('Overwring app with "{}" (version {})'.format(from_app.name, from_app.version))
        overwrite_app(app, from_app, self.report_map)
 def test_missing_ucrs(self):
     with self.assertRaises(AppEditingError):
         overwrite_app(self.linked_app, self.master_app_with_report_modules,
                       {})
Beispiel #13
0
 def test_missing_ucrs(self):
     with self.assertRaises(AppEditingError):
         overwrite_app(self.target_json, self.master_app, {})
Beispiel #14
0
 def test_report_mapping(self):
     report_map = {'master_report_id': 'mapped_id'}
     overwrite_app(self.linked_app, self.master_app_with_report_modules, report_map)
     linked_app = Application.get(self.linked_app._id)
     self.assertEqual(linked_app.modules[0].report_configs[0].report_id, 'mapped_id')
Beispiel #15
0
 def test_missing_ucrs(self):
     with self.assertRaises(AppEditingError):
         overwrite_app(self.linked_app, self.master_app_with_report_modules, {})
Beispiel #16
0
def _mock_pull_remote_master(master_app, linked_app, report_map=None):
    master_source = convert_app_for_remote_linking(master_app)
    master_app = _convert_app_from_remote_linking_source(master_source)
    overwrite_app(linked_app, master_app, report_map or {})
    return Application.get(linked_app._id)
def _mock_pull_remote_master(master_app, linked_app, report_map=None):
    master_source = convert_app_for_remote_linking(master_app)
    master_app = _convert_app_from_remote_linking_source(master_source)
    overwrite_app(linked_app, master_app, report_map or {})
    return Application.get(linked_app._id)
Beispiel #18
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]))