def _get_apps(self, restore_state, restore_user): app_aware_sync_app = restore_state.params.app if app_aware_sync_app: apps = [app_aware_sync_app] elif (toggles.ROLE_WEBAPPS_PERMISSIONS.enabled(restore_user.domain) and restore_state.params.device_id and "WebAppsLogin" in restore_state.params.device_id): # Only sync reports for apps the user has access to if this is a restore from webapps role = restore_user.get_role(restore_user.domain) if role: allowed_app_ids = [ app['_id'] for app in get_brief_apps_in_domain(restore_user.domain) if role.permissions.view_web_app(app) ] apps = get_apps_by_id(restore_user.domain, allowed_app_ids) else: # If there is no role, allow access to all apps apps = get_apps_in_domain(restore_user.domain, include_remote=False) else: apps = get_apps_in_domain(restore_user.domain, include_remote=False) return apps
def __call__(self, restore_state): """ Generates a report fixture for mobile that can be used by a report module """ restore_user = restore_state.restore_user if not toggles.MOBILE_UCR.enabled(restore_user.domain) or not _should_sync(restore_state): return [] if toggles.PREVENT_MOBILE_UCR_SYNC.enabled(restore_user.domain): return [] app_aware_sync_app = restore_state.params.app if app_aware_sync_app: apps = [app_aware_sync_app] elif ( toggles.ROLE_WEBAPPS_PERMISSIONS.enabled(restore_user.domain) and restore_state.params.device_id and "WebAppsLogin" in restore_state.params.device_id ): # Only sync reports for apps the user has access to if this is a restore from webapps role = restore_user.get_role(restore_user.domain) if role: allowed_app_ids = [app['_id'] for app in get_brief_apps_in_domain(restore_user.domain) if role.permissions.view_web_app(app)] apps = get_apps_by_id(restore_user.domain, allowed_app_ids) else: # If there is no role, allow access to all apps apps = get_apps_in_domain(restore_user.domain, include_remote=False) else: apps = get_apps_in_domain(restore_user.domain, include_remote=False) report_configs = [ report_config for app_ in apps for module in app_.modules if isinstance(module, ReportModule) for report_config in module.report_configs ] if not report_configs: return [] root = E.fixture(id=self.id, user_id=restore_user.user_id) reports_elem = E.reports(last_sync=datetime.utcnow().isoformat()) for report_config in report_configs: try: reports_elem.append(self.report_config_to_fixture(report_config, restore_user)) except ReportConfigurationNotFoundError as err: logging.exception('Error generating report fixture: {}'.format(err)) continue except UserReportsError: if settings.UNIT_TESTING or settings.DEBUG: raise except Exception as err: logging.exception('Error generating report fixture: {}'.format(err)) if settings.UNIT_TESTING or settings.DEBUG: raise root.append(reports_elem) return [root]
def handle(self, domain, app_id, form_id, cleanup=False, **options): app = get_apps_by_id(domain, app_id)[0] form = app.get_form(form_id) source = form.source if any(suspicious_string in source for suspicious_string in SUSPICIOUS_STRINGS): print('FORM CONTAINS SUSPICIOUS STRING') if cleanup: if 'y' == input( 'Did you confirm that there are no app updates to publish? [y/N]' ): print('Cleaning form...') form.source = source.encode('latin1').decode('utf-8') app.save() print('Done.') else: print('Aborting...')
def _get_apps(self, restore_state, restore_user): app_aware_sync_app = restore_state.params.app if app_aware_sync_app: apps = [app_aware_sync_app] elif ( toggles.ROLE_WEBAPPS_PERMISSIONS.enabled(restore_user.domain) and restore_state.params.device_id and "WebAppsLogin" in restore_state.params.device_id ): # Only sync reports for apps the user has access to if this is a restore from webapps role = restore_user.get_role(restore_user.domain) if role: allowed_app_ids = [app['_id'] for app in get_brief_apps_in_domain(restore_user.domain) if role.permissions.view_web_app(app)] apps = get_apps_by_id(restore_user.domain, allowed_app_ids) else: # If there is no role, allow access to all apps apps = get_apps_in_domain(restore_user.domain, include_remote=False) else: apps = get_apps_in_domain(restore_user.domain, include_remote=False) return apps
def test_get_apps_by_id(self): apps = get_apps_by_id(self.domain, [self.app_id]) self.assertEqual(1, len(apps)) self.assertEqual(apps[0].version, 5)