##// END OF EJS Templates
Code refactoring,models renames...
marcink -
r629:7e536d1a beta
parent child Browse files
Show More
@@ -6,7 +6,7 from rhodecode.config.routing import mak
6 6 from rhodecode.lib.auth import set_available_permissions, set_base_path
7 7 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config
8 8 from rhodecode.model import init_model
9 from rhodecode.model.hg_model import _get_repos_cached_initial
9 from rhodecode.model.hg import _get_repos_cached_initial
10 10 from sqlalchemy import engine_from_config
11 11 import logging
12 12 import os
@@ -30,10 +30,9 from pylons.i18n.translation import _
30 30 from rhodecode.lib import helpers as h
31 31 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
32 32 from rhodecode.lib.base import BaseController, render
33 from rhodecode.model.db import User, UserLog
34 33 from rhodecode.model.forms import UserForm, DefaultPermissionsForm
35 34 from rhodecode.model.permission_model import PermissionModel
36 from rhodecode.model.user_model import UserModel
35 from rhodecode.model.user import UserModel
37 36 import formencode
38 37 import logging
39 38 import traceback
@@ -35,8 +35,8 from rhodecode.lib.base import BaseContr
35 35 from rhodecode.lib.utils import invalidate_cache, action_logger
36 36 from rhodecode.model.db import User
37 37 from rhodecode.model.forms import RepoForm
38 from rhodecode.model.hg_model import HgModel
39 from rhodecode.model.repo_model import RepoModel
38 from rhodecode.model.hg import HgModel
39 from rhodecode.model.repo import RepoModel
40 40 import formencode
41 41 import logging
42 42 import traceback
@@ -32,12 +32,12 from rhodecode.lib.auth import LoginRequ
32 32 HasPermissionAnyDecorator
33 33 from rhodecode.lib.base import BaseController, render
34 34 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
35 set_rhodecode_config, get_hg_settings, get_hg_ui_settings, make_ui
36 from rhodecode.model.db import User, UserLog, RhodeCodeSettings, RhodeCodeUi
35 set_rhodecode_config, get_hg_settings, get_hg_ui_settings
36 from rhodecode.model.db import RhodeCodeSettings, RhodeCodeUi
37 37 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
38 38 ApplicationUiSettingsForm
39 from rhodecode.model.hg_model import HgModel
40 from rhodecode.model.user_model import UserModel
39 from rhodecode.model.hg import HgModel
40 from rhodecode.model.user import UserModel
41 41 from rhodecode.lib.celerylib import tasks, run_task
42 42 import formencode
43 43 import logging
@@ -231,7 +231,7 class SettingsController(BaseController)
231 231 GET /_admin/my_account Displays info about my account
232 232 """
233 233 # url('admin_settings_my_account')
234 c.user = self.sa.query(User).get(c.rhodecode_user.user_id)
234 c.user = UserModel(self.sa).get(c.rhodecode_user.user_id, cache=False)
235 235 c.user_repos = []
236 236 for repo in c.cached_repo_list.values():
237 237 if repo.dbrepo.user.username == c.user.username:
@@ -270,7 +270,7 class SettingsController(BaseController)
270 270 category='success')
271 271
272 272 except formencode.Invalid, errors:
273 c.user = self.sa.query(User).get(c.rhodecode_user.user_id)
273 c.user = user_model.get(c.rhodecode_user.user_id, cache=False)
274 274 c.user_repos = []
275 275 for repo in c.cached_repo_list.values():
276 276 if repo.dbrepo.user.username == c.user.username:
@@ -33,7 +33,7 from rhodecode.lib.auth import LoginRequ
33 33 from rhodecode.lib.base import BaseController, render
34 34 from rhodecode.model.db import User, UserLog
35 35 from rhodecode.model.forms import UserForm
36 from rhodecode.model.user_model import UserModel, DefaultUserException
36 from rhodecode.model.user import UserModel, DefaultUserException
37 37 import formencode
38 38 import logging
39 39 import traceback
@@ -100,7 +100,7 class UsersController(BaseController):
100 100 # method='put')
101 101 # url('user', id=ID)
102 102 user_model = UserModel()
103 c.user = user_model.get_user(id)
103 c.user = user_model.get(id)
104 104
105 105 _form = UserForm(edit=True, old_data={'user_id':id,
106 106 'email':c.user.email})()
@@ -26,7 +26,7 from pylons import tmpl_context as c
26 26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 27 from rhodecode.lib.base import BaseController, render
28 28 from rhodecode.lib.utils import OrderedDict
29 from rhodecode.model.hg_model import HgModel
29 from rhodecode.model.hg import HgModel
30 30 import logging
31 31 log = logging.getLogger(__name__)
32 32
@@ -32,7 +32,7 from mercurial.graphmod import colored,
32 32 from pylons import request, session, tmpl_context as c
33 33 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
34 34 from rhodecode.lib.base import BaseController, render
35 from rhodecode.model.hg_model import HgModel
35 from rhodecode.model.hg import HgModel
36 36 from webhelpers.paginate import Page
37 37 import logging
38 38 log = logging.getLogger(__name__)
@@ -27,7 +27,7 from pylons.i18n.translation import _
27 27 from pylons.controllers.util import redirect
28 28 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
29 29 from rhodecode.lib.base import BaseController, render
30 from rhodecode.model.hg_model import HgModel
30 from rhodecode.model.hg import HgModel
31 31 from vcs.exceptions import RepositoryError, ChangesetError
32 32 from vcs.nodes import FileNode
33 33 from vcs.utils import diffs as differ
@@ -24,7 +24,7 feed controller for pylons
24 24 """
25 25 from pylons import tmpl_context as c, url, response
26 26 from rhodecode.lib.base import BaseController, render
27 from rhodecode.model.hg_model import HgModel
27 from rhodecode.model.hg import HgModel
28 28 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
29 29 import logging
30 30 log = logging.getLogger(__name__)
@@ -29,7 +29,7 from pylons.controllers.util import redi
29 29 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
30 30 from rhodecode.lib.base import BaseController, render
31 31 from rhodecode.lib.utils import EmptyChangeset
32 from rhodecode.model.hg_model import HgModel
32 from rhodecode.model.hg import HgModel
33 33 from vcs.exceptions import RepositoryError, ChangesetError
34 34 from vcs.nodes import FileNode
35 35 from vcs.utils import diffs as differ
@@ -26,7 +26,7 from operator import itemgetter
26 26 from pylons import tmpl_context as c, request
27 27 from rhodecode.lib.auth import LoginRequired
28 28 from rhodecode.lib.base import BaseController, render
29 from rhodecode.model.hg_model import HgModel
29 from rhodecode.model.hg import HgModel
30 30 import logging
31 31 log = logging.getLogger(__name__)
32 32
@@ -31,7 +31,7 from rhodecode.lib.base import BaseContr
31 31 import rhodecode.lib.helpers as h
32 32 from pylons.i18n.translation import _
33 33 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
34 from rhodecode.model.user_model import UserModel
34 from rhodecode.model.user import UserModel
35 35 import formencode
36 36 import logging
37 37
@@ -55,7 +55,7 class LoginController(BaseController):
55 55 try:
56 56 c.form_result = login_form.to_python(dict(request.POST))
57 57 username = c.form_result['username']
58 user = UserModel().get_user_by_name(username)
58 user = UserModel().get_by_username(username)
59 59 auth_user = AuthUser()
60 60 auth_user.username = user.username
61 61 auth_user.is_authenticated = True
@@ -89,7 +89,7 class LoginController(BaseController):
89 89 def register(self):
90 90 user_model = UserModel()
91 91 c.auto_active = False
92 for perm in user_model.get_default().user_perms:
92 for perm in user_model.get_by_username('default', cache=False).user_perms:
93 93 if perm.permission.permission_name == 'hg.register.auto_activate':
94 94 c.auto_active = True
95 95 break
@@ -30,7 +30,7 from rhodecode.lib.auth import LoginRequ
30 30 from rhodecode.lib.base import BaseController, render
31 31 from rhodecode.lib.utils import invalidate_cache, action_logger
32 32 from rhodecode.model.forms import RepoSettingsForm, RepoForkForm
33 from rhodecode.model.repo_model import RepoModel
33 from rhodecode.model.repo import RepoModel
34 34 import formencode
35 35 import logging
36 36 import rhodecode.lib.helpers as h
@@ -25,7 +25,7 shortlog controller for pylons
25 25 from pylons import tmpl_context as c, request
26 26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 27 from rhodecode.lib.base import BaseController, render
28 from rhodecode.model.hg_model import HgModel
28 from rhodecode.model.hg import HgModel
29 29 from webhelpers.paginate import Page
30 30 import logging
31 31 log = logging.getLogger(__name__)
@@ -26,7 +26,7 from pylons import tmpl_context as c, re
26 26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 27 from rhodecode.lib.base import BaseController, render
28 28 from rhodecode.lib.utils import OrderedDict
29 from rhodecode.model.hg_model import HgModel
29 from rhodecode.model.hg import HgModel
30 30 from rhodecode.model.db import Statistics
31 31 from webhelpers.paginate import Page
32 32 from rhodecode.lib.celerylib import run_task
@@ -26,7 +26,7 from pylons import tmpl_context as c
26 26 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 27 from rhodecode.lib.base import BaseController, render
28 28 from rhodecode.lib.utils import OrderedDict
29 from rhodecode.model.hg_model import HgModel
29 from rhodecode.model.hg import HgModel
30 30 import logging
31 31 log = logging.getLogger(__name__)
32 32
@@ -22,7 +22,6 Created on April 4, 2010
22 22
23 23 @author: marcink
24 24 """
25 from beaker.cache import cache_region
26 25 from pylons import config, session, url, request
27 26 from pylons.controllers.util import abort, redirect
28 27 from rhodecode.lib.utils import get_repo_slug
@@ -30,8 +29,6 from rhodecode.model import meta
30 29 from rhodecode.model.caching_query import FromCache
31 30 from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \
32 31 UserToPerm
33 from sqlalchemy.exc import OperationalError
34 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
35 32 import bcrypt
36 33 from decorator import decorator
37 34 import logging
@@ -74,21 +71,9 def get_crypt_password(password):
74 71 def check_password(password, hashed):
75 72 return bcrypt.hashpw(password, hashed) == hashed
76 73
77 @cache_region('super_short_term', 'cached_user')
78 def get_user_cached(username):
79 sa = meta.Session
80 try:
81 user = sa.query(User).filter(User.username == username).one()
82 finally:
83 meta.Session.remove()
84 return user
85
86 74 def authfunc(environ, username, password):
87 try:
88 user = get_user_cached(username)
89 except (NoResultFound, MultipleResultsFound, OperationalError), e:
90 log.error(e)
91 user = None
75 from rhodecode.model.user import UserModel
76 user = UserModel().get_by_username(username, cache=False)
92 77
93 78 if user:
94 79 if user.active:
@@ -125,8 +110,10 def set_available_permissions(config):
125 110 """
126 111 log.info('getting information about all available permissions')
127 112 try:
128 sa = meta.Session
113 sa = meta.Session()
129 114 all_perms = sa.query(Permission).all()
115 except:
116 pass
130 117 finally:
131 118 meta.Session.remove()
132 119
@@ -141,10 +128,16 def fill_data(user):
141 128 in database
142 129 :param user:
143 130 """
144 sa = meta.Session
145 dbuser = sa.query(User).options(FromCache('sql_cache_short',
146 'getuser_%s' % user.user_id))\
131 sa = meta.Session()
132 try:
133 dbuser = sa.query(User)\
134 .options(FromCache('sql_cache_short', 'getuser_%s' % user.user_id))\
147 135 .get(user.user_id)
136 except:
137 pass
138 finally:
139 meta.Session.remove()
140
148 141 if dbuser:
149 142 user.username = dbuser.username
150 143 user.is_admin = dbuser.admin
@@ -153,7 +146,8 def fill_data(user):
153 146 user.email = dbuser.email
154 147 else:
155 148 user.is_authenticated = False
156 meta.Session.remove()
149
150
157 151 return user
158 152
159 153 def fill_perms(user):
@@ -162,7 +156,7 def fill_perms(user):
162 156 :param user:
163 157 """
164 158
165 sa = meta.Session
159 sa = meta.Session()
166 160 user.permissions['repositories'] = {}
167 161 user.permissions['global'] = set()
168 162
@@ -9,7 +9,7 from rhodecode import __version__
9 9 from rhodecode.lib import auth
10 10 from rhodecode.lib.utils import get_repo_slug
11 11 from rhodecode.model import meta
12 from rhodecode.model.hg_model import _get_repos_cached, \
12 from rhodecode.model.hg import _get_repos_cached, \
13 13 _get_repos_switcher_cached
14 14
15 15 class BaseController(WSGIController):
@@ -31,7 +31,7 class BaseController(WSGIController):
31 31 c.repository_tags = {}
32 32 c.repository_branches = {}
33 33
34 self.sa = meta.Session
34 self.sa = meta.Session()
35 35
36 36 def __call__(self, environ, start_response):
37 37 """Invoke the Controller"""
@@ -38,7 +38,7 def get_session():
38 38 else:
39 39 #If we don't use celery reuse our current application Session
40 40 from rhodecode.model.meta import Session
41 sa = Session
41 sa = Session()
42 42
43 43 return sa
44 44
@@ -285,7 +285,7 def send_email(recipients, subject, body
285 285 @task
286 286 def create_repo_fork(form_data, cur_user):
287 287 import os
288 from rhodecode.model.repo_model import RepoModel
288 from rhodecode.model.repo import RepoModel
289 289 sa = get_session()
290 290 rm = RepoModel(sa)
291 291
@@ -48,7 +48,7 class DbManage(object):
48 48 dburi = 'sqlite:////%s' % jn(self.root, self.dbname)
49 49 engine = create_engine(dburi, echo=log_sql)
50 50 init_model(engine)
51 self.sa = meta.Session
51 self.sa = meta.Session()
52 52 self.db_exists = False
53 53
54 54 def check_for_db(self, override):
@@ -59,7 +59,7 def user_action_mapper(ui, repo, hooktyp
59 59 """
60 60
61 61 try:
62 sa = meta.Session
62 sa = meta.Session()
63 63 username = kwargs['url'].split(':')[-1]
64 64 user_log = sa.query(UserLog)\
65 65 .filter(UserLog.user == sa.query(User)\
@@ -1,6 +1,6
1 1 from os.path import dirname as dn, join as jn
2 2 from rhodecode.config.environment import load_environment
3 from rhodecode.model.hg_model import HgModel
3 from rhodecode.model.hg import HgModel
4 4 from shutil import rmtree
5 5 from webhelpers.html.builder import escape
6 6 from vcs.utils.lazy import LazyProperty
@@ -33,7 +33,7 project_path = dn(dn(dn(dn(os.path.realp
33 33 sys.path.append(project_path)
34 34
35 35 from rhodecode.lib.pidlock import LockHeld, DaemonLock
36 from rhodecode.model.hg_model import HgModel
36 from rhodecode.model.hg import HgModel
37 37 from rhodecode.lib.helpers import safe_unicode
38 38 from whoosh.index import create_in, open_dir
39 39 from shutil import rmtree
@@ -30,10 +30,10 from mercurial.hgweb import hgweb
30 30 from mercurial.hgweb.request import wsgiapplication
31 31 from paste.auth.basic import AuthBasicAuthenticator
32 32 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
33 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware, \
34 get_user_cached
33 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware
35 34 from rhodecode.lib.utils import is_mercurial, make_ui, invalidate_cache, \
36 35 check_repo_fast, ui_sections
36 from rhodecode.model.user import UserModel
37 37 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
38 38 from rhodecode.lib.utils import action_logger
39 39 import logging
@@ -163,7 +163,7 class SimpleHg(object):
163 163 return environ.get('REMOTE_USER')
164 164
165 165 def __get_user(self, username):
166 return get_user_cached(username)
166 return UserModel().get_by_username(username, cache=True)
167 167
168 168 def __get_action(self, environ):
169 169 """
@@ -22,10 +22,12 Created on April 18, 2010
22 22 Utilities for RhodeCode
23 23 @author: marcink
24 24 """
25 from beaker.cache import cache_region
25 from rhodecode.model.caching_query import FromCache
26 26 from mercurial import ui, config, hg
27 27 from mercurial.error import RepoError
28 28 from rhodecode.model import meta
29 from rhodecode.model.user import UserModel
30 from rhodecode.model.repo import RepoModel
29 31 from rhodecode.model.db import Repository, User, RhodeCodeUi, RhodeCodeSettings, UserLog
30 32 from vcs.backends.base import BaseChangeset
31 33 from vcs.utils.lazy import LazyProperty
@@ -67,13 +69,13 def action_logger(user, action, repo, ip
67 69 """
68 70
69 71 if not sa:
70 sa = meta.Session
72 sa = meta.Session()
71 73
72 74 try:
73 75 if hasattr(user, 'user_id'):
74 76 user_id = user.user_id
75 77 elif isinstance(user, basestring):
76 user_id = sa.query(User).filter(User.username == user).one()
78 user_id = UserModel(sa).get_by_username(user, cache=False).user_id
77 79 else:
78 80 raise Exception('You have to provide user object or username')
79 81
@@ -82,8 +84,7 def action_logger(user, action, repo, ip
82 84 user_log.user_id = user_id
83 85 user_log.action = action
84 86 user_log.repository_name = repo_name
85 user_log.repository = sa.query(Repository)\
86 .filter(Repository.repo_name == repo_name).one()
87 user_log.repository = RepoModel(sa).get(repo_name, cache=False)
87 88 user_log.action_date = datetime.datetime.now()
88 89 user_log.user_ip = ipaddr
89 90 sa.add(user_log)
@@ -135,11 +136,14 def ask_ok(prompt, retries=4, complaint=
135 136 if retries < 0: raise IOError
136 137 print complaint
137 138
138 @cache_region('super_short_term', 'cached_hg_ui')
139 139 def get_hg_ui_cached():
140 140 try:
141 141 sa = meta.Session
142 ret = sa.query(RhodeCodeUi).all()
142 ret = sa.query(RhodeCodeUi)\
143 .options(FromCache("sql_cache_short", "get_hg_ui_settings"))\
144 .all()
145 except:
146 pass
143 147 finally:
144 148 meta.Session.remove()
145 149 return ret
@@ -147,8 +151,12 def get_hg_ui_cached():
147 151
148 152 def get_hg_settings():
149 153 try:
150 sa = meta.Session
151 ret = sa.query(RhodeCodeSettings).all()
154 sa = meta.Session()
155 ret = sa.query(RhodeCodeSettings)\
156 .options(FromCache("sql_cache_short", "get_hg_settings"))\
157 .all()
158 except:
159 pass
152 160 finally:
153 161 meta.Session.remove()
154 162
@@ -162,8 +170,10 def get_hg_settings():
162 170
163 171 def get_hg_ui_settings():
164 172 try:
165 sa = meta.Session
173 sa = meta.Session()
166 174 ret = sa.query(RhodeCodeUi).all()
175 except:
176 pass
167 177 finally:
168 178 meta.Session.remove()
169 179
@@ -255,11 +265,11 def invalidate_cache(name, *args):
255 265 args = tuple(tmp)
256 266
257 267 if name == 'cached_repo_list':
258 from rhodecode.model.hg_model import _get_repos_cached
268 from rhodecode.model.hg import _get_repos_cached
259 269 region_invalidate(_get_repos_cached, None, *args)
260 270
261 271 if name == 'full_changelog':
262 from rhodecode.model.hg_model import _full_changelog_cached
272 from rhodecode.model.hg import _full_changelog_cached
263 273 region_invalidate(_full_changelog_cached, None, *args)
264 274
265 275 class EmptyChangeset(BaseChangeset):
@@ -296,15 +306,14 def repo2db_mapper(initial_repo_list, re
296 306 """
297 307 maps all found repositories into db
298 308 """
299 from rhodecode.model.repo_model import RepoModel
300 309
301 sa = meta.Session
310 sa = meta.Session()
302 311 user = sa.query(User).filter(User.admin == True).first()
303 312
304 313 rm = RepoModel()
305 314
306 315 for name, repo in initial_repo_list.items():
307 if not sa.query(Repository).filter(Repository.repo_name == name).scalar():
316 if not RepoModel(sa).get(name, cache=False):
308 317 log.info('repository %s not found creating default', name)
309 318
310 319 form_data = {
@@ -429,7 +438,7 class OrderedDict(dict, DictMixin):
429 438
430 439
431 440 #===============================================================================
432 # TEST FUNCTIONS
441 # TEST FUNCTIONS AND CREATORS
433 442 #===============================================================================
434 443 def create_test_index(repo_location, full_index):
435 444 """Makes default test index
@@ -26,18 +26,17 from pylons import session
26 26 from pylons.i18n.translation import _
27 27 from rhodecode.lib.auth import check_password, get_crypt_password
28 28 from rhodecode.model import meta
29 from rhodecode.model.user_model import UserModel
30 from rhodecode.model.db import User, Repository
31 from sqlalchemy.exc import OperationalError
32 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
29 from rhodecode.model.user import UserModel
30 from rhodecode.model.repo import RepoModel
31 from rhodecode.model.db import User
33 32 from webhelpers.pylonslib.secure_form import authentication_token
34 33 import formencode
35 34 import logging
36 35 import os
37 36 import rhodecode.lib.helpers as h
37
38 38 log = logging.getLogger(__name__)
39 39
40
41 40 #this is needed to translate the messages using _() in validators
42 41 class State_obj(object):
43 42 _ = staticmethod(_)
@@ -60,17 +59,15 def ValidUsername(edit, old_data):
60 59 def validate_python(self, value, state):
61 60 if value in ['default', 'new_user']:
62 61 raise formencode.Invalid(_('Invalid username'), value, state)
63 #check if user is uniq
64 sa = meta.Session
62 #check if user is unique
65 63 old_un = None
66 64 if edit:
67 old_un = sa.query(User).get(old_data.get('user_id')).username
65 old_un = UserModel().get(old_data.get('user_id')).username
68 66
69 67 if old_un != value or not edit:
70 if sa.query(User).filter(User.username == value).scalar():
68 if UserModel().get_by_username(value, cache=False):
71 69 raise formencode.Invalid(_('This username already exists') ,
72 70 value, state)
73 meta.Session.remove()
74 71
75 72 return _ValidUsername
76 73
@@ -95,7 +92,7 class ValidAuth(formencode.validators.Fa
95 92 def validate_python(self, value, state):
96 93 password = value['password']
97 94 username = value['username']
98 user = UserModel().get_user_by_name(username)
95 user = UserModel().get_by_username(username)
99 96 if user is None:
100 97 raise formencode.Invalid(self.message('invalid_password',
101 98 state=State_obj), value, state,
@@ -120,8 +117,9 class ValidAuth(formencode.validators.Fa
120 117 class ValidRepoUser(formencode.validators.FancyValidator):
121 118
122 119 def to_python(self, value, state):
120 sa = meta.Session()
123 121 try:
124 self.user_db = meta.Session.query(User)\
122 self.user_db = sa.query(User)\
125 123 .filter(User.active == True)\
126 124 .filter(User.username == value).one()
127 125 except Exception:
@@ -141,11 +139,9 def ValidRepoName(edit, old_data):
141 139 raise formencode.Invalid(_('This repository name is disallowed'),
142 140 value, state)
143 141 if old_data.get('repo_name') != value or not edit:
144 sa = meta.Session
145 if sa.query(Repository).filter(Repository.repo_name == slug).scalar():
142 if RepoModel().get(slug, cache=False):
146 143 raise formencode.Invalid(_('This repository already exists') ,
147 144 value, state)
148 meta.Session.remove()
149 145 return slug
150 146
151 147
@@ -213,7 +209,7 def UniqSystemEmail(old_data):
213 209 class _UniqSystemEmail(formencode.validators.FancyValidator):
214 210 def to_python(self, value, state):
215 211 if old_data.get('email') != value:
216 sa = meta.Session
212 sa = meta.Session()
217 213 try:
218 214 user = sa.query(User).filter(User.email == value).scalar()
219 215 if user:
@@ -25,7 +25,6 Model for RhodeCode
25 25 from beaker.cache import cache_region
26 26 from mercurial import ui
27 27 from mercurial.hgweb.hgwebdir_mod import findrepos
28 from pylons.i18n.translation import _
29 28 from rhodecode.lib import helpers as h
30 29 from rhodecode.lib.utils import invalidate_cache
31 30 from rhodecode.lib.auth import HasRepoPermissionAny
@@ -23,8 +23,8 Model for permissions
23 23 @author: marcink
24 24 """
25 25
26 from pylons.i18n.translation import _
27 26 from rhodecode.model.db import User, Permission, UserToPerm, RepoToPerm
27 from rhodecode.model.caching_query import FromCache
28 28 from rhodecode.model.meta import Session
29 29 import logging
30 30 import traceback
@@ -33,28 +33,35 log = logging.getLogger(__name__)
33 33
34 34 class PermissionModel(object):
35 35
36 def __init__(self):
36 def __init__(self, sa=None):
37 if not sa:
37 38 self.sa = Session()
38
39 def get_default(self):
40 return self.sa.query(User).filter(User.username == 'default').scalar()
39 else:
40 self.sa = sa
41 41
42 def get_permission(self, id):
43 return self.sa.query(Permission).get(id)
42 def get_permission(self, permission_id, cache=False):
43 perm = self.sa.query(Permission)
44 if cache:
45 perm = perm.options(FromCache("sql_cache_short",
46 "get_permission_%s" % permission_id))
47 return perm.get(permission_id)
44 48
45 def get_permission_by_name(self, name):
46 return self.sa.query(Permission)\
47 .filter(Permission.permission_name == name).scalar()
48
49 def get_permission_by_name(self, name, cache=False):
50 perm = self.sa.query(Permission)\
51 .filter(Permission.permission_name == name)
52 if cache:
53 perm = perm.options(FromCache("sql_cache_short",
54 "get_permission_%s" % name))
55 return perm.scalar()
49 56
50 57 def update(self, form_result):
51 58 perm_user = self.sa.query(User)\
52 59 .filter(User.username == form_result['perm_user_name']).scalar()
53 60 u2p = self.sa.query(UserToPerm).filter(UserToPerm.user == perm_user).all()
54 61 if len(u2p) != 3:
55 raise Exception('There is more than 3 defined \
56 permissions for defualt user. This should not happen please verify\
57 your database')
62 raise Exception('There is more than 3 defined'
63 ' permissions for default user. This should not happen please verify'
64 ' your database')
58 65
59 66 try:
60 67 #stage 1 change defaults
@@ -19,15 +19,15
19 19 """
20 20 Created on Jun 5, 2010
21 21 model for handling repositories actions
22 @author: marcink
22 :author: marcink
23 23 """
24
24 25 from datetime import datetime
25 26 from pylons import app_globals as g
26 from rhodecode.lib.utils import check_repo
27 27 from rhodecode.model.db import Repository, RepoToPerm, User, Permission
28 28 from rhodecode.model.meta import Session
29 from rhodecode.model.user_model import UserModel
30 from rhodecode.lib.celerylib.tasks import create_repo_fork, run_task
29 from rhodecode.model.user import UserModel
30 from rhodecode.model.caching_query import FromCache
31 31 import logging
32 32 import os
33 33 import shutil
@@ -42,9 +42,14 class RepoModel(object):
42 42 else:
43 43 self.sa = sa
44 44
45 def get(self, id):
46 return self.sa.query(Repository)\
47 .filter(Repository.repo_name == id).scalar()
45 def get(self, repo_id, cache=False):
46 repo = self.sa.query(Repository)\
47 .filter(Repository.repo_name == repo_id)
48
49 if cache:
50 repo = repo.options(FromCache("sql_cache_short",
51 "get_repo_%s" % repo))
52 return repo.scalar()
48 53
49 54 def get_users_js(self):
50 55
@@ -62,8 +67,7 class RepoModel(object):
62 67 #update permissions
63 68 for username, perm in form_data['perms_updates']:
64 69 r2p = self.sa.query(RepoToPerm)\
65 .filter(RepoToPerm.user == self.sa.query(User)\
66 .filter(User.username == username).one())\
70 .filter(RepoToPerm.user == UserModel(self.sa).get_by_username(username, cache=False))\
67 71 .filter(RepoToPerm.repository == self.get(repo_name))\
68 72 .one()
69 73
@@ -76,8 +80,7 class RepoModel(object):
76 80 for username, perm in form_data['perms_new']:
77 81 r2p = RepoToPerm()
78 82 r2p.repository = self.get(repo_name)
79 r2p.user = self.sa.query(User)\
80 .filter(User.username == username).one()
83 r2p.user = UserModel(self.sa).get_by_username(username, cache=False)
81 84
82 85 r2p.permission_id = self.sa.query(Permission).filter(
83 86 Permission.permission_name == perm)\
@@ -85,7 +88,7 class RepoModel(object):
85 88 self.sa.add(r2p)
86 89
87 90 #update current repo
88 cur_repo = self.get(repo_name)
91 cur_repo = self.get(repo_name, cache=False)
89 92
90 93 for k, v in form_data.items():
91 94 if k == 'user':
@@ -130,7 +133,7 class RepoModel(object):
130 133 #create default permission
131 134 repo_to_perm = RepoToPerm()
132 135 default = 'repository.read'
133 for p in UserModel(self.sa).get_default().user_perms:
136 for p in UserModel(self.sa).get_by_username('default', cache=False).user_perms:
134 137 if p.permission.permission_name.startswith('repository.'):
135 138 default = p.permission.permission_name
136 139 break
@@ -142,8 +145,7 class RepoModel(object):
142 145 .one().permission_id
143 146
144 147 repo_to_perm.repository_id = new_repo.repo_id
145 repo_to_perm.user_id = self.sa.query(User)\
146 .filter(User.username == 'default').one().user_id
148 repo_to_perm.user_id = UserModel(self.sa).get_by_username('default', cache=False).user_id
147 149
148 150 self.sa.add(repo_to_perm)
149 151 self.sa.commit()
@@ -155,7 +157,8 class RepoModel(object):
155 157 raise
156 158
157 159 def create_fork(self, form_data, cur_user):
158 run_task(create_repo_fork, form_data, cur_user)
160 from rhodecode.lib.celerylib import tasks, run_task
161 run_task(tasks.create_repo_fork, form_data, cur_user)
159 162
160 163 def delete(self, repo):
161 164 try:
@@ -179,6 +182,7 class RepoModel(object):
179 182 raise
180 183
181 184 def __create_repo(self, repo_name):
185 from rhodecode.lib.utils import check_repo
182 186 repo_path = os.path.join(g.base_path, repo_name)
183 187 if check_repo(repo_name, g.base_path):
184 188 log.info('creating repo %s in %s', repo_name, repo_path)
@@ -17,19 +17,19
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19 # MA 02110-1301, USA.
20
21 20 """
22 21 Created on April 9, 2010
23 22 Model for users
24 @author: marcink
23 :author: marcink
25 24 """
26 from rhodecode.lib import auth
25
27 26 from pylons.i18n.translation import _
28 from rhodecode.lib.celerylib import tasks, run_task
27 from rhodecode.model.caching_query import FromCache
29 28 from rhodecode.model.db import User
30 29 from rhodecode.model.meta import Session
30 import logging
31 31 import traceback
32 import logging
32
33 33 log = logging.getLogger(__name__)
34 34
35 35 class DefaultUserException(Exception):pass
@@ -42,14 +42,21 class UserModel(object):
42 42 else:
43 43 self.sa = sa
44 44
45 def get_default(self):
46 return self.sa.query(User).filter(User.username == 'default').scalar()
45 def get(self, user_id, cache=False):
46 user = self.sa.query(User)
47 if cache:
48 user = user.options(FromCache("sql_cache_short",
49 "get_user_%s" % user_id))
50 return user.get(user_id)
51
47 52
48 def get_user(self, id):
49 return self.sa.query(User).get(id)
50
51 def get_user_by_name(self, name):
52 return self.sa.query(User).filter(User.username == name).scalar()
53 def get_by_username(self, username, cache=False):
54 user = self.sa.query(User)\
55 .filter(User.username == username)
56 if cache:
57 user = user.options(FromCache("sql_cache_short",
58 "get_user_%s" % username))
59 return user.scalar()
53 60
54 61 def create(self, form_data):
55 62 try:
@@ -78,9 +85,9 class UserModel(object):
78 85 self.sa.rollback()
79 86 raise
80 87
81 def update(self, uid, form_data):
88 def update(self, user_id, form_data):
82 89 try:
83 new_user = self.sa.query(User).get(uid)
90 new_user = self.get(user_id, cache=False)
84 91 if new_user.username == 'default':
85 92 raise DefaultUserException(
86 93 _("You can't Edit this user since it's"
@@ -98,9 +105,9 class UserModel(object):
98 105 self.sa.rollback()
99 106 raise
100 107
101 def update_my_account(self, uid, form_data):
108 def update_my_account(self, user_id, form_data):
102 109 try:
103 new_user = self.sa.query(User).get(uid)
110 new_user = self.get(user_id, cache=False)
104 111 if new_user.username == 'default':
105 112 raise DefaultUserException(
106 113 _("You can't Edit this user since it's"
@@ -119,10 +126,9 class UserModel(object):
119 126 self.sa.rollback()
120 127 raise
121 128
122 def delete(self, id):
129 def delete(self, user_id):
123 130 try:
124
125 user = self.sa.query(User).get(id)
131 user = self.get(user_id, cache=False)
126 132 if user.username == 'default':
127 133 raise DefaultUserException(
128 134 _("You can't remove this user since it's"
@@ -135,4 +141,5 class UserModel(object):
135 141 raise
136 142
137 143 def reset_password(self, data):
144 from rhodecode.lib.celerylib import tasks, run_task
138 145 run_task(tasks.reset_user_password, data['email'])
@@ -2301,6 +2301,8 padding-left:5px;
2301 2301
2302 2302 #changeset_content .container .left .date,.ac .match {
2303 2303 font-weight:700;
2304 padding-top: 5px;
2305 padding-bottom:5px;
2304 2306 }
2305 2307
2306 2308 div#legend_container table td,div#legend_choices table td {
@@ -49,19 +49,32 cache_dir = %(here)s/data
49 49 ####################################
50 50 beaker.cache.data_dir=/%(here)s/data/cache/data
51 51 beaker.cache.lock_dir=/%(here)s/data/cache/lock
52 beaker.cache.regions=super_short_term,short_term,long_term
52 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
53
54 beaker.cache.super_short_term.type=memory
55 beaker.cache.super_short_term.expire=10
56
57 beaker.cache.short_term.type=memory
58 beaker.cache.short_term.expire=60
59
53 60 beaker.cache.long_term.type=memory
54 61 beaker.cache.long_term.expire=36000
55 beaker.cache.short_term.type=memory
56 beaker.cache.short_term.expire=60
57 beaker.cache.super_short_term.type=memory
58 beaker.cache.super_short_term.expire=10
62
63
64 beaker.cache.sql_cache_short.type=memory
65 beaker.cache.sql_cache_short.expire=5
66
67 beaker.cache.sql_cache_med.type=memory
68 beaker.cache.sql_cache_med.expire=360
69
70 beaker.cache.sql_cache_long.type=file
71 beaker.cache.sql_cache_long.expire=3600
59 72
60 73 ####################################
61 74 ### BEAKER SESSION ####
62 75 ####################################
63 76 ## Type of storage used for the session, current types are
64 ## "dbm", "file", "memcached", "database", and "memory".
77 ## dbm, file, memcached, database, and memory.
65 78 ## The storage uses the Container API
66 79 ##that is also used by the cache system.
67 80 beaker.session.type = file
General Comments 0
You need to be logged in to leave comments. Login now