Show More
@@ -1,103 +1,109 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2016-2019 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2019 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 re |
|
21 | import re | |
22 | import logging |
|
22 | import logging | |
23 | import collections |
|
23 | import collections | |
24 |
|
24 | |||
|
25 | from pyramid.httpexceptions import HTTPNotFound | |||
25 | from pyramid.view import view_config |
|
26 | from pyramid.view import view_config | |
26 |
|
27 | |||
27 | from rhodecode.apps._base import BaseAppView, RepoAppView |
|
28 | from rhodecode.apps._base import BaseAppView, RepoAppView | |
28 | from rhodecode.lib import helpers as h |
|
29 | from rhodecode.lib import helpers as h | |
29 | from rhodecode.lib.auth import ( |
|
30 | from rhodecode.lib.auth import ( | |
30 | LoginRequired, NotAnonymous, HasRepoGroupPermissionAnyDecorator, CSRFRequired, |
|
31 | LoginRequired, NotAnonymous, HasRepoGroupPermissionAnyDecorator, CSRFRequired, | |
31 | HasRepoPermissionAnyDecorator) |
|
32 | HasRepoPermissionAnyDecorator) | |
32 | from rhodecode.lib.codeblocks import filenode_as_lines_tokens |
|
33 | from rhodecode.lib.codeblocks import filenode_as_lines_tokens | |
33 | from rhodecode.lib.index import searcher_from_config |
|
34 | from rhodecode.lib.index import searcher_from_config | |
34 | from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int |
|
35 | from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int | |
35 | from rhodecode.lib.ext_json import json |
|
36 | from rhodecode.lib.ext_json import json | |
|
37 | from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError | |||
36 | from rhodecode.lib.vcs.nodes import FileNode |
|
38 | from rhodecode.lib.vcs.nodes import FileNode | |
37 | from rhodecode.model.db import ( |
|
39 | from rhodecode.model.db import ( | |
38 | func, true, or_, case, in_filter_generator, Repository, RepoGroup, User, UserGroup, PullRequest) |
|
40 | func, true, or_, case, in_filter_generator, Repository, RepoGroup, User, UserGroup, PullRequest) | |
39 | from rhodecode.model.repo import RepoModel |
|
41 | from rhodecode.model.repo import RepoModel | |
40 | from rhodecode.model.repo_group import RepoGroupModel |
|
42 | from rhodecode.model.repo_group import RepoGroupModel | |
41 | from rhodecode.model.scm import RepoGroupList, RepoList |
|
43 | from rhodecode.model.scm import RepoGroupList, RepoList | |
42 | from rhodecode.model.user import UserModel |
|
44 | from rhodecode.model.user import UserModel | |
43 | from rhodecode.model.user_group import UserGroupModel |
|
45 | from rhodecode.model.user_group import UserGroupModel | |
44 |
|
46 | |||
45 | log = logging.getLogger(__name__) |
|
47 | log = logging.getLogger(__name__) | |
46 |
|
48 | |||
47 |
|
49 | |||
48 | class HoverCardsView(BaseAppView): |
|
50 | class HoverCardsView(BaseAppView): | |
49 |
|
51 | |||
50 | def load_default_context(self): |
|
52 | def load_default_context(self): | |
51 | c = self._get_local_tmpl_context() |
|
53 | c = self._get_local_tmpl_context() | |
52 | return c |
|
54 | return c | |
53 |
|
55 | |||
54 | @LoginRequired() |
|
56 | @LoginRequired() | |
55 | @view_config( |
|
57 | @view_config( | |
56 | route_name='hovercard_user', request_method='GET', xhr=True, |
|
58 | route_name='hovercard_user', request_method='GET', xhr=True, | |
57 | renderer='rhodecode:templates/hovercards/hovercard_user.mako') |
|
59 | renderer='rhodecode:templates/hovercards/hovercard_user.mako') | |
58 | def hovercard_user(self): |
|
60 | def hovercard_user(self): | |
59 | c = self.load_default_context() |
|
61 | c = self.load_default_context() | |
60 | user_id = self.request.matchdict['user_id'] |
|
62 | user_id = self.request.matchdict['user_id'] | |
61 | c.user = User.get_or_404(user_id) |
|
63 | c.user = User.get_or_404(user_id) | |
62 | return self._get_template_context(c) |
|
64 | return self._get_template_context(c) | |
63 |
|
65 | |||
64 | @LoginRequired() |
|
66 | @LoginRequired() | |
65 | @view_config( |
|
67 | @view_config( | |
66 | route_name='hovercard_user_group', request_method='GET', xhr=True, |
|
68 | route_name='hovercard_user_group', request_method='GET', xhr=True, | |
67 | renderer='rhodecode:templates/hovercards/hovercard_user_group.mako') |
|
69 | renderer='rhodecode:templates/hovercards/hovercard_user_group.mako') | |
68 | def hovercard_user_group(self): |
|
70 | def hovercard_user_group(self): | |
69 | c = self.load_default_context() |
|
71 | c = self.load_default_context() | |
70 | user_group_id = self.request.matchdict['user_group_id'] |
|
72 | user_group_id = self.request.matchdict['user_group_id'] | |
71 | c.user_group = UserGroup.get_or_404(user_group_id) |
|
73 | c.user_group = UserGroup.get_or_404(user_group_id) | |
72 | return self._get_template_context(c) |
|
74 | return self._get_template_context(c) | |
73 |
|
75 | |||
74 | @LoginRequired() |
|
76 | @LoginRequired() | |
75 | @view_config( |
|
77 | @view_config( | |
76 | route_name='hovercard_pull_request', request_method='GET', xhr=True, |
|
78 | route_name='hovercard_pull_request', request_method='GET', xhr=True, | |
77 | renderer='rhodecode:templates/hovercards/hovercard_pull_request.mako') |
|
79 | renderer='rhodecode:templates/hovercards/hovercard_pull_request.mako') | |
78 | def hovercard_pull_request(self): |
|
80 | def hovercard_pull_request(self): | |
79 | c = self.load_default_context() |
|
81 | c = self.load_default_context() | |
80 | c.pull_request = PullRequest.get_or_404( |
|
82 | c.pull_request = PullRequest.get_or_404( | |
81 | self.request.matchdict['pull_request_id']) |
|
83 | self.request.matchdict['pull_request_id']) | |
82 | perms = ['repository.read', 'repository.write', 'repository.admin'] |
|
84 | perms = ['repository.read', 'repository.write', 'repository.admin'] | |
83 | c.can_view_pr = h.HasRepoPermissionAny(*perms)( |
|
85 | c.can_view_pr = h.HasRepoPermissionAny(*perms)( | |
84 | c.pull_request.target_repo.repo_name) |
|
86 | c.pull_request.target_repo.repo_name) | |
85 | return self._get_template_context(c) |
|
87 | return self._get_template_context(c) | |
86 |
|
88 | |||
87 |
|
89 | |||
88 | class HoverCardsRepoView(RepoAppView): |
|
90 | class HoverCardsRepoView(RepoAppView): | |
89 | def load_default_context(self): |
|
91 | def load_default_context(self): | |
90 | c = self._get_local_tmpl_context() |
|
92 | c = self._get_local_tmpl_context() | |
91 | return c |
|
93 | return c | |
92 |
|
94 | |||
93 | @LoginRequired() |
|
95 | @LoginRequired() | |
94 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') |
|
96 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') | |
95 | @view_config( |
|
97 | @view_config( | |
96 | route_name='hovercard_repo_commit', request_method='GET', xhr=True, |
|
98 | route_name='hovercard_repo_commit', request_method='GET', xhr=True, | |
97 | renderer='rhodecode:templates/hovercards/hovercard_repo_commit.mako') |
|
99 | renderer='rhodecode:templates/hovercards/hovercard_repo_commit.mako') | |
98 | def hovercard_repo_commit(self): |
|
100 | def hovercard_repo_commit(self): | |
99 | c = self.load_default_context() |
|
101 | c = self.load_default_context() | |
100 | commit_id = self.request.matchdict['commit_id'] |
|
102 | commit_id = self.request.matchdict['commit_id'] | |
101 | pre_load = ['author', 'branch', 'date', 'message'] |
|
103 | pre_load = ['author', 'branch', 'date', 'message'] | |
102 | c.commit = self.rhodecode_vcs_repo.get_commit(commit_id=commit_id, pre_load=pre_load) |
|
104 | try: | |
|
105 | c.commit = self.rhodecode_vcs_repo.get_commit(commit_id=commit_id, pre_load=pre_load) | |||
|
106 | except CommitDoesNotExistError: | |||
|
107 | raise HTTPNotFound() | |||
|
108 | ||||
103 | return self._get_template_context(c) |
|
109 | return self._get_template_context(c) |
General Comments 0
You need to be logged in to leave comments.
Login now