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