##// END OF EJS Templates
audit-logs: added web strip command to audit logs
audit-logs: added web strip command to audit logs

File last commit:

r1699:5efb37e3 default
r1699:5efb37e3 default
Show More
strip.py
117 lines | 4.2 KiB | text/x-python | PythonLexer
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 # -*- coding: utf-8 -*-
strip: cleanup code.
r1698 # Copyright (C) 2017-2017 RhodeCode GmbH
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 #
# 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
from pyramid.view import view_config
from rhodecode.apps._base import RepoAppView
audit-logs: added web strip command to audit logs
r1699 from rhodecode.lib import audit_logger
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator,
NotAnonymous)
strip: cleanup code.
r1698 from rhodecode.lib.ext_json import json
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587
log = logging.getLogger(__name__)
class StripView(RepoAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
# TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead
c.repo_info = self.db_repo
self._register_global_c(c)
return c
@LoginRequired()
@NotAnonymous()
@HasRepoPermissionAnyDecorator('repository.admin')
@view_config(
route_name='strip', request_method='GET',
renderer='rhodecode:templates/admin/repos/repo_edit.mako')
def strip(self):
c = self.load_default_context()
c.active = 'strip'
c.strip_limit = 10
return self._get_template_context(c)
@LoginRequired()
@NotAnonymous()
@HasRepoPermissionAnyDecorator('repository.admin')
@view_config(
route_name='strip_check', request_method='POST',
strip: cleanup code.
r1698 renderer='json', xhr=True)
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 def strip_check(self):
from rhodecode.lib.vcs.backends.base import EmptyCommit
data = {}
rp = self.request.POST
for i in range(1, 11):
strip: cleanup code.
r1698 chset = 'changeset_id-%d' % (i,)
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 check = rp.get(chset)
if check:
data[i] = self.db_repo.get_changeset(rp[chset])
if isinstance(data[i], EmptyCommit):
data[i] = {'rev': None, 'commit': rp[chset]}
else:
strip: cleanup code.
r1698 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch,
'author': data[i].author,
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 'comment': data[i].message}
else:
break
return data
@LoginRequired()
@NotAnonymous()
@HasRepoPermissionAnyDecorator('repository.admin')
@view_config(
route_name='strip_execute', request_method='POST',
strip: cleanup code.
r1698 renderer='json', xhr=True)
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 def strip_execute(self):
from rhodecode.model.scm import ScmModel
c = self.load_default_context()
user = self._rhodecode_user
rp = self.request.POST
data = {}
for idx in rp:
commit = json.loads(rp[idx])
strip: cleanup code.
r1698 # If someone put two times the same branch
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 if commit['branch'] in data.keys():
continue
try:
strip: cleanup code.
r1698 ScmModel().strip(
repo=c.repo_info,
commit_id=commit['rev'], branch=commit['branch'])
log.info('Stripped commit %s from repo `%s` by %s' % (
commit['rev'], c.repo_info.repo_name, user))
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 data[commit['rev']] = True
audit-logs: added web strip command to audit logs
r1699
audit_logger.store(
action='repo.commit.strip',
action_data={'commit_id': commit['rev']},
repo=self.db_repo,
user=self._rhodecode_user, commit=True)
strip: cleanup code.
r1698 except Exception as e:
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 data[commit['rev']] = False
strip: cleanup code.
r1698 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (
commit['rev'], self.db_repo_name, user, e.message))
Bartłomiej Wołyńczyk
strip: added functionality to stip choosen commits on repo settings
r1587 return data