def _create_linked_app(request, master_app, link_domain, link_app_name): master_domain = master_app.domain master_version = get_latest_released_app_version(master_domain, master_app._id) if not master_version: messages.error( request, _("Creating linked app failed." " Unable to get latest released version of your app." " Make sure you have at least one released build.")) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[master_domain, master_app._id])) linked_app = create_linked_app(master_domain, master_app._id, link_domain, link_app_name) try: update_linked_app(linked_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=[master_domain, master_app._id])) messages.success(request, _('Application successfully copied and linked.')) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id]))
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]))
def pull_master_app(request, domain, app_id): async_update = request.POST.get('notify') == 'on' if async_update: update_linked_app_and_notify_task.delay(domain, app_id, request.couch_user.get_id, request.couch_user.email) messages.success( request, _('Your request has been submitted. We will notify you via email once completed.' )) else: app = get_current_app(domain, app_id) try: update_linked_app(app, request.couch_user.get_id) except AppLinkError as e: messages.error(request, six.text_type(e)) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[domain, app_id])) messages.success( request, _('Your linked application was successfully updated to the latest version.' )) track_workflow(request.couch_user.username, "Linked domain: master app pulled") return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[domain, app_id]))
def _inner(request, link_domain, data, master_domain=domain): clear_app_cache(request, link_domain) if data['toggles']: for slug in data['toggles'].split(","): set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN) linked = data.get('linked') if linked: for module in app.modules: if isinstance(module, ReportModule): 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.')) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) master_version = get_latest_released_app_version(app.domain, app_id) if not master_version: messages.error(request, _("Creating linked app failed." " Unable to get latest released version of your app." " Make sure you have at least one released build.")) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) linked_app = create_linked_app(master_domain, app_id, link_domain, data['name']) try: update_linked_app(linked_app, request.couch_user.get_id) except AppLinkError as e: messages.error(request, str(e)) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) messages.success(request, _('Application successfully copied and linked.')) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id])) else: extra_properties = {'name': data['name']} app_copy = import_app_util(app_id_or_source, link_domain, extra_properties) return back_to_main(request, app_copy.domain, app_id=app_copy._id)
def _inner(request, link_domain, data, master_domain=domain): clear_app_cache(request, link_domain) if data['toggles']: for slug in data['toggles'].split(","): set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN) linked = data.get('linked') if linked: master_version = get_latest_released_app_version(app.domain, app_id) if not master_version: messages.error(request, _("Creating linked app failed." " Unable to get latest released version of your app." " Make sure you have at least one released build.")) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) linked_app = create_linked_app(master_domain, app_id, link_domain, data['name']) try: update_linked_app(linked_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=[domain, app_id])) messages.success(request, _('Application successfully copied and linked.')) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id])) else: extra_properties = {'name': data['name']} try: app_copy = import_app_util(app_id_or_source, link_domain, extra_properties) except ReportConfigurationNotFoundError: messages.error(request, _("Copying the application failed because " "your application contains a Report Module " "that references a static UCR configuration.")) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) return back_to_main(request, app_copy.domain, app_id=app_copy._id)
def _inner(request, link_domain, data, master_domain=domain): clear_app_cache(request, link_domain) if data['toggles']: for slug in data['toggles'].split(","): set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN) linked = data.get('linked') if linked: master_version = get_latest_released_app_version( app.domain, app_id) if not master_version: messages.error( request, _("Creating linked app failed." " Unable to get latest released version of your app." " Make sure you have at least one released build.")) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[domain, app_id])) linked_app = create_linked_app(master_domain, app_id, link_domain, data['name']) try: update_linked_app(linked_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=[domain, app_id])) messages.success( request, _('Application successfully copied and linked.')) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id])) else: extra_properties = {'name': data['name']} try: app_copy = import_app_util(app_id_or_source, link_domain, extra_properties) except ReportConfigurationNotFoundError: messages.error( request, _("Copying the application failed because " "your application contains a Report Module " "that references a static UCR configuration.")) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[domain, app_id])) return back_to_main(request, app_copy.domain, app_id=app_copy._id)
def pull_master_app(request, domain, app_id): app = get_current_app(domain, app_id) try: update_linked_app(app, request.couch_user.get_id) except AppLinkError as e: messages.error(request, str(e)) 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]))
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]))
def pull_master_app(request, domain, app_id): async_update = request.POST.get('notify') == 'on' if async_update: update_linked_app_and_notify_task.delay(domain, app_id, request.couch_user.get_id, request.couch_user.email) messages.success(request, _('Your request has been submitted. We will notify you via email once completed.')) else: app = get_current_app(domain, app_id) try: update_linked_app(app, request.couch_user.get_id) except AppLinkError as e: messages.error(request, six.text_type(e)) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id])) messages.success(request, _('Your linked application was successfully updated to the latest version.')) track_workflow(request.couch_user.username, "Linked domain: master app pulled") return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))
def _create_linked_app(request, master_app, link_domain, link_app_name): master_domain = master_app.domain master_version = get_latest_released_app_version(master_domain, master_app._id) if not master_version: messages.error(request, _("Creating linked app failed." " Unable to get latest released version of your app." " Make sure you have at least one released build.")) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[master_domain, master_app._id])) linked_app = create_linked_app(master_domain, master_app._id, link_domain, link_app_name) try: update_linked_app(linked_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=[master_domain, master_app._id])) messages.success(request, _('Application successfully copied and linked.')) return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id]))
def _copy_app_helper(request, master_domain, master_app_id_or_source, copy_to_domain, copy_to_app_name, app_id): extra_properties = {'name': copy_to_app_name} try: app_copy = import_app_util(master_app_id_or_source, copy_to_domain, extra_properties) except ReportConfigurationNotFoundError: messages.error( request, _("Copying the application failed because " "your application contains a Report Module " "that references a static UCR configuration.")) return HttpResponseRedirect( reverse_util('app_settings', params={}, args=[master_domain, app_id])) return back_to_main(request, app_copy.domain, app_id=app_copy._id)
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) params = {} if app['domain'] in master_app.linked_whitelist: excluded_fields = set(Application._meta_fields).union([ 'date_created', 'build_profiles', 'copy_history', 'copy_of', 'name', 'comment', 'doc_type' ]) master_json = latest_master_build.to_json() for key, value in master_json.iteritems(): if key not in excluded_fields: app[key] = value app['version'] = master_json['version'] wrapped_app = wrap_app(app) mobile_ucrs = False for module in wrapped_app.modules: if isinstance(module, ReportModule): mobile_ucrs = True break if mobile_ucrs: 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.' )) wrapped_app.copy_attachments(latest_master_build) wrapped_app.save(increment_version=False) 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=params, args=[domain, app_id]))
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]))