##// END OF EJS Templates
updated docs on every controller
marcink -
r861:fd2ea6ce beta
parent child Browse files
Show More
@@ -1,104 +1,105 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 package.rhodecode.controllers.admin.ldap_settings
4 ~~~~~~~~~~~~~~
3 rhodecode.controllers.admin.ldap_settings
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 ldap controller for RhodeCode
7
7 8 :created_on: Nov 26, 2010
8 9 :author: marcink
9 10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
10 11 :license: GPLv3, see COPYING for more details.
11 12 """
12 13 # This program is free software; you can redistribute it and/or
13 14 # modify it under the terms of the GNU General Public License
14 15 # as published by the Free Software Foundation; version 2
15 16 # of the License or (at your opinion) any later version of the license.
16 17 #
17 18 # This program is distributed in the hope that it will be useful,
18 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 21 # GNU General Public License for more details.
21 22 #
22 23 # You should have received a copy of the GNU General Public License
23 24 # along with this program; if not, write to the Free Software
24 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 26 # MA 02110-1301, USA.
26 27 import logging
27 28 import formencode
28 29 import traceback
29 30
30 31 from formencode import htmlfill
31 32
32 33 from pylons import request, response, session, tmpl_context as c, url
33 34 from pylons.controllers.util import abort, redirect
34 35 from pylons.i18n.translation import _
35 36
36 37 from rhodecode.lib.base import BaseController, render
37 38 from rhodecode.lib import helpers as h
38 39 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
39 40 from rhodecode.lib.auth_ldap import LdapImportError
40 41 from rhodecode.model.settings import SettingsModel
41 42 from rhodecode.model.forms import LdapSettingsForm
42 43 from sqlalchemy.exc import DatabaseError
43 44
44 45 log = logging.getLogger(__name__)
45 46
46 47
47 48
48 49 class LdapSettingsController(BaseController):
49 50
50 51 @LoginRequired()
51 52 @HasPermissionAllDecorator('hg.admin')
52 53 def __before__(self):
53 54 c.admin_user = session.get('admin_user')
54 55 c.admin_username = session.get('admin_username')
55 56 super(LdapSettingsController, self).__before__()
56 57
57 58 def index(self):
58 59 defaults = SettingsModel().get_ldap_settings()
59 60
60 61 return htmlfill.render(
61 62 render('admin/ldap/ldap.html'),
62 63 defaults=defaults,
63 64 encoding="UTF-8",
64 65 force_defaults=True,)
65 66
66 67 def ldap_settings(self):
67 68 """POST ldap create and store ldap settings"""
68 69
69 70 settings_model = SettingsModel()
70 71 _form = LdapSettingsForm()()
71 72
72 73 try:
73 74 form_result = _form.to_python(dict(request.POST))
74 75 try:
75 76
76 77 for k, v in form_result.items():
77 78 if k.startswith('ldap_'):
78 79 setting = settings_model.get(k)
79 80 setting.app_settings_value = v
80 81 self.sa.add(setting)
81 82
82 83 self.sa.commit()
83 84 h.flash(_('Ldap settings updated successfully'),
84 85 category='success')
85 86 except (DatabaseError,):
86 87 raise
87 88 except LdapImportError:
88 89 h.flash(_('Unable to activate ldap. The "python-ldap" library '
89 90 'is missing.'), category='warning')
90 91
91 92 except formencode.Invalid, errors:
92 93
93 94 return htmlfill.render(
94 95 render('admin/ldap/ldap.html'),
95 96 defaults=errors.value,
96 97 errors=errors.error_dict or {},
97 98 prefix_error=False,
98 99 encoding="UTF-8")
99 100 except Exception:
100 101 log.error(traceback.format_exc())
101 102 h.flash(_('error occurred during update of ldap settings'),
102 103 category='error')
103 104
104 105 return redirect(url('ldap_home'))
@@ -1,47 +1,54 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # branches controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.branches
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 branches controller for rhodecode
7
8 :created_on: Apr 21, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 21, 2010
22 branches controller for pylons
23 @author: marcink
24 """
27
28 import logging
29
25 30 from pylons import tmpl_context as c
31
26 32 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 33 from rhodecode.lib.base import BaseController, render
28 34 from rhodecode.lib.utils import OrderedDict
29 35 from rhodecode.model.scm import ScmModel
30 import logging
36
31 37 log = logging.getLogger(__name__)
32 38
33 39 class BranchesController(BaseController):
34 40
35 41 @LoginRequired()
36 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
43 'repository.admin')
37 44 def __before__(self):
38 45 super(BranchesController, self).__before__()
39 46
40 47 def index(self):
41 48 hg_model = ScmModel()
42 49 c.repo_info = hg_model.get_repo(c.repo_name)
43 50 c.repo_branches = OrderedDict()
44 51 for name, hash_ in c.repo_info.branches.items():
45 52 c.repo_branches[name] = c.repo_info.get_changeset(hash_)
46 53
47 54 return render('branches/branches.html')
@@ -1,99 +1,106 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # changelog controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.changelog
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 changelog controller for rhodecode
7
8 :created_on: Apr 21, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 21, 2010
22 changelog controller for pylons
23 @author: marcink
24 """
27
28 import logging
25 29
26 30 try:
27 31 import json
28 32 except ImportError:
29 33 #python 2.5 compatibility
30 34 import simplejson as json
35
31 36 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
32 37 from pylons import request, session, tmpl_context as c
38
33 39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
34 40 from rhodecode.lib.base import BaseController, render
35 41 from rhodecode.model.scm import ScmModel
42
36 43 from webhelpers.paginate import Page
37 import logging
44
38 45 log = logging.getLogger(__name__)
39 46
40 47 class ChangelogController(BaseController):
41 48
42 49 @LoginRequired()
43 50 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
44 51 'repository.admin')
45 52 def __before__(self):
46 53 super(ChangelogController, self).__before__()
47 54
48 55 def index(self):
49 56 limit = 100
50 57 default = 20
51 58 if request.params.get('size'):
52 59 try:
53 60 int_size = int(request.params.get('size'))
54 61 except ValueError:
55 62 int_size = default
56 63 int_size = int_size if int_size <= limit else limit
57 64 c.size = int_size
58 65 session['changelog_size'] = c.size
59 66 session.save()
60 67 else:
61 68 c.size = int(session.get('changelog_size', default))
62 69
63 70 changesets = ScmModel().get_repo(c.repo_name)
64 71
65 72 p = int(request.params.get('page', 1))
66 73 c.total_cs = len(changesets)
67 74 c.pagination = Page(changesets, page=p, item_count=c.total_cs,
68 75 items_per_page=c.size)
69 76
70 77 self._graph(changesets, c.size, p)
71 78
72 79 return render('changelog/changelog.html')
73 80
74 81
75 82 def _graph(self, repo, size, p):
76 83 revcount = size
77 84 if not repo.revisions or repo.alias == 'git':
78 85 c.jsdata = json.dumps([])
79 86 return
80 87
81 88 max_rev = repo.revisions[-1]
82 89
83 90 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
84 91
85 92 rev_start = repo.revisions[(-1 * offset)]
86 93
87 94 revcount = min(max_rev, revcount)
88 95 rev_end = max(0, rev_start - revcount)
89 96 dag = graph_rev(repo.repo, rev_start, rev_end)
90 97
91 98 c.dag = tree = list(colored(dag))
92 99 data = []
93 100 for (id, type, ctx, vtx, edges) in tree:
94 101 if type != CHANGESET:
95 102 continue
96 103 data.append(('', vtx, edges))
97 104
98 105 c.jsdata = json.dumps(data)
99 106
@@ -1,80 +1,86 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # feed controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.feed
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Feed controller for rhodecode
7
8 :created_on: Apr 23, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 23, 2010
22 feed controller for pylons
23 @author: marcink
24 """
25 from pylons import tmpl_context as c, url, response
26 from rhodecode.lib.base import BaseController, render
27
28
29 import logging
30
31 from pylons import url, response
32 from rhodecode.lib.base import BaseController
27 33 from rhodecode.model.scm import ScmModel
28 34 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
29 import logging
35
30 36 log = logging.getLogger(__name__)
31 37
32 38 class FeedController(BaseController):
33 39
34 40 #secure it or not ?
35 41 def __before__(self):
36 42 super(FeedController, self).__before__()
37 43 #common values for feeds
38 44 self.description = 'Changes on %s repository'
39 45 self.title = "%s feed"
40 46 self.language = 'en-us'
41 47 self.ttl = "5"
42 48 self.feed_nr = 10
43 49
44 50 def atom(self, repo_name):
45 51 """Produce an atom-1.0 feed via feedgenerator module"""
46 52 feed = Atom1Feed(title=self.title % repo_name,
47 53 link=url('summary_home', repo_name=repo_name, qualified=True),
48 54 description=self.description % repo_name,
49 55 language=self.language,
50 56 ttl=self.ttl)
51 57
52 58 changesets = ScmModel().get_repo(repo_name)
53 59
54 60 for cs in changesets[:self.feed_nr]:
55 61 feed.add_item(title=cs.message,
56 62 link=url('changeset_home', repo_name=repo_name,
57 63 revision=cs.raw_id, qualified=True),
58 64 description=str(cs.date))
59 65
60 66 response.content_type = feed.mime_type
61 67 return feed.writeString('utf-8')
62 68
63 69
64 70 def rss(self, repo_name):
65 71 """Produce an rss2 feed via feedgenerator module"""
66 72 feed = Rss201rev2Feed(title=self.title % repo_name,
67 73 link=url('summary_home', repo_name=repo_name, qualified=True),
68 74 description=self.description % repo_name,
69 75 language=self.language,
70 76 ttl=self.ttl)
71 77
72 78 changesets = ScmModel().get_repo(repo_name)
73 79 for cs in changesets[:self.feed_nr]:
74 80 feed.add_item(title=cs.message,
75 81 link=url('changeset_home', repo_name=repo_name,
76 82 revision=cs.raw_id, qualified=True),
77 83 description=str(cs.date))
78 84
79 85 response.content_type = feed.mime_type
80 86 return feed.writeString('utf-8')
@@ -1,58 +1,66 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # hg controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.home
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Home controller for Rhodecode
7
8 :created_on: Feb 18, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on February 18, 2010
22 hg controller for pylons
23 @author: marcink
24 """
27
28 import logging
25 29 from operator import itemgetter
30
26 31 from pylons import tmpl_context as c, request
32
27 33 from rhodecode.lib.auth import LoginRequired
28 34 from rhodecode.lib.base import BaseController, render
29 35 from rhodecode.model.scm import ScmModel
30 import logging
36
31 37 log = logging.getLogger(__name__)
32 38
33 39 class HomeController(BaseController):
34 40
35 41 @LoginRequired()
36 42 def __before__(self):
37 43 super(HomeController, self).__before__()
38 44
39 45 def index(self):
40 46 sortables = ['name', 'description', 'last_change', 'tip', 'contact']
41 47 current_sort = request.GET.get('sort', 'name')
42 48 current_sort_slug = current_sort.replace('-', '')
43 49
44 50 if current_sort_slug not in sortables:
45 51 c.sort_by = 'name'
46 52 current_sort_slug = c.sort_by
47 53 else:
48 54 c.sort_by = current_sort
49 55 c.sort_slug = current_sort_slug
50 56 cached_repo_list = ScmModel().get_repos()
51 57
52 58 sort_key = current_sort_slug + '_sort'
53 59 if c.sort_by.startswith('-'):
54 c.repos_list = sorted(cached_repo_list, key=itemgetter(sort_key), reverse=True)
60 c.repos_list = sorted(cached_repo_list, key=itemgetter(sort_key),
61 reverse=True)
55 62 else:
56 c.repos_list = sorted(cached_repo_list, key=itemgetter(sort_key), reverse=False)
63 c.repos_list = sorted(cached_repo_list, key=itemgetter(sort_key),
64 reverse=False)
57 65
58 66 return render('/index.html')
@@ -1,93 +1,97 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # journal controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.journal
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Journal controller for pylons
7
8 :created_on: Nov 21, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on November 21, 2010
22 journal controller for pylons
23 @author: marcink
24 """
27
28 import logging
29 from sqlalchemy import or_
25 30
26 31 from pylons import request, response, session, tmpl_context as c, url
27 from pylons.controllers.util import abort, redirect
32
28 33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
29 34 from rhodecode.lib.base import BaseController, render
30 35 from rhodecode.lib.helpers import get_token
31 36 from rhodecode.model.db import UserLog, UserFollowing
32 37 from rhodecode.model.scm import ScmModel
33 from sqlalchemy import or_
34 import logging
35 from paste.httpexceptions import HTTPInternalServerError, HTTPNotFound
38
39 from paste.httpexceptions import HTTPInternalServerError
36 40
37 41 log = logging.getLogger(__name__)
38 42
39 43 class JournalController(BaseController):
40 44
41 45
42 46 @LoginRequired()
43 47 @NotAnonymous()
44 48 def __before__(self):
45 49 super(JournalController, self).__before__()
46 50
47 51 def index(self):
48 52 # Return a rendered template
49 53
50 54 c.following = self.sa.query(UserFollowing)\
51 55 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
52 56
53 57 repo_ids = [x.follows_repository.repo_id for x in c.following
54 58 if x.follows_repository is not None]
55 59 user_ids = [x.follows_user.user_id for x in c.following
56 60 if x.follows_user is not None]
57 61
58 62 c.journal = self.sa.query(UserLog)\
59 63 .filter(or_(
60 64 UserLog.repository_id.in_(repo_ids),
61 65 UserLog.user_id.in_(user_ids),
62 66 ))\
63 67 .order_by(UserLog.action_date.desc())\
64 68 .limit(20)\
65 69 .all()
66 70 return render('/journal.html')
67 71
68 72 def toggle_following(self):
69 73
70 74 if request.POST.get('auth_token') == get_token():
71 75 scm_model = ScmModel()
72 76
73 77 user_id = request.POST.get('follows_user_id')
74 78 if user_id:
75 79 try:
76 80 scm_model.toggle_following_user(user_id,
77 81 c.rhodecode_user.user_id)
78 82 return 'ok'
79 83 except:
80 84 raise HTTPInternalServerError()
81 85
82 86 repo_id = request.POST.get('follows_repo_id')
83 87 if repo_id:
84 88 try:
85 89 scm_model.toggle_following_repo(repo_id,
86 90 c.rhodecode_user.user_id)
87 91 return 'ok'
88 92 except:
89 93 raise HTTPInternalServerError()
90 94
91 95
92 96
93 97 raise HTTPInternalServerError()
@@ -1,146 +1,152 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # login controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.login
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Login controller for rhodeocode
7
8 :created_on: Apr 22, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 27
21 """
22 Created on April 22, 2010
23 login controller for pylons
24 @author: marcink
25 """
28 import logging
29 import formencode
30
26 31 from formencode import htmlfill
32
33 from pylons.i18n.translation import _
34 from pylons.controllers.util import abort, redirect
27 35 from pylons import request, response, session, tmpl_context as c, url
28 from pylons.controllers.util import abort, redirect
36
37 import rhodecode.lib.helpers as h
29 38 from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator
30 39 from rhodecode.lib.base import BaseController, render
31 import rhodecode.lib.helpers as h
32 from pylons.i18n.translation import _
33 40 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
34 41 from rhodecode.model.user import UserModel
35 import formencode
36 import logging
42
37 43
38 44 log = logging.getLogger(__name__)
39 45
40 46 class LoginController(BaseController):
41 47
42 48 def __before__(self):
43 49 super(LoginController, self).__before__()
44 50
45 51 def index(self):
46 52 #redirect if already logged in
47 53 c.came_from = request.GET.get('came_from', None)
48 54
49 55 if c.rhodecode_user.is_authenticated \
50 56 and c.rhodecode_user.username != 'default':
51 57
52 58 return redirect(url('home'))
53 59
54 60 if request.POST:
55 61 #import Login Form validator class
56 62 login_form = LoginForm()
57 63 try:
58 64 c.form_result = login_form.to_python(dict(request.POST))
59 65 username = c.form_result['username']
60 66 user = UserModel().get_by_username(username, case_insensitive=True)
61 67 auth_user = AuthUser()
62 68 auth_user.username = user.username
63 69 auth_user.is_authenticated = True
64 70 auth_user.is_admin = user.admin
65 71 auth_user.user_id = user.user_id
66 72 auth_user.name = user.name
67 73 auth_user.lastname = user.lastname
68 74 session['rhodecode_user'] = auth_user
69 75 session.save()
70 76 log.info('user %s is now authenticated', username)
71 77
72 78 user.update_lastlogin()
73 79
74 80 if c.came_from:
75 81 return redirect(c.came_from)
76 82 else:
77 83 return redirect(url('home'))
78 84
79 85 except formencode.Invalid, errors:
80 86 return htmlfill.render(
81 87 render('/login.html'),
82 88 defaults=errors.value,
83 89 errors=errors.error_dict or {},
84 90 prefix_error=False,
85 91 encoding="UTF-8")
86 92
87 93 return render('/login.html')
88 94
89 95 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate',
90 96 'hg.register.manual_activate')
91 97 def register(self):
92 98 user_model = UserModel()
93 99 c.auto_active = False
94 100 for perm in user_model.get_by_username('default', cache=False).user_perms:
95 101 if perm.permission.permission_name == 'hg.register.auto_activate':
96 102 c.auto_active = True
97 103 break
98 104
99 105 if request.POST:
100 106
101 107 register_form = RegisterForm()()
102 108 try:
103 109 form_result = register_form.to_python(dict(request.POST))
104 110 form_result['active'] = c.auto_active
105 111 user_model.create_registration(form_result)
106 112 h.flash(_('You have successfully registered into rhodecode'),
107 113 category='success')
108 114 return redirect(url('login_home'))
109 115
110 116 except formencode.Invalid, errors:
111 117 return htmlfill.render(
112 118 render('/register.html'),
113 119 defaults=errors.value,
114 120 errors=errors.error_dict or {},
115 121 prefix_error=False,
116 122 encoding="UTF-8")
117 123
118 124 return render('/register.html')
119 125
120 126 def password_reset(self):
121 127 user_model = UserModel()
122 128 if request.POST:
123 129
124 130 password_reset_form = PasswordResetForm()()
125 131 try:
126 132 form_result = password_reset_form.to_python(dict(request.POST))
127 133 user_model.reset_password(form_result)
128 134 h.flash(_('Your new password was sent'),
129 135 category='success')
130 136 return redirect(url('login_home'))
131 137
132 138 except formencode.Invalid, errors:
133 139 return htmlfill.render(
134 140 render('/password_reset.html'),
135 141 defaults=errors.value,
136 142 errors=errors.error_dict or {},
137 143 prefix_error=False,
138 144 encoding="UTF-8")
139 145
140 146 return render('/password_reset.html')
141 147
142 148 def logout(self):
143 149 session['rhodecode_user'] = AuthUser()
144 150 session.save()
145 151 log.info('Logging out and setting user as Empty')
146 152 redirect(url('home'))
@@ -1,113 +1,120 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # search controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.search
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Search controller for rhodecode
7
8 :created_on: Aug 7, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on Aug 7, 2010
22 search controller for pylons
23 @author: marcink
24 """
27 import logging
28 import traceback
29
30 from pylons.i18n.translation import _
25 31 from pylons import request, response, config, session, tmpl_context as c, url
26 32 from pylons.controllers.util import abort, redirect
33
27 34 from rhodecode.lib.auth import LoginRequired
28 35 from rhodecode.lib.base import BaseController, render
29 36 from rhodecode.lib.indexers import SCHEMA, IDX_NAME, ResultWrapper
37
30 38 from webhelpers.paginate import Page
31 39 from webhelpers.util import update_params
32 from pylons.i18n.translation import _
40
33 41 from whoosh.index import open_dir, EmptyIndexError
34 42 from whoosh.qparser import QueryParser, QueryParserError
35 43 from whoosh.query import Phrase
36 import logging
37 import traceback
38 44
39 45 log = logging.getLogger(__name__)
40 46
41 47 class SearchController(BaseController):
42 48
43 49 @LoginRequired()
44 50 def __before__(self):
45 51 super(SearchController, self).__before__()
46 52
47 53 def index(self, search_repo=None):
48 54 c.repo_name = search_repo
49 55 c.formated_results = []
50 56 c.runtime = ''
51 57 c.cur_query = request.GET.get('q', None)
52 58 c.cur_type = request.GET.get('type', 'source')
53 59 c.cur_search = search_type = {'content':'content',
54 60 'commit':'content',
55 61 'path':'path',
56 62 'repository':'repository'}\
57 63 .get(c.cur_type, 'content')
58 64
59 65
60 66 if c.cur_query:
61 67 cur_query = c.cur_query.lower()
62 68
63 69 if c.cur_query:
64 70 p = int(request.params.get('page', 1))
65 71 highlight_items = set()
66 72 try:
67 73 idx = open_dir(config['app_conf']['index_dir']
68 74 , indexname=IDX_NAME)
69 75 searcher = idx.searcher()
70 76
71 77 qp = QueryParser(search_type, schema=SCHEMA)
72 78 if c.repo_name:
73 79 cur_query = u'repository:%s %s' % (c.repo_name, cur_query)
74 80 try:
75 81 query = qp.parse(unicode(cur_query))
76 82
77 83 if isinstance(query, Phrase):
78 84 highlight_items.update(query.words)
79 85 else:
80 86 for i in query.all_terms():
81 87 if i[0] == 'content':
82 88 highlight_items.add(i[1])
83 89
84 90 matcher = query.matcher(searcher)
85 91
86 92 log.debug(query)
87 93 log.debug(highlight_items)
88 94 results = searcher.search(query)
89 95 res_ln = len(results)
90 96 c.runtime = '%s results (%.3f seconds)' \
91 97 % (res_ln, results.runtime)
92 98
93 99 def url_generator(**kw):
94 100 return update_params("?q=%s&type=%s" \
95 101 % (c.cur_query, c.cur_search), **kw)
96 102
97 103 c.formated_results = Page(
98 104 ResultWrapper(search_type, searcher, matcher,
99 105 highlight_items),
100 106 page=p, item_count=res_ln,
101 107 items_per_page=10, url=url_generator)
102 108
103 109
104 110 except QueryParserError:
105 111 c.runtime = _('Invalid search query. Try quoting it.')
106 112 searcher.close()
107 113 except (EmptyIndexError, IOError):
108 114 log.error(traceback.format_exc())
109 115 log.error('Empty Index data')
110 c.runtime = _('There is no index to search in. Please run whoosh indexer')
116 c.runtime = _('There is no index to search in. '
117 'Please run whoosh indexer')
111 118
112 119 # Return a rendered template
113 120 return render('/search/search.html')
@@ -1,178 +1,184 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # settings controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.settings
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Settings controller for rhodecode
7
8 :created_on: Jun 30, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on June 30, 2010
22 settings controller for pylons
23 @author: marcink
24 """
27
28 import logging
29 import traceback
30
31 import formencode
25 32 from formencode import htmlfill
33
26 34 from pylons import tmpl_context as c, request, url
27 35 from pylons.controllers.util import redirect
28 36 from pylons.i18n.translation import _
37
38 import rhodecode.lib.helpers as h
29 39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAllDecorator
30 40 from rhodecode.lib.base import BaseController, render
31 41 from rhodecode.lib.utils import invalidate_cache, action_logger
32 42 from rhodecode.model.forms import RepoSettingsForm, RepoForkForm
33 43 from rhodecode.model.repo import RepoModel
34 import formencode
35 import logging
36 import rhodecode.lib.helpers as h
37 import traceback
38 44
39 45 log = logging.getLogger(__name__)
40 46
41 47 class SettingsController(BaseController):
42 48
43 49 @LoginRequired()
44 50 @HasRepoPermissionAllDecorator('repository.admin')
45 51 def __before__(self):
46 52 super(SettingsController, self).__before__()
47 53
48 54 def index(self, repo_name):
49 55 repo_model = RepoModel()
50 56 c.repo_info = repo = repo_model.get_by_repo_name(repo_name)
51 57 if not repo:
52 58 h.flash(_('%s repository is not mapped to db perhaps'
53 59 ' it was created or renamed from the file system'
54 60 ' please run the application again'
55 61 ' in order to rescan repositories') % repo_name,
56 62 category='error')
57 63
58 64 return redirect(url('home'))
59 65 defaults = c.repo_info.get_dict()
60 66 defaults.update({'user':c.repo_info.user.username})
61 67 c.users_array = repo_model.get_users_js()
62 68
63 69 for p in c.repo_info.repo_to_perm:
64 70 defaults.update({'perm_%s' % p.user.username:
65 71 p.permission.permission_name})
66 72
67 73 return htmlfill.render(
68 74 render('settings/repo_settings.html'),
69 75 defaults=defaults,
70 76 encoding="UTF-8",
71 77 force_defaults=False
72 78 )
73 79
74 80 def update(self, repo_name):
75 81 repo_model = RepoModel()
76 82 changed_name = repo_name
77 83 _form = RepoSettingsForm(edit=True, old_data={'repo_name':repo_name})()
78 84 try:
79 85 form_result = _form.to_python(dict(request.POST))
80 86 repo_model.update(repo_name, form_result)
81 87 invalidate_cache('get_repo_cached_%s' % repo_name)
82 88 h.flash(_('Repository %s updated successfully' % repo_name),
83 89 category='success')
84 90 changed_name = form_result['repo_name']
85 91 action_logger(self.rhodecode_user, 'user_updated_repo',
86 92 changed_name, '', self.sa)
87 93 except formencode.Invalid, errors:
88 94 c.repo_info = repo_model.get_by_repo_name(repo_name)
89 95 c.users_array = repo_model.get_users_js()
90 96 errors.value.update({'user':c.repo_info.user.username})
91 97 return htmlfill.render(
92 98 render('settings/repo_settings.html'),
93 99 defaults=errors.value,
94 100 errors=errors.error_dict or {},
95 101 prefix_error=False,
96 102 encoding="UTF-8")
97 103 except Exception:
98 104 log.error(traceback.format_exc())
99 105 h.flash(_('error occurred during update of repository %s') \
100 106 % repo_name, category='error')
101 107
102 108 return redirect(url('repo_settings_home', repo_name=changed_name))
103 109
104 110
105 111
106 112 def delete(self, repo_name):
107 113 """DELETE /repos/repo_name: Delete an existing item"""
108 114 # Forms posted to this method should contain a hidden field:
109 115 # <input type="hidden" name="_method" value="DELETE" />
110 116 # Or using helpers:
111 117 # h.form(url('repo_settings_delete', repo_name=ID),
112 118 # method='delete')
113 119 # url('repo_settings_delete', repo_name=ID)
114 120
115 121 repo_model = RepoModel()
116 122 repo = repo_model.get_by_repo_name(repo_name)
117 123 if not repo:
118 124 h.flash(_('%s repository is not mapped to db perhaps'
119 125 ' it was moved or renamed from the filesystem'
120 126 ' please run the application again'
121 127 ' in order to rescan repositories') % repo_name,
122 128 category='error')
123 129
124 130 return redirect(url('home'))
125 131 try:
126 132 action_logger(self.rhodecode_user, 'user_deleted_repo',
127 133 repo_name, '', self.sa)
128 134 repo_model.delete(repo)
129 135 invalidate_cache('get_repo_cached_%s' % repo_name)
130 136 h.flash(_('deleted repository %s') % repo_name, category='success')
131 137 except Exception:
132 138 h.flash(_('An error occurred during deletion of %s') % repo_name,
133 139 category='error')
134 140
135 141 return redirect(url('home'))
136 142
137 143 def fork(self, repo_name):
138 144 repo_model = RepoModel()
139 145 c.repo_info = repo = repo_model.get_by_repo_name(repo_name)
140 146 if not repo:
141 147 h.flash(_('%s repository is not mapped to db perhaps'
142 148 ' it was created or renamed from the file system'
143 149 ' please run the application again'
144 150 ' in order to rescan repositories') % repo_name,
145 151 category='error')
146 152
147 153 return redirect(url('home'))
148 154
149 155 return render('settings/repo_fork.html')
150 156
151 157
152 158
153 159 def fork_create(self, repo_name):
154 160 repo_model = RepoModel()
155 161 c.repo_info = repo_model.get_by_repo_name(repo_name)
156 162 _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})()
157 163 form_result = {}
158 164 try:
159 165 form_result = _form.to_python(dict(request.POST))
160 166 form_result.update({'repo_name':repo_name})
161 167 repo_model.create_fork(form_result, c.rhodecode_user)
162 168 h.flash(_('forked %s repository as %s') \
163 169 % (repo_name, form_result['fork_name']),
164 170 category='success')
165 171 action_logger(self.rhodecode_user,
166 172 'user_forked_repo:%s' % form_result['fork_name'],
167 173 repo_name, '', self.sa)
168 174 except formencode.Invalid, errors:
169 175 c.new_repo = errors.value['fork_name']
170 176 r = render('settings/repo_fork.html')
171 177
172 178 return htmlfill.render(
173 179 r,
174 180 defaults=errors.value,
175 181 errors=errors.error_dict or {},
176 182 prefix_error=False,
177 183 encoding="UTF-8")
178 184 return redirect(url('home'))
@@ -1,49 +1,56 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # shortlog controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.shortlog
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Shortlog controller for rhodecode
7
8 :created_on: Apr 18, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 18, 2010
22 shortlog controller for pylons
23 @author: marcink
24 """
27
28 import logging
29
25 30 from pylons import tmpl_context as c, request
31
32 from webhelpers.paginate import Page
33
26 34 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 35 from rhodecode.lib.base import BaseController, render
28 36 from rhodecode.model.scm import ScmModel
29 from webhelpers.paginate import Page
30 import logging
37
31 38 log = logging.getLogger(__name__)
32 39
33 40 class ShortlogController(BaseController):
34 41
35 42 @LoginRequired()
36 43 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
37 44 'repository.admin')
38 45 def __before__(self):
39 46 super(ShortlogController, self).__before__()
40 47
41 48 def index(self):
42 49 p = int(request.params.get('page', 1))
43 50 repo = ScmModel().get_repo(c.repo_name)
44 51 c.repo_changesets = Page(repo, page=p, items_per_page=20)
45 52 c.shortlog_data = render('shortlog/shortlog_data.html')
46 53 if request.params.get('partial'):
47 54 return c.shortlog_data
48 55 r = render('shortlog/shortlog.html')
49 56 return r
@@ -1,47 +1,53 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # tags controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.tags
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Tags controller for rhodecode
7
8 :created_on: Apr 21, 2010
9 :author: marcink
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on April 21, 2010
22 tags controller for pylons
23 @author: marcink
24 """
27 import logging
28
25 29 from pylons import tmpl_context as c
30
26 31 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 32 from rhodecode.lib.base import BaseController, render
28 33 from rhodecode.lib.utils import OrderedDict
29 34 from rhodecode.model.scm import ScmModel
30 import logging
35
31 36 log = logging.getLogger(__name__)
32 37
33 38 class TagsController(BaseController):
34 39
35 40 @LoginRequired()
36 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin')
41 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
42 'repository.admin')
37 43 def __before__(self):
38 44 super(TagsController, self).__before__()
39 45
40 46 def index(self):
41 47 hg_model = ScmModel()
42 48 c.repo_info = hg_model.get_repo(c.repo_name)
43 49 c.repo_tags = OrderedDict()
44 50 for name, hash_ in c.repo_info.tags.items():
45 51 c.repo_tags[name] = c.repo_info.get_changeset(hash_)
46 52
47 53 return render('tags/tags.html')
General Comments 0
You need to be logged in to leave comments. Login now