Mercurial > kallithea
comparison rhodecode/model/repo.py @ 2142:a21eab6ff42f beta
Added gravatars into permissions view and permissions autocomplete
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 19 Mar 2012 21:04:36 +0200 |
parents | 8ecfed1d8f8b |
children | dc2584ba5fbc eac0d6194783 |
comparison
equal
deleted
inserted
replaced
2141:9d54d6516e2e | 2142:a21eab6ff42f |
---|---|
27 import logging | 27 import logging |
28 import traceback | 28 import traceback |
29 from datetime import datetime | 29 from datetime import datetime |
30 | 30 |
31 from rhodecode.lib.vcs.backends import get_backend | 31 from rhodecode.lib.vcs.backends import get_backend |
32 | 32 from rhodecode.lib.compat import json |
33 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode | 33 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode |
34 from rhodecode.lib.caching_query import FromCache | 34 from rhodecode.lib.caching_query import FromCache |
35 from rhodecode.lib.hooks import log_create_repository | 35 from rhodecode.lib.hooks import log_create_repository |
36 | 36 |
37 from rhodecode.model import BaseModel | 37 from rhodecode.model import BaseModel |
38 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \ | 38 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \ |
39 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup | 39 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup |
40 from rhodecode.lib import helpers as h | |
40 | 41 |
41 | 42 |
42 log = logging.getLogger(__name__) | 43 log = logging.getLogger(__name__) |
43 | 44 |
44 | 45 |
92 repo = repo.options(FromCache("sql_cache_short", | 93 repo = repo.options(FromCache("sql_cache_short", |
93 "get_repo_%s" % repo_name)) | 94 "get_repo_%s" % repo_name)) |
94 return repo.scalar() | 95 return repo.scalar() |
95 | 96 |
96 def get_users_js(self): | 97 def get_users_js(self): |
97 | |
98 users = self.sa.query(User).filter(User.active == True).all() | 98 users = self.sa.query(User).filter(User.active == True).all() |
99 u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},''' | 99 return json.dumps([ |
100 users_array = '[%s]' % '\n'.join([u_tmpl % (u.user_id, u.name, | 100 { |
101 u.lastname, u.username) | 101 'id': u.user_id, |
102 for u in users]) | 102 'fname': u.name, |
103 return users_array | 103 'lname': u.lastname, |
104 'nname': u.username, | |
105 'gravatar_lnk': h.gravatar_url(u.email, 14) | |
106 } for u in users] | |
107 ) | |
104 | 108 |
105 def get_users_groups_js(self): | 109 def get_users_groups_js(self): |
106 users_groups = self.sa.query(UsersGroup)\ | 110 users_groups = self.sa.query(UsersGroup)\ |
107 .filter(UsersGroup.users_group_active == True).all() | 111 .filter(UsersGroup.users_group_active == True).all() |
108 | 112 |
109 g_tmpl = '''{id:%s, grname:"%s",grmembers:"%s"},''' | 113 return json.dumps([ |
110 | 114 { |
111 users_groups_array = '[%s]' % '\n'.join([g_tmpl % \ | 115 'id': gr.users_group_id, |
112 (gr.users_group_id, gr.users_group_name, | 116 'grname': gr.users_group_name, |
113 len(gr.members)) | 117 'grmembers': len(gr.members), |
114 for gr in users_groups]) | 118 } for gr in users_groups] |
115 return users_groups_array | 119 ) |
116 | 120 |
117 def _get_defaults(self, repo_name): | 121 def _get_defaults(self, repo_name): |
118 """ | 122 """ |
119 Get's information about repository, and returns a dict for | 123 Get's information about repository, and returns a dict for |
120 usage in forms | 124 usage in forms |
343 Revoke permission for user on given repository | 347 Revoke permission for user on given repository |
344 | 348 |
345 :param repo: Instance of Repository, repository_id, or repository name | 349 :param repo: Instance of Repository, repository_id, or repository name |
346 :param user: Instance of User, user_id or username | 350 :param user: Instance of User, user_id or username |
347 """ | 351 """ |
352 | |
348 user = self.__get_user(user) | 353 user = self.__get_user(user) |
349 repo = self.__get_repo(repo) | 354 repo = self.__get_repo(repo) |
350 | 355 |
351 obj = self.sa.query(UserRepoToPerm)\ | 356 obj = self.sa.query(UserRepoToPerm)\ |
352 .filter(UserRepoToPerm.repository == repo)\ | 357 .filter(UserRepoToPerm.repository == repo)\ |