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))
def pull_missing_multimedia(request, domain, app_id): async_update = request.POST.get('notify') == 'on' if async_update: pull_missing_multimedia_for_app_and_notify_task.delay(domain, app_id, request.user.email) messages.success(request, ugettext('Your request has been submitted. ' 'We will notify you via email once completed.')) else: app = get_app(domain, app_id) pull_missing_multimedia_for_app(app) return HttpResponseRedirect(reverse('app_settings', args=[domain, app_id]))
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