annotate rhodecode/controllers/feed.py @ 862:4bdd0bf1b1f4 beta

security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 Dec 2010 16:59:52 +0100
parents fd2ea6ceadc8
children 07a6e8c65526 a3b2b4b4e440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
1 # -*- coding: utf-8 -*-
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
2 """
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
3 rhodecode.controllers.feed
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
5
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
6 Feed controller for rhodecode
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
7
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
8 :created_on: Apr 23, 2010
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
9 :author: marcink
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
11 :license: GPLv3, see COPYING for more details.
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
12 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
13 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
14 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
15 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
16 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
17 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
18 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
21 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
22 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
23 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
24 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
26 # MA 02110-1301, USA.
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
27
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
28 import logging
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
29
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
30 from pylons import url, response
862
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
31
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
32 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
33 from rhodecode.lib.base import BaseController
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
34 from rhodecode.model.scm import ScmModel
862
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
35
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 207
diff changeset
36 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
37
205
66b20f525750 Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 log = logging.getLogger(__name__)
66b20f525750 Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
66b20f525750 Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 class FeedController(BaseController):
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
41
862
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
42 @LoginRequired()
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
43 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
4bdd0bf1b1f4 security bugfix: protected feeds, from unauthorized access, even without this, the feeds would crash and were unreadable, But proper way of securing it is with the secure decarators.
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
44 'repository.admin')
205
66b20f525750 Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 def __before__(self):
66b20f525750 Added feed controllers, urls,and changed index page to use them.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 super(FeedController, self).__before__()
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
47 #common values for feeds
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
48 self.description = 'Changes on %s repository'
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
49 self.title = "%s feed"
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
50 self.language = 'en-us'
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
51 self.ttl = "5"
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
52 self.feed_nr = 10
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
53
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
54 def atom(self, repo_name):
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
55 """Produce an atom-1.0 feed via feedgenerator module"""
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
56 feed = Atom1Feed(title=self.title % repo_name,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
57 link=url('summary_home', repo_name=repo_name, qualified=True),
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
58 description=self.description % repo_name,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
59 language=self.language,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
60 ttl=self.ttl)
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
61
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
62 changesets = ScmModel().get_repo(repo_name)
507
f420e86db893 drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
63
f420e86db893 drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
64 for cs in changesets[:self.feed_nr]:
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
65 feed.add_item(title=cs.message,
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 207
diff changeset
66 link=url('changeset_home', repo_name=repo_name,
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
67 revision=cs.raw_id, qualified=True),
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 207
diff changeset
68 description=str(cs.date))
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
69
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
70 response.content_type = feed.mime_type
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
71 return feed.writeString('utf-8')
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
72
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
73
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
74 def rss(self, repo_name):
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
75 """Produce an rss2 feed via feedgenerator module"""
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
76 feed = Rss201rev2Feed(title=self.title % repo_name,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
77 link=url('summary_home', repo_name=repo_name, qualified=True),
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
78 description=self.description % repo_name,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
79 language=self.language,
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
80 ttl=self.ttl)
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
81
691
7486da5f0628 Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
82 changesets = ScmModel().get_repo(repo_name)
507
f420e86db893 drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
83 for cs in changesets[:self.feed_nr]:
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
84 feed.add_item(title=cs.message,
507
f420e86db893 drastic speed improvment in feed generation (was using old method)
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
85 link=url('changeset_home', repo_name=repo_name,
636
ffd07396d315 Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
86 revision=cs.raw_id, qualified=True),
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
87 description=str(cs.date))
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
88
207
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
89 response.content_type = feed.mime_type
8bdec09436cb bumped version to 0.7.1 added atom and rss feeds. Moved https Fixud middleware before error middleware to proper generate debug page (static imports)
Marcin Kuzminski <marcin@python-works.com>
parents: 205
diff changeset
90 return feed.writeString('utf-8')