def wildcard_handler(col, wc_term): if wc_term.startswith('*') and not wc_term.endswith('*'): #postfix == endswith wc_term = remove_prefix(wc_term, prefix='*') return func.lower(col).endswith(wc_term) elif wc_term.startswith('*') and wc_term.endswith('*'): #wildcard == ilike wc_term = remove_prefix(wc_term, prefix='*') wc_term = remove_suffix(wc_term, suffix='*') return func.lower(col).contains(wc_term)
def update(self, repo, **kwargs): try: cur_repo = self._get_repo(repo) source_repo_name = cur_repo.repo_name if 'user' in kwargs: cur_repo.user = User.get_by_username(kwargs['user']) if 'repo_group' in kwargs: cur_repo.group = RepoGroup.get(kwargs['repo_group']) log.debug('Updating repo %s with params:%s', cur_repo, kwargs) update_keys = [(1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (1, 'repo_private'), (1, 'repo_enable_statistics'), (0, 'clone_uri'), (0, 'fork_id')] for strip, k in update_keys: if k in kwargs: val = kwargs[k] if strip: k = remove_prefix(k, 'repo_') if k == 'clone_uri': from rhodecode.model.validators import Missing _change = kwargs.get('clone_uri_change') if _change in [Missing, 'OLD']: # we don't change the value, so use original one val = cur_repo.clone_uri setattr(cur_repo, k, val) new_name = cur_repo.get_new_name(kwargs['repo_name']) cur_repo.repo_name = new_name # if private flag is set, reset default permission to NONE if kwargs.get('repo_private'): EMPTY_PERM = 'repository.none' RepoModel().grant_user_permission(repo=cur_repo, user=User.DEFAULT_USER, perm=EMPTY_PERM) # handle extra fields for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), kwargs): k = RepositoryField.un_prefix_key(field) ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo) if ex_field: ex_field.field_value = kwargs[field] self.sa.add(ex_field) self.sa.add(cur_repo) if source_repo_name != new_name: # rename repository self._rename_filesystem_repo(old=source_repo_name, new=new_name) return cur_repo except Exception: log.error(traceback.format_exc()) raise
def update(self, org_repo_name, **kwargs): try: cur_repo = self.get_by_repo_name(org_repo_name, cache=False) # update permissions for member, perm, member_type in kwargs['perms_updates']: if member_type == 'user': # this updates existing one RepoModel().grant_user_permission( repo=cur_repo, user=member, perm=perm ) else: RepoModel().grant_users_group_permission( repo=cur_repo, group_name=member, perm=perm ) # set new permissions for member, perm, member_type in kwargs['perms_new']: if member_type == 'user': RepoModel().grant_user_permission( repo=cur_repo, user=member, perm=perm ) else: RepoModel().grant_users_group_permission( repo=cur_repo, group_name=member, perm=perm ) if 'user' in kwargs: cur_repo.user = User.get_by_username(kwargs['user']) if 'repo_group' in kwargs: cur_repo.group = RepoGroup.get(kwargs['repo_group']) for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (0, 'clone_uri'), (1, 'repo_private'), (1, 'repo_enable_statistics')]: if k in kwargs: val = kwargs[k] if strip: k = remove_prefix(k, 'repo_') setattr(cur_repo, k, val) new_name = cur_repo.get_new_name(kwargs['repo_name']) cur_repo.repo_name = new_name self.sa.add(cur_repo) if org_repo_name != new_name: # rename repository self.__rename_repo(old=org_repo_name, new=new_name) return cur_repo except: log.error(traceback.format_exc()) raise
def get_default_repo_settings(self, strip_prefix=False): q = self._get_settings_query() q = q.filter( self.SettingsDbModel.app_settings_name.startswith('default_')) rows = q.all() result = {} for row in rows: key = row.app_settings_name if strip_prefix: key = remove_prefix(key, prefix='default_') result.update({key: row.app_settings_value}) return result
def update(self, org_repo_name, **kwargs): try: cur_repo = self.get_by_repo_name(org_repo_name, cache=False) if 'user' in kwargs: cur_repo.user = User.get_by_username(kwargs['user']) if 'repo_group' in kwargs: cur_repo.group = RepoGroup.get(kwargs['repo_group']) for strip, k in [ (1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (0, 'clone_uri'), (1, 'repo_private'), (1, 'repo_enable_statistics') ]: if k in kwargs: val = kwargs[k] if strip: k = remove_prefix(k, 'repo_') setattr(cur_repo, k, val) new_name = cur_repo.get_new_name(kwargs['repo_name']) cur_repo.repo_name = new_name #if private flag is set, reset default permission to NONE if kwargs.get('repo_private'): EMPTY_PERM = 'repository.none' RepoModel().grant_user_permission(repo=cur_repo, user='******', perm=EMPTY_PERM) #handle extra fields for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), kwargs): k = RepositoryField.un_prefix_key(field) ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo) if ex_field: ex_field.field_value = kwargs[field] self.sa.add(ex_field) self.sa.add(cur_repo) if org_repo_name != new_name: # rename repository self.__rename_repo(old=org_repo_name, new=new_name) return cur_repo except Exception: log.error(traceback.format_exc()) raise
def _get_defaults(self, repo_name): """ Get's information about repository, and returns a dict for usage in forms :param repo_name: """ repo_info = Repository.get_by_repo_name(repo_name) if repo_info is None: return None defaults = repo_info.get_dict() group, repo_name, repo_name_full = repo_info.groups_and_repo defaults['repo_name'] = repo_name defaults['repo_group'] = getattr(group[-1] if group else None, 'group_id', None) for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (0, 'clone_uri'), (1, 'repo_private'), (1, 'repo_enable_statistics')]: attr = k if strip: attr = remove_prefix(k, 'repo_') defaults[k] = defaults[attr] # fill owner if repo_info.user: defaults.update({'user': repo_info.user.username}) else: replacement_user = User.query().filter( User.admin == True).first().username defaults.update({'user': replacement_user}) # fill repository users for p in repo_info.repo_to_perm: defaults.update( {'u_perm_%s' % p.user.username: p.permission.permission_name}) # fill repository groups for p in repo_info.users_group_to_perm: defaults.update({ 'g_perm_%s' % p.users_group.users_group_name: p.permission.permission_name }) return defaults
def _get_defaults(self, repo_name): """ Get's information about repository, and returns a dict for usage in forms :param repo_name: """ repo_info = Repository.get_by_repo_name(repo_name) if repo_info is None: return None defaults = repo_info.get_dict() group, repo_name, repo_name_full = repo_info.groups_and_repo defaults['repo_name'] = repo_name defaults['repo_group'] = getattr(group[-1] if group else None, 'group_id', None) for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (0, 'clone_uri'), (1, 'repo_private'), (1, 'repo_enable_statistics')]: attr = k if strip: attr = remove_prefix(k, 'repo_') defaults[k] = defaults[attr] # fill owner if repo_info.user: defaults.update({'user': repo_info.user.username}) else: replacement_user = User.query().filter(User.admin == True).first().username defaults.update({'user': replacement_user}) # fill repository users for p in repo_info.repo_to_perm: defaults.update({'u_perm_%s' % p.user.username: p.permission.permission_name}) # fill repository groups for p in repo_info.users_group_to_perm: defaults.update({'g_perm_%s' % p.users_group.users_group_name: p.permission.permission_name}) return defaults
def update(self, org_repo_name, **kwargs): try: cur_repo = self.get_by_repo_name(org_repo_name, cache=False) if 'user' in kwargs: cur_repo.user = User.get_by_username(kwargs['user']) if 'repo_group' in kwargs: cur_repo.group = RepoGroup.get(kwargs['repo_group']) for strip, k in [(1, 'repo_enable_downloads'), (1, 'repo_description'), (1, 'repo_enable_locking'), (1, 'repo_landing_rev'), (0, 'clone_uri'), (1, 'repo_private'), (1, 'repo_enable_statistics')]: if k in kwargs: val = kwargs[k] if strip: k = remove_prefix(k, 'repo_') setattr(cur_repo, k, val) new_name = cur_repo.get_new_name(kwargs['repo_name']) cur_repo.repo_name = new_name #if private flag is set, reset default permission to NONE if kwargs.get('repo_private'): EMPTY_PERM = 'repository.none' RepoModel().grant_user_permission( repo=cur_repo, user='******', perm=EMPTY_PERM ) #handle extra fields for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), kwargs): k = RepositoryField.un_prefix_key(field) ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo) if ex_field: ex_field.field_value = kwargs[field] self.sa.add(ex_field) self.sa.add(cur_repo) if org_repo_name != new_name: # rename repository self.__rename_repo(old=org_repo_name, new=new_name) return cur_repo except Exception: log.error(traceback.format_exc()) raise
def _get_defaults(self, repo_name): """ Gets information about repository, and returns a dict for usage in forms :param repo_name: """ repo_info = Repository.get_by_repo_name(repo_name) if repo_info is None: return None defaults = repo_info.get_dict() defaults['repo_name'] = repo_info.just_name groups = repo_info.groups_with_parents parent_group = groups[-1] if groups else None # we use -1 as this is how in HTML, we mark an empty group defaults['repo_group'] = getattr(parent_group, 'group_id', -1) keys_to_process = ({ 'k': 'repo_type', 'strip': False }, { 'k': 'repo_enable_downloads', 'strip': True }, { 'k': 'repo_description', 'strip': True }, { 'k': 'repo_enable_locking', 'strip': True }, { 'k': 'repo_landing_rev', 'strip': True }, { 'k': 'clone_uri', 'strip': False }, { 'k': 'repo_private', 'strip': True }, { 'k': 'repo_enable_statistics', 'strip': True }) for item in keys_to_process: attr = item['k'] if item['strip']: attr = remove_prefix(item['k'], 'repo_') val = defaults[attr] if item['k'] == 'repo_landing_rev': val = ':'.join(defaults[attr]) defaults[item['k']] = val if item['k'] == 'clone_uri': defaults['clone_uri_hidden'] = repo_info.clone_uri_hidden # fill owner if repo_info.user: defaults.update({'user': repo_info.user.username}) else: replacement_user = User.get_first_super_admin().username defaults.update({'user': replacement_user}) # fill repository users for p in repo_info.repo_to_perm: defaults.update( {'u_perm_%s' % p.user.user_id: p.permission.permission_name}) # fill repository groups for p in repo_info.users_group_to_perm: defaults.update({ 'g_perm_%s' % p.users_group.users_group_id: p.permission.permission_name }) return defaults