Show More
@@ -1,110 +1,108 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2011-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2011-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 |
|
22 | |||
23 | from pyramid.view import view_config |
|
23 | from pyramid.view import view_config | |
24 | from pyramid.httpexceptions import HTTPFound, HTTPNotFound |
|
24 | from pyramid.httpexceptions import HTTPFound, HTTPNotFound | |
25 |
|
25 | |||
26 | from rhodecode.apps._base import BaseAppView |
|
26 | from rhodecode.apps._base import BaseAppView | |
27 | from rhodecode.lib import helpers as h |
|
27 | from rhodecode.lib import helpers as h | |
28 | from rhodecode.lib.auth import (NotAnonymous, HasRepoPermissionAny) |
|
28 | from rhodecode.lib.auth import (NotAnonymous, HasRepoPermissionAny) | |
29 | from rhodecode.model.db import Repository |
|
29 | from rhodecode.model.db import Repository | |
30 |
|
30 | |||
31 | log = logging.getLogger(__name__) |
|
31 | log = logging.getLogger(__name__) | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | class RepoChecksView(BaseAppView): |
|
34 | class RepoChecksView(BaseAppView): | |
35 | def load_default_context(self): |
|
35 | def load_default_context(self): | |
36 | c = self._get_local_tmpl_context() |
|
36 | c = self._get_local_tmpl_context() | |
37 | self._register_global_c(c) |
|
37 | self._register_global_c(c) | |
38 | return c |
|
38 | return c | |
39 |
|
39 | |||
40 | @NotAnonymous() |
|
40 | @NotAnonymous() | |
41 | @view_config( |
|
41 | @view_config( | |
42 | route_name='repo_creating', request_method='GET', |
|
42 | route_name='repo_creating', request_method='GET', | |
43 | renderer='rhodecode:templates/admin/repos/repo_creating.mako') |
|
43 | renderer='rhodecode:templates/admin/repos/repo_creating.mako') | |
44 | def repo_creating(self): |
|
44 | def repo_creating(self): | |
45 | c = self.load_default_context() |
|
45 | c = self.load_default_context() | |
46 |
|
46 | |||
47 | repo_name = self.request.matchdict['repo_name'] |
|
47 | repo_name = self.request.matchdict['repo_name'] | |
48 | db_repo = Repository.get_by_repo_name(repo_name) |
|
48 | db_repo = Repository.get_by_repo_name(repo_name) | |
49 | if not db_repo: |
|
|||
50 | raise HTTPNotFound() |
|
|||
51 |
|
49 | |||
52 | # check if maybe repo is already created |
|
50 | # check if maybe repo is already created | |
53 | if db_repo.repo_state in [Repository.STATE_CREATED]: |
|
51 | if db_repo and db_repo.repo_state in [Repository.STATE_CREATED]: | |
54 | # re-check permissions before redirecting to prevent resource |
|
52 | # re-check permissions before redirecting to prevent resource | |
55 | # discovery by checking the 302 code |
|
53 | # discovery by checking the 302 code | |
56 | perm_set = ['repository.read', 'repository.write', 'repository.admin'] |
|
54 | perm_set = ['repository.read', 'repository.write', 'repository.admin'] | |
57 | has_perm = HasRepoPermissionAny(*perm_set)( |
|
55 | has_perm = HasRepoPermissionAny(*perm_set)( | |
58 | db_repo.repo_name, 'Repo Creating check') |
|
56 | db_repo.repo_name, 'Repo Creating check') | |
59 | if not has_perm: |
|
57 | if not has_perm: | |
60 | raise HTTPNotFound() |
|
58 | raise HTTPNotFound() | |
61 |
|
59 | |||
62 | raise HTTPFound(h.route_path( |
|
60 | raise HTTPFound(h.route_path( | |
63 | 'repo_summary', repo_name=db_repo.repo_name)) |
|
61 | 'repo_summary', repo_name=db_repo.repo_name)) | |
64 |
|
62 | |||
65 | c.task_id = self.request.GET.get('task_id') |
|
63 | c.task_id = self.request.GET.get('task_id') | |
66 | c.repo_name = repo_name |
|
64 | c.repo_name = repo_name | |
67 |
|
65 | |||
68 | return self._get_template_context(c) |
|
66 | return self._get_template_context(c) | |
69 |
|
67 | |||
70 | @NotAnonymous() |
|
68 | @NotAnonymous() | |
71 | @view_config( |
|
69 | @view_config( | |
72 | route_name='repo_creating_check', request_method='GET', |
|
70 | route_name='repo_creating_check', request_method='GET', | |
73 | renderer='json_ext') |
|
71 | renderer='json_ext') | |
74 | def repo_creating_check(self): |
|
72 | def repo_creating_check(self): | |
75 | _ = self.request.translate |
|
73 | _ = self.request.translate | |
76 | task_id = self.request.GET.get('task_id') |
|
74 | task_id = self.request.GET.get('task_id') | |
77 | self.load_default_context() |
|
75 | self.load_default_context() | |
78 |
|
76 | |||
79 | repo_name = self.request.matchdict['repo_name'] |
|
77 | repo_name = self.request.matchdict['repo_name'] | |
80 |
|
78 | |||
81 | if task_id and task_id not in ['None']: |
|
79 | if task_id and task_id not in ['None']: | |
82 | import rhodecode |
|
80 | import rhodecode | |
83 | from celery.result import AsyncResult |
|
81 | from celery.result import AsyncResult | |
84 | if rhodecode.CELERY_ENABLED: |
|
82 | if rhodecode.CELERY_ENABLED: | |
85 | task = AsyncResult(task_id) |
|
83 | task = AsyncResult(task_id) | |
86 | if task.failed(): |
|
84 | if task.failed(): | |
87 | msg = self._log_creation_exception(task.result, repo_name) |
|
85 | msg = self._log_creation_exception(task.result, repo_name) | |
88 | h.flash(msg, category='error') |
|
86 | h.flash(msg, category='error') | |
89 | raise HTTPFound(h.route_path('home'), code=501) |
|
87 | raise HTTPFound(h.route_path('home'), code=501) | |
90 |
|
88 | |||
91 | db_repo = Repository.get_by_repo_name(repo_name) |
|
89 | db_repo = Repository.get_by_repo_name(repo_name) | |
92 | if db_repo and db_repo.repo_state == Repository.STATE_CREATED: |
|
90 | if db_repo and db_repo.repo_state == Repository.STATE_CREATED: | |
93 | if db_repo.clone_uri: |
|
91 | if db_repo.clone_uri: | |
94 | clone_uri = db_repo.clone_uri_hidden |
|
92 | clone_uri = db_repo.clone_uri_hidden | |
95 | h.flash(_('Created repository %s from %s') |
|
93 | h.flash(_('Created repository %s from %s') | |
96 | % (db_repo.repo_name, clone_uri), category='success') |
|
94 | % (db_repo.repo_name, clone_uri), category='success') | |
97 | else: |
|
95 | else: | |
98 | repo_url = h.link_to( |
|
96 | repo_url = h.link_to( | |
99 | db_repo.repo_name, |
|
97 | db_repo.repo_name, | |
100 | h.route_path('repo_summary', repo_name=db_repo.repo_name)) |
|
98 | h.route_path('repo_summary', repo_name=db_repo.repo_name)) | |
101 | fork = db_repo.fork |
|
99 | fork = db_repo.fork | |
102 | if fork: |
|
100 | if fork: | |
103 | fork_name = fork.repo_name |
|
101 | fork_name = fork.repo_name | |
104 | h.flash(h.literal(_('Forked repository %s as %s') |
|
102 | h.flash(h.literal(_('Forked repository %s as %s') | |
105 | % (fork_name, repo_url)), category='success') |
|
103 | % (fork_name, repo_url)), category='success') | |
106 | else: |
|
104 | else: | |
107 | h.flash(h.literal(_('Created repository %s') % repo_url), |
|
105 | h.flash(h.literal(_('Created repository %s') % repo_url), | |
108 | category='success') |
|
106 | category='success') | |
109 | return {'result': True} |
|
107 | return {'result': True} | |
110 | return {'result': False} |
|
108 | return {'result': False} |
General Comments 0
You need to be logged in to leave comments.
Login now