##// END OF EJS Templates
docs: updated docs for importing repos and fixed howto on building them
docs: updated docs for importing repos and fixed howto on building them

File last commit:

r5608:6d33e504 default
r5654:f7519e5d default
Show More
repo_strip.py
105 lines | 3.8 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2017-2024 RhodeCode GmbH
repo-strip: rename file to adjust same naming as other views....
r1723 #
# 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 logging
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
repo-strip: rename file to adjust same naming as other views....
r1723
from rhodecode.apps._base import RepoAppView
from rhodecode.lib import audit_logger
security: fix self-xss inside repo strip view.
r1809 from rhodecode.lib import helpers as h
repositories: rewrote whole admin section to pyramid....
r2014 from rhodecode.lib.auth import (
LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
repo-strip: rename file to adjust same naming as other views....
r1723 from rhodecode.lib.ext_json import json
log = logging.getLogger(__name__)
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610 class RepoStripView(RepoAppView):
repo-strip: rename file to adjust same naming as other views....
r1723 def load_default_context(self):
c = self._get_local_tmpl_context()
pylons: remove pylons as dependency...
r2351
repo-strip: rename file to adjust same naming as other views....
r1723 return c
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
def strip(self):
c = self.load_default_context()
c.active = 'strip'
c.strip_limit = 10
return self._get_template_context(c)
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
security: added missing csrf checks in few missing views.
r1811 @CSRFRequired()
repo-strip: rename file to adjust same naming as other views....
r1723 def strip_check(self):
from rhodecode.lib.vcs.backends.base import EmptyCommit
data = {}
rp = self.request.POST
for i in range(1, 11):
fix(git): fixed strip command to always require a valid branch name for git....
r5253 changeset_id_key = f'changeset_id-{i}'
changeset_id_branch_key = f'changeset_id_branch-{i}'
check = rp.get(changeset_id_key)
security: fix self-xss inside repo strip view.
r1809
repo-strip: rename file to adjust same naming as other views....
r1723 if check:
fix(git): fixed strip command to always require a valid branch name for git....
r5253 data[i] = self.db_repo.get_commit(rp[changeset_id_key])
repo-strip: rename file to adjust same naming as other views....
r1723 if isinstance(data[i], EmptyCommit):
fix(git): fixed strip command to always require a valid branch name for git....
r5253 data[i] = {'rev': None, 'commit': h.escape(rp[changeset_id_key])}
repo-strip: rename file to adjust same naming as other views....
r1723 else:
fix(git): fixed strip command to always require a valid branch name for git....
r5253 rp_branch = rp.get(changeset_id_branch_key)
data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch or rp_branch,
security: fix XSS in repo strip view.
r2155 'author': h.escape(data[i].author),
'comment': h.escape(data[i].message)}
repo-strip: rename file to adjust same naming as other views....
r1723 else:
break
return data
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
security: added missing csrf checks in few missing views.
r1811 @CSRFRequired()
repo-strip: rename file to adjust same naming as other views....
r1723 def strip_execute(self):
from rhodecode.model.scm import ScmModel
c = self.load_default_context()
user = self._rhodecode_user
rp = self.request.POST
data = {}
fix(git): fixed strip command to always require a valid branch name for git....
r5253
repo-strip: rename file to adjust same naming as other views....
r1723 for idx in rp:
commit = json.loads(rp[idx])
# If someone put two times the same branch
if commit['branch'] in data.keys():
continue
try:
ScmModel().strip(
repositories: rewrote whole admin section to pyramid....
r2014 repo=self.db_repo,
repo-strip: rename file to adjust same naming as other views....
r1723 commit_id=commit['rev'], branch=commit['branch'])
logging: use lazy parameter evaluation in log calls.
r3061 log.info('Stripped commit %s from repo `%s` by %s',
commit['rev'], self.db_repo_name, user)
repo-strip: rename file to adjust same naming as other views....
r1723 data[commit['rev']] = True
audit-logs: use specific web/api calls....
r1806 audit_logger.store_web(
audit-logs: implemented full audit logs across application....
r1829 'repo.commit.strip', action_data={'commit_id': commit['rev']},
repo=self.db_repo, user=self._rhodecode_user, commit=True)
repo-strip: rename file to adjust same naming as other views....
r1723
except Exception as e:
data[commit['rev']] = False
logging: use lazy parameter evaluation in log calls.
r3061 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s',
fix(git): fixed strip command to always require a valid branch name for git....
r5253 commit['rev'], self.db_repo_name, user, e)
repo-strip: rename file to adjust same naming as other views....
r1723 return data