Show More
@@ -1,97 +1,98 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | rhodecode.controllers.journal |
|
4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 | 5 | |
|
6 | 6 | Journal controller for pylons |
|
7 | 7 | |
|
8 | 8 | :created_on: Nov 21, 2010 |
|
9 | 9 | :author: marcink |
|
10 | 10 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
11 | 11 | :license: GPLv3, see COPYING for more details. |
|
12 | 12 | """ |
|
13 | 13 | # This program is free software; you can redistribute it and/or |
|
14 | 14 | # modify it under the terms of the GNU General Public License |
|
15 | 15 | # as published by the Free Software Foundation; version 2 |
|
16 | 16 | # of the License or (at your opinion) any later version of the license. |
|
17 | 17 | # |
|
18 | 18 | # This program is distributed in the hope that it will be useful, |
|
19 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 | 21 | # GNU General Public License for more details. |
|
22 | 22 | # |
|
23 | 23 | # You should have received a copy of the GNU General Public License |
|
24 | 24 | # along with this program; if not, write to the Free Software |
|
25 | 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
26 | 26 | # MA 02110-1301, USA. |
|
27 | 27 | |
|
28 | 28 | import logging |
|
29 | 29 | from sqlalchemy import or_ |
|
30 | 30 | |
|
31 | 31 | from pylons import request, response, session, tmpl_context as c, url |
|
32 | 32 | |
|
33 | 33 | from rhodecode.lib.auth import LoginRequired, NotAnonymous |
|
34 | 34 | from rhodecode.lib.base import BaseController, render |
|
35 | 35 | from rhodecode.lib.helpers import get_token |
|
36 | 36 | from rhodecode.model.db import UserLog, UserFollowing |
|
37 | 37 | from rhodecode.model.scm import ScmModel |
|
38 | 38 | |
|
39 | 39 | from paste.httpexceptions import HTTPInternalServerError |
|
40 | 40 | |
|
41 | 41 | log = logging.getLogger(__name__) |
|
42 | 42 | |
|
43 | 43 | class JournalController(BaseController): |
|
44 | 44 | |
|
45 | 45 | |
|
46 | 46 | @LoginRequired() |
|
47 | 47 | @NotAnonymous() |
|
48 | 48 | def __before__(self): |
|
49 | 49 | super(JournalController, self).__before__() |
|
50 | 50 | |
|
51 | 51 | def index(self): |
|
52 | 52 | # Return a rendered template |
|
53 | 53 | |
|
54 | 54 | c.following = self.sa.query(UserFollowing)\ |
|
55 | 55 | .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all() |
|
56 | 56 | |
|
57 | 57 | repo_ids = [x.follows_repository.repo_id for x in c.following |
|
58 | 58 | if x.follows_repository is not None] |
|
59 | 59 | user_ids = [x.follows_user.user_id for x in c.following |
|
60 | 60 | if x.follows_user is not None] |
|
61 | 61 | |
|
62 | 62 | c.journal = self.sa.query(UserLog)\ |
|
63 | 63 | .filter(or_( |
|
64 | 64 | UserLog.repository_id.in_(repo_ids), |
|
65 | 65 | UserLog.user_id.in_(user_ids), |
|
66 | 66 | ))\ |
|
67 | 67 | .order_by(UserLog.action_date.desc())\ |
|
68 | 68 | .limit(20)\ |
|
69 | 69 | .all() |
|
70 | 70 | return render('/journal.html') |
|
71 | 71 | |
|
72 | 72 | def toggle_following(self): |
|
73 | ||
|
74 |
|
|
|
73 | cur_token = request.POST.get('auth_token') | |
|
74 | token = get_token() | |
|
75 | if cur_token == token: | |
|
75 | 76 | scm_model = ScmModel() |
|
76 | 77 | |
|
77 | 78 | user_id = request.POST.get('follows_user_id') |
|
78 | 79 | if user_id: |
|
79 | 80 | try: |
|
80 | 81 | scm_model.toggle_following_user(user_id, |
|
81 | 82 | c.rhodecode_user.user_id) |
|
82 | 83 | return 'ok' |
|
83 | 84 | except: |
|
84 | 85 | raise HTTPInternalServerError() |
|
85 | 86 | |
|
86 | 87 | repo_id = request.POST.get('follows_repo_id') |
|
87 | 88 | if repo_id: |
|
88 | 89 | try: |
|
89 | 90 | scm_model.toggle_following_repo(repo_id, |
|
90 | 91 | c.rhodecode_user.user_id) |
|
91 | 92 | return 'ok' |
|
92 | 93 | except: |
|
93 | 94 | raise HTTPInternalServerError() |
|
94 | 95 | |
|
95 | 96 | |
|
96 | ||
|
97 | log.debug('token mismatch %s vs %s', cur_token, token) | |
|
97 | 98 | raise HTTPInternalServerError() |
@@ -1,11 +1,15 b'' | |||
|
1 | 1 | from rhodecode.tests import * |
|
2 | 2 | |
|
3 | 3 | class TestHomeController(TestController): |
|
4 | 4 | |
|
5 | 5 | def test_index(self): |
|
6 | 6 | self.log_user() |
|
7 | 7 | response = self.app.get(url(controller='home', action='index')) |
|
8 | 8 | #if global permission is set |
|
9 |
assert 'ADD NEW REPOSITORY' in response.body, ' |
|
|
9 | assert 'ADD NEW REPOSITORY' in response.body, 'No Button for add new repository' | |
|
10 | 10 | assert 'href="/%s/summary"' % HG_REPO in response.body, ' mising repository in list' |
|
11 | 11 | # Test response... |
|
12 | ||
|
13 | assert """<img class="icon" title="Mercurial repository" alt="Mercurial repository" src="/images/icons/hgicon.png"/>""" in response.body, 'wrong info about type of repositry' | |
|
14 | assert """<img class="icon" title="public repository" alt="public repository" src="/images/icons/lock_open.png"/>""" in response.body, 'wrong info about repository availabilty' | |
|
15 | assert """<a class="tooltip" href="/vcs_test_hg/changeset/27cd5cce30c96924232dffcd24178a07ffeb5dfc" tooltip_title="merge">r173:27cd5cce30c9</a>""" in response.body, 'no info about tooltip' |
@@ -1,7 +1,47 b'' | |||
|
1 | 1 | from rhodecode.tests import * |
|
2 | from rhodecode.model.db import UserFollowing, User, Repository | |
|
3 | from rhodecode.lib.helpers import get_token | |
|
2 | 4 | |
|
3 | 5 | class TestJournalController(TestController): |
|
4 | 6 | |
|
5 | 7 | def test_index(self): |
|
8 | self.log_user() | |
|
6 | 9 | response = self.app.get(url(controller='journal', action='index')) |
|
7 | 10 | # Test response... |
|
11 | assert """<div class="currently_following"> | |
|
12 | ||
|
13 | ||
|
14 | <img class="icon" title="public repository" alt="public repository" src="/images/icons/lock_open.png"/> | |
|
15 | ||
|
16 | <a href="/vcs_test_hg/summary">vcs_test_hg</a> | |
|
17 | ||
|
18 | </div>""" in response.body, 'following repo list' | |
|
19 | ||
|
20 | ||
|
21 | ||
|
22 | def test_stop_following_repository(self): | |
|
23 | session = self.log_user() | |
|
24 | # usr = self.sa.query(User).filter(User.username == 'test_admin').one() | |
|
25 | # repo = self.sa.query(Repository).filter(Repository.repo_name == HG_REPO).one() | |
|
26 | # | |
|
27 | # followings = self.sa.query(UserFollowing)\ | |
|
28 | # .filter(UserFollowing.user == usr)\ | |
|
29 | # .filter(UserFollowing.follows_repository == repo).all() | |
|
30 | # | |
|
31 | # assert len(followings) == 1, 'Not following any repository' | |
|
32 | # | |
|
33 | # response = self.app.post(url(controller='journal', | |
|
34 | # action='toggle_following'), | |
|
35 | # {'auth_token':get_token(session), | |
|
36 | # 'follows_repo_id':repo.repo_id}) | |
|
37 | ||
|
38 | def test_start_following_repository(self): | |
|
39 | self.log_user() | |
|
40 | response = self.app.get(url(controller='journal', action='index'),) | |
|
41 | ||
|
42 | ||
|
43 | def __add_repo(self): | |
|
44 | pass | |
|
45 | ||
|
46 | def __remove_repo(self): | |
|
47 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now