Exemple #1
0
def migrate_repeater(repeater_doc):
    if "use_basic_auth" in repeater_doc:
        use_basic_auth = repeater_doc['use_basic_auth'] is True
        del repeater_doc['use_basic_auth']
        if use_basic_auth:
            repeater_doc["auth_type"] = "basic"
        return DocUpdate(repeater_doc)
        def _add_field(doc):
            updated = False
            log_prefix = "{} Domain {}, form unique_id {}".format(
                "[DRY RUN]" if dry_run else "", doc['domain'],
                doc['form_unique_id'])

            if doc.get('form_unique_id', None) and not doc.get('app_id', None):
                doc['app_id'] = get_app_id_from_form_unique_id(
                    doc['domain'], doc['form_unique_id'])
                if doc['app_id']:
                    updated = True
                    logger.info("{}: Updated {} to use app id {}".format(
                        log_prefix, doc['_id'], doc['app_id']))
                else:
                    logger.info("{}: Could not find app".format(log_prefix))

            for action in doc.get('actions', []):
                if action.get('form_unique_id',
                              None) and not action.get('app_id', None):
                    action['app_id'] = get_app_id_from_form_unique_id(
                        doc['domain'], action['form_unique_id'])
                    if action['app_id']:
                        updated = True
                        logger.info(
                            "{}: Updated action in {} to use app id {}".format(
                                log_prefix, doc['_id'], action['app_id']))
                    else:
                        logger.info(
                            "{}: Could not find app".format(log_prefix))

            if updated and not dry_run:
                return DocUpdate(doc)
Exemple #3
0
def migrate_repeater(repeater_doc):
    from .models import BASIC_AUTH
    if "use_basic_auth" in repeater_doc:
        use_basic_auth = repeater_doc['use_basic_auth'] is True
        del repeater_doc['use_basic_auth']
        if use_basic_auth:
            repeater_doc["auth_type"] = BASIC_AUTH
        return DocUpdate(repeater_doc)
Exemple #4
0
 def update_domain(doc):
     domain = Domain.wrap(doc)
     new_bu = name_by_map[domain.name]
     if new_bu not in BUSINESS_UNITS:
         print('Unknown BU: domain={}, BU={}'.format(domain.name, new_bu))
         return
     domain.internal.business_unit = new_bu
     return DocUpdate(doc)
Exemple #5
0
def _remove_role(user_doc):
    changed = False
    for dm in user_doc['domain_memberships']:
        if dm['is_admin'] and dm['role_id']:
            dm['role_id'] = None
            changed = True

    if changed:
        return DocUpdate(user_doc)
Exemple #6
0
 def migrate_report(self, report_config):
     rc = ReportConfiguration.wrap(report_config)
     for column in rc.report_columns:
         if column.transform and column.transform['type'] == 'translation':
             column.transform['mobile_or_web'] = 'mobile'
             column.transform['translations'] = reformat_translations(
                 column.transform['translations'])
             self.reports_using_transform.add(rc._id)
     if not self.dry_run:
         return DocUpdate(rc.to_json())
Exemple #7
0
 def _migrate_app(self, app_doc):
     try:
         if app_doc["doc_type"] in ["Application", "Application-Deleted"]:
             migrated_app = self.migrate_app(app_doc)
             if migrated_app:
                 return DocUpdate(migrated_app)
     except Exception as e:
         logger.exception("App {id} not properly migrated".format(id=app_doc['_id']))
         if self.options['failfast']:
             raise e
def clean_user(doc):
    """Take any users with no location_id and clear the location user_data"""
    if doc['location_id']:
        return

    had_bad_data = any([
        doc.get('user_data', {}).pop('commcare_location_id', False),
        doc.get('user_data', {}).pop('commtrack-supply-point', False),
    ])
    if had_bad_data:
        return DocUpdate(doc)
def _copy_permissions(role_doc):
    role = UserRole.wrap(role_doc)
    permissions = role_doc['permissions']
    if permissions.get('access_all_apps') != permissions.get('view_web_apps'):
        role.permissions.access_all_apps = permissions.get(
            'view_web_apps', True)
    if permissions.get('allowed_app_list') != permissions.get(
            'view_web_apps_list'):
        role.permissions.allowed_app_list = permissions.get(
            'view_web_apps_list', [])
    return DocUpdate(role)
    def migrate_web_user(cls, doc):
        def should_skip(dm):
            if not dm.get('location_id'):
                return True

            if dm['location_id'] in dm.get('assigned_location_ids', []):
                return True

        if all([should_skip(dm) for dm in doc['domain_memberships']]):
            return

        for membership in doc['domain_memberships']:
            if not should_skip(membership):
                apply_migration(membership)

        return DocUpdate(doc)
Exemple #11
0
    def migrate_cc_user(cls, doc):

        # skip if doesn't have location
        if not doc.get('location_id'):
            return

        # skip if already migrated
        if doc['location_id'] in doc.get('assigned_location_ids', []):
            user_data = doc.get('user_data', {})
            expected = user_location_data(doc['assigned_location_ids'])
            actual = user_data.get('commcare_location_ids', None)
            if expected == actual:
                return

        apply_migration(doc)
        apply_migration(doc['domain_membership'])
        if doc['assigned_location_ids']:
            doc['user_data'].update({
                'commcare_location_ids': user_location_data(doc['assigned_location_ids'])
            })
        return DocUpdate(doc)
 def update_username(event_dict):
     event_dict['user'] = new_username
     return DocUpdate(doc=event_dict)
Exemple #13
0
 def archive(user_doc):
     if user_doc['is_active']:
         user_doc['is_active'] = False
         return DocUpdate(user_doc)
Exemple #14
0
def _pop_field(app_doc):
    if 'uses_master_app_form_ids' in app_doc:
        app_doc.pop('uses_master_app_form_ids')
        return DocUpdate(app_doc)
Exemple #15
0
 def update_domain(doc):
     doc['location_restriction_for_users'] = False
     return DocUpdate(doc)
 def update_domain(doc):
     Domain.wrap(doc).internal.business_unit = updates[doc['_id']]
     return DocUpdate(doc)
Exemple #17
0
def _add_fields(app_doc):
    app_doc['family_id'] = app_doc['master']
    app_doc['upstream_app_id'] = app_doc['master']
    app_doc['upstream_version'] = app_doc['version']
    return DocUpdate(app_doc)
Exemple #18
0
def update_role(role_doc):
    role = UserRole.wrap(role_doc)
    # Currently we just use `edit_commcare_users` for both, so for existing
    # roles, let's default to that behavior
    role.permissions.edit_locations = role.permissions.edit_commcare_users
    return DocUpdate(role.to_json())