##// END OF EJS Templates
- fixes celery sqlalchemy session issues for async forking...
marcink -
r1728:07e56179 beta
parent child Browse files
Show More
@@ -301,7 +301,7 b' class AuthUser(object):'
301
301
302 def propagate_data(self):
302 def propagate_data(self):
303 user_model = UserModel()
303 user_model = UserModel()
304 self.anonymous_user = User.get_by_username('default')
304 self.anonymous_user = User.get_by_username('default', cache=True)
305 is_user_loaded = False
305 is_user_loaded = False
306
306
307 # try go get user by api key
307 # try go get user by api key
@@ -488,8 +488,6 b' class PermsDecorator(object):'
488
488
489 else:
489 else:
490 log.warning('Permission denied for %s %s', cls, self.user)
490 log.warning('Permission denied for %s %s', cls, self.user)
491
492
493 anonymous = self.user.username == 'default'
491 anonymous = self.user.username == 'default'
494
492
495 if anonymous:
493 if anonymous:
@@ -587,8 +585,7 b' class PermsFunction(object):'
587 self.repo_name = None
585 self.repo_name = None
588
586
589 def __call__(self, check_Location=''):
587 def __call__(self, check_Location=''):
590 cookie_store = session.get('rhodecode_user')
588 user = request.user
591 user = AuthUser.from_cookie_store(cookie_store)
592 if not user:
589 if not user:
593 return False
590 return False
594 self.user_perms = user.permissions
591 self.user_perms = user.permissions
@@ -52,6 +52,7 b' class BaseController(WSGIController):'
52 username = get_container_username(environ, config)
52 username = get_container_username(environ, config)
53
53
54 auth_user = AuthUser(user_id, api_key, username)
54 auth_user = AuthUser(user_id, api_key, username)
55 request.user = auth_user
55 self.rhodecode_user = c.rhodecode_user = auth_user
56 self.rhodecode_user = c.rhodecode_user = auth_user
56 if not self.rhodecode_user.is_authenticated and \
57 if not self.rhodecode_user.is_authenticated and \
57 self.rhodecode_user.user_id is not None:
58 self.rhodecode_user.user_id is not None:
@@ -322,8 +322,8 b' def send_email(recipients, subject, body'
322 :param html_body: html version of body
322 :param html_body: html version of body
323 """
323 """
324 log = get_logger(send_email)
324 log = get_logger(send_email)
325 sa = get_session()
325 email_config = config
326 email_config = config
326
327 subject = "%s %s" % (email_config.get('email_prefix'), subject)
327 subject = "%s %s" % (email_config.get('email_prefix'), subject)
328 if not recipients:
328 if not recipients:
329 # if recipients are not defined we send to email_config + all admins
329 # if recipients are not defined we send to email_config + all admins
@@ -1,3 +1,4 b''
1 import rhodecode
1 from rhodecode.lib.utils import BasePasterCommand, Command
2 from rhodecode.lib.utils import BasePasterCommand, Command
2 from celery.app import app_or_default
3 from celery.app import app_or_default
3 from celery.bin import camqadm, celerybeat, celeryd, celeryev
4 from celery.bin import camqadm, celerybeat, celeryd, celeryev
@@ -37,7 +38,7 b' class CeleryCommand(BasePasterCommand):'
37 if CELERY_ON == False:
38 if CELERY_ON == False:
38 raise Exception('Please enable celery_on in .ini config '
39 raise Exception('Please enable celery_on in .ini config '
39 'file before running celeryd')
40 'file before running celeryd')
40
41 rhodecode.CELERY_ON = CELERY_ON
41 cmd = self.celery_command(app_or_default())
42 cmd = self.celery_command(app_or_default())
42 return cmd.run(**vars(self.options))
43 return cmd.run(**vars(self.options))
43
44
@@ -371,17 +371,16 b' class UsersGroup(Base, BaseModel):'
371 return '<userGroup(%s)>' % (self.users_group_name)
371 return '<userGroup(%s)>' % (self.users_group_name)
372
372
373 @classmethod
373 @classmethod
374 def get_by_group_name(cls, group_name, cache=False, case_insensitive=False):
374 def get_by_group_name(cls, group_name, cache=False,
375 case_insensitive=False):
375 if case_insensitive:
376 if case_insensitive:
376 gr = cls.query()\
377 q = cls.query().filter(cls.users_group_name.ilike(group_name))
377 .filter(cls.users_group_name.ilike(group_name))
378 else:
378 else:
379 gr = cls.query()\
379 q = cls.query().filter(cls.users_group_name == group_name)
380 .filter(cls.users_group_name == group_name)
381 if cache:
380 if cache:
382 gr = gr.options(FromCache("sql_cache_short",
381 q = q.options(FromCache("sql_cache_short",
383 "get_user_%s" % group_name))
382 "get_user_%s" % group_name))
384 return gr.scalar()
383 return q.scalar()
385
384
386
385
387 @classmethod
386 @classmethod
@@ -535,9 +534,9 b' class Repository(Base, BaseModel):'
535
534
536 :param cls:
535 :param cls:
537 """
536 """
538 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
537 q = Session().query(RhodeCodeUi)\
539 cls.url_sep())
538 .filter(RhodeCodeUi.ui_key == cls.url_sep())
540 q.options(FromCache("sql_cache_short", "repository_repo_path"))
539 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
541 return q.one().ui_value
540 return q.one().ui_value
542
541
543 @property
542 @property
@@ -849,6 +848,18 b' class Permission(Base, BaseModel):'
849 def get_by_key(cls, key):
848 def get_by_key(cls, key):
850 return cls.query().filter(cls.permission_name == key).scalar()
849 return cls.query().filter(cls.permission_name == key).scalar()
851
850
851 @classmethod
852 def get_default_perms(cls, default_user_id, cache=True):
853 q = Session().query(UserRepoToPerm, Repository, cls)\
854 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
855 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
856 .filter(UserRepoToPerm.user_id == default_user_id)
857 if cache:
858 q = q.options(FromCache("sql_cache_short", "get_default_perms"))
859
860 return q.all()
861
862
852 class UserRepoToPerm(Base, BaseModel):
863 class UserRepoToPerm(Base, BaseModel):
853 __tablename__ = 'repo_to_perm'
864 __tablename__ = 'repo_to_perm'
854 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
865 __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
@@ -869,7 +880,7 b' class UserToPerm(Base, BaseModel):'
869 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
880 permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
870
881
871 user = relationship('User')
882 user = relationship('User')
872 permission = relationship('Permission')
883 permission = relationship('Permission', lazy='joined')
873
884
874 @classmethod
885 @classmethod
875 def has_perm(cls, user_id, perm):
886 def has_perm(cls, user_id, perm):
@@ -76,9 +76,7 b' class CachedRepoList(object):'
76
76
77 def __iter__(self):
77 def __iter__(self):
78 for dbr in self.db_repo_list:
78 for dbr in self.db_repo_list:
79
80 scmr = dbr.scm_instance_cached
79 scmr = dbr.scm_instance_cached
81
82 # check permission at this level
80 # check permission at this level
83 if not HasRepoPermissionAny('repository.read', 'repository.write',
81 if not HasRepoPermissionAny('repository.read', 'repository.write',
84 'repository.admin')(dbr.repo_name,
82 'repository.admin')(dbr.repo_name,
@@ -100,8 +98,7 b' class CachedRepoList(object):'
100 tmp_d['description'] = dbr.description
98 tmp_d['description'] = dbr.description
101 tmp_d['description_sort'] = tmp_d['description']
99 tmp_d['description_sort'] = tmp_d['description']
102 tmp_d['last_change'] = last_change
100 tmp_d['last_change'] = last_change
103 tmp_d['last_change_sort'] = time.mktime(last_change \
101 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
104 .timetuple())
105 tmp_d['tip'] = tip.raw_id
102 tmp_d['tip'] = tip.raw_id
106 tmp_d['tip_sort'] = tip.revision
103 tmp_d['tip_sort'] = tip.revision
107 tmp_d['rev'] = tip.revision
104 tmp_d['rev'] = tip.revision
@@ -112,8 +109,7 b' class CachedRepoList(object):'
112 tmp_d['last_msg'] = tip.message
109 tmp_d['last_msg'] = tip.message
113 tmp_d['author'] = tip.author
110 tmp_d['author'] = tip.author
114 tmp_d['dbrepo'] = dbr.get_dict()
111 tmp_d['dbrepo'] = dbr.get_dict()
115 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork \
112 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork else {}
116 else {}
117 yield tmp_d
113 yield tmp_d
118
114
119 class ScmModel(BaseModel):
115 class ScmModel(BaseModel):
@@ -89,7 +89,7 b' class UserModel(BaseModel):'
89 raise
89 raise
90
90
91
91
92 def create_or_update(self, username, password, email, name, lastname,
92 def create_or_update(self, username, password, email, name, lastname,
93 active=True, admin=False, ldap_dn=None):
93 active=True, admin=False, ldap_dn=None):
94 """
94 """
95 Creates a new instance if not found, or updates current one
95 Creates a new instance if not found, or updates current one
@@ -104,18 +104,18 b' class UserModel(BaseModel):'
104 :param admin:
104 :param admin:
105 :param ldap_dn:
105 :param ldap_dn:
106 """
106 """
107
107
108 from rhodecode.lib.auth import get_crypt_password
108 from rhodecode.lib.auth import get_crypt_password
109
109
110 log.debug('Checking for %s account in RhodeCode database', username)
110 log.debug('Checking for %s account in RhodeCode database', username)
111 user = User.get_by_username(username, case_insensitive=True)
111 user = User.get_by_username(username, case_insensitive=True)
112 if user is None:
112 if user is None:
113 log.debug('creating new user %s', username)
113 log.debug('creating new user %s', username)
114 new_user = User()
114 new_user = User()
115 else:
115 else:
116 log.debug('updating user %s', username)
116 log.debug('updating user %s', username)
117 new_user = user
117 new_user = user
118
118
119 try:
119 try:
120 new_user.username = username
120 new_user.username = username
121 new_user.admin = admin
121 new_user.admin = admin
@@ -134,8 +134,8 b' class UserModel(BaseModel):'
134 log.error(traceback.format_exc())
134 log.error(traceback.format_exc())
135 self.sa.rollback()
135 self.sa.rollback()
136 raise
136 raise
137
137
138
138
139 def create_for_container_auth(self, username, attrs):
139 def create_for_container_auth(self, username, attrs):
140 """
140 """
141 Creates the given user if it's not already in the database
141 Creates the given user if it's not already in the database
@@ -354,14 +354,10 b' class UserModel(BaseModel):'
354 #======================================================================
354 #======================================================================
355 # fetch default permissions
355 # fetch default permissions
356 #======================================================================
356 #======================================================================
357 default_user = User.get_by_username('default')
357 default_user = User.get_by_username('default', cache=True)
358 default_user_id = default_user.user_id
358
359
359 default_perms = self.sa.query(UserRepoToPerm, Repository, Permission)\
360 default_perms = Permission.get_default_perms(default_user_id)
360 .join((Repository, UserRepoToPerm.repository_id ==
361 Repository.repo_id))\
362 .join((Permission, UserRepoToPerm.permission_id ==
363 Permission.permission_id))\
364 .filter(UserRepoToPerm.user == default_user).all()
365
361
366 if user.is_admin:
362 if user.is_admin:
367 #==================================================================
363 #==================================================================
@@ -382,7 +378,7 b' class UserModel(BaseModel):'
382
378
383 #default global
379 #default global
384 default_global_perms = self.sa.query(UserToPerm)\
380 default_global_perms = self.sa.query(UserToPerm)\
385 .filter(UserToPerm.user == default_user)
381 .filter(UserToPerm.user_id == default_user_id)
386
382
387 for perm in default_global_perms:
383 for perm in default_global_perms:
388 user.permissions['global'].add(perm.permission.permission_name)
384 user.permissions['global'].add(perm.permission.permission_name)
@@ -391,7 +387,7 b' class UserModel(BaseModel):'
391 for perm in default_perms:
387 for perm in default_perms:
392 if perm.Repository.private and not (perm.Repository.user_id ==
388 if perm.Repository.private and not (perm.Repository.user_id ==
393 uid):
389 uid):
394 #diself.sable defaults for private repos,
390 #disable defaults for private repos,
395 p = 'repository.none'
391 p = 'repository.none'
396 elif perm.Repository.user_id == uid:
392 elif perm.Repository.user_id == uid:
397 #set admin if owner
393 #set admin if owner
@@ -438,7 +434,7 b' class UserModel(BaseModel):'
438 # (or replace with higher) permissions
434 # (or replace with higher) permissions
439 #==================================================================
435 #==================================================================
440
436
441 #users group global
437 # users group global
442 user_perms_from_users_groups = self.sa.query(UsersGroupToPerm)\
438 user_perms_from_users_groups = self.sa.query(UsersGroupToPerm)\
443 .options(joinedload(UsersGroupToPerm.permission))\
439 .options(joinedload(UsersGroupToPerm.permission))\
444 .join((UsersGroupMember, UsersGroupToPerm.users_group_id ==
440 .join((UsersGroupMember, UsersGroupToPerm.users_group_id ==
@@ -448,7 +444,7 b' class UserModel(BaseModel):'
448 for perm in user_perms_from_users_groups:
444 for perm in user_perms_from_users_groups:
449 user.permissions['global'].add(perm.permission.permission_name)
445 user.permissions['global'].add(perm.permission.permission_name)
450
446
451 #users group repositories
447 # users group repositories
452 user_repo_perms_from_users_groups = self.sa.query(
448 user_repo_perms_from_users_groups = self.sa.query(
453 UsersGroupRepoToPerm,
449 UsersGroupRepoToPerm,
454 Permission, Repository,)\
450 Permission, Repository,)\
@@ -465,7 +461,7 b' class UserModel(BaseModel):'
465 cur_perm = user.permissions['repositories'][perm.
461 cur_perm = user.permissions['repositories'][perm.
466 UsersGroupRepoToPerm.
462 UsersGroupRepoToPerm.
467 repository.repo_name]
463 repository.repo_name]
468 #overwrite permission only if it's greater than permission
464 # overwrite permission only if it's greater than permission
469 # given from other sources
465 # given from other sources
470 if PERM_WEIGHTS[p] > PERM_WEIGHTS[cur_perm]:
466 if PERM_WEIGHTS[p] > PERM_WEIGHTS[cur_perm]:
471 user.permissions['repositories'][perm.UsersGroupRepoToPerm.
467 user.permissions['repositories'][perm.UsersGroupRepoToPerm.
@@ -1053,7 +1053,9 b' div.options a {'
1053 #content div.box div.form div.fields div.field div.input.summary {
1053 #content div.box div.form div.fields div.field div.input.summary {
1054 margin: 0 0 0 110px;
1054 margin: 0 0 0 110px;
1055 }
1055 }
1056
1056 #content div.box div.form div.fields div.field div.input.summary-short {
1057 margin: 0 0 0 110px;
1058 }
1057 #content div.box div.form div.fields div.field div.file {
1059 #content div.box div.form div.fields div.field div.file {
1058 margin: 0 0 0 200px;
1060 margin: 0 0 0 200px;
1059 }
1061 }
@@ -16,11 +16,10 b''
16 ${self.menu('summary')}
16 ${self.menu('summary')}
17 </%def>
17 </%def>
18
18
19 <%
20 summary = lambda n:{False:'summary'}.get(n)
21 %>
22
23 <%def name="main()">
19 <%def name="main()">
20 <%
21 summary = lambda n:{False:'summary-short'}.get(n)
22 %>
24 %if c.show_stats:
23 %if c.show_stats:
25 <div class="box box-left">
24 <div class="box box-left">
26 %else:
25 %else:
@@ -38,7 +37,7 b" summary = lambda n:{False:'summary'}.get"
38 <div class="label-summary">
37 <div class="label-summary">
39 <label>${_('Name')}:</label>
38 <label>${_('Name')}:</label>
40 </div>
39 </div>
41 <div class="input summary(c.show_stats)">
40 <div class="input ${summary(c.show_stats)}">
42 <div style="float:right;padding:5px 0px 0px 5px">
41 <div style="float:right;padding:5px 0px 0px 5px">
43 %if c.rhodecode_user.username != 'default':
42 %if c.rhodecode_user.username != 'default':
44 ${h.link_to(_('RSS'),h.url('rss_feed_home',repo_name=c.dbrepo.repo_name,api_key=c.rhodecode_user.api_key),class_='rss_icon')}
43 ${h.link_to(_('RSS'),h.url('rss_feed_home',repo_name=c.dbrepo.repo_name,api_key=c.rhodecode_user.api_key),class_='rss_icon')}
@@ -100,14 +99,14 b" summary = lambda n:{False:'summary'}.get"
100 <div class="label-summary">
99 <div class="label-summary">
101 <label>${_('Description')}:</label>
100 <label>${_('Description')}:</label>
102 </div>
101 </div>
103 <div class="input summary(c.show_stats) desc">${h.urlify_text(c.dbrepo.description)}</div>
102 <div class="input ${summary(c.show_stats)} desc">${h.urlify_text(c.dbrepo.description)}</div>
104 </div>
103 </div>
105
104
106 <div class="field">
105 <div class="field">
107 <div class="label-summary">
106 <div class="label-summary">
108 <label>${_('Contact')}:</label>
107 <label>${_('Contact')}:</label>
109 </div>
108 </div>
110 <div class="input summary(c.show_stats)">
109 <div class="input ${summary(c.show_stats)}">
111 <div class="gravatar">
110 <div class="gravatar">
112 <img alt="gravatar" src="${h.gravatar_url(c.dbrepo.user.email)}"/>
111 <img alt="gravatar" src="${h.gravatar_url(c.dbrepo.user.email)}"/>
113 </div>
112 </div>
@@ -121,7 +120,7 b" summary = lambda n:{False:'summary'}.get"
121 <div class="label-summary">
120 <div class="label-summary">
122 <label>${_('Last change')}:</label>
121 <label>${_('Last change')}:</label>
123 </div>
122 </div>
124 <div class="input summary(c.show_stats)">
123 <div class="input ${summary(c.show_stats)}">
125 <b>${'r%s:%s' % (h.get_changeset_safe(c.rhodecode_repo,'tip').revision,
124 <b>${'r%s:%s' % (h.get_changeset_safe(c.rhodecode_repo,'tip').revision,
126 h.get_changeset_safe(c.rhodecode_repo,'tip').short_id)}</b> -
125 h.get_changeset_safe(c.rhodecode_repo,'tip').short_id)}</b> -
127 <span class="tooltip" title="${c.rhodecode_repo.last_change}">
126 <span class="tooltip" title="${c.rhodecode_repo.last_change}">
@@ -134,7 +133,7 b" summary = lambda n:{False:'summary'}.get"
134 <div class="label-summary">
133 <div class="label-summary">
135 <label>${_('Clone url')}:</label>
134 <label>${_('Clone url')}:</label>
136 </div>
135 </div>
137 <div class="input summary(c.show_stats)">
136 <div class="input ${summary(c.show_stats)}">
138 <input type="text" id="clone_url" readonly="readonly" value="${c.rhodecode_repo.alias} clone ${c.clone_repo_url}" size="70"/>
137 <input type="text" id="clone_url" readonly="readonly" value="${c.rhodecode_repo.alias} clone ${c.clone_repo_url}" size="70"/>
139 </div>
138 </div>
140 </div>
139 </div>
@@ -143,13 +142,14 b" summary = lambda n:{False:'summary'}.get"
143 <div class="label-summary">
142 <div class="label-summary">
144 <label>${_('Trending files')}:</label>
143 <label>${_('Trending files')}:</label>
145 </div>
144 </div>
146 <div class="input summary(c.show_stats)">
145 <div class="input ${summary(c.show_stats)}">
147 %if c.show_stats:
146 %if c.show_stats:
148 <div id="lang_stats"></div>
147 <div id="lang_stats"></div>
149 %else:
148 %else:
149 ${_('Statistics are disabled for this repository')}
150 %if h.HasPermissionAll('hg.admin')('enable stats on from summary'):
150 %if h.HasPermissionAll('hg.admin')('enable stats on from summary'):
151 ${_('Statistics are disabled for this repository')} ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-button-small")}
151 ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-button-small")}
152 %endif
152 %endif
153 %endif
153 %endif
154 </div>
154 </div>
155 </div>
155 </div>
@@ -158,7 +158,7 b" summary = lambda n:{False:'summary'}.get"
158 <div class="label-summary">
158 <div class="label-summary">
159 <label>${_('Download')}:</label>
159 <label>${_('Download')}:</label>
160 </div>
160 </div>
161 <div class="input summary(c.show_stats)">
161 <div class="input ${summary(c.show_stats)}">
162 %if len(c.rhodecode_repo.revisions) == 0:
162 %if len(c.rhodecode_repo.revisions) == 0:
163 ${_('There are no downloads yet')}
163 ${_('There are no downloads yet')}
164 %elif c.enable_downloads is False:
164 %elif c.enable_downloads is False:
General Comments 0
You need to be logged in to leave comments. Login now