##// END OF EJS Templates
docs: added newline
docs: added newline

File last commit:

r5651:bad147da default
r5656:629f48be default
Show More
repo_files.py
1601 lines | 62.7 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2011-2024 RhodeCode GmbH
files: ported repository files controllers to pyramid views.
r1927 #
# 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/
import itertools
import logging
import os
import collections
apps: various fixes and improvements for python3
r5072 import urllib.request
import urllib.parse
import urllib.error
files: drop usage of pathlib2, it's now in core python
r5025 import pathlib
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 import time
import random
files: ported repository files controllers to pyramid views.
r1927
from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest, HTTPFound
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
files: ported repository files controllers to pyramid views.
r1927 from pyramid.renderers import render
from pyramid.response import Response
cache: turn off caches if expiration_time is 0
r2848 import rhodecode
files: ported repository files controllers to pyramid views.
r1927 from rhodecode.apps._base import RepoAppView
app: dropped deprecated controllers to view_utils which are actually proper name
r3346
caches: new cache context managers....
r2932 from rhodecode.lib import diffs, helpers as h, rc_cache
files: ported repository files controllers to pyramid views.
r1927 from rhodecode.lib import audit_logger
apps: various fixes and improvements for python3
r5072 from rhodecode.lib.hash_utils import sha1_safe
feat(archive-cache): implemented s3 based backend for filecaches
r5433 from rhodecode.lib.archive_cache import (
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 get_archival_cache_store,
get_archival_config,
ArchiveCacheGenerationLock,
archive_iterator,
)
archives: fixed bugs with serving archives from non-ascii repos, and also deliver archives at much bigger reading blocks for faster downloads
r5135 from rhodecode.lib.str_utils import safe_bytes, convert_special_chars
app: dropped deprecated controllers to view_utils which are actually proper name
r3346 from rhodecode.lib.view_utils import parse_path_ref
files: ported repository files controllers to pyramid views.
r1927 from rhodecode.lib.exceptions import NonRelativePathError
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 from rhodecode.lib.codeblocks import filenode_as_lines_tokens, filenode_as_annotated_lines_tokens
apps: various fixes and improvements for python3
r5072 from rhodecode.lib.utils2 import convert_line_endings, detect_mode
from rhodecode.lib.type_utils import str2bool
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 from rhodecode.lib.str_utils import safe_str, safe_int, header_safe_str
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired
files: ported repository files controllers to pyramid views.
r1927 from rhodecode.lib.vcs import path as vcspath
from rhodecode.lib.vcs.backends.base import EmptyCommit
from rhodecode.lib.vcs.conf import settings
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.lib.vcs.exceptions import (
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 RepositoryError,
CommitDoesNotExistError,
EmptyRepositoryError,
ImproperArchiveTypeError,
VCSError,
NodeAlreadyExistsError,
NodeDoesNotExistError,
CommitError,
NodeError,
)
files: ported repository files controllers to pyramid views.
r1927
from rhodecode.model.scm import ScmModel
from rhodecode.model.db import Repository
log = logging.getLogger(__name__)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 def get_archive_name(db_repo_id, db_repo_name, commit_sha, ext, subrepos=False, path_sha="", with_hash=True):
apps: various fixes and improvements for python3
r5072 # original backward compat name of archive
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 clean_name = safe_str(convert_special_chars(db_repo_name).replace("/", "_"))
apps: various fixes and improvements for python3
r5072
archives: fixed bugs with serving archives from non-ascii repos, and also deliver archives at much bigger reading blocks for faster downloads
r5135 # e.g vcsserver-id-abcd-sub-1-abcfdef-archive-all.zip
# vcsserver-id-abcd-sub-0-abcfdef-COMMIT_SHA-PATH_SHA.zip
id_sha = sha1_safe(str(db_repo_id))[:4]
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 sub_repo = "sub-1" if subrepos else "sub-0"
commit = commit_sha if with_hash else "archive"
path_marker = (path_sha if with_hash else "") or "all"
archive_name = f"{clean_name}-id-{id_sha}-{sub_repo}-{commit}-{path_marker}{ext}"
apps: various fixes and improvements for python3
r5072
return archive_name
def get_path_sha(at_path):
return safe_str(sha1_safe(at_path)[:8])
def _get_archive_spec(fname):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("Detecting archive spec for: `%s`", fname)
apps: various fixes and improvements for python3
r5072
fileformat = None
ext = None
content_type = None
for a_type, content_type, extension in settings.ARCHIVE_SPECS:
if fname.endswith(extension):
fileformat = a_type
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("archive is of type: %s", fileformat)
apps: various fixes and improvements for python3
r5072 ext = extension
break
if not fileformat:
raise ValueError()
# left over part of whole fname is the commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit_id = fname[: -len(ext)]
apps: various fixes and improvements for python3
r5072
return commit_id, ext, fileformat, content_type
files: ported repository files controllers to pyramid views.
r1927 class RepoFilesView(RepoAppView):
@staticmethod
def adjust_file_path_for_svn(f_path, repo):
"""
Computes the relative path of `f_path`.
This is mainly based on prefix matching of the recognized tags and
branches in the underlying repository.
"""
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 tags_and_branches = itertools.chain(repo.branches.keys(), repo.tags.keys())
files: ported repository files controllers to pyramid views.
r1927 tags_and_branches = sorted(tags_and_branches, key=len, reverse=True)
for name in tags_and_branches:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if f_path.startswith(f"{name}/"):
files: ported repository files controllers to pyramid views.
r1927 f_path = vcspath.relpath(f_path, name)
break
return f_path
def load_default_context(self):
c = self._get_local_tmpl_context(include_app_defaults=True)
c.rhodecode_repo = self.rhodecode_vcs_repo
dan
Files: expose downloads onto files view
r3374 c.enable_downloads = self.db_repo.enable_downloads
files: ported repository files controllers to pyramid views.
r1927 return c
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 def _ensure_not_locked(self, commit_id="tip"):
files: ported repository files controllers to pyramid views.
r1927 _ = self.request.translate
repo = self.db_repo
if repo.enable_locking and repo.locked[0]:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(
_("This repository has been locked by %s on %s")
% (h.person_by_id(repo.locked[0]), h.format_date(h.time_to_datetime(repo.locked[1]))),
"warning",
)
files_url = h.route_path("repo_files:default_path", repo_name=self.db_repo_name, commit_id=commit_id)
files: ported repository files controllers to pyramid views.
r1927 raise HTTPFound(files_url)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 def forbid_non_head(self, is_head, f_path, commit_id="tip", json_mode=False):
dan
file: new file editors...
r3754 _ = self.request.translate
if not is_head:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 message = _("Cannot modify file. " "Given commit `{}` is not head of a branch.").format(commit_id)
h.flash(message, category="warning")
dan
file: new file editors...
r3754
if json_mode:
return message
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 files_url = h.route_path("repo_files", repo_name=self.db_repo_name, commit_id=commit_id, f_path=f_path)
dan
file: new file editors...
r3754 raise HTTPFound(files_url)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 def check_branch_permission(self, branch_name, commit_id="tip", json_mode=False):
files: added branch permissions checks into web edit operations.
r2978 _ = self.request.translate
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 rule, branch_perm = self._rhodecode_user.get_rule_and_branch_permission(self.db_repo_name, branch_name)
if branch_perm and branch_perm not in ["branch.push", "branch.push_force"]:
message = _("Branch `{}` changes forbidden by rule {}.").format(h.escape(branch_name), h.escape(rule))
h.flash(message, "warning")
dan
file: new file editors...
r3754
if json_mode:
return message
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 files_url = h.route_path("repo_files:default_path", repo_name=self.db_repo_name, commit_id=commit_id)
dan
file: new file editors...
r3754
files: added branch permissions checks into web edit operations.
r2978 raise HTTPFound(files_url)
files: ported repository files controllers to pyramid views.
r1927 def _get_commit_and_path(self):
landing-refs: create helpers for landing ref to make clear indication about type/name
r4370 default_commit_id = self.db_repo.landing_ref_name
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_f_path = "/"
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit_id = self.request.matchdict.get("commit_id", default_commit_id)
routing: use a common method to extract the f_path for repo views....
r1929 f_path = self._get_f_path(self.request.matchdict, default_f_path)
files: ported repository files controllers to pyramid views.
r1927
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 bytes_path = safe_bytes(f_path)
return commit_id, f_path, bytes_path
@classmethod
def _get_default_encoding(cls, c):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 enc_list = getattr(c, "default_encodings", [])
return enc_list[0] if enc_list else "UTF-8"
files: ported repository files controllers to pyramid views.
r1927
def _get_commit_or_redirect(self, commit_id, redirect_after=True):
"""
This is a safe way to get commit. If an error occurs it redirects to
tip with proper message
:param commit_id: id of commit to fetch
:param redirect_after: toggle redirection
"""
_ = self.request.translate
try:
return self.rhodecode_vcs_repo.get_commit(commit_id)
except EmptyRepositoryError:
if not redirect_after:
return None
apps: various fixes and improvements for python3
r5072 add_new = upload_new = ""
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if h.HasRepoPermissionAny("repository.write", "repository.admin")(self.db_repo_name):
_url = h.route_path("repo_files_add_file", repo_name=self.db_repo_name, commit_id=0, f_path="")
add_new = h.link_to(_("add a new file"), _url, class_="alert-link")
apps: various fixes and improvements for python3
r5072
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _url_upld = h.route_path("repo_files_upload_file", repo_name=self.db_repo_name, commit_id=0, f_path="")
upload_new = h.link_to(_("upload a new file"), _url_upld, class_="alert-link")
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(
h.literal(_("There are no files yet. Click here to %s or %s.") % (add_new, upload_new)),
category="warning",
)
raise HTTPFound(h.route_path("repo_summary", repo_name=self.db_repo_name))
files: ported repository files controllers to pyramid views.
r1927
files: report the name of missing commit.
r4371 except (CommitDoesNotExistError, LookupError) as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 msg = _("No such commit exists for this repository. Commit: {}").format(commit_id)
h.flash(msg, category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
except RepositoryError as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(h.escape(safe_str(e)), category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
apps: various fixes and improvements for python3
r5072 def _get_filenode_or_redirect(self, commit_obj, path, pre_load=None):
files: ported repository files controllers to pyramid views.
r1927 """
Returns file_node, if error occurs or given path is directory,
it'll redirect to top level path
"""
_ = self.request.translate
try:
apps: various fixes and improvements for python3
r5072 file_node = commit_obj.get_node(path, pre_load=pre_load)
files: ported repository files controllers to pyramid views.
r1927 if file_node.is_dir():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 raise RepositoryError("The given path is a directory")
files: ported repository files controllers to pyramid views.
r1927 except CommitDoesNotExistError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("No such commit exists for this repository")
h.flash(_("No such commit exists for this repository"), category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
except RepositoryError as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.warning("Repository error while fetching filenode `%s`. Err:%s", path, e)
h.flash(h.escape(safe_str(e)), category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
return file_node
dan
files: fixed creation of new files for empty repos....
r4463 def _is_valid_head(self, commit_id, repo, landing_ref):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 branch_name = sha_commit_id = ""
files: added branch permissions checks into web edit operations.
r2978 is_head = False
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("Checking if commit_id `%s` is a head for %s.", commit_id, repo)
files: ported repository files controllers to pyramid views.
r1927
files: added branch permissions checks into web edit operations.
r2978 for _branch_name, branch_commit_id in repo.branches.items():
# simple case we pass in branch name, it's a HEAD
if commit_id == _branch_name:
is_head = True
branch_name = _branch_name
sha_commit_id = branch_commit_id
break
# case when we pass in full sha commit_id, which is a head
elif commit_id == branch_commit_id:
is_head = True
branch_name = _branch_name
sha_commit_id = branch_commit_id
break
tests: fixed some tests for files pages.
r3776 if h.is_svn(repo) and not repo.is_empty():
# Note: Subversion only has one head.
if commit_id == repo.get_commit(commit_idx=-1).raw_id:
is_head = True
return branch_name, sha_commit_id, is_head
files: added branch permissions checks into web edit operations.
r2978 # checked branches, means we only need to try to get the branch/commit_sha
dan
files: fixed creation of new files for empty repos....
r4463 if repo.is_empty():
is_head = True
branch_name = landing_ref
sha_commit_id = EmptyCommit().raw_id
else:
files: added branch permissions checks into web edit operations.
r2978 commit = repo.get_commit(commit_id=commit_id)
if commit:
branch_name = commit.branch
sha_commit_id = commit.raw_id
return branch_name, sha_commit_id, is_head
files: ported repository files controllers to pyramid views.
r1927
dan
files: fixed the repo switcher at flag beeing nor persistens...
r4294 def _get_tree_at_commit(self, c, commit_id, f_path, full_load=False, at_rev=None):
caches: don't use beaker for file caches anymore
r2846 repo_id = self.db_repo.repo_id
caches: allow cache disable for file tree
r3469 force_recache = self.get_recache_flag()
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 cache_seconds = rhodecode.ConfigGet().get_int("rc_cache.cache_repo.expiration_time")
caches: allow cache disable for file tree
r3469 cache_on = not force_recache and cache_seconds > 0
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651
cache: turn off caches if expiration_time is 0
r2848 log.debug(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "Computing FILE TREE for repo_id %s commit_id `%s` and path `%s`"
"with caching: %s[TTL: %ss]" % (repo_id, commit_id, f_path, cache_on, cache_seconds or 0)
)
cache: turn off caches if expiration_time is 0
r2848
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 cache_namespace_uid = f"repo.{rc_cache.FILE_TREE_CACHE_VER}.{repo_id}"
region = rc_cache.get_or_create_region("cache_repo", cache_namespace_uid)
caches: don't use beaker for file caches anymore
r2846
files: ensure caches are invalidated for file viewer when name, or parent group changes
r4349 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache_on)
caches: make sure the global cache namespace prefixes are used....
r5106 def compute_file_tree(_name_hash, _repo_id, _commit_id, _f_path, _full_load, _at_rev):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("Generating cached file tree at for repo_id: %s, %s, %s", _repo_id, _commit_id, _f_path)
files: ported repository files controllers to pyramid views.
r1927
files: ensure caches are invalidated for file viewer when name, or parent group changes
r4349 c.full_load = _full_load
files: ported repository files controllers to pyramid views.
r1927 return render(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "rhodecode:templates/files/files_browser_tree.mako",
self._get_template_context(c),
self.request,
_at_rev,
)
files: ported repository files controllers to pyramid views.
r1927
cache: bump file-tree caches to next iteration
r4036 return compute_file_tree(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 self.db_repo.repo_name_hash, self.db_repo.repo_id, commit_id, f_path, full_load, at_rev
)
files: ported repository files controllers to pyramid views.
r1927
dan
file: new file editors...
r3754 def create_pure_path(self, *parts):
# Split paths and sanitize them, removing any ../ etc
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 sanitized_path = [x for x in pathlib.PurePath(*parts).parts if x not in [".", ".."]]
dan
file: new file editors...
r3754
files: drop usage of pathlib2, it's now in core python
r5025 pure_path = pathlib.PurePath(*sanitized_path)
dan
file: new file editors...
r3754 return pure_path
files: only check for git_lfs/hg_largefiles if they are enabled....
r3894 def _is_lf_enabled(self, target_repo):
lf_enabled = False
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 lf_key_for_vcs_map = {"hg": "extensions_largefiles", "git": "vcs_git_lfs_enabled"}
files: only check for git_lfs/hg_largefiles if they are enabled....
r3894
lf_key_for_vcs = lf_key_for_vcs_map.get(target_repo.repo_type)
if lf_key_for_vcs:
lf_enabled = self._get_repo_setting(target_repo, lf_key_for_vcs)
return lf_enabled
files: ported repository files controllers to pyramid views.
r1927 @LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_archivefile(self):
# archive cache config
from rhodecode import CONFIG
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651
files: ported repository files controllers to pyramid views.
r1927 _ = self.request.translate
self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 subrepos = self.request.GET.get("subrepos") == "true"
with_hash = str2bool(self.request.GET.get("with_hash", "1"))
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_at_path = "/"
fname = self.request.matchdict["fname"]
at_path = self.request.GET.get("at_path") or default_at_path
files: ported repository files controllers to pyramid views.
r1927
if not self.db_repo.enable_downloads:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(_("Downloads disabled"))
files: ported repository files controllers to pyramid views.
r1927
try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, ext, file_format, content_type = _get_archive_spec(fname)
files: ported repository files controllers to pyramid views.
r1927 except ValueError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(_("Unknown archive type for: `{}`").format(h.escape(fname)))
files: ported repository files controllers to pyramid views.
r1927
try:
commit = self.rhodecode_vcs_repo.get_commit(commit_id)
except CommitDoesNotExistError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(_("Unknown commit_id {}").format(h.escape(commit_id)))
files: ported repository files controllers to pyramid views.
r1927 except EmptyRepositoryError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(_("Empty repository"))
files: ported repository files controllers to pyramid views.
r1927
archives: if implicit ref name was used to obtain archive, redirect to explicit commit sha so we can...
r4648 # we used a ref, or a shorter version, lets redirect client ot use explicit hash
if commit_id != commit.raw_id:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 fname = f"{commit.raw_id}{ext}"
archives: if implicit ref name was used to obtain archive, redirect to explicit commit sha so we can...
r4648 raise HTTPFound(self.request.current_route_path(fname=fname))
files: allow partial tree downloads
r3709 try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 at_path = commit.get_node(safe_bytes(at_path)).path or default_at_path
files: allow partial tree downloads
r3709 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(_("No node at path {} for this repository").format(h.escape(at_path)))
files: allow partial tree downloads
r3709
apps: various fixes and improvements for python3
r5072 path_sha = get_path_sha(at_path)
# used for cache etc, consistent unique archive name
archive_name_key = get_archive_name(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 self.db_repo.repo_id,
self.db_repo_name,
commit_sha=commit.short_id,
ext=ext,
subrepos=subrepos,
path_sha=path_sha,
with_hash=True,
)
files: archive, ensure we use same hash structure for old version of archives with full tree
r3726
archvies: allowing to obtain archives without the commit short id in the name for better automation of obtained artifacts.
r4534 if not with_hash:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 path_sha = ""
archvies: allowing to obtain archives without the commit short id in the name for better automation of obtained artifacts.
r4534
# what end client gets served
apps: various fixes and improvements for python3
r5072 response_archive_name = get_archive_name(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 self.db_repo.repo_id,
self.db_repo_name,
commit_sha=commit.short_id,
ext=ext,
subrepos=subrepos,
path_sha=path_sha,
with_hash=with_hash,
)
apps: various fixes and improvements for python3
r5072
archvies: allowing to obtain archives without the commit short id in the name for better automation of obtained artifacts.
r4534 # remove extension from our archive directory name
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 archive_dir_name = response_archive_name[: -len(ext)]
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 archive_cache_disable = self.request.GET.get("no_cache")
apps: various fixes and improvements for python3
r5072
d_cache = get_archival_cache_store(config=CONFIG)
core: revamp of automation/scheduler/artifacts EE functionality
r5137
apps: various fixes and improvements for python3
r5072 # NOTE: we get the config to pass to a call to lazy-init the SAME type of cache on vcsserver
d_cache_conf = get_archival_config(config=CONFIG)
files: ported repository files controllers to pyramid views.
r1927
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 # This is also a cache key, and lock key
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 reentrant_lock_key = archive_name_key + ".lock"
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420
use_cached_archive = False
if not archive_cache_disable and archive_name_key in d_cache:
reader, metadata = d_cache.fetch(archive_name_key)
files: ported repository files controllers to pyramid views.
r1927
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 use_cached_archive = True
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug(
"Found cached archive as key=%s tag=%s, serving archive from cache reader=%s",
archive_name_key,
metadata,
reader.name,
)
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 else:
reader = None
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("Archive with key=%s is not yet cached, creating one now...", archive_name_key)
apps: various fixes and improvements for python3
r5072
if not reader:
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 # generate new archive, as previous was not found in the cache
try:
with d_cache.get_lock(reentrant_lock_key):
try:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit.archive_repo(
archive_name_key,
archive_dir_name=archive_dir_name,
kind=file_format,
subrepos=subrepos,
archive_at_path=at_path,
cache_config=d_cache_conf,
)
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 except ImproperArchiveTypeError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return _("Unknown archive type")
feat(archive-cache): added retry mechanism, and some code cleanups
r5426
except ArchiveCacheGenerationLock:
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 retry_after = round(random.uniform(0.3, 3.0), 1)
time.sleep(retry_after)
files: ported repository files controllers to pyramid views.
r1927
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420 location = self.request.url
response = Response(
f"archive {archive_name_key} generation in progress, Retry-After={retry_after}, Location={location}"
)
response.headers["Retry-After"] = str(retry_after)
feat(archive-cache): added retry mechanism, and some code cleanups
r5426 response.status_code = 307 # temporary redirect
feat(disk-cache): rewrite diskcache backend to be k8s and NFS safe....
r5420
response.location = location
return response
feat(disk-cache): use fsync to force flush changes on NFS, and use retry mechanism to archive caches...
r5427 reader, metadata = d_cache.fetch(archive_name_key, retry=True, retry_attempts=30)
files: ported repository files controllers to pyramid views.
r1927
apps: various fixes and improvements for python3
r5072 response = Response(app_iter=archive_iterator(reader))
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 response.content_disposition = f"attachment; filename={response_archive_name}"
files: ported repository files controllers to pyramid views.
r1927 response.content_type = str(content_type)
apps: various fixes and improvements for python3
r5072 try:
return response
finally:
# store download action
audit_logger.store_web(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "repo.archive.download",
action_data={
"user_agent": self.request.user_agent,
"archive_name": archive_name_key,
"archive_spec": fname,
"archive_cached": use_cached_archive,
},
apps: various fixes and improvements for python3
r5072 user=self._rhodecode_user,
repo=self.db_repo,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit=True,
apps: various fixes and improvements for python3
r5072 )
files: ported repository files controllers to pyramid views.
r1927
def _get_file_node(self, commit_id, f_path):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if commit_id not in ["", None, "None", "0" * 12, "0" * 40]:
files: ported repository files controllers to pyramid views.
r1927 commit = self.rhodecode_vcs_repo.get_commit(commit_id=commit_id)
try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 node = commit.get_node(safe_bytes(f_path))
files: ported repository files controllers to pyramid views.
r1927 if node.is_dir():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 raise NodeError(f"{node} path is a {type(node)} not a file")
files: ported repository files controllers to pyramid views.
r1927 except NodeDoesNotExistError:
commit = EmptyCommit(
commit_id=commit_id,
idx=commit.idx,
repo=commit.repository,
alias=commit.repository.alias,
message=commit.message,
author=commit.author,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 date=commit.date,
)
node = FileNode(safe_bytes(f_path), b"", commit=commit)
files: ported repository files controllers to pyramid views.
r1927 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit = EmptyCommit(repo=self.rhodecode_vcs_repo, alias=self.rhodecode_vcs_repo.alias)
node = FileNode(safe_bytes(f_path), b"", commit=commit)
files: ported repository files controllers to pyramid views.
r1927 return node
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_diff(self):
c = self.load_default_context()
routing: use a common method to extract the f_path for repo views....
r1929 f_path = self._get_f_path(self.request.matchdict)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 diff1 = self.request.GET.get("diff1", "")
diff2 = self.request.GET.get("diff2", "")
files: ported repository files controllers to pyramid views.
r1927
path1, diff1 = parse_path_ref(diff1, default_path=f_path)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 ignore_whitespace = str2bool(self.request.GET.get("ignorews"))
line_context = self.request.GET.get("context", 3)
files: ported repository files controllers to pyramid views.
r1927
if not any((diff1, diff2)):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash('Need query parameter "diff1" or "diff2" to generate a diff.', category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPBadRequest()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.action = self.request.GET.get("diff")
if c.action not in ["download", "raw"]:
compare: migrated code from pylons to pyramid views.
r1957 compare_url = h.route_path(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "repo_compare",
compare: migrated code from pylons to pyramid views.
r1957 repo_name=self.db_repo_name,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 source_ref_type="rev",
files: ported repository files controllers to pyramid views.
r1927 source_ref=diff1,
target_repo=self.db_repo_name,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 target_ref_type="rev",
files: ported repository files controllers to pyramid views.
r1927 target_ref=diff2,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _query=dict(f_path=f_path),
)
files: ported repository files controllers to pyramid views.
r1927 # redirect to new view if we render diff
raise HTTPFound(compare_url)
try:
node1 = self._get_file_node(diff1, path1)
node2 = self._get_file_node(diff2, f_path)
except (RepositoryError, NodeError):
log.exception("Exception while trying to get node from repository")
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 raise HTTPFound(h.route_path("repo_files", repo_name=self.db_repo_name, commit_id="tip", f_path=f_path))
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if all(isinstance(node.commit, EmptyCommit) for node in (node1, node2)):
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
c.commit_1 = node1.commit
c.commit_2 = node2.commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if c.action == "download":
_diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context)
apps: various fixes and improvements for python3
r5072 # NOTE: this was using diff_format='gitdiff'
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 diff = diffs.DiffProcessor(_diff, diff_format="newdiff")
files: ported repository files controllers to pyramid views.
r1927
path-permissions: Initial support for path-based permissions
r2618 response = Response(self.path_filter.get_raw_patch(diff))
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 response.content_type = "text/plain"
response.content_disposition = f"attachment; filename={f_path}_{diff1}_vs_{diff2}.diff"
files: ported repository files controllers to pyramid views.
r1927 charset = self._get_default_encoding(c)
if charset:
response.charset = charset
return response
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 elif c.action == "raw":
_diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context)
apps: various fixes and improvements for python3
r5072 # NOTE: this was using diff_format='gitdiff'
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 diff = diffs.DiffProcessor(_diff, diff_format="newdiff")
files: ported repository files controllers to pyramid views.
r1927
path-permissions: Initial support for path-based permissions
r2618 response = Response(self.path_filter.get_raw_patch(diff))
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 response.content_type = "text/plain"
files: ported repository files controllers to pyramid views.
r1927 charset = self._get_default_encoding(c)
if charset:
response.charset = charset
return response
# in case we ever end up here
raise HTTPNotFound()
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_diff_2way_redirect(self):
"""
Kept only to make OLD links work
"""
path-permissions: Introduced a _get_f_path_unchecked method, which can be used by redirects, which don't have to create a template context
r2620 f_path = self._get_f_path_unchecked(self.request.matchdict)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 diff1 = self.request.GET.get("diff1", "")
diff2 = self.request.GET.get("diff2", "")
files: ported repository files controllers to pyramid views.
r1927
if not any((diff1, diff2)):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash('Need query parameter "diff1" or "diff2" to generate a diff.', category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPBadRequest()
compare: migrated code from pylons to pyramid views.
r1957 compare_url = h.route_path(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "repo_compare",
compare: migrated code from pylons to pyramid views.
r1957 repo_name=self.db_repo_name,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 source_ref_type="rev",
files: ported repository files controllers to pyramid views.
r1927 source_ref=diff1,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 target_ref_type="rev",
files: ported repository files controllers to pyramid views.
r1927 target_ref=diff2,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _query=dict(
f_path=f_path,
diffmode="sideside",
target_repo=self.db_repo_name,
),
)
files: ported repository files controllers to pyramid views.
r1927 raise HTTPFound(compare_url)
@LoginRequired()
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610 def repo_files_default_commit_redirect(self):
"""
Special page that redirects to the landing page of files based on the default
commit for repository
"""
files: use ref names in the url, and make usage of default landing refs....
r4372 c = self.load_default_context()
files: use a common function to handle url-by-refs, and fix landing refs for SVN....
r4373 ref_name = c.rhodecode_db_repo.landing_ref_name
landing_url = h.repo_files_by_ref_url(
c.rhodecode_db_repo.repo_name,
c.rhodecode_db_repo.repo_type,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 f_path="",
files: use a common function to handle url-by-refs, and fix landing refs for SVN....
r4373 ref_name=ref_name,
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 commit_id="tip",
query=dict(at=ref_name),
files: use a common function to handle url-by-refs, and fix landing refs for SVN....
r4373 )
files: use ref names in the url, and make usage of default landing refs....
r4372
raise HTTPFound(landing_url)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files(self):
c = self.load_default_context()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 view_name = getattr(self.request.matched_route, "name", None)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.annotate = view_name == "repo_files:annotated"
files: ported repository files controllers to pyramid views.
r1927 # default is false, but .rst/.md files later are auto rendered, we can
# overwrite auto rendering by setting this GET flag
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.renderer = view_name == "repo_files:rendered" or not self.request.GET.get("no-render", False)
files: ported repository files controllers to pyramid views.
r1927
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
c.commit = self._get_commit_or_redirect(commit_id)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.branch = self.request.GET.get("branch", None)
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 at_rev = self.request.GET.get("at")
files: ported repository files controllers to pyramid views.
r1927
# files or dirs
try:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.file = c.commit.get_node(bytes_path, pre_load=["is_binary", "size", "data"])
files: drop usage of pathlib2, it's now in core python
r5025
files: ported repository files controllers to pyramid views.
r1927 c.file_author = True
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.file_tree = ""
files: ported repository files controllers to pyramid views.
r1927
fix(submodules): fixed an error if reaching out submodule path....
r5261 # prev link
try:
prev_commit = c.commit.prev(c.branch)
c.prev_commit = prev_commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_prev = h.route_path(
"repo_files", repo_name=self.db_repo_name, commit_id=prev_commit.raw_id, f_path=f_path
)
fix(submodules): fixed an error if reaching out submodule path....
r5261 if c.branch:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_prev += f"?branch={c.branch}"
fix(submodules): fixed an error if reaching out submodule path....
r5261 except (CommitDoesNotExistError, VCSError):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_prev = "#"
fix(submodules): fixed an error if reaching out submodule path....
r5261 c.prev_commit = EmptyCommit()
# next link
try:
next_commit = c.commit.next(c.branch)
c.next_commit = next_commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_next = h.route_path(
"repo_files", repo_name=self.db_repo_name, commit_id=next_commit.raw_id, f_path=f_path
)
fix(submodules): fixed an error if reaching out submodule path....
r5261 if c.branch:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_next += f"?branch={c.branch}"
fix(submodules): fixed an error if reaching out submodule path....
r5261 except (CommitDoesNotExistError, VCSError):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.url_next = "#"
fix(submodules): fixed an error if reaching out submodule path....
r5261 c.next_commit = EmptyCommit()
files: ported repository files controllers to pyramid views.
r1927 # load file content
if c.file.is_file():
files: only check for git_lfs/hg_largefiles if they are enabled....
r3894 c.lf_node = {}
has_lf_enabled = self._is_lf_enabled(self.db_repo)
if has_lf_enabled:
c.lf_node = c.file.get_largefile_node()
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.file_source_page = "true"
files: ported repository files controllers to pyramid views.
r1927 c.file_last_commit = c.file.last_commit
dan
file-source: ensure over size limit files never do any content fetching when viewing the files....
r3897
c.file_size_too_big = c.file.size > c.visual.cut_off_limit_file
dan
files: ensure we don't parse any content on binary files.
r3898 if not (c.file_size_too_big or c.file.is_binary):
files: ported repository files controllers to pyramid views.
r1927 if c.annotate: # annotation has precedence over renderer
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.annotated_lines = filenode_as_annotated_lines_tokens(c.file)
files: ported repository files controllers to pyramid views.
r1927 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.renderer = c.renderer and h.renderer_from_filename(c.file.path)
files: ported repository files controllers to pyramid views.
r1927 if not c.renderer:
c.lines = filenode_as_lines_tokens(c.file)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: added branch permissions checks into web edit operations.
r2978 c.on_branch_head = is_head
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 branch = c.commit.branch if (c.commit.branch and "/" not in c.commit.branch) else None
files: ported repository files controllers to pyramid views.
r1927 c.branch_or_raw_id = branch or c.commit.raw_id
c.branch_name = c.commit.branch or h.short_id(c.commit.raw_id)
author = c.file_last_commit.author
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.authors = [[h.email(author), h.person(author, "username_or_name_or_email"), 1]]
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 else: # load tree content (dir content) at path
c.file_source_page = "false"
files: ported repository files controllers to pyramid views.
r1927 c.authors = []
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651
dir_node = c.file
c.file_nodes = dir_node.commit.get_nodes(dir_node.bytes_path, pre_load=dir_node.default_pre_load)
files: ported repository files controllers to pyramid views.
r1927 # this loads a simple tree without metadata to speed things up
# later via ajax we call repo_nodetree_full and fetch whole
dan
files: fixed the repo switcher at flag beeing nor persistens...
r4294 c.file_tree = self._get_tree_at_commit(c, c.commit.raw_id, f_path, at_rev=at_rev)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.readme_data, c.readme_file = self._get_readme_data(
self.db_repo, c.visual.default_renderer, c.commit.raw_id, bytes_path, nodes=c.file_nodes
)
files: render readme files found in repository file browser....
r3924
files: ported repository files controllers to pyramid views.
r1927 except RepositoryError as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(h.escape(safe_str(e)), category="error")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPNotFound()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if self.request.environ.get("HTTP_X_PJAX"):
html = render("rhodecode:templates/files/files_pjax.mako", self._get_template_context(c), self.request)
files: ported repository files controllers to pyramid views.
r1927 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 html = render("rhodecode:templates/files/files.mako", self._get_template_context(c), self.request)
files: ported repository files controllers to pyramid views.
r1927 return Response(html)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_annotated_previous(self):
self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, bytes_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
prev_commit_id = commit.raw_id
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 line_anchor = self.request.GET.get("line_anchor")
files: ported repository files controllers to pyramid views.
r1927 is_file = False
try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 _file = commit.get_node(bytes_path)
files: ported repository files controllers to pyramid views.
r1927 is_file = _file.is_file()
except (NodeDoesNotExistError, CommitDoesNotExistError, VCSError):
pass
if is_file:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 history = commit.get_path_history(bytes_path)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 prev_commit_id = history[1].raw_id if len(history) > 1 else prev_commit_id
files: ported repository files controllers to pyramid views.
r1927 prev_url = h.route_path(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "repo_files:annotated",
repo_name=self.db_repo_name,
commit_id=prev_commit_id,
f_path=bytes_path,
_anchor=f"L{line_anchor}",
)
files: ported repository files controllers to pyramid views.
r1927
raise HTTPFound(prev_url)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_nodetree_full(self):
"""
Returns rendered html of file tree that contains commit date,
author, commit_id for the specified combination of
repo, commit_id and file path
"""
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 dir_node = commit.get_node(bytes_path)
files: ported repository files controllers to pyramid views.
r1927 except RepositoryError as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response(f"error: {h.escape(safe_str(e))}")
files: ported repository files controllers to pyramid views.
r1927
if dir_node.is_file():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return Response("")
files: ported repository files controllers to pyramid views.
r1927
c.file = dir_node
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.file_nodes = dir_node.commit.get_nodes(dir_node.bytes_path, pre_load=dir_node.default_pre_load)
files: ported repository files controllers to pyramid views.
r1927 c.commit = commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 at_rev = self.request.GET.get("at")
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 html = self._get_tree_at_commit(c, commit.raw_id, dir_node.path, full_load=True, at_rev=at_rev)
files: ported repository files controllers to pyramid views.
r1927
return Response(html)
downlaods: properly encode " in the filenames, and add RFC 5987 header for non-ascii files.
r3343 def _get_attachement_headers(self, f_path):
f_name = safe_str(f_path.split(Repository.NAME_SEP)[-1])
safe_path = f_name.replace('"', '\\"')
python3: fix urllib usage
r4914 encoded_path = urllib.parse.quote(f_name)
downlaods: properly encode " in the filenames, and add RFC 5987 header for non-ascii files.
r3343
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 headers = f"attachment; " f'filename="{safe_path}"; ' f"filename*=UTF-8''{encoded_path}"
fix(app): Added proper encoding to avoid app crashes while downloading files. Fixes: RCCE-37
r5269
feat(artifacts): new artifact storage engines allowing an s3 based uploads
r5516 return header_safe_str(headers)
files: ported repository files controllers to pyramid views.
r1927
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_file_raw(self):
"""
Action for show as raw, some mimetypes are "rendered",
those include images, icons.
"""
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 file_node = self._get_filenode_or_redirect(commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
raw_mimetype_mapping = {
# map original mimetype to a mimetype used for "show as raw"
# you can also provide a content-disposition to override the
# default "attachment" disposition.
# orig_type: (new_type, new_dispo)
# show images inline:
# Do not re-add SVG: it is unsafe and permits XSS attacks. One can
# for example render an SVG with javascript inside or even render
# HTML.
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "image/x-icon": ("image/x-icon", "inline"),
"image/png": ("image/png", "inline"),
"image/gif": ("image/gif", "inline"),
"image/jpeg": ("image/jpeg", "inline"),
"application/pdf": ("application/pdf", "inline"),
files: ported repository files controllers to pyramid views.
r1927 }
mimetype = file_node.mimetype
try:
mimetype, disposition = raw_mimetype_mapping[mimetype]
except KeyError:
# we don't know anything special about this, handle it safely
if file_node.is_binary:
# do same as download raw for binary files
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 mimetype, disposition = "application/octet-stream", "attachment"
files: ported repository files controllers to pyramid views.
r1927 else:
# do not just use the original mimetype, but force text/plain,
# otherwise it would serve text/html and that might be unsafe.
# Note: underlying vcs library fakes text/plain mimetype if the
# mimetype can not be determined and it thinks it is not
# binary.This might lead to erroneous text display in some
# cases, but helps in other cases, like with text files
# without extension.
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 mimetype, disposition = "text/plain", "inline"
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if disposition == "attachment":
downlaods: properly encode " in the filenames, and add RFC 5987 header for non-ascii files.
r3343 disposition = self._get_attachement_headers(f_path)
files: ported repository files controllers to pyramid views.
r1927
dan
file-nodes: added streaming remote attributes for vcsserver....
r3895 stream_content = file_node.stream_bytes()
files: ported repository files controllers to pyramid views.
r1927
dan
file-nodes: added streaming remote attributes for vcsserver....
r3895 response = Response(app_iter=stream_content)
files: ported repository files controllers to pyramid views.
r1927 response.content_disposition = disposition
response.content_type = mimetype
charset = self._get_default_encoding(c)
if charset:
response.charset = charset
return response
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_file_download(self):
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 file_node = self._get_filenode_or_redirect(commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if self.request.GET.get("lf"):
files: ported repository files controllers to pyramid views.
r1927 # only if lf get flag is passed, we download this file
# as LFS/Largefile
lf_node = file_node.get_largefile_node()
if lf_node:
# overwrite our pointer with the REAL large-file
file_node = lf_node
downlaods: properly encode " in the filenames, and add RFC 5987 header for non-ascii files.
r3343 disposition = self._get_attachement_headers(f_path)
files: ported repository files controllers to pyramid views.
r1927
dan
file-nodes: added streaming remote attributes for vcsserver....
r3895 stream_content = file_node.stream_bytes()
files: ported repository files controllers to pyramid views.
r1927
dan
file-nodes: added streaming remote attributes for vcsserver....
r3895 response = Response(app_iter=stream_content)
files: ported repository files controllers to pyramid views.
r1927 response.content_disposition = disposition
response.content_type = file_node.mimetype
charset = self._get_default_encoding(c)
if charset:
response.charset = charset
return response
caches: don't use beaker for file caches anymore
r2846 def _get_nodelist_at_commit(self, repo_name, repo_id, commit_id, f_path):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 cache_seconds = rhodecode.ConfigGet().get_int("rc_cache.cache_repo.expiration_time")
cache: turn off caches if expiration_time is 0
r2848 cache_on = cache_seconds > 0
log.debug(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "Computing FILE SEARCH for repo_id %s commit_id `%s` and path `%s`"
"with caching: %s[TTL: %ss]" % (repo_id, commit_id, f_path, cache_on, cache_seconds or 0)
)
cache: turn off caches if expiration_time is 0
r2848
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 cache_namespace_uid = f"repo.{repo_id}"
region = rc_cache.get_or_create_region("cache_repo", cache_namespace_uid)
caches: don't use beaker for file caches anymore
r2846
files: ensure caches are invalidated for file viewer when name, or parent group changes
r4349 @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, condition=cache_on)
def compute_file_search(_name_hash, _repo_id, _commit_id, _f_path):
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.debug("Generating cached nodelist for repo_id:%s, %s, %s", _repo_id, commit_id, f_path)
files: protect against 500 errors on nodelist.
r2152 try:
files: ensure caches are invalidated for file viewer when name, or parent group changes
r4349 _d, _f = ScmModel().get_quick_filter_nodes(repo_name, _commit_id, _f_path)
files: protect against 500 errors on nodelist.
r2152 except (RepositoryError, CommitDoesNotExistError, Exception) as e:
log.exception(safe_str(e))
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(h.escape(safe_str(e)), category="error")
raise HTTPFound(h.route_path("repo_files", repo_name=self.db_repo_name, commit_id="tip", f_path="/"))
path-filter: enable for quick search menu.
r3817
files: ported repository files controllers to pyramid views.
r1927 return _d + _f
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 result = compute_file_search(self.db_repo.repo_name_hash, self.db_repo.repo_id, commit_id, f_path)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return filter(lambda n: self.path_filter.path_access_allowed(n["name"]), result)
files: ported repository files controllers to pyramid views.
r1927
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_nodelist(self):
self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 metadata = self._get_nodelist_at_commit(self.db_repo_name, self.db_repo.repo_id, commit.raw_id, f_path)
return {"nodes": [x for x in metadata]}
files: ported repository files controllers to pyramid views.
r1927
files: updated based on new design
r3706 def _create_references(self, branches_or_tags, symbolic_reference, f_path, ref_type):
files: ported repository files controllers to pyramid views.
r1927 items = []
for name, commit_id in branches_or_tags.items():
files: updated based on new design
r3706 sym_ref = symbolic_reference(commit_id, name, f_path, ref_type)
items.append((sym_ref, name, ref_type))
files: ported repository files controllers to pyramid views.
r1927 return items
files: updated based on new design
r3706 def _symbolic_reference(self, commit_id, name, f_path, ref_type):
files: ported repository files controllers to pyramid views.
r1927 return commit_id
files: updated based on new design
r3706 def _symbolic_reference_svn(self, commit_id, name, f_path, ref_type):
dan
files: fixed SVN refs switcher that used old format of diff between files....
r4293 return commit_id
# NOTE(dan): old code we used in "diff" mode compare
files: ported repository files controllers to pyramid views.
r1927 new_f_path = vcspath.join(name, f_path)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return f"{new_f_path}@{commit_id}"
files: ported repository files controllers to pyramid views.
r1927
def _get_node_history(self, commit_obj, f_path, commits=None):
"""
get commit history for given node
:param commit_obj: commit to calculate history
:param f_path: path for node to calculate history for
:param commits: if passed don't calculate history and take
commits defined in this list
"""
_ = self.request.translate
# calculate history based on tip
tip = self.rhodecode_vcs_repo.get_commit()
if commits is None:
pre_load = ["author", "branch"]
try:
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commits = tip.get_path_history(safe_bytes(f_path), pre_load=pre_load)
files: ported repository files controllers to pyramid views.
r1927 except (NodeDoesNotExistError, CommitError):
# this node is not present at tip!
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commits = commit_obj.get_path_history(safe_bytes(f_path), pre_load=pre_load)
files: ported repository files controllers to pyramid views.
r1927
history = []
commits_group = ([], _("Changesets"))
for commit in commits:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 branch = " (%s)" % commit.branch if commit.branch else ""
n_desc = f"r{commit.idx}:{commit.short_id}{branch}"
commits_group[0].append((commit.raw_id, n_desc, "sha"))
files: ported repository files controllers to pyramid views.
r1927 history.append(commits_group)
symbolic_reference = self._symbolic_reference
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if self.rhodecode_vcs_repo.alias == "svn":
adjusted_f_path = RepoFilesView.adjust_file_path_for_svn(f_path, self.rhodecode_vcs_repo)
files: ported repository files controllers to pyramid views.
r1927 if adjusted_f_path != f_path:
log.debug(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 'Recognized svn tag or branch in file "%s", using svn ' "specific symbolic references", f_path
)
files: ported repository files controllers to pyramid views.
r1927 f_path = adjusted_f_path
symbolic_reference = self._symbolic_reference_svn
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 branches = self._create_references(self.rhodecode_vcs_repo.branches, symbolic_reference, f_path, "branch")
files: ported repository files controllers to pyramid views.
r1927 branches_group = (branches, _("Branches"))
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 tags = self._create_references(self.rhodecode_vcs_repo.tags, symbolic_reference, f_path, "tag")
files: ported repository files controllers to pyramid views.
r1927 tags_group = (tags, _("Tags"))
history.append(branches_group)
history.append(tags_group)
return history, commits
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_file_history(self):
self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 file_node = self._get_filenode_or_redirect(commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
if file_node.is_file():
file_history, _hist = self._get_node_history(commit, f_path)
res = []
dan
files: fixed the repo switcher at flag beeing nor persistens...
r4294 for section_items, section in file_history:
items = []
for obj_id, obj_text, obj_type in section_items:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 at_rev = ""
if obj_type in ["branch", "bookmark", "tag"]:
dan
files: fixed the repo switcher at flag beeing nor persistens...
r4294 at_rev = obj_text
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 entry = {"id": obj_id, "text": obj_text, "type": obj_type, "at_rev": at_rev}
dan
files: fixed the repo switcher at flag beeing nor persistens...
r4294
items.append(entry)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 res.append({"text": section, "children": items})
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 data = {"more": False, "results": res}
files: ported repository files controllers to pyramid views.
r1927 return data
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.warning("Cannot fetch history for directory")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPBadRequest()
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.read", "repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_file_authors(self):
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927 commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 file_node = self._get_filenode_or_redirect(commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
if not file_node.is_file():
raise HTTPBadRequest()
c.file_last_commit = file_node.last_commit
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if self.request.GET.get("annotate") == "1":
files: ported repository files controllers to pyramid views.
r1927 # use _hist from annotation if annotation mode is on
apps: modernize for python3
r5093 commit_ids = {x[1] for x in file_node.annotate}
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _hist = (self.rhodecode_vcs_repo.get_commit(commit_id) for commit_id in commit_ids)
files: ported repository files controllers to pyramid views.
r1927 else:
_f_history, _hist = self._get_node_history(commit, f_path)
c.file_author = False
unique = collections.OrderedDict()
for commit in _hist:
author = commit.author
if author not in unique:
unique[commit.author] = [
h.email(author),
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.person(author, "username_or_name_or_email"),
1, # counter
files: ported repository files controllers to pyramid views.
r1927 ]
else:
# increase counter
unique[commit.author][2] += 1
c.authors = [val for val in unique.values()]
return self._get_template_context(c)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302 def repo_files_check_head(self):
self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 new_path = self.request.POST.get("path")
operation = self.request.POST.get("operation")
path_exist = ""
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if new_path and operation in ["create", "upload"]:
new_f_path = os.path.join(f_path.lstrip("/"), new_path)
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302 try:
commit_obj = self.rhodecode_vcs_repo.get_commit(commit_id)
# NOTE(dan): construct whole path without leading /
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 file_node = commit_obj.get_node(safe_bytes(new_f_path))
if file_node:
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302 path_exist = new_f_path
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 except (EmptyRepositoryError, NodeDoesNotExistError):
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302 pass
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"branch": _branch_name, "sha": _sha_commit_id, "is_head": is_head, "path_exists": path_exist}
dan
files: add pre-commit checks on file operations to prevent loosing content while editing when repositories change....
r4302
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_remove_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: ported repository files controllers to pyramid views.
r1927
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path)
self.check_branch_permission(_branch_name)
files: ported repository files controllers to pyramid views.
r1927
c.commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 c.file = self._get_filenode_or_redirect(c.commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Deleted file {} via RhodeCode Enterprise").format(f_path)
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
return self._get_template_context(c)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 @CSRFRequired()
def repo_files_delete_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: ported repository files controllers to pyramid views.
r1927
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path)
files: added branch permissions checks into web edit operations.
r2978 self.check_branch_permission(_branch_name)
files: ported repository files controllers to pyramid views.
r1927
c.commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 c.file = self._get_filenode_or_redirect(c.commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Deleted file {} via RhodeCode Enterprise").format(f_path)
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
node_path = f_path
author = self._rhodecode_db_user.full_contact
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 message = self.request.POST.get("message") or c.default_message
files: ported repository files controllers to pyramid views.
r1927 try:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 nodes = {safe_bytes(node_path): {"content": b""}}
files: ported repository files controllers to pyramid views.
r1927 ScmModel().delete_nodes(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 user=self._rhodecode_db_user.user_id,
repo=self.db_repo,
files: ported repository files controllers to pyramid views.
r1927 message=message,
nodes=nodes,
parent_commit=c.commit,
author=author,
)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("Successfully deleted file `{}`").format(h.escape(f_path)), category="success")
files: ported repository files controllers to pyramid views.
r1927 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Error during commit operation")
h.flash(_("Error occurred during commit"), category="error")
raise HTTPFound(h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id="tip"))
files: ported repository files controllers to pyramid views.
r1927
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_edit_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: ported repository files controllers to pyramid views.
r1927
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path, commit_id=commit_id)
self.check_branch_permission(_branch_name, commit_id=commit_id)
files: ported repository files controllers to pyramid views.
r1927
c.commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 c.file = self._get_filenode_or_redirect(c.commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
if c.file.is_binary:
files_url = h.route_path(
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "repo_files", repo_name=self.db_repo_name, commit_id=c.commit.raw_id, f_path=f_path
)
files: ported repository files controllers to pyramid views.
r1927 raise HTTPFound(files_url)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Edited file {} via RhodeCode Enterprise").format(f_path)
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
return self._get_template_context(c)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 @CSRFRequired()
def repo_files_update_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
files: added branch permissions checks into web edit operations.
r2978
files: ported repository files controllers to pyramid views.
r1927 c.commit = self._get_commit_or_redirect(commit_id)
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 c.file = self._get_filenode_or_redirect(c.commit, bytes_path)
files: ported repository files controllers to pyramid views.
r1927
if c.file.is_binary:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 raise HTTPFound(
h.route_path("repo_files", repo_name=self.db_repo_name, commit_id=c.commit.raw_id, f_path=f_path)
)
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: ported repository files controllers to pyramid views.
r1927
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path, commit_id=commit_id)
self.check_branch_permission(_branch_name, commit_id=commit_id)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Edited file {} via RhodeCode Enterprise").format(f_path)
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
dan
file: new file editors...
r3754
apps: various fixes and improvements for python3
r5072 old_content = c.file.str_content
files: ported repository files controllers to pyramid views.
r1927 sl = old_content.splitlines(1)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 first_line = sl[0] if sl else ""
files: ported repository files controllers to pyramid views.
r1927
r_post = self.request.POST
dan
Files: preserve filemode on web edits.
r3410 # line endings: 0 - Unix, 1 - Mac, 2 - DOS
line_ending_mode = detect_mode(first_line, 0)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 content = convert_line_endings(r_post.get("content", ""), line_ending_mode)
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 message = r_post.get("message") or c.default_message
apps: various fixes and improvements for python3
r5072
org_node_path = c.file.str_path
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 filename = r_post["filename"]
dan
file: new file editors...
r3754
root_path = c.file.dir_path
pure_path = self.create_pure_path(root_path, filename)
files: drop usage of pathlib2, it's now in core python
r5025 node_path = pure_path.as_posix()
files: ported repository files controllers to pyramid views.
r1927
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id=commit_id)
dan
file: new file editors...
r3754 if content == old_content and node_path == org_node_path:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("No changes detected on {}").format(h.escape(org_node_path)), category="warning")
dan
file: new file editors...
r3754 raise HTTPFound(default_redirect_url)
files: ported repository files controllers to pyramid views.
r1927 try:
mapping = {
apps: various fixes and improvements for python3
r5072 c.file.bytes_path: {
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "org_filename": org_node_path,
"filename": safe_bytes(node_path),
"content": safe_bytes(content),
"lexer": "",
"op": "mod",
"mode": c.file.mode,
files: ported repository files controllers to pyramid views.
r1927 }
}
dan
file: new file editors...
r3754 commit = ScmModel().update_nodes(
files: ported repository files controllers to pyramid views.
r1927 user=self._rhodecode_db_user.user_id,
repo=self.db_repo,
message=message,
nodes=mapping,
parent_commit=c.commit,
)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("Successfully committed changes to file `{}`").format(h.escape(f_path)), category="success")
default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id=commit.raw_id)
dan
file: new file editors...
r3754
files: ported repository files controllers to pyramid views.
r1927 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Error occurred during commit")
h.flash(_("Error occurred during commit"), category="error")
dan
file: new file editors...
r3754
raise HTTPFound(default_redirect_url)
files: ported repository files controllers to pyramid views.
r1927
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 def repo_files_add_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 # Check if we need to use this page to upload binary
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 upload_binary = str2bool(self.request.params.get("upload_binary", False))
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
files: ported repository files controllers to pyramid views.
r1927 c.commit = self._get_commit_or_redirect(commit_id, redirect_after=False)
if c.commit is None:
c.commit = EmptyCommit(alias=self.rhodecode_vcs_repo.alias)
dan
file: new file editors...
r3754 if self.rhodecode_vcs_repo.is_empty():
files: added branch permissions checks into web edit operations.
r2978 # for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = c.commit.branch, "", True
files: added branch permissions checks into web edit operations.
r2978 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: added branch permissions checks into web edit operations.
r2978
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path, commit_id=commit_id)
self.check_branch_permission(_branch_name, commit_id=commit_id)
files: added branch permissions checks into web edit operations.
r2978
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = (
(_("Added file via RhodeCode Enterprise"))
if not upload_binary
else (_("Edited file {} via RhodeCode Enterprise").format(f_path))
)
c.f_path = f_path.lstrip("/") # ensure not relative path
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 c.replace_binary = upload_binary
files: added branch permissions checks into web edit operations.
r2978
files: ported repository files controllers to pyramid views.
r1927 return self._get_template_context(c)
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
files: ported repository files controllers to pyramid views.
r1927 @CSRFRequired()
def repo_files_create_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
files: ported repository files controllers to pyramid views.
r1927
self._ensure_not_locked()
dan
file: new file editors...
r3754 c.commit = self._get_commit_or_redirect(commit_id, redirect_after=False)
files: ported repository files controllers to pyramid views.
r1927 if c.commit is None:
c.commit = EmptyCommit(alias=self.rhodecode_vcs_repo.alias)
files: added branch permissions checks into web edit operations.
r2978
dan
file: new file editors...
r3754 # calculate redirect URL
if self.rhodecode_vcs_repo.is_empty():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_summary", repo_name=self.db_repo_name)
dan
file: new file editors...
r3754 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id="tip")
dan
file: new file editors...
r3754
if self.rhodecode_vcs_repo.is_empty():
files: added branch permissions checks into web edit operations.
r2978 # for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = c.commit.branch, "", True
files: added branch permissions checks into web edit operations.
r2978 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
files: added branch permissions checks into web edit operations.
r2978
dan
file: new file editors...
r3754 self.forbid_non_head(is_head, f_path, commit_id=commit_id)
self.check_branch_permission(_branch_name, commit_id=commit_id)
files: added branch permissions checks into web edit operations.
r2978
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Added file via RhodeCode Enterprise")
files: ported repository files controllers to pyramid views.
r1927 c.f_path = f_path
dan
file: new file editors...
r3754
r_post = self.request.POST
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 message = r_post.get("message") or c.default_message
filename = r_post.get("filename")
files: ported repository files controllers to pyramid views.
r1927 unix_mode = 0
files: drop usage of pathlib2, it's now in core python
r5025
files: ported repository files controllers to pyramid views.
r1927 if not filename:
dan
file: new file editors...
r3754 # If there's no commit, redirect to repo summary
if type(c.commit) is EmptyCommit:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 redirect_url = h.route_path("repo_summary", repo_name=self.db_repo_name)
dan
file: new file editors...
r3754 else:
redirect_url = default_redirect_url
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("No filename specified"), category="warning")
files: ported repository files controllers to pyramid views.
r1927 raise HTTPFound(redirect_url)
dan
file: new file editors...
r3754 root_path = f_path
pure_path = self.create_pure_path(root_path, filename)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 node_path = pure_path.as_posix().lstrip("/")
files: ported repository files controllers to pyramid views.
r1927
author = self._rhodecode_db_user.full_contact
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 content = convert_line_endings(r_post.get("content", ""), unix_mode)
nodes = {safe_bytes(node_path): {"content": safe_bytes(content)}}
files: ported repository files controllers to pyramid views.
r1927
try:
dan
file: new file editors...
r3754 commit = ScmModel().create_nodes(
files: ported repository files controllers to pyramid views.
r1927 user=self._rhodecode_db_user.user_id,
repo=self.db_repo,
message=message,
nodes=nodes,
parent_commit=c.commit,
author=author,
)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("Successfully committed new file `{}`").format(h.escape(node_path)), category="success")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id=commit.raw_id)
dan
file: new file editors...
r3754
files: ported repository files controllers to pyramid views.
r1927 except NonRelativePathError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Non Relative path found")
h.flash(
_("The location specified must be a relative path and must not " "contain .. in the path"),
category="warning",
)
files: ported repository files controllers to pyramid views.
r1927 raise HTTPFound(default_redirect_url)
except (NodeError, NodeAlreadyExistsError) as e:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(h.escape(safe_str(e)), category="error")
files: ported repository files controllers to pyramid views.
r1927 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Error occurred during commit")
h.flash(_("Error occurred during commit"), category="error")
files: ported repository files controllers to pyramid views.
r1927
raise HTTPFound(default_redirect_url)
dan
file: new file editors...
r3754
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
dan
file: new file editors...
r3754 @CSRFRequired()
def repo_files_upload_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
dan
file: new file editors...
r3754
self._ensure_not_locked()
c.commit = self._get_commit_or_redirect(commit_id, redirect_after=False)
if c.commit is None:
c.commit = EmptyCommit(alias=self.rhodecode_vcs_repo.alias)
# calculate redirect URL
if self.rhodecode_vcs_repo.is_empty():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_summary", repo_name=self.db_repo_name)
dan
file: new file editors...
r3754 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id="tip")
dan
file: new file editors...
r3754
if self.rhodecode_vcs_repo.is_empty():
# for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = c.commit.branch, "", True
dan
file: new file editors...
r3754 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
dan
file: new file editors...
r3754
error = self.forbid_non_head(is_head, f_path, json_mode=True)
if error:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754 error = self.check_branch_permission(_branch_name, json_mode=True)
if error:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Added file via RhodeCode Enterprise")
dan
file: new file editors...
r3754 c.f_path = f_path
r_post = self.request.POST
message = c.default_message
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 user_message = r_post.getall("message")
dan
file: new file editors...
r3754 if isinstance(user_message, list) and user_message:
# we take the first from duplicated results if it's not empty
message = user_message[0] if user_message[0] else message
nodes = {}
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 for file_obj in r_post.getall("files_upload") or []:
dan
file: new file editors...
r3754 content = file_obj.file
filename = file_obj.filename
root_path = f_path
pure_path = self.create_pure_path(root_path, filename)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 node_path = pure_path.as_posix().lstrip("/")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 nodes[safe_bytes(node_path)] = {"content": content}
dan
file: new file editors...
r3754
if not nodes:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 error = "missing files"
return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754
author = self._rhodecode_db_user.full_contact
try:
commit = ScmModel().create_nodes(
user=self._rhodecode_db_user.user_id,
repo=self.db_repo,
message=message,
nodes=nodes,
parent_commit=c.commit,
author=author,
)
if len(nodes) == 1:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 flash_message = _("Successfully committed {} new files").format(len(nodes))
dan
file: new file editors...
r3754 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 flash_message = _("Successfully committed 1 new file")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(flash_message, category="success")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id=commit.raw_id)
dan
file: new file editors...
r3754
except NonRelativePathError:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Non Relative path found")
error = _("The location specified must be a relative path and must not " "contain .. in the path")
h.flash(error, category="warning")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754 except (NodeError, NodeAlreadyExistsError) as e:
error = h.escape(e)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(error, category="error")
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Error occurred during commit")
error = _("Error occurred during commit")
h.flash(error, category="error")
return {"error": error, "redirect_url": default_redirect_url}
dan
file: new file editors...
r3754
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": None, "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
@LoginRequired()
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 @HasRepoPermissionAnyDecorator("repository.write", "repository.admin")
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 @CSRFRequired()
def repo_files_replace_file(self):
_ = self.request.translate
c = self.load_default_context()
fix(encoding for file): fixed support of non utf-8 files in all backends
r5647 commit_id, f_path, bytes_path = self._get_commit_and_path()
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
self._ensure_not_locked()
c.commit = self._get_commit_or_redirect(commit_id, redirect_after=False)
if c.commit is None:
c.commit = EmptyCommit(alias=self.rhodecode_vcs_repo.alias)
if self.rhodecode_vcs_repo.is_empty():
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_summary", repo_name=self.db_repo_name)
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id="tip")
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
if self.rhodecode_vcs_repo.is_empty():
# for empty repository we cannot check for current branch, we rely on
# c.commit.branch instead
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = c.commit.branch, "", True
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 else:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 _branch_name, _sha_commit_id, is_head = self._is_valid_head(
commit_id, self.rhodecode_vcs_repo, landing_ref=self.db_repo.landing_ref_name
)
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
error = self.forbid_non_head(is_head, f_path, json_mode=True)
if error:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 error = self.check_branch_permission(_branch_name, json_mode=True)
if error:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 c.default_message = _("Edited file {} via RhodeCode Enterprise").format(f_path)
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 c.f_path = f_path
r_post = self.request.POST
message = c.default_message
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 user_message = r_post.getall("message")
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 if isinstance(user_message, list) and user_message:
# we take the first from duplicated results if it's not empty
message = user_message[0] if user_message[0] else message
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 data_for_replacement = r_post.getall("files_upload") or []
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 if (objects_count := len(data_for_replacement)) > 1:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": "too many files for replacement", "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 elif not objects_count:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": "missing files", "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
content = data_for_replacement[0].file
retrieved_filename = data_for_replacement[0].filename
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 if retrieved_filename.split(".")[-1] != f_path.split(".")[-1]:
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 return {
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "error": "file extension of uploaded file doesn't match an original file's extension",
"redirect_url": default_redirect_url,
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 }
author = self._rhodecode_db_user.full_contact
try:
commit = ScmModel().update_binary_node(
user=self._rhodecode_db_user.user_id,
repo=self.db_repo,
message=message,
node={
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 "content": content,
"file_path": f_path.encode(),
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 },
parent_commit=c.commit,
author=author,
)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(_("Successfully committed 1 new file"), category="success")
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 default_redirect_url = h.route_path("repo_commit", repo_name=self.db_repo_name, commit_id=commit.raw_id)
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
except (NodeError, NodeAlreadyExistsError) as e:
error = h.escape(e)
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 h.flash(error, category="error")
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": error, "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274 except Exception:
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 log.exception("Error occurred during commit")
error = _("Error occurred during commit")
h.flash(error, category="error")
return {"error": error, "redirect_url": default_redirect_url}
feat(ui): added ability to replace binary file through UI, added related tests. Fixes: RCCE-19
r5274
fix(file-caching): fixed cases when old cache was used before changes to operate on bytestrings
r5651 return {"error": None, "redirect_url": default_redirect_url}