# HG changeset patch # User Marcin Kuzminski # Date 2011-11-26 15:51:03 # Node ID 07e56179633e5898277a48c5271bab65d986a07a # Parent 8e9f510912298d4b9e3875cab356815b14278e4a - fixes celery sqlalchemy session issues for async forking - summary page css fixes - speed optimizations diff --git a/rhodecode/lib/auth.py b/rhodecode/lib/auth.py --- a/rhodecode/lib/auth.py +++ b/rhodecode/lib/auth.py @@ -301,7 +301,7 @@ class AuthUser(object): def propagate_data(self): user_model = UserModel() - self.anonymous_user = User.get_by_username('default') + self.anonymous_user = User.get_by_username('default', cache=True) is_user_loaded = False # try go get user by api key @@ -488,8 +488,6 @@ class PermsDecorator(object): else: log.warning('Permission denied for %s %s', cls, self.user) - - anonymous = self.user.username == 'default' if anonymous: @@ -587,8 +585,7 @@ class PermsFunction(object): self.repo_name = None def __call__(self, check_Location=''): - cookie_store = session.get('rhodecode_user') - user = AuthUser.from_cookie_store(cookie_store) + user = request.user if not user: return False self.user_perms = user.permissions diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -52,6 +52,7 @@ class BaseController(WSGIController): username = get_container_username(environ, config) auth_user = AuthUser(user_id, api_key, username) + request.user = auth_user self.rhodecode_user = c.rhodecode_user = auth_user if not self.rhodecode_user.is_authenticated and \ self.rhodecode_user.user_id is not None: diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -322,8 +322,8 @@ def send_email(recipients, subject, body :param html_body: html version of body """ log = get_logger(send_email) + sa = get_session() email_config = config - subject = "%s %s" % (email_config.get('email_prefix'), subject) if not recipients: # if recipients are not defined we send to email_config + all admins diff --git a/rhodecode/lib/celerypylons/commands.py b/rhodecode/lib/celerypylons/commands.py --- a/rhodecode/lib/celerypylons/commands.py +++ b/rhodecode/lib/celerypylons/commands.py @@ -1,3 +1,4 @@ +import rhodecode from rhodecode.lib.utils import BasePasterCommand, Command from celery.app import app_or_default from celery.bin import camqadm, celerybeat, celeryd, celeryev @@ -37,7 +38,7 @@ class CeleryCommand(BasePasterCommand): if CELERY_ON == False: raise Exception('Please enable celery_on in .ini config ' 'file before running celeryd') - + rhodecode.CELERY_ON = CELERY_ON cmd = self.celery_command(app_or_default()) return cmd.run(**vars(self.options)) diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -371,17 +371,16 @@ class UsersGroup(Base, BaseModel): return '' % (self.users_group_name) @classmethod - def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): + def get_by_group_name(cls, group_name, cache=False, + case_insensitive=False): if case_insensitive: - gr = cls.query()\ - .filter(cls.users_group_name.ilike(group_name)) + q = cls.query().filter(cls.users_group_name.ilike(group_name)) else: - gr = cls.query()\ - .filter(cls.users_group_name == group_name) + q = cls.query().filter(cls.users_group_name == group_name) if cache: - gr = gr.options(FromCache("sql_cache_short", - "get_user_%s" % group_name)) - return gr.scalar() + q = q.options(FromCache("sql_cache_short", + "get_user_%s" % group_name)) + return q.scalar() @classmethod @@ -535,9 +534,9 @@ class Repository(Base, BaseModel): :param cls: """ - q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == - cls.url_sep()) - q.options(FromCache("sql_cache_short", "repository_repo_path")) + q = Session().query(RhodeCodeUi)\ + .filter(RhodeCodeUi.ui_key == cls.url_sep()) + q = q.options(FromCache("sql_cache_short", "repository_repo_path")) return q.one().ui_value @property @@ -849,6 +848,18 @@ class Permission(Base, BaseModel): def get_by_key(cls, key): return cls.query().filter(cls.permission_name == key).scalar() + @classmethod + def get_default_perms(cls, default_user_id, cache=True): + q = Session().query(UserRepoToPerm, Repository, cls)\ + .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ + .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ + .filter(UserRepoToPerm.user_id == default_user_id) + if cache: + q = q.options(FromCache("sql_cache_short", "get_default_perms")) + + return q.all() + + class UserRepoToPerm(Base, BaseModel): __tablename__ = 'repo_to_perm' __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True}) @@ -869,7 +880,7 @@ class UserToPerm(Base, BaseModel): permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None) user = relationship('User') - permission = relationship('Permission') + permission = relationship('Permission', lazy='joined') @classmethod def has_perm(cls, user_id, perm): diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -76,9 +76,7 @@ class CachedRepoList(object): def __iter__(self): for dbr in self.db_repo_list: - scmr = dbr.scm_instance_cached - # check permission at this level if not HasRepoPermissionAny('repository.read', 'repository.write', 'repository.admin')(dbr.repo_name, @@ -100,8 +98,7 @@ class CachedRepoList(object): tmp_d['description'] = dbr.description tmp_d['description_sort'] = tmp_d['description'] tmp_d['last_change'] = last_change - tmp_d['last_change_sort'] = time.mktime(last_change \ - .timetuple()) + tmp_d['last_change_sort'] = time.mktime(last_change.timetuple()) tmp_d['tip'] = tip.raw_id tmp_d['tip_sort'] = tip.revision tmp_d['rev'] = tip.revision @@ -112,8 +109,7 @@ class CachedRepoList(object): tmp_d['last_msg'] = tip.message tmp_d['author'] = tip.author tmp_d['dbrepo'] = dbr.get_dict() - tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork \ - else {} + tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork else {} yield tmp_d class ScmModel(BaseModel): diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -89,7 +89,7 @@ class UserModel(BaseModel): raise - def create_or_update(self, username, password, email, name, lastname, + def create_or_update(self, username, password, email, name, lastname, active=True, admin=False, ldap_dn=None): """ Creates a new instance if not found, or updates current one @@ -104,18 +104,18 @@ class UserModel(BaseModel): :param admin: :param ldap_dn: """ - + from rhodecode.lib.auth import get_crypt_password - + log.debug('Checking for %s account in RhodeCode database', username) user = User.get_by_username(username, case_insensitive=True) if user is None: - log.debug('creating new user %s', username) + log.debug('creating new user %s', username) new_user = User() else: - log.debug('updating user %s', username) + log.debug('updating user %s', username) new_user = user - + try: new_user.username = username new_user.admin = admin @@ -134,8 +134,8 @@ class UserModel(BaseModel): log.error(traceback.format_exc()) self.sa.rollback() raise - - + + def create_for_container_auth(self, username, attrs): """ Creates the given user if it's not already in the database @@ -354,14 +354,10 @@ class UserModel(BaseModel): #====================================================================== # fetch default permissions #====================================================================== - default_user = User.get_by_username('default') + default_user = User.get_by_username('default', cache=True) + default_user_id = default_user.user_id - default_perms = self.sa.query(UserRepoToPerm, Repository, Permission)\ - .join((Repository, UserRepoToPerm.repository_id == - Repository.repo_id))\ - .join((Permission, UserRepoToPerm.permission_id == - Permission.permission_id))\ - .filter(UserRepoToPerm.user == default_user).all() + default_perms = Permission.get_default_perms(default_user_id) if user.is_admin: #================================================================== @@ -382,7 +378,7 @@ class UserModel(BaseModel): #default global default_global_perms = self.sa.query(UserToPerm)\ - .filter(UserToPerm.user == default_user) + .filter(UserToPerm.user_id == default_user_id) for perm in default_global_perms: user.permissions['global'].add(perm.permission.permission_name) @@ -391,7 +387,7 @@ class UserModel(BaseModel): for perm in default_perms: if perm.Repository.private and not (perm.Repository.user_id == uid): - #diself.sable defaults for private repos, + #disable defaults for private repos, p = 'repository.none' elif perm.Repository.user_id == uid: #set admin if owner @@ -438,7 +434,7 @@ class UserModel(BaseModel): # (or replace with higher) permissions #================================================================== - #users group global + # users group global user_perms_from_users_groups = self.sa.query(UsersGroupToPerm)\ .options(joinedload(UsersGroupToPerm.permission))\ .join((UsersGroupMember, UsersGroupToPerm.users_group_id == @@ -448,7 +444,7 @@ class UserModel(BaseModel): for perm in user_perms_from_users_groups: user.permissions['global'].add(perm.permission.permission_name) - #users group repositories + # users group repositories user_repo_perms_from_users_groups = self.sa.query( UsersGroupRepoToPerm, Permission, Repository,)\ @@ -465,7 +461,7 @@ class UserModel(BaseModel): cur_perm = user.permissions['repositories'][perm. UsersGroupRepoToPerm. repository.repo_name] - #overwrite permission only if it's greater than permission + # overwrite permission only if it's greater than permission # given from other sources if PERM_WEIGHTS[p] > PERM_WEIGHTS[cur_perm]: user.permissions['repositories'][perm.UsersGroupRepoToPerm. diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -1053,7 +1053,9 @@ div.options a { #content div.box div.form div.fields div.field div.input.summary { margin: 0 0 0 110px; } - +#content div.box div.form div.fields div.field div.input.summary-short { + margin: 0 0 0 110px; +} #content div.box div.form div.fields div.field div.file { margin: 0 0 0 200px; } diff --git a/rhodecode/templates/summary/summary.html b/rhodecode/templates/summary/summary.html --- a/rhodecode/templates/summary/summary.html +++ b/rhodecode/templates/summary/summary.html @@ -16,11 +16,10 @@ ${self.menu('summary')} -<% -summary = lambda n:{False:'summary'}.get(n) -%> - <%def name="main()"> + <% + summary = lambda n:{False:'summary-short'}.get(n) + %> %if c.show_stats:
%else: @@ -38,7 +37,7 @@ summary = lambda n:{False:'summary'}.get
-
+
%if c.rhodecode_user.username != 'default': ${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 @@ summary = lambda n:{False:'summary'}.get
-
${h.urlify_text(c.dbrepo.description)}
+
${h.urlify_text(c.dbrepo.description)}
-
+
gravatar
@@ -121,7 +120,7 @@ summary = lambda n:{False:'summary'}.get
-
+
${'r%s:%s' % (h.get_changeset_safe(c.rhodecode_repo,'tip').revision, h.get_changeset_safe(c.rhodecode_repo,'tip').short_id)} - @@ -134,7 +133,7 @@ summary = lambda n:{False:'summary'}.get
-
+
@@ -143,13 +142,14 @@ summary = lambda n:{False:'summary'}.get
-
+
%if c.show_stats:
%else: + ${_('Statistics are disabled for this repository')} %if h.HasPermissionAll('hg.admin')('enable stats on from summary'): - ${_('Statistics are disabled for this repository')} ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-button-small")} - %endif + ${h.link_to(_('enable'),h.url('edit_repo',repo_name=c.repo_name),class_="ui-button-small")} + %endif %endif
@@ -158,7 +158,7 @@ summary = lambda n:{False:'summary'}.get
-
+
%if len(c.rhodecode_repo.revisions) == 0: ${_('There are no downloads yet')} %elif c.enable_downloads is False: