##// END OF EJS Templates
system-info: refactor func_name to prevent refactor
system-info: refactor func_name to prevent refactor

File last commit:

r4610:1c249462 stable
r4984:61cdb36d default
Show More
views.py
856 lines | 30.3 KiB | text/x-python | PythonLexer
core: moved users and user groups autocomplete into pyramid....
r1666 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2016-2020 RhodeCode GmbH
core: moved users and user groups autocomplete into pyramid....
r1666 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
core: moved goto_switcher views into pyramid.
r1668 import re
core: moved users and user groups autocomplete into pyramid....
r1666 import logging
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 import collections
core: moved users and user groups autocomplete into pyramid....
r1666
dashboard: main page grids async load....
r4148 from pyramid.httpexceptions import HTTPNotFound
core: moved users and user groups autocomplete into pyramid....
r1666
dashboard: main page grids async load....
r4148 from rhodecode.apps._base import BaseAppView, DataGridAppView
core: moved repo_list data to pyramid.
r1667 from rhodecode.lib import helpers as h
apps: cleanup imports
r2080 from rhodecode.lib.auth import (
dashboard: main page grids async load....
r4148 LoginRequired, NotAnonymous, HasRepoGroupPermissionAnyDecorator, CSRFRequired,
grids: fixed tests and added one for permissions to repository group.
r4151 HasRepoGroupPermissionAny, AuthUser)
dan
file: new file editors...
r3754 from rhodecode.lib.codeblocks import filenode_as_lines_tokens
core: moved goto_switcher views into pyramid.
r1668 from rhodecode.lib.index import searcher_from_config
quick-search-bar: fixes #5634
r4499 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int, safe_str
dan
file: new file editors...
r3754 from rhodecode.lib.vcs.nodes import FileNode
goto-switcher: optimized performance and query capabilities....
r2038 from rhodecode.model.db import (
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 func, true, or_, case, cast, in_filter_generator, String, Session,
Repository, RepoGroup, User, UserGroup, PullRequest)
core: moved users and user groups autocomplete into pyramid....
r1666 from rhodecode.model.repo import RepoModel
home: moved home and repo group views into pyramid....
r1774 from rhodecode.model.repo_group import RepoGroupModel
users: moved get_users from RepoModel to UserModel.
r1677 from rhodecode.model.user import UserModel
user-groups: moved get_user_groups from RepoModel to UserGroupModel.
r1676 from rhodecode.model.user_group import UserGroupModel
core: moved users and user groups autocomplete into pyramid....
r1666
log = logging.getLogger(__name__)
dashboard: main page grids async load....
r4148 class HomeView(BaseAppView, DataGridAppView):
core: moved users and user groups autocomplete into pyramid....
r1666
def load_default_context(self):
c = self._get_local_tmpl_context()
c.user = c.auth_user.get_instance()
return c
@LoginRequired()
def user_autocomplete_data(self):
views: load template context for XHR views....
r2308 self.load_default_context()
core: moved users and user groups autocomplete into pyramid....
r1666 query = self.request.GET.get('query')
active = str2bool(self.request.GET.get('active') or True)
include_groups = str2bool(self.request.GET.get('user_groups'))
pull-request-reviewers: added option to add reviewers by picking an user group for pull requests....
r1678 expand_groups = str2bool(self.request.GET.get('user_groups_expand'))
user-autocomplete: allow skipping default user.
r1768 skip_default_user = str2bool(self.request.GET.get('skip_default_user'))
core: moved users and user groups autocomplete into pyramid....
r1666
log.debug('generating user list, query:%s, active:%s, with_groups:%s',
query, active, include_groups)
users: moved get_users from RepoModel to UserModel.
r1677 _users = UserModel().get_users(
core: moved users and user groups autocomplete into pyramid....
r1666 name_contains=query, only_active=active)
user-autocomplete: allow skipping default user.
r1768 def maybe_skip_default_user(usr):
if skip_default_user and usr['username'] == UserModel.cls.DEFAULT_USER:
return False
return True
_users = filter(maybe_skip_default_user, _users)
core: moved users and user groups autocomplete into pyramid....
r1666 if include_groups:
# extend with user groups
user-groups: moved get_user_groups from RepoModel to UserGroupModel.
r1676 _user_groups = UserGroupModel().get_user_groups(
pull-request-reviewers: added option to add reviewers by picking an user group for pull requests....
r1678 name_contains=query, only_active=active,
expand_groups=expand_groups)
core: moved users and user groups autocomplete into pyramid....
r1666 _users = _users + _user_groups
return {'suggestions': _users}
@LoginRequired()
@NotAnonymous()
def user_group_autocomplete_data(self):
views: load template context for XHR views....
r2308 self.load_default_context()
core: moved users and user groups autocomplete into pyramid....
r1666 query = self.request.GET.get('query')
active = str2bool(self.request.GET.get('active') or True)
pull-request-reviewers: added option to add reviewers by picking an user group for pull requests....
r1678 expand_groups = str2bool(self.request.GET.get('user_groups_expand'))
core: moved users and user groups autocomplete into pyramid....
r1666 log.debug('generating user group list, query:%s, active:%s',
query, active)
user-groups: moved get_user_groups from RepoModel to UserGroupModel.
r1676 _user_groups = UserGroupModel().get_user_groups(
pull-request-reviewers: added option to add reviewers by picking an user group for pull requests....
r1678 name_contains=query, only_active=active,
expand_groups=expand_groups)
core: moved users and user groups autocomplete into pyramid....
r1666 _user_groups = _user_groups
return {'suggestions': _user_groups}
core: moved repo_list data to pyramid.
r1667
go-to search: updated logic of goto switcher...
r3556 def _get_repo_list(self, name_contains=None, repo_type=None, repo_group_name='', limit=20):
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 org_query = name_contains
goto-switcher: optimized performance and query capabilities....
r2038 allowed_ids = self._rhodecode_user.repo_acl_ids(
['repository.read', 'repository.write', 'repository.admin'],
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 cache=True, name_filter=name_contains) or [-1]
goto-switcher: optimized performance and query capabilities....
r2038
goto-switcher: reduce query data to only required attributes for speedups.
r4152 query = Session().query(
Repository.repo_name,
Repository.repo_id,
Repository.repo_type,
Repository.private,
)\
repositories: added option to archive repositories instead of deleting them....
r3090 .filter(Repository.archived.isnot(true()))\
goto-switcher: optimized performance and query capabilities....
r2038 .filter(or_(
# generate multiple IN to fix limitation problems
*in_filter_generator(Repository.repo_id, allowed_ids)
))
core: moved repo_list data to pyramid.
r1667
go-to search: updated logic of goto switcher...
r3556 query = query.order_by(case(
[
(Repository.repo_name.startswith(repo_group_name), repo_group_name+'/'),
],
))
query = query.order_by(func.length(Repository.repo_name))
query = query.order_by(Repository.repo_name)
core: moved repo_list data to pyramid.
r1667 if repo_type:
query = query.filter(Repository.repo_type == repo_type)
if name_contains:
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
query = query.filter(
Repository.repo_name.ilike(ilike_expression))
query = query.limit(limit)
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 acl_iter = query
goto-switcher: optimized performance and query capabilities....
r2038
core: moved repo_list data to pyramid.
r1667 return [
{
goto-switcher: optimized performance and query capabilities....
r2038 'id': obj.repo_name,
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'value': org_query,
'value_display': obj.repo_name,
goto-switcher: optimized performance and query capabilities....
r2038 'text': obj.repo_name,
core: moved repo_list data to pyramid.
r1667 'type': 'repo',
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'repo_id': obj.repo_id,
'repo_type': obj.repo_type,
'private': obj.private,
goto-switcher: optimized performance and query capabilities....
r2038 'url': h.route_path('repo_summary', repo_name=obj.repo_name)
core: moved repo_list data to pyramid.
r1667 }
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 for obj in acl_iter]
core: moved repo_list data to pyramid.
r1667
go-to search: updated logic of goto switcher...
r3556 def _get_repo_group_list(self, name_contains=None, repo_group_name='', limit=20):
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 org_query = name_contains
goto-switcher: optimized performance and query capabilities....
r2038 allowed_ids = self._rhodecode_user.repo_group_acl_ids(
['group.read', 'group.write', 'group.admin'],
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 cache=True, name_filter=name_contains) or [-1]
goto-switcher: optimized performance and query capabilities....
r2038
goto-switcher: reduce query data to only required attributes for speedups.
r4152 query = Session().query(
RepoGroup.group_id,
RepoGroup.group_name,
)\
goto-switcher: optimized performance and query capabilities....
r2038 .filter(or_(
# generate multiple IN to fix limitation problems
*in_filter_generator(RepoGroup.group_id, allowed_ids)
))
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 query = query.order_by(case(
[
(RepoGroup.group_name.startswith(repo_group_name), repo_group_name+'/'),
],
))
query = query.order_by(func.length(RepoGroup.group_name))
query = query.order_by(RepoGroup.group_name)
core: moved goto_switcher views into pyramid.
r1668 if name_contains:
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
query = query.filter(
RepoGroup.group_name.ilike(ilike_expression))
query = query.limit(limit)
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 acl_iter = query
goto-switcher: optimized performance and query capabilities....
r2038
core: moved goto_switcher views into pyramid.
r1668 return [
{
'id': obj.group_name,
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'value': org_query,
'value_display': obj.group_name,
dan
ui: introduce user-bookmarks for creation of quick shortcuts
r3424 'text': obj.group_name,
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'type': 'repo_group',
dan
ui: introduce user-bookmarks for creation of quick shortcuts
r3424 'repo_group_id': obj.group_id,
goto-switcher: use special commit: prefix to explicitly search for commits....
r2035 'url': h.route_path(
'repo_group_home', repo_group_name=obj.group_name)
core: moved goto_switcher views into pyramid.
r1668 }
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 for obj in acl_iter]
def _get_user_list(self, name_contains=None, limit=20):
org_query = name_contains
if not name_contains:
go-to search: updated logic of goto switcher...
r3556 return [], False
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774
go-to search: updated logic of goto switcher...
r3556 # TODO(marcink): should all logged in users be allowed to search others?
allowed_user_search = self._rhodecode_user.username != User.DEFAULT_USER
if not allowed_user_search:
return [], False
name_contains = re.compile('(?:user:[ ]?)(.+)').findall(name_contains)
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 if len(name_contains) != 1:
go-to search: updated logic of goto switcher...
r3556 return [], False
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 name_contains = name_contains[0]
query = User.query()\
.order_by(func.length(User.username))\
.order_by(User.username) \
.filter(User.username != User.DEFAULT_USER)
core: moved goto_switcher views into pyramid.
r1668
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 if name_contains:
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
query = query.filter(
User.username.ilike(ilike_expression))
query = query.limit(limit)
acl_iter = query
return [
{
'id': obj.user_id,
'value': org_query,
go-to search: updated logic of goto switcher...
r3556 'value_display': 'user: `{}`'.format(obj.username),
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'type': 'user',
'icon_link': h.gravatar_url(obj.email, 30),
'url': h.route_path(
'user_profile', username=obj.username)
}
go-to search: updated logic of goto switcher...
r3556 for obj in acl_iter], True
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774
quick-serach: added option to also search user-groups.
r2795 def _get_user_groups_list(self, name_contains=None, limit=20):
org_query = name_contains
if not name_contains:
go-to search: updated logic of goto switcher...
r3556 return [], False
quick-serach: added option to also search user-groups.
r2795
go-to search: updated logic of goto switcher...
r3556 # TODO(marcink): should all logged in users be allowed to search others?
allowed_user_search = self._rhodecode_user.username != User.DEFAULT_USER
if not allowed_user_search:
return [], False
name_contains = re.compile('(?:user_group:[ ]?)(.+)').findall(name_contains)
quick-serach: added option to also search user-groups.
r2795 if len(name_contains) != 1:
go-to search: updated logic of goto switcher...
r3556 return [], False
quick-serach: added option to also search user-groups.
r2795 name_contains = name_contains[0]
query = UserGroup.query()\
.order_by(func.length(UserGroup.users_group_name))\
.order_by(UserGroup.users_group_name)
if name_contains:
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
query = query.filter(
UserGroup.users_group_name.ilike(ilike_expression))
query = query.limit(limit)
acl_iter = query
return [
{
'id': obj.users_group_id,
'value': org_query,
go-to search: updated logic of goto switcher...
r3556 'value_display': 'user_group: `{}`'.format(obj.users_group_name),
quick-serach: added option to also search user-groups.
r2795 'type': 'user_group',
'url': h.route_path(
'user_group_profile', user_group_name=obj.users_group_name)
}
go-to search: updated logic of goto switcher...
r3556 for obj in acl_iter], True
quick-serach: added option to also search user-groups.
r2795
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 def _get_pull_request_list(self, name_contains=None, limit=20):
org_query = name_contains
if not name_contains:
return [], False
# TODO(marcink): should all logged in users be allowed to search others?
allowed_user_search = self._rhodecode_user.username != User.DEFAULT_USER
if not allowed_user_search:
return [], False
name_contains = re.compile('(?:pr:[ ]?)(.+)').findall(name_contains)
if len(name_contains) != 1:
return [], False
name_contains = name_contains[0]
allowed_ids = self._rhodecode_user.repo_acl_ids(
['repository.read', 'repository.write', 'repository.admin'],
cache=True) or [-1]
query = Session().query(
PullRequest.pull_request_id,
PullRequest.title,
)
query = query.join(Repository, Repository.repo_id == PullRequest.target_repo_id)
query = query.filter(or_(
# generate multiple IN to fix limitation problems
*in_filter_generator(Repository.repo_id, allowed_ids)
))
query = query.order_by(PullRequest.pull_request_id)
if name_contains:
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
query = query.filter(or_(
cast(PullRequest.pull_request_id, String).ilike(ilike_expression),
PullRequest.title.ilike(ilike_expression),
PullRequest.description.ilike(ilike_expression),
))
query = query.limit(limit)
acl_iter = query
return [
{
'id': obj.pull_request_id,
'value': org_query,
quick-search-bar: fixes #5634
r4499 'value_display': 'pull request: `!{} - {}`'.format(
obj.pull_request_id, safe_str(obj.title[:50])),
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 'type': 'pull_request',
'url': h.route_path('pull_requests_global', pull_request_id=obj.pull_request_id)
}
for obj in acl_iter], True
go-to search: updated logic of goto switcher...
r3556 def _get_hash_commit_list(self, auth_user, searcher, query, repo=None, repo_group=None):
repo_name = repo_group_name = None
if repo:
repo_name = repo.repo_name
if repo_group:
repo_group_name = repo_group.group_name
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 org_query = query
dan
search: add support for elastic search 6...
r3319 if not query or len(query) < 3 or not searcher:
go-to search: updated logic of goto switcher...
r3556 return [], False
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 commit_hashes = re.compile('(?:commit:[ ]?)([0-9a-f]{2,40})').findall(query)
core: moved goto_switcher views into pyramid.
r1668
if len(commit_hashes) != 1:
go-to search: updated logic of goto switcher...
r3556 return [], False
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 commit_hash = commit_hashes[0]
core: moved goto_switcher views into pyramid.
r1668
result = searcher.search(
dan
search: add support for elastic search 6...
r3319 'commit_id:{}*'.format(commit_hash), 'commit', auth_user,
go-to search: updated logic of goto switcher...
r3556 repo_name, repo_group_name, raise_on_exc=False)
core: moved goto_switcher views into pyramid.
r1668
dan
quick-search: improve styling of search input and results.
r3443 commits = []
for entry in result['results']:
repo_data = {
'repository_id': entry.get('repository_id'),
'repository_type': entry.get('repo_type'),
'repository_name': entry.get('repository'),
}
commit_entry = {
core: moved goto_switcher views into pyramid.
r1668 'id': entry['commit_id'],
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'value': org_query,
dan
quick-search: improve styling of search input and results.
r3443 'value_display': '`{}` commit: {}'.format(
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 entry['repository'], entry['commit_id']),
core: moved goto_switcher views into pyramid.
r1668 'type': 'commit',
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 'repo': entry['repository'],
dan
quick-search: improve styling of search input and results.
r3443 'repo_data': repo_data,
goto-switcher: use special commit: prefix to explicitly search for commits....
r2035 'url': h.route_path(
'repo_commit',
repo_name=entry['repository'], commit_id=entry['commit_id'])
core: moved goto_switcher views into pyramid.
r1668 }
dan
quick-search: improve styling of search input and results.
r3443
commits.append(commit_entry)
go-to search: updated logic of goto switcher...
r3556 return commits, True
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 def _get_path_list(self, auth_user, searcher, query, repo=None, repo_group=None):
repo_name = repo_group_name = None
if repo:
repo_name = repo.repo_name
if repo_group:
repo_group_name = repo_group.group_name
dan
search: allow quick search for path globally
r3542 org_query = query
if not query or len(query) < 3 or not searcher:
go-to search: updated logic of goto switcher...
r3556 return [], False
dan
search: allow quick search for path globally
r3542
go-to search: updated logic of goto switcher...
r3556 paths_re = re.compile('(?:file:[ ]?)(.+)').findall(query)
dan
search: allow quick search for path globally
r3542 if len(paths_re) != 1:
go-to search: updated logic of goto switcher...
r3556 return [], False
dan
search: allow quick search for path globally
r3542 file_path = paths_re[0]
search_path = searcher.escape_specials(file_path)
result = searcher.search(
'file.raw:*{}*'.format(search_path), 'path', auth_user,
go-to search: updated logic of goto switcher...
r3556 repo_name, repo_group_name, raise_on_exc=False)
dan
search: allow quick search for path globally
r3542
files = []
for entry in result['results']:
repo_data = {
'repository_id': entry.get('repository_id'),
'repository_type': entry.get('repo_type'),
'repository_name': entry.get('repository'),
}
file_entry = {
'id': entry['commit_id'],
'value': org_query,
'value_display': '`{}` file: {}'.format(
entry['repository'], entry['file']),
'type': 'file',
'repo': entry['repository'],
'repo_data': repo_data,
'url': h.route_path(
'repo_files',
repo_name=entry['repository'], commit_id=entry['commit_id'],
f_path=entry['file'])
}
files.append(file_entry)
go-to search: updated logic of goto switcher...
r3556 return files, True
dan
search: allow quick search for path globally
r3542
core: moved repo_list data to pyramid.
r1667 @LoginRequired()
def repo_list_data(self):
_ = self.request.translate
views: load template context for XHR views....
r2308 self.load_default_context()
core: moved repo_list data to pyramid.
r1667
query = self.request.GET.get('query')
repo_type = self.request.GET.get('repo_type')
log.debug('generating repo list, query:%s, repo_type:%s',
query, repo_type)
res = []
repos = self._get_repo_list(query, repo_type=repo_type)
if repos:
res.append({
'text': _('Repositories'),
'children': repos
})
data = {
'more': False,
'results': res
}
return data
core: moved goto_switcher views into pyramid.
r1668
dan
ui: introduce user-bookmarks for creation of quick shortcuts
r3424 @LoginRequired()
def repo_group_list_data(self):
_ = self.request.translate
self.load_default_context()
query = self.request.GET.get('query')
log.debug('generating repo group list, query:%s',
query)
res = []
repo_groups = self._get_repo_group_list(query)
if repo_groups:
res.append({
'text': _('Repository Groups'),
'children': repo_groups
})
data = {
'more': False,
'results': res
}
return data
dan
search: add support for elastic search 6...
r3319 def _get_default_search_queries(self, search_context, searcher, query):
if not searcher:
return []
dan
search: new UI for search, and repo group context search...
r3442
dan
search: add support for elastic search 6...
r3319 is_es_6 = searcher.is_es_6
queries = []
repo_group_name, repo_name, repo_context = None, None, None
# repo group context
if search_context.get('search_context[repo_group_name]'):
repo_group_name = search_context.get('search_context[repo_group_name]')
if search_context.get('search_context[repo_name]'):
repo_name = search_context.get('search_context[repo_name]')
repo_context = search_context.get('search_context[repo_view_type]')
if is_es_6 and repo_name:
dan
search: add option to search within a repository group.
r3441 # files
dan
search: add support for elastic search 6...
r3319 def query_modifier():
dan
search: add option to search within a repository group.
r3441 qry = query
dan
search: add support for elastic search 6...
r3319 return {'q': qry, 'type': 'content'}
quick-filter: added nicer UI and hints.
r3750
dan
ux: change file search to file content search which makes a better description of what we search for.
r4207 label = u'File content search for `{}`'.format(h.escape(query))
go-to search: updated logic of goto switcher...
r3556 file_qry = {
'id': -10,
'value': query,
'value_display': label,
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-code"></i>',
go-to search: updated logic of goto switcher...
r3556 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'repo',
go-to search: updated logic of goto switcher...
r3556 'url': h.route_path('search_repo',
repo_name=repo_name,
_query=query_modifier())
dan
search: add option to search within a repository group.
r3441 }
# commits
def query_modifier():
qry = query
return {'q': qry, 'type': 'commit'}
quick-filter: added nicer UI and hints.
r3750 label = u'Commit search for `{}`'.format(h.escape(query))
go-to search: updated logic of goto switcher...
r3556 commit_qry = {
'id': -20,
'value': query,
'value_display': label,
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-history"></i>',
go-to search: updated logic of goto switcher...
r3556 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'repo',
go-to search: updated logic of goto switcher...
r3556 'url': h.route_path('search_repo',
repo_name=repo_name,
_query=query_modifier())
dan
search: add support for elastic search 6...
r3319 }
go-to search: updated logic of goto switcher...
r3556
changelog: rename changelog to commits pages
r3742 if repo_context in ['commit', 'commits']:
go-to search: updated logic of goto switcher...
r3556 queries.extend([commit_qry, file_qry])
elif repo_context in ['files', 'summary']:
queries.extend([file_qry, commit_qry])
else:
queries.extend([commit_qry, file_qry])
dan
search: add support for elastic search 6...
r3319
elif is_es_6 and repo_group_name:
dan
search: add option to search within a repository group.
r3441 # files
dan
search: add support for elastic search 6...
r3319 def query_modifier():
dan
search: add option to search within a repository group.
r3441 qry = query
dan
search: add support for elastic search 6...
r3319 return {'q': qry, 'type': 'content'}
dan
search: add option to search within a repository group.
r3441
dan
ux: change file search to file content search which makes a better description of what we search for.
r4207 label = u'File content search for `{}`'.format(query)
go-to search: updated logic of goto switcher...
r3556 file_qry = {
'id': -30,
'value': query,
'value_display': label,
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-code"></i>',
go-to search: updated logic of goto switcher...
r3556 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'repo_group',
go-to search: updated logic of goto switcher...
r3556 'url': h.route_path('search_repo_group',
repo_group_name=repo_group_name,
_query=query_modifier())
dan
search: add option to search within a repository group.
r3441 }
# commits
def query_modifier():
qry = query
return {'q': qry, 'type': 'commit'}
quick-filter: added nicer UI and hints.
r3750 label = u'Commit search for `{}`'.format(query)
go-to search: updated logic of goto switcher...
r3556 commit_qry = {
'id': -40,
'value': query,
'value_display': label,
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-history"></i>',
go-to search: updated logic of goto switcher...
r3556 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'repo_group',
go-to search: updated logic of goto switcher...
r3556 'url': h.route_path('search_repo_group',
repo_group_name=repo_group_name,
_query=query_modifier())
dan
search: add support for elastic search 6...
r3319 }
changelog: rename changelog to commits pages
r3742 if repo_context in ['commit', 'commits']:
go-to search: updated logic of goto switcher...
r3556 queries.extend([commit_qry, file_qry])
elif repo_context in ['files', 'summary']:
queries.extend([file_qry, commit_qry])
else:
queries.extend([commit_qry, file_qry])
# Global, not scoped
dan
search: add support for elastic search 6...
r3319 if not queries:
queries.append(
{
'id': -1,
'value': query,
dan
ux: change file search to file content search which makes a better description of what we search for.
r4207 'value_display': u'File content search for: `{}`'.format(query),
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-code"></i>',
dan
search: add support for elastic search 6...
r3319 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'global',
dan
search: add support for elastic search 6...
r3319 'url': h.route_path('search',
_query={'q': query, 'type': 'content'})
dan
search: new UI for search, and repo group context search...
r3442 })
queries.append(
{
dan
quick-search: improve styling of search input and results.
r3443 'id': -2,
dan
search: new UI for search, and repo group context search...
r3442 'value': query,
dan
quick-search: improve styling of search input and results.
r3443 'value_display': u'Commit search for: `{}`'.format(query),
ui: use more distinctive icons for search hints
r4096 'value_icon': '<i class="icon-history"></i>',
dan
search: new UI for search, and repo group context search...
r3442 'type': 'search',
quick-filter: added nicer UI and hints.
r3750 'subtype': 'global',
dan
search: new UI for search, and repo group context search...
r3442 'url': h.route_path('search',
_query={'q': query, 'type': 'commit'})
})
dan
search: add support for elastic search 6...
r3319
return queries
core: moved goto_switcher views into pyramid.
r1668 @LoginRequired()
def goto_switcher_data(self):
c = self.load_default_context()
_ = self.request.translate
query = self.request.GET.get('query')
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 log.debug('generating main filter data, query %s', query)
res = []
if not query:
return {'suggestions': res}
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 def no_match(name):
return {
'id': -1,
'value': "",
'value_display': name,
'type': 'text',
'url': ""
}
dan
search: add support for elastic search 6...
r3319 searcher = searcher_from_config(self.request.registry.settings)
go-to search: updated logic of goto switcher...
r3556 has_specialized_search = False
dan
search: add support for elastic search 6...
r3319
go-to search: updated logic of goto switcher...
r3556 # set repo context
repo = None
repo_id = safe_int(self.request.GET.get('search_context[repo_id]'))
if repo_id:
repo = Repository.get(repo_id)
# set group context
repo_group = None
dan
search: add support for elastic search 6...
r3319 repo_group_id = safe_int(self.request.GET.get('search_context[repo_group_id]'))
quick-search: use smart group search when browsing inside a repository group....
r2804 if repo_group_id:
repo_group = RepoGroup.get(repo_group_id)
go-to search: updated logic of goto switcher...
r3556 prefix_match = False
# user: type search
if not prefix_match:
users, prefix_match = self._get_user_list(query)
if users:
has_specialized_search = True
for serialized_user in users:
res.append(serialized_user)
elif prefix_match:
has_specialized_search = True
res.append(no_match('No matching users found'))
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774
go-to search: updated logic of goto switcher...
r3556 # user_group: type search
if not prefix_match:
user_groups, prefix_match = self._get_user_groups_list(query)
if user_groups:
has_specialized_search = True
for serialized_user_group in user_groups:
res.append(serialized_user_group)
elif prefix_match:
has_specialized_search = True
res.append(no_match('No matching user groups found'))
core: moved goto_switcher views into pyramid.
r1668
quick-search: added ability to search for pull-requests using `pr:` prefix....
r4329 # pr: type search
if not prefix_match:
pull_requests, prefix_match = self._get_pull_request_list(query)
if pull_requests:
has_specialized_search = True
for serialized_pull_request in pull_requests:
res.append(serialized_pull_request)
elif prefix_match:
has_specialized_search = True
res.append(no_match('No matching pull requests found'))
go-to search: updated logic of goto switcher...
r3556 # FTS commit: type search
if not prefix_match:
commits, prefix_match = self._get_hash_commit_list(
c.auth_user, searcher, query, repo, repo_group)
if commits:
has_specialized_search = True
unique_repos = collections.OrderedDict()
for commit in commits:
repo_name = commit['repo']
unique_repos.setdefault(repo_name, []).append(commit)
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774
go-to search: updated logic of goto switcher...
r3556 for _repo, commits in unique_repos.items():
for commit in commits:
res.append(commit)
elif prefix_match:
has_specialized_search = True
res.append(no_match('No matching commits found'))
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 # FTS file: type search
if not prefix_match:
paths, prefix_match = self._get_path_list(
c.auth_user, searcher, query, repo, repo_group)
if paths:
has_specialized_search = True
unique_repos = collections.OrderedDict()
for path in paths:
repo_name = path['repo']
unique_repos.setdefault(repo_name, []).append(path)
quick-serach: added option to also search user-groups.
r2795
go-to search: updated logic of goto switcher...
r3556 for repo, paths in unique_repos.items():
for path in paths:
res.append(path)
elif prefix_match:
has_specialized_search = True
res.append(no_match('No matching files found'))
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 # main suggestions
if not has_specialized_search:
repo_group_name = ''
if repo_group:
repo_group_name = repo_group.group_name
core: moved goto_switcher views into pyramid.
r1668
go-to search: updated logic of goto switcher...
r3556 for _q in self._get_default_search_queries(self.request.GET, searcher, query):
res.append(_q)
repo_groups = self._get_repo_group_list(query, repo_group_name=repo_group_name)
for serialized_repo_group in repo_groups:
res.append(serialized_repo_group)
dan
search: allow quick search for path globally
r3542
go-to search: updated logic of goto switcher...
r3556 repos = self._get_repo_list(query, repo_group_name=repo_group_name)
for serialized_repo in repos:
res.append(serialized_repo)
if not repos and not repo_groups:
res.append(no_match('No matches found'))
dan
search: allow quick search for path globally
r3542
repo-switcher: new unified search box for filtering/accessing users, repos and repo groups....
r2774 return {'suggestions': res}
home: moved home and repo group views into pyramid....
r1774
@LoginRequired()
def main_page(self):
c = self.load_default_context()
c.repo_group = None
dashboard: main page grids async load....
r4148 return self._get_template_context(c)
home: moved home and repo group views into pyramid....
r1774
dashboard: main page grids async load....
r4148 def _main_page_repo_groups_data(self, repo_group_id):
column_map = {
grids: columns and sorting fixes
r4150 'name': 'group_name_hash',
dashboard: main page grids async load....
r4148 'desc': 'group_description',
grids: columns and sorting fixes
r4150 'last_change': 'updated_on',
dashboard: main page grids async load....
r4148 'owner': 'user_username',
}
draw, start, limit = self._extract_chunk(self.request)
search_q, order_by, order_dir = self._extract_ordering(
self.request, column_map=column_map)
return RepoGroupModel().get_repo_groups_data_table(
draw, start, limit,
search_q, order_by, order_dir,
self._rhodecode_user, repo_group_id)
def _main_page_repos_data(self, repo_group_id):
column_map = {
grids: columns and sorting fixes
r4150 'name': 'repo_name',
dashboard: main page grids async load....
r4148 'desc': 'description',
grids: columns and sorting fixes
r4150 'last_change': 'updated_on',
dashboard: main page grids async load....
r4148 'owner': 'user_username',
}
draw, start, limit = self._extract_chunk(self.request)
search_q, order_by, order_dir = self._extract_ordering(
self.request, column_map=column_map)
return RepoModel().get_repos_data_table(
draw, start, limit,
search_q, order_by, order_dir,
self._rhodecode_user, repo_group_id)
home: moved home and repo group views into pyramid....
r1774
dashboard: main page grids async load....
r4148 @LoginRequired()
def main_page_repo_groups_data(self):
self.load_default_context()
repo_group_id = safe_int(self.request.GET.get('repo_group_id'))
if repo_group_id:
group = RepoGroup.get_or_404(repo_group_id)
grids: fixed tests and added one for permissions to repository group.
r4151 _perms = AuthUser.repo_group_read_perms
dashboard: main page grids async load....
r4148 if not HasRepoGroupPermissionAny(*_perms)(
group.group_name, 'user is allowed to list repo group children'):
raise HTTPNotFound()
return self._main_page_repo_groups_data(repo_group_id)
@LoginRequired()
def main_page_repos_data(self):
self.load_default_context()
repo_group_id = safe_int(self.request.GET.get('repo_group_id'))
if repo_group_id:
group = RepoGroup.get_or_404(repo_group_id)
grids: fixed tests and added one for permissions to repository group.
r4151 _perms = AuthUser.repo_group_read_perms
dashboard: main page grids async load....
r4148 if not HasRepoGroupPermissionAny(*_perms)(
group.group_name, 'user is allowed to list repo group children'):
raise HTTPNotFound()
return self._main_page_repos_data(repo_group_id)
home: moved home and repo group views into pyramid....
r1774
@LoginRequired()
grids: fixed tests and added one for permissions to repository group.
r4151 @HasRepoGroupPermissionAnyDecorator(*AuthUser.repo_group_read_perms)
home: moved home and repo group views into pyramid....
r1774 def repo_group_main_page(self):
c = self.load_default_context()
c.repo_group = self.request.db_repo_group
return self._get_template_context(c)
pull-requests: allow markup rendered description.
r2816
@LoginRequired()
@CSRFRequired()
def markup_preview(self):
# Technically a CSRF token is not needed as no state changes with this
# call. However, as this is a POST is better to have it, so automated
# tools don't flag it as potential CSRF.
# Post is required because the payload could be bigger than the maximum
# allowed by GET.
text = self.request.POST.get('text')
renderer = self.request.POST.get('renderer') or 'rst'
if text:
return h.render(text, renderer=renderer, mentions=True)
return ''
users: use new session store for temporary settings for users....
r3088
@LoginRequired()
@CSRFRequired()
dan
file: new file editors...
r3754 def file_preview(self):
# Technically a CSRF token is not needed as no state changes with this
# call. However, as this is a POST is better to have it, so automated
# tools don't flag it as potential CSRF.
# Post is required because the payload could be bigger than the maximum
# allowed by GET.
text = self.request.POST.get('text')
file_path = self.request.POST.get('file_path')
renderer = h.renderer_from_filename(file_path)
if renderer:
return h.render(text, renderer=renderer, mentions=True)
else:
self.load_default_context()
_render = self.request.get_partial_renderer(
'rhodecode:templates/files/file_content.mako')
lines = filenode_as_lines_tokens(FileNode(file_path, text))
return _render('render_lines', lines)
@LoginRequired()
@CSRFRequired()
users: use new session store for temporary settings for users....
r3088 def store_user_session_attr(self):
key = self.request.POST.get('key')
val = self.request.POST.get('val')
existing_value = self.request.session.get(key)
if existing_value != val:
self.request.session[key] = val
diffs: store wide-diff mode in user sessions for saved state.
r3642 return 'stored:{}:{}'.format(key, val)