##// END OF EJS Templates
repo-strip: rename file to adjust same naming as other views....
marcink -
r1723:6dac428a default
parent child Browse files
Show More
@@ -1,117 +1,114 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2017-2017 RhodeCode GmbH
3 # Copyright (C) 2017-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 from pyramid.view import view_config
22 from pyramid.view import view_config
23
23
24 from rhodecode.apps._base import RepoAppView
24 from rhodecode.apps._base import RepoAppView
25 from rhodecode.lib import audit_logger
25 from rhodecode.lib import audit_logger
26 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator,
26 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator,
27 NotAnonymous)
27 NotAnonymous)
28 from rhodecode.lib.ext_json import json
28 from rhodecode.lib.ext_json import json
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32
32
33 class StripView(RepoAppView):
33 class StripView(RepoAppView):
34 def load_default_context(self):
34 def load_default_context(self):
35 c = self._get_local_tmpl_context()
35 c = self._get_local_tmpl_context()
36
36
37 # TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead
37 # TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead
38 c.repo_info = self.db_repo
38 c.repo_info = self.db_repo
39
39
40 self._register_global_c(c)
40 self._register_global_c(c)
41 return c
41 return c
42
42
43 @LoginRequired()
43 @LoginRequired()
44 @NotAnonymous()
45 @HasRepoPermissionAnyDecorator('repository.admin')
44 @HasRepoPermissionAnyDecorator('repository.admin')
46 @view_config(
45 @view_config(
47 route_name='strip', request_method='GET',
46 route_name='strip', request_method='GET',
48 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
47 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
49 def strip(self):
48 def strip(self):
50 c = self.load_default_context()
49 c = self.load_default_context()
51 c.active = 'strip'
50 c.active = 'strip'
52 c.strip_limit = 10
51 c.strip_limit = 10
53
52
54 return self._get_template_context(c)
53 return self._get_template_context(c)
55
54
56 @LoginRequired()
55 @LoginRequired()
57 @NotAnonymous()
58 @HasRepoPermissionAnyDecorator('repository.admin')
56 @HasRepoPermissionAnyDecorator('repository.admin')
59 @view_config(
57 @view_config(
60 route_name='strip_check', request_method='POST',
58 route_name='strip_check', request_method='POST',
61 renderer='json', xhr=True)
59 renderer='json', xhr=True)
62 def strip_check(self):
60 def strip_check(self):
63 from rhodecode.lib.vcs.backends.base import EmptyCommit
61 from rhodecode.lib.vcs.backends.base import EmptyCommit
64 data = {}
62 data = {}
65 rp = self.request.POST
63 rp = self.request.POST
66 for i in range(1, 11):
64 for i in range(1, 11):
67 chset = 'changeset_id-%d' % (i,)
65 chset = 'changeset_id-%d' % (i,)
68 check = rp.get(chset)
66 check = rp.get(chset)
69 if check:
67 if check:
70 data[i] = self.db_repo.get_changeset(rp[chset])
68 data[i] = self.db_repo.get_changeset(rp[chset])
71 if isinstance(data[i], EmptyCommit):
69 if isinstance(data[i], EmptyCommit):
72 data[i] = {'rev': None, 'commit': rp[chset]}
70 data[i] = {'rev': None, 'commit': rp[chset]}
73 else:
71 else:
74 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch,
72 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch,
75 'author': data[i].author,
73 'author': data[i].author,
76 'comment': data[i].message}
74 'comment': data[i].message}
77 else:
75 else:
78 break
76 break
79 return data
77 return data
80
78
81 @LoginRequired()
79 @LoginRequired()
82 @NotAnonymous()
83 @HasRepoPermissionAnyDecorator('repository.admin')
80 @HasRepoPermissionAnyDecorator('repository.admin')
84 @view_config(
81 @view_config(
85 route_name='strip_execute', request_method='POST',
82 route_name='strip_execute', request_method='POST',
86 renderer='json', xhr=True)
83 renderer='json', xhr=True)
87 def strip_execute(self):
84 def strip_execute(self):
88 from rhodecode.model.scm import ScmModel
85 from rhodecode.model.scm import ScmModel
89
86
90 c = self.load_default_context()
87 c = self.load_default_context()
91 user = self._rhodecode_user
88 user = self._rhodecode_user
92 rp = self.request.POST
89 rp = self.request.POST
93 data = {}
90 data = {}
94 for idx in rp:
91 for idx in rp:
95 commit = json.loads(rp[idx])
92 commit = json.loads(rp[idx])
96 # If someone put two times the same branch
93 # If someone put two times the same branch
97 if commit['branch'] in data.keys():
94 if commit['branch'] in data.keys():
98 continue
95 continue
99 try:
96 try:
100 ScmModel().strip(
97 ScmModel().strip(
101 repo=c.repo_info,
98 repo=c.repo_info,
102 commit_id=commit['rev'], branch=commit['branch'])
99 commit_id=commit['rev'], branch=commit['branch'])
103 log.info('Stripped commit %s from repo `%s` by %s' % (
100 log.info('Stripped commit %s from repo `%s` by %s' % (
104 commit['rev'], c.repo_info.repo_name, user))
101 commit['rev'], c.repo_info.repo_name, user))
105 data[commit['rev']] = True
102 data[commit['rev']] = True
106
103
107 audit_logger.store(
104 audit_logger.store(
108 action='repo.commit.strip',
105 action='repo.commit.strip',
109 action_data={'commit_id': commit['rev']},
106 action_data={'commit_id': commit['rev']},
110 repo=self.db_repo,
107 repo=self.db_repo,
111 user=self._rhodecode_user, commit=True)
108 user=self._rhodecode_user, commit=True)
112
109
113 except Exception as e:
110 except Exception as e:
114 data[commit['rev']] = False
111 data[commit['rev']] = False
115 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (
112 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (
116 commit['rev'], self.db_repo_name, user, e.message))
113 commit['rev'], self.db_repo_name, user, e.message))
117 return data
114 return data
General Comments 0
You need to be logged in to leave comments. Login now