def update_linked_model(self, in_data): model = in_data['model'] type_ = model['type'] detail = model['detail'] detail_obj = wrap_detail(type_, detail) if detail else None master_link = get_domain_master_link(self.domain) error = "" try: update_model_type(master_link, type_, detail_obj) model_detail = detail_obj.to_json() if detail_obj else None master_link.update_last_pull(type_, self.request.couch_user._id, model_detail=model_detail) except (DomainLinkError, UnsupportedActionError) as e: error = str(e) track_workflow(self.request.couch_user.username, "Linked domain: updated '{}' model".format(type_)) timezone = get_timezone_for_request() return { 'success': not error, 'error': error, 'last_update': server_to_user_time(master_link.last_pull, timezone) }
def _release_model(self, domain_link, model, user): update_model_type(domain_link, model['type'], model_detail=model['detail']) domain_link.update_last_pull(model['type'], user._id, model_detail=model['detail'])
def update_linked_model(self, in_data): model = in_data['model'] type_ = model['type'] detail = model['detail'] detail_obj = wrap_detail(type_, detail) if detail else None master_link = get_domain_master_link(self.domain) update_model_type(master_link, type_, detail_obj) master_link.update_last_pull(type_, self.request.couch_user._id, model_details=detail_obj) track_workflow(self.request.couch_user.username, "Linked domain: updated '{}' model".format(type_)) timezone = get_timezone_for_request() return { 'success': True, 'last_update': server_to_user_time(master_link.last_pull, timezone) }
def update_linked_model(self, in_data): model = in_data['model'] type_ = model['type'] detail = model['detail'] detail_obj = wrap_detail(type, detail) if detail else None master_link = get_domain_master_link(self.domain) update_model_type(master_link, type_, detail_obj) master_link.update_last_pull(type_, self.request.couch_user._id, model_details=detail_obj) track_workflow(self.request.couch_user.username, "Linked domain: updated '{}' model".format(type_)) timezone = get_timezone_for_request() return { 'success': True, 'last_update': server_to_user_time(master_link.last_pull, timezone) }
def push_models(master_domain, models, linked_domains, build_apps, username): domain_links_by_linked_domain = { link.linked_domain: link for link in get_linked_domains(master_domain) } user = CouchUser.get_by_username(username) errors_by_domain = defaultdict(list) successes_by_domain = defaultdict(list) for linked_domain in linked_domains: if linked_domain not in domain_links_by_linked_domain: errors_by_domain[linked_domain].append( _("Project space {} is no longer linked to {}. No content " "was released to it.").format(master_domain, linked_domain)) continue domain_link = domain_links_by_linked_domain[linked_domain] for model in models: try: found = False updated_app = False built_app = False if model['type'] == MODEL_APP: app_id = model['detail']['app_id'] for linked_app in get_apps_in_domain(linked_domain, include_remote=False): if is_linked_app( linked_app) and linked_app.family_id == app_id: found = True if toggles.MULTI_MASTER_LINKED_DOMAINS.enabled( linked_domain): errors_by_domain[linked_domain].append( textwrap.dedent( _(""" Could not update {} because multi master flag is in use """.strip()).format(model['name']))) continue app = update_linked_app(linked_app, app_id, user.user_id) updated_app = True if build_apps: build = app.make_build() build.is_released = True build.save(increment_version=False) built_app = True elif model['type'] == MODEL_REPORT: report_id = model['detail']['report_id'] for linked_report in get_report_configs_for_domain( linked_domain): if linked_report.report_meta.master_id == report_id: found = True update_linked_ucr(domain_link, linked_report.get_id) elif (model['type'] == MODEL_CASE_SEARCH and not toggles.SYNC_SEARCH_CASE_CLAIM.enabled(linked_domain) ): errors_by_domain[linked_domain].append( textwrap.dedent( _(""" Could not update {} because case claim flag is not on """.strip()).format(model['name']))) continue else: found = True update_model_type(domain_link, model['type'], model_detail=model['detail']) domain_link.update_last_pull(model['type'], user._id, model_details=model['detail']) if found: successes_by_domain[linked_domain].append( _("{} was updated").format(model['name'])) else: errors_by_domain[linked_domain].append( _("Could not find {}").format(model['name'])) except Exception as e: # intentionally broad if model[ 'type'] == MODEL_APP and updated_app and build_apps and not built_app: # Updating an app can be a 2-step process, make it clear which one failed errors_by_domain[linked_domain].append( textwrap.dedent( _(""" Updated {} but could not make and release build: {} """.strip()).format(model['name'], str(e)))) else: errors_by_domain[linked_domain].append( textwrap.dedent( _(""" Could not update {}: {} """.strip()).format(model['name'], str(e)))) notify_exception( None, "Exception pushing linked domains: {}".format(e)) subject = _("Linked project release complete.") if errors_by_domain: subject += _(" Errors occurred.") error_domain_count = len(errors_by_domain) success_domain_count = len(linked_domains) - error_domain_count message = _(""" Release complete. {} project(s) succeeded. {} The following content was released: {} The following linked project spaces received content: """).format( success_domain_count, _("{} project(s) encountered errors.").format(error_domain_count) if error_domain_count else "", "\n".join(["- " + m['name'] for m in models])) for linked_domain in linked_domains: if linked_domain not in errors_by_domain: message += _("\n- {} updated successfully").format(linked_domain) else: message += _("\n- {} encountered errors:").format(linked_domain) for msg in errors_by_domain[linked_domain] + successes_by_domain[ linked_domain]: message += "\n - " + msg send_mail_async.delay(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email or user.username])