Show More
@@ -1,110 +1,108 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | |
|
23 | 23 | from pyramid.view import view_config |
|
24 | 24 | from pyramid.httpexceptions import HTTPFound, HTTPNotFound |
|
25 | 25 | |
|
26 | 26 | from rhodecode.apps._base import BaseAppView |
|
27 | 27 | from rhodecode.lib import helpers as h |
|
28 | 28 | from rhodecode.lib.auth import (NotAnonymous, HasRepoPermissionAny) |
|
29 | 29 | from rhodecode.model.db import Repository |
|
30 | 30 | |
|
31 | 31 | log = logging.getLogger(__name__) |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | class RepoChecksView(BaseAppView): |
|
35 | 35 | def load_default_context(self): |
|
36 | 36 | c = self._get_local_tmpl_context() |
|
37 | 37 | self._register_global_c(c) |
|
38 | 38 | return c |
|
39 | 39 | |
|
40 | 40 | @NotAnonymous() |
|
41 | 41 | @view_config( |
|
42 | 42 | route_name='repo_creating', request_method='GET', |
|
43 | 43 | renderer='rhodecode:templates/admin/repos/repo_creating.mako') |
|
44 | 44 | def repo_creating(self): |
|
45 | 45 | c = self.load_default_context() |
|
46 | 46 | |
|
47 | 47 | repo_name = self.request.matchdict['repo_name'] |
|
48 | 48 | db_repo = Repository.get_by_repo_name(repo_name) |
|
49 | if not db_repo: | |
|
50 | raise HTTPNotFound() | |
|
51 | 49 | |
|
52 | 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 | 52 | # re-check permissions before redirecting to prevent resource |
|
55 | 53 | # discovery by checking the 302 code |
|
56 | 54 | perm_set = ['repository.read', 'repository.write', 'repository.admin'] |
|
57 | 55 | has_perm = HasRepoPermissionAny(*perm_set)( |
|
58 | 56 | db_repo.repo_name, 'Repo Creating check') |
|
59 | 57 | if not has_perm: |
|
60 | 58 | raise HTTPNotFound() |
|
61 | 59 | |
|
62 | 60 | raise HTTPFound(h.route_path( |
|
63 | 61 | 'repo_summary', repo_name=db_repo.repo_name)) |
|
64 | 62 | |
|
65 | 63 | c.task_id = self.request.GET.get('task_id') |
|
66 | 64 | c.repo_name = repo_name |
|
67 | 65 | |
|
68 | 66 | return self._get_template_context(c) |
|
69 | 67 | |
|
70 | 68 | @NotAnonymous() |
|
71 | 69 | @view_config( |
|
72 | 70 | route_name='repo_creating_check', request_method='GET', |
|
73 | 71 | renderer='json_ext') |
|
74 | 72 | def repo_creating_check(self): |
|
75 | 73 | _ = self.request.translate |
|
76 | 74 | task_id = self.request.GET.get('task_id') |
|
77 | 75 | self.load_default_context() |
|
78 | 76 | |
|
79 | 77 | repo_name = self.request.matchdict['repo_name'] |
|
80 | 78 | |
|
81 | 79 | if task_id and task_id not in ['None']: |
|
82 | 80 | import rhodecode |
|
83 | 81 | from celery.result import AsyncResult |
|
84 | 82 | if rhodecode.CELERY_ENABLED: |
|
85 | 83 | task = AsyncResult(task_id) |
|
86 | 84 | if task.failed(): |
|
87 | 85 | msg = self._log_creation_exception(task.result, repo_name) |
|
88 | 86 | h.flash(msg, category='error') |
|
89 | 87 | raise HTTPFound(h.route_path('home'), code=501) |
|
90 | 88 | |
|
91 | 89 | db_repo = Repository.get_by_repo_name(repo_name) |
|
92 | 90 | if db_repo and db_repo.repo_state == Repository.STATE_CREATED: |
|
93 | 91 | if db_repo.clone_uri: |
|
94 | 92 | clone_uri = db_repo.clone_uri_hidden |
|
95 | 93 | h.flash(_('Created repository %s from %s') |
|
96 | 94 | % (db_repo.repo_name, clone_uri), category='success') |
|
97 | 95 | else: |
|
98 | 96 | repo_url = h.link_to( |
|
99 | 97 | db_repo.repo_name, |
|
100 | 98 | h.route_path('repo_summary', repo_name=db_repo.repo_name)) |
|
101 | 99 | fork = db_repo.fork |
|
102 | 100 | if fork: |
|
103 | 101 | fork_name = fork.repo_name |
|
104 | 102 | h.flash(h.literal(_('Forked repository %s as %s') |
|
105 | 103 | % (fork_name, repo_url)), category='success') |
|
106 | 104 | else: |
|
107 | 105 | h.flash(h.literal(_('Created repository %s') % repo_url), |
|
108 | 106 | category='success') |
|
109 | 107 | return {'result': True} |
|
110 | 108 | return {'result': False} |
General Comments 0
You need to be logged in to leave comments.
Login now