def handle(self, *args, **options): # Find all apps using vellum case management app_query = AppES().is_build(False).term( 'vellum_case_management', True).source(['domain', '_id']) # Find all domains created after vellum case management was released, # since their apps were never in the old world and therefore never migrated epoch = datetime(year=2016, month=7, day=15) domain_query = DomainES().date_range('date_created', gt=epoch).source('name') new_domains = {d['name']: 1 for d in domain_query.run().hits} hits = app_query.run().hits for hit in hits: if hit['domain'] not in new_domains: try: app = get_app(hit['domain'], hit['_id']) modules = [ m for m in app.modules if m.module_type == 'basic' ] for module in modules: forms = [ f for f in module.forms if f.doc_type == 'Form' ] for form in forms: if form.requires != 'case' and 'load' in form.case_references: if form.case_references['load']: logger.info( '{} is suspicious: /a/{}/apps/view/{}/modules-{}/forms-{}' .format(form.unique_id, app.domain, app.id, module.id, form.id)) except Http404: pass logger.info('done with cmitfb_identify_broken_forms')
def handle(self, commit, **options): logger.setLevel('DEBUG') start_date = datetime(2020, 3, 19) # Initial release of FFX app end_date = datetime(2020, 4, 4) # Release of analytics app_query = AppES().term('doc_type', 'Application') \ .missing('created_from_template') \ .date_range('date_created', gt=start_date, lt=end_date) hits = app_query.run().hits logger.info(f"Pulled {len(hits)} apps from ES") hits = [ h for h in hits if 'FFX' in h['name'] and len(h['modules']) == 9 and ( not h['family_id'] or h['family_id'] in KNOWN_FAMILY_IDS) ] logger.info( f"Filtered to {len(hits)} apps likely imported from app library") for hit in hits: app = wrap_app(Application.get_db().get(hit['_id'])) app.created_from_template = _get_app_id(hit['date_created']) if commit: app.save(increment_version=False) logger.info( f"Done with backfill_created_from_template, commit={commit}")
def handle(self, commit, **options): logger.setLevel('DEBUG') app_query = AppES().is_build(False).term('vellum_case_management', False) \ .term('doc_type', 'Application').size(500).source(['domain', '_id']) hits = app_query.run().hits logger.info('found {} apps to migrate'.format(len(hits))) failures = {} for hit in hits: try: call_command('migrate_app_to_cmitfb', hit['_id'], dry_run=not(commit), fail_hard=True) except Exception: failures[hit['_id']] = hit['domain'] for id, domain in failures.items(): logger.info('Failed: {} in {}'.format(id, domain)) logger.info('Total: {} successes, {} failures'.format(len(hits) - len(failures), len(failures))) logger.info('Done with migrate_all_apps_to_cmitfb')
def handle(self, *args, **options): app_query = AppES().is_build(False).term('vellum_case_management', False) \ .term('doc_type', 'Application').size(500).source(['domain', '_id']) hits = app_query.run().hits logger.info('found {} apps to migrate'.format(len(hits))) failures = {} for hit in hits: try: call_command('migrate_app_to_cmitfb', hit['_id']) except Exception: logger.info('migration failed') failures[hit['_id']] = hit['domain'] for id, domain in failures.iteritems(): logger.info('Failed: {} in {}'.format(id, domain)) logger.info('Total: {} successes, {} failures'.format(len(hits) - len(failures), len(failures))) logger.info('Done with migrate_all_apps_to_cmitfb')
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') only_show_released = json.loads( request.GET.get('only_show_released', 'false')) query = request.GET.get('query') page = int(request.GET.get('page', 1)) page = max(page, 1) try: limit = int(limit) except (TypeError, ValueError): limit = 10 skip = (page - 1) * limit timezone = get_timezone_for_user(request.couch_user, domain) def _get_batch(start_build=None, skip=None): start_build = {} if start_build is None else start_build return Application.get_db().view( 'app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, skip=skip, wrapper=lambda x: (SavedAppBuild.wrap(x['value'], scrap_old_conventions=False). releases_list_json(timezone)), ).all() if not bool(only_show_released or query): # If user is limiting builds by released status or build comment, it's much # harder to be performant with couch. So if they're not doing so, take shortcuts. total_apps = len(get_built_app_ids_for_app_id(domain, app_id)) saved_apps = _get_batch(skip=skip) else: app_es = (AppES().start((page - 1) * limit).size(limit).sort( 'version', desc=True).domain(domain).is_build().app_id(app_id)) if only_show_released: app_es = app_es.is_released() if query: app_es = app_es.add_query(build_comment(query), queries.SHOULD) try: app_es = app_es.add_query(version(int(query)), queries.SHOULD) except ValueError: pass results = app_es.exclude_source().run() total_apps = results.total app_ids = results.doc_ids apps = get_docs(Application.get_db(), app_ids) saved_apps = [ SavedAppBuild.wrap( app, scrap_old_conventions=False).releases_list_json(timezone) for app in apps ] if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) num_pages = int(ceil(total_apps / limit)) return json_response({ 'apps': saved_apps, 'pagination': { 'total': total_apps, 'num_pages': num_pages, 'current_page': page, 'more': page * limit < total_apps, # needed when select2 uses this endpoint } })