##// END OF EJS Templates
fixed issue with ldap disabling after initially enabling it
fixed issue with ldap disabling after initially enabling it

File last commit:

r3960:5293d4bb merge default
r3973:7e9494f4 default
Show More
journal.py
379 lines | 14.1 KiB | text/x-python | PythonLexer
updated docs on every controller
r861 # -*- coding: utf-8 -*-
"""
rhodecode.controllers.journal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Journal controller for pylons
source code cleanup: remove trailing white space, normalize file endings
r1203
updated docs on every controller
r861 :created_on: Nov 21, 2010
:author: marcink
2012 copyrights
r1824 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
updated docs on every controller
r861 :license: GPLv3, see COPYING for more details.
"""
fixed license issue #149
r1206 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
implemented user dashboards, and following system.
r734 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
implemented user dashboards, and following system.
r734 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
updated docs on every controller
r861 import logging
#235 forking page repo group selection...
r1722 from itertools import groupby
implemented user dashboards, and following system.
r734
Updated new Journal with users and dates aggregates
r1041 from sqlalchemy import or_
#235 forking page repo group selection...
r1722 from sqlalchemy.orm import joinedload
Use common function for generation of grid data...
r3154 from sqlalchemy.sql.expression import func
#235 forking page repo group selection...
r1722 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
updated docs on every controller
r861
Use webob exception as often as possible
r2242 from webob.exc import HTTPBadRequest
made simple global rss and atom feed
r1088 from pylons import request, tmpl_context as c, response, url
from pylons.i18n.translation import _
fixes for journal, added paging now it's possible to view whole journal...
r995
Unified the paginators for pylons and YUI....
r3776 from rhodecode.controllers.admin.admin import _journal_filter
from rhodecode.model.db import UserLog, UserFollowing, Repository, User
from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
made simple global rss and atom feed
r1088 import rhodecode.lib.helpers as h
Unified the paginators for pylons and YUI....
r3776 from rhodecode.lib.helpers import Page
disabled journal for anonymous users
r793 from rhodecode.lib.auth import LoginRequired, NotAnonymous
implemented user dashboards, and following system.
r734 from rhodecode.lib.base import BaseController, render
fixed issue with public journal rss/atom feeds after journal filter implementation
r3075 from rhodecode.lib.utils2 import safe_int, AttributeDict
Use common function for generation of grid data...
r3154 from rhodecode.lib.compat import json
updated docs on every controller
r861
implemented user dashboards, and following system.
r734 log = logging.getLogger(__name__)
pep8ify
r1212
implemented user dashboards, and following system.
r734 class JournalController(BaseController):
def __before__(self):
super(JournalController, self).__before__()
made simple global rss and atom feed
r1088 self.language = 'en-us'
self.ttl = "5"
self.feed_nr = 20
fixed issue with public journal rss/atom feeds after journal filter implementation
r3075 c.search_term = request.GET.get('filter')
implemented user dashboards, and following system.
r734
auth decorators are not used anymore on __before__...
r3749 def _get_daily_aggregate(self, journal):
groups = []
for k, g in groupby(journal, lambda x: x.action_as_day):
user_group = []
#groupby username if it's a present value, else fallback to journal username
for _, g2 in groupby(list(g), lambda x: x.user.username if x.user else x.username):
l = list(g2)
user_group.append((l[0].user, l))
groups.append((k, user_group,))
return groups
def _get_journal_data(self, following_repos):
repo_ids = [x.follows_repository.repo_id for x in following_repos
if x.follows_repository is not None]
user_ids = [x.follows_user.user_id for x in following_repos
if x.follows_user is not None]
filtering_criterion = None
if repo_ids and user_ids:
filtering_criterion = or_(UserLog.repository_id.in_(repo_ids),
UserLog.user_id.in_(user_ids))
if repo_ids and not user_ids:
filtering_criterion = UserLog.repository_id.in_(repo_ids)
if not repo_ids and user_ids:
filtering_criterion = UserLog.user_id.in_(user_ids)
if filtering_criterion is not None:
journal = self.sa.query(UserLog)\
.options(joinedload(UserLog.user))\
.options(joinedload(UserLog.repository))
#filter
try:
journal = _journal_filter(journal, c.search_term)
except Exception:
# we want this to crash for now
raise
journal = journal.filter(filtering_criterion)\
.order_by(UserLog.action_date.desc())
else:
journal = []
return journal
def _atom_feed(self, repos, public=True):
journal = self._get_journal_data(repos)
if public:
_link = url('public_journal_atom', qualified=True)
_desc = '%s %s %s' % (c.rhodecode_name, _('public journal'),
'atom feed')
else:
_link = url('journal_atom', qualified=True)
_desc = '%s %s %s' % (c.rhodecode_name, _('journal'), 'atom feed')
feed = Atom1Feed(title=_desc,
link=_link,
description=_desc,
language=self.language,
ttl=self.ttl)
for entry in journal[:self.feed_nr]:
user = entry.user
if user is None:
#fix deleted users
user = AttributeDict({'short_contact': entry.username,
'email': '',
'full_contact': ''})
action, action_extra, ico = h.action_parser(entry, feed=True)
title = "%s - %s %s" % (user.short_contact, action(),
entry.repository.repo_name)
desc = action_extra()
_url = None
if entry.repository is not None:
_url = url('changelog_home',
repo_name=entry.repository.repo_name,
qualified=True)
feed.add_item(title=title,
pubdate=entry.action_date,
link=_url or url('', qualified=True),
author_email=user.email,
author_name=user.full_contact,
description=desc)
response.content_type = feed.mime_type
return feed.writeString('utf-8')
def _rss_feed(self, repos, public=True):
journal = self._get_journal_data(repos)
if public:
_link = url('public_journal_atom', qualified=True)
_desc = '%s %s %s' % (c.rhodecode_name, _('public journal'),
'rss feed')
else:
_link = url('journal_atom', qualified=True)
_desc = '%s %s %s' % (c.rhodecode_name, _('journal'), 'rss feed')
feed = Rss201rev2Feed(title=_desc,
link=_link,
description=_desc,
language=self.language,
ttl=self.ttl)
for entry in journal[:self.feed_nr]:
user = entry.user
if user is None:
#fix deleted users
user = AttributeDict({'short_contact': entry.username,
'email': '',
'full_contact': ''})
action, action_extra, ico = h.action_parser(entry, feed=True)
title = "%s - %s %s" % (user.short_contact, action(),
entry.repository.repo_name)
desc = action_extra()
_url = None
if entry.repository is not None:
_url = url('changelog_home',
repo_name=entry.repository.repo_name,
qualified=True)
feed.add_item(title=title,
pubdate=entry.action_date,
link=_url or url('', qualified=True),
author_email=user.email,
author_name=user.full_contact,
description=desc)
response.content_type = feed.mime_type
return feed.writeString('utf-8')
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal...
r1120 @LoginRequired()
implemented public journal for anonymous users, admin can control which repositories...
r1085 @NotAnonymous()
implemented user dashboards, and following system.
r734 def index(self):
# Return a rendered template
usage of request.GET is now more consistent
r3748 p = safe_int(request.GET.get('page', 1), 1)
personal Journal UI...
r1741 c.user = User.get(self.rhodecode_user.user_id)
implemented user dashboards, and following system.
r734 c.following = self.sa.query(UserFollowing)\
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
Optimized queries on journal, and added quick stop following action button in journal
r1000 .options(joinedload(UserFollowing.follows_repository))\
.all()
disabled journal for anonymous users
r793
implemented public journal for anonymous users, admin can control which repositories...
r1085 journal = self._get_journal_data(c.following)
Added grouping by days in journal
r994
final implementation of #210 journal filtering.
r3070 def url_generator(**kw):
return url.current(filter=c.search_term, **kw)
c.journal_pager = Page(journal, page=p, items_per_page=20, url=url_generator)
fixes for journal, added paging now it's possible to view whole journal...
r995 c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
another major codes rewrite:...
r1045
fixes for journal, added paging now it's possible to view whole journal...
r995 c.journal_data = render('journal/journal_data.html')
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
r1421 if request.environ.get('HTTP_X_PARTIAL_XHR'):
fixes for journal, added paging now it's possible to view whole journal...
r995 return c.journal_data
Use common function for generation of grid data...
r3154
repos_list = Session().query(Repository)\
.filter(Repository.user_id ==
self.rhodecode_user.user_id)\
.order_by(func.lower(Repository.repo_name)).all()
repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
admin=True)
#json used to render the grid
c.data = json.dumps(repos_data)
watched_repos_data = []
## watched repos
_render = RepoModel._render_datatable
def quick_menu(repo_name):
return _render('quick_menu', repo_name)
def repo_lnk(name, rtype, private, fork_of):
return _render('repo_name', name, rtype, private, fork_of,
short_name=False, admin=False)
def last_rev(repo_name, cs_cache):
return _render('revision', repo_name, cs_cache.get('revision'),
cs_cache.get('raw_id'), cs_cache.get('author'),
cs_cache.get('message'))
implemented user dashboards, and following system.
r734
Use common function for generation of grid data...
r3154 def desc(desc):
from pylons import tmpl_context as c
if c.visual.stylify_metatags:
return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
else:
return h.urlify_text(h.truncate(desc, 60))
def repo_actions(repo_name):
return _render('repo_actions', repo_name)
def owner_actions(user_id, username):
return _render('user_name', user_id, username)
def toogle_follow(repo_id):
return _render('toggle_follow', repo_id)
for entry in c.following:
repo = entry.follows_repository
cs_cache = repo.changeset_cache
row = {
"menu": quick_menu(repo.repo_name),
"raw_name": repo.repo_name.lower(),
"name": repo_lnk(repo.repo_name, repo.repo_type,
repo.private, repo.fork),
"last_changeset": last_rev(repo.repo_name, cs_cache),
"raw_tip": cs_cache.get('revision'),
"action": toogle_follow(repo.repo_id)
}
watched_repos_data.append(row)
c.watched_data = json.dumps({
"totalRecords": len(c.following),
"startIndex": 0,
"sort": "name",
"dir": "asc",
"records": watched_repos_data
})
return render('journal/journal.html')
Lazy loading on my journal page
r2951
added rss/atom feeds into personalized journal
r2397 @LoginRequired(api_access=True)
Add API access to personal journal, and forbid anonymous access on them
r2410 @NotAnonymous()
added rss/atom feeds into personalized journal
r2397 def journal_atom(self):
"""
Produce an atom-1.0 feed via feedgenerator module
"""
following = self.sa.query(UserFollowing)\
.filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
.options(joinedload(UserFollowing.follows_repository))\
.all()
return self._atom_feed(following, public=False)
@LoginRequired(api_access=True)
Add API access to personal journal, and forbid anonymous access on them
r2410 @NotAnonymous()
added rss/atom feeds into personalized journal
r2397 def journal_rss(self):
"""
Produce an rss feed via feedgenerator module
"""
following = self.sa.query(UserFollowing)\
.filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
.options(joinedload(UserFollowing.follows_repository))\
.all()
return self._rss_feed(following, public=False)
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal...
r1120 @LoginRequired()
implemented public journal for anonymous users, admin can control which repositories...
r1085 @NotAnonymous()
implemented user dashboards, and following system.
r734 def toggle_following(self):
tests update
r875 cur_token = request.POST.get('auth_token')
made simple global rss and atom feed
r1088 token = h.get_token()
tests update
r875 if cur_token == token:
implemented user dashboards, and following system.
r734
user_id = request.POST.get('follows_user_id')
if user_id:
try:
another major codes rewrite:...
r1045 self.scm_model.toggle_following_user(user_id,
pep8ify
r1212 self.rhodecode_user.user_id)
commit less models...
r1749 Session.commit()
implemented user dashboards, and following system.
r734 return 'ok'
Don't catch all exceptions
r3631 except Exception:
Journal Should not return 500 errors on failure, rather better is to return bad request error
r1175 raise HTTPBadRequest()
implemented user dashboards, and following system.
r734
repo_id = request.POST.get('follows_repo_id')
if repo_id:
try:
another major codes rewrite:...
r1045 self.scm_model.toggle_following_repo(repo_id,
pep8ify
r1212 self.rhodecode_user.user_id)
commit less models...
r1749 Session.commit()
implemented user dashboards, and following system.
r734 return 'ok'
Don't catch all exceptions
r3631 except Exception:
Journal Should not return 500 errors on failure, rather better is to return bad request error
r1175 raise HTTPBadRequest()
implemented user dashboards, and following system.
r734
garden...
r1976 log.debug('token mismatch %s vs %s' % (cur_token, token))
Journal Should not return 500 errors on failure, rather better is to return bad request error
r1175 raise HTTPBadRequest()
implemented public journal for anonymous users, admin can control which repositories...
r1085
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal...
r1120 @LoginRequired()
implemented public journal for anonymous users, admin can control which repositories...
r1085 def public_journal(self):
# Return a rendered template
usage of request.GET is now more consistent
r3748 p = safe_int(request.GET.get('page', 1), 1)
implemented public journal for anonymous users, admin can control which repositories...
r1085
c.following = self.sa.query(UserFollowing)\
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
implemented public journal for anonymous users, admin can control which repositories...
r1085 .options(joinedload(UserFollowing.follows_repository))\
.all()
journal = self._get_journal_data(c.following)
c.journal_pager = Page(journal, page=p, items_per_page=20)
c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
c.journal_data = render('journal/journal_data.html')
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
r1421 if request.environ.get('HTTP_X_PARTIAL_XHR'):
implemented public journal for anonymous users, admin can control which repositories...
r1085 return c.journal_data
return render('journal/public_journal.html')
made simple global rss and atom feed
r1088
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal...
r1120 @LoginRequired(api_access=True)
made simple global rss and atom feed
r1088 def public_journal_atom(self):
"""
Produce an atom-1.0 feed via feedgenerator module
"""
c.following = self.sa.query(UserFollowing)\
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
made simple global rss and atom feed
r1088 .options(joinedload(UserFollowing.follows_repository))\
.all()
added rss/atom feeds into personalized journal
r2397 return self._atom_feed(c.following)
made simple global rss and atom feed
r1088
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal...
r1120 @LoginRequired(api_access=True)
made simple global rss and atom feed
r1088 def public_journal_rss(self):
"""
Produce an rss2 feed via feedgenerator module
"""
c.following = self.sa.query(UserFollowing)\
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
made simple global rss and atom feed
r1088 .options(joinedload(UserFollowing.follows_repository))\
.all()
added rss/atom feeds into personalized journal
r2397 return self._rss_feed(c.following)