Commits

Marcin Kuzminski committed 2c0d35e

refactoring of models names for repoGroup permissions

Comments (0)

Files changed (22)

rhodecode/controllers/admin/ldap_settings.py

 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
 from rhodecode.lib.exceptions import LdapImportError
 from rhodecode.model.forms import LdapSettingsForm
-from rhodecode.model.db import RhodeCodeSettings
+from rhodecode.model.db import RhodeCodeSetting
 
 log = logging.getLogger(__name__)
 
         super(LdapSettingsController, self).__before__()
 
     def index(self):
-        defaults = RhodeCodeSettings.get_ldap_settings()
+        defaults = RhodeCodeSetting.get_ldap_settings()
         c.search_scope_cur = defaults.get('ldap_search_scope')
         c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert')
         c.tls_kind_cur = defaults.get('ldap_tls_kind')
 
                 for k, v in form_result.items():
                     if k.startswith('ldap_'):
-                        setting = RhodeCodeSettings.get_by_name(k)
+                        setting = RhodeCodeSetting.get_by_name(k)
                         setting.app_settings_value = v
                         self.sa.add(setting)
 

rhodecode/controllers/admin/repos.py

 from rhodecode.lib.base import BaseController, render
 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
 from rhodecode.lib.helpers import get_token
-from rhodecode.model.db import User, Repository, UserFollowing, Group
+from rhodecode.model.db import User, Repository, UserFollowing, RepoGroup
 from rhodecode.model.forms import RepoForm
 from rhodecode.model.scm import ScmModel
 from rhodecode.model.repo import RepoModel
         super(ReposController, self).__before__()
 
     def __load_defaults(self):
-        c.repo_groups = Group.groups_choices()
+        c.repo_groups = RepoGroup.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
         
         repo_model = RepoModel()

rhodecode/controllers/admin/repos_groups.py

 from rhodecode.lib import helpers as h
 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator
 from rhodecode.lib.base import BaseController, render
-from rhodecode.model.db import Group
+from rhodecode.model.db import RepoGroup
 from rhodecode.model.repos_group import ReposGroupModel
 from rhodecode.model.forms import ReposGroupForm
 
         super(ReposGroupsController, self).__before__()
 
     def __load_defaults(self):
-        c.repo_groups = Group.groups_choices()
+        c.repo_groups = RepoGroup.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
     def __load_data(self, group_id):
         """
         self.__load_defaults()
 
-        repo_group = Group.get(group_id)
+        repo_group = RepoGroup.get(group_id)
 
         data = repo_group.get_dict()
 
         # url('repos_groups')
 
         sk = lambda g:g.parents[0].group_name if g.parents else g.group_name
-        c.groups = sorted(Group.query().all(), key=sk)
+        c.groups = sorted(RepoGroup.query().all(), key=sk)
         return render('admin/repos_groups/repos_groups_show.html')
 
     @HasPermissionAnyDecorator('hg.admin')
         # url('repos_group', id=ID)
 
         self.__load_defaults()
-        c.repos_group = Group.get(id)
+        c.repos_group = RepoGroup.get(id)
 
         repos_group_model = ReposGroupModel()
         repos_group_form = ReposGroupForm(edit=True,
         # url('repos_group', id=ID)
 
         repos_group_model = ReposGroupModel()
-        gr = Group.get(id)
+        gr = RepoGroup.get(id)
         repos = gr.repositories.all()
         if repos:
             h.flash(_('This group contains %s repositores and cannot be '
         return redirect(url('repos_groups'))
 
     def show_by_name(self, group_name):
-        id_ = Group.get_by_group_name(group_name).group_id
+        id_ = RepoGroup.get_by_group_name(group_name).group_id
         return self.show(id_)
 
     def show(self, id, format='html'):
         """GET /repos_groups/id: Show a specific item"""
         # url('repos_group', id=ID)
 
-        c.group = Group.get(id)
+        c.group = RepoGroup.get(id)
 
         if c.group:
             c.group_repos = c.group.repositories.all()
 
         c.repo_cnt = 0
 
-        c.groups = self.sa.query(Group).order_by(Group.group_name)\
-            .filter(Group.group_parent_id == id).all()
+        c.groups = self.sa.query(RepoGroup).order_by(RepoGroup.group_name)\
+            .filter(RepoGroup.group_parent_id == id).all()
 
         return render('admin/repos_groups/repos_groups.html')
 
 
         id_ = int(id)
 
-        c.repos_group = Group.get(id_)
+        c.repos_group = RepoGroup.get(id_)
         defaults = self.__load_data(id_)
 
         # we need to exclude this group from the group list for editing

rhodecode/controllers/admin/settings.py

 from rhodecode.lib.celerylib import tasks, run_task
 from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
     set_rhodecode_config, repo_name_slug
-from rhodecode.model.db import RhodeCodeUi, Repository, Group, \
-    RhodeCodeSettings
+from rhodecode.model.db import RhodeCodeUi, Repository, RepoGroup, \
+    RhodeCodeSetting
 from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
     ApplicationUiSettingsForm
 from rhodecode.model.scm import ScmModel
         """GET /admin/settings: All items in the collection"""
         # url('admin_settings')
 
-        defaults = RhodeCodeSettings.get_app_settings()
+        defaults = RhodeCodeSetting.get_app_settings()
         defaults.update(self.get_hg_ui_settings())
         return htmlfill.render(
             render('admin/settings/settings.html'),
                 form_result = application_form.to_python(dict(request.POST))
 
                 try:
-                    hgsettings1 = RhodeCodeSettings.get_by_name('title')
+                    hgsettings1 = RhodeCodeSetting.get_by_name('title')
                     hgsettings1.app_settings_value = \
                         form_result['rhodecode_title']
 
-                    hgsettings2 = RhodeCodeSettings.get_by_name('realm')
+                    hgsettings2 = RhodeCodeSetting.get_by_name('realm')
                     hgsettings2.app_settings_value = \
                         form_result['rhodecode_realm']
 
-                    hgsettings3 = RhodeCodeSettings.get_by_name('ga_code')
+                    hgsettings3 = RhodeCodeSetting.get_by_name('ga_code')
                     hgsettings3.app_settings_value = \
                         form_result['rhodecode_ga_code']
 
     def create_repository(self):
         """GET /_admin/create_repository: Form to create a new item"""
 
-        c.repo_groups = Group.groups_choices()
+        c.repo_groups = RepoGroup.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
 
         new_repo = request.GET.get('repo', '')

rhodecode/controllers/admin/users.py

 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
 from rhodecode.lib.base import BaseController, render
 
-from rhodecode.model.db import User, RepoToPerm, UserToPerm, Permission
+from rhodecode.model.db import User, UserRepoToPerm, UserToPerm, Permission
 from rhodecode.model.forms import UserForm
 from rhodecode.model.user import UserModel
 

rhodecode/controllers/api/api.py

     HasPermissionAnyDecorator
 from rhodecode.model.scm import ScmModel
 
-from rhodecode.model.db import User, UsersGroup, Group, Repository
+from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository
 from rhodecode.model.repo import RepoModel
 from rhodecode.model.user import UserModel
 from rhodecode.model.repo_permission import RepositoryPermissionModel
             groups = groups[:-1]
             parent_id = None
             for g in groups:
-                group = Group.get_by_group_name(g)
+                group = RepoGroup.get_by_group_name(g)
                 if not group:
                     group = ReposGroupModel().create(dict(group_name=g,
                                                   group_description='',

rhodecode/controllers/home.py

 
 from rhodecode.lib.auth import LoginRequired
 from rhodecode.lib.base import BaseController, render
-from rhodecode.model.db import Group, Repository
+from rhodecode.model.db import RepoGroup, Repository
 
 log = logging.getLogger(__name__)
 
 
         c.repos_list = self.scm_model.get_repos()
 
-        c.groups = Group.query().filter(Group.group_parent_id == None).all()
+        c.groups = RepoGroup.query().filter(RepoGroup.group_parent_id == None).all()
 
         return render('/index.html')
 

rhodecode/controllers/settings.py

 
 from rhodecode.model.forms import RepoSettingsForm, RepoForkForm
 from rhodecode.model.repo import RepoModel
-from rhodecode.model.db import Group
+from rhodecode.model.db import RepoGroup
 
 log = logging.getLogger(__name__)
 
         super(SettingsController, self).__before__()
     
     def __load_defaults(self):
-        c.repo_groups = Group.groups_choices()
+        c.repo_groups = RepoGroup.groups_choices()
         c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
         
         repo_model = RepoModel()

rhodecode/lib/auth.py

 
 from rhodecode.model import meta
 from rhodecode.model.user import UserModel
-from rhodecode.model.db import Permission, RhodeCodeSettings, User
+from rhodecode.model.db import Permission, RhodeCodeSetting, User
 
 log = logging.getLogger(__name__)
 
             log.debug('this user already exists as non ldap')
             return False
 
-        ldap_settings = RhodeCodeSettings.get_ldap_settings()
+        ldap_settings = RhodeCodeSetting.get_ldap_settings()
         #======================================================================
         # FALLBACK TO LDAP AUTH IF ENABLE
         #======================================================================

rhodecode/lib/db_manage.py

 from rhodecode.lib.utils import ask_ok
 from rhodecode.model import init_model
 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
-    RhodeCodeSettings, UserToPerm, DbMigrateVersion
+    RhodeCodeSetting, UserToPerm, DbMigrateVersion
 
 from sqlalchemy.engine import create_engine
 
         """Fixes rhodecode settings adds ga_code key for google analytics
         """
 
-        hgsettings3 = RhodeCodeSettings('ga_code', '')
+        hgsettings3 = RhodeCodeSetting('ga_code', '')
 
         try:
             self.sa.add(hgsettings3)
                         ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
                         ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
 
-                if skip_existing and RhodeCodeSettings.get_by_name(k) != None:
+                if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
                     log.debug('Skipping option %s' % k)
                     continue
-                setting = RhodeCodeSettings(k, v)
+                setting = RhodeCodeSetting(k, v)
                 self.sa.add(setting)
             self.sa.commit()
         except:
         paths.ui_key = '/'
         paths.ui_value = path
 
-        hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
-        hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
-        hgsettings3 = RhodeCodeSettings('ga_code', '')
+        hgsettings1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
+        hgsettings2 = RhodeCodeSetting('title', 'RhodeCode')
+        hgsettings3 = RhodeCodeSetting('ga_code', '')
 
         try:
             self.sa.add(web1)

rhodecode/lib/utils.py

 
 from rhodecode.model import meta
 from rhodecode.model.caching_query import FromCache
-from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, Group, \
-    RhodeCodeSettings
+from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, RepoGroup, \
+    RhodeCodeSetting
 from rhodecode.model.repo import RepoModel
 
 log = logging.getLogger(__name__)
 
     :param config:
     """
-    hgsettings = RhodeCodeSettings.get_app_settings()
+    hgsettings = RhodeCodeSetting.get_app_settings()
 
     for k, v in hgsettings.items():
         config[k] = v
 
     for lvl, group_name in enumerate(groups):
         group_name = '/'.join(groups[:lvl] + [group_name])
-        group = sa.query(Group).filter(Group.group_name == group_name).scalar()
+        group = sa.query(RepoGroup).filter(RepoGroup.group_name == group_name).scalar()
 
         if group is None:
-            group = Group(group_name, parent)
+            group = RepoGroup(group_name, parent)
             sa.add(group)
             sa.commit()
         parent = group
     added = []
     # fixup groups paths to new format on the fly
     # TODO: remove this in future
-    for g in Group.query().all():
+    for g in RepoGroup.query().all():
         g.group_name = g.get_new_name(g.name)
         sa.add(g)    
     for name, repo in initial_repo_list.items():

rhodecode/model/db.py

         Session.commit()
 
 
-class RhodeCodeSettings(Base, BaseModel):
+class RhodeCodeSetting(Base, BaseModel):
     __tablename__ = 'rhodecode_settings'
     __table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True})
     app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
     repositories = relationship('Repository')
     user_followers = relationship('UserFollowing', primaryjoin='UserFollowing.follows_user_id==User.user_id', cascade='all')
-    repo_to_perm = relationship('RepoToPerm', primaryjoin='RepoToPerm.user_id==User.user_id', cascade='all')
+    repo_to_perm = relationship('UserRepoToPerm', primaryjoin='UserRepoToPerm.user_id==User.user_id', cascade='all')
 
     group_member = relationship('UsersGroupMember', cascade='all')
 
                         users_group_id).all()
 
             if assigned_groups:
-                raise UsersGroupsAssignedException('Group assigned to %s' %
+                raise UsersGroupsAssignedException('RepoGroup assigned to %s' %
                                                    assigned_groups)
 
             users_group = cls.get(users_group_id, cache=False)
 
     user = relationship('User')
     fork = relationship('Repository', remote_side=repo_id)
-    group = relationship('Group')
-    repo_to_perm = relationship('RepoToPerm', cascade='all', order_by='RepoToPerm.repo_to_perm_id')
+    group = relationship('RepoGroup')
+    repo_to_perm = relationship('UserRepoToPerm', cascade='all', order_by='UserRepoToPerm.repo_to_perm_id')
     users_group_to_perm = relationship('UsersGroupRepoToPerm', cascade='all')
     stats = relationship('Statistics', cascade='all', uselist=False)
 
         return repo
 
 
-class Group(Base, BaseModel):
+class RepoGroup(Base, BaseModel):
     __tablename__ = 'groups'
     __table_args__ = (UniqueConstraint('group_name', 'group_parent_id'),
                       CheckConstraint('group_id != group_parent_id'), {'extend_existing':True},)
     group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
     group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
-    parent_group = relationship('Group', remote_side=group_id)
+    parent_group = relationship('RepoGroup', remote_side=group_id)
 
 
     def __init__(self, group_name='', parent_group=None):
 
     @property
     def children(self):
-        return Group.query().filter(Group.parent_group == self)
+        return RepoGroup.query().filter(RepoGroup.parent_group == self)
 
     @property
     def name(self):
-        return self.group_name.split(Group.url_sep())[-1]
+        return self.group_name.split(RepoGroup.url_sep())[-1]
 
     @property
     def full_path(self):
 
     @property
     def full_path_splitted(self):
-        return self.group_name.split(Group.url_sep())
+        return self.group_name.split(RepoGroup.url_sep())
 
     @property
     def repositories(self):
         """
         path_prefix = (self.parent_group.full_path_splitted if
                        self.parent_group else [])
-        return Group.url_sep().join(path_prefix + [group_name])
+        return RepoGroup.url_sep().join(path_prefix + [group_name])
 
 
 class Permission(Base, BaseModel):
     def get_by_key(cls, key):
         return cls.query().filter(cls.permission_name == key).scalar()
 
-class RepoToPerm(Base, BaseModel):
+class UserRepoToPerm(Base, BaseModel):
     __tablename__ = 'repo_to_perm'
     __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'extend_existing':True})
     repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
             Session.rollback()
 
 
-class GroupToPerm(Base, BaseModel):
+class UserRepoGroupToPerm(Base, BaseModel):
     __tablename__ = 'group_to_perm'
     __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
 
 
     user = relationship('User')
     permission = relationship('Permission')
-    group = relationship('Group')
+    group = relationship('RepoGroup')
+
+class UsersGroupRepoGroupToPerm(Base, BaseModel):
+    __tablename__ = 'users_group_repo_group_to_perm'
+    __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
+
+    users_group_repo_group_to_perm_id = Column("users_group_repo_group_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
+    users_group_id = Column("users_group_id", Integer(), ForeignKey('users_groups.users_group_id'), nullable=False, unique=None, default=None)
+    permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
+    group_id = Column("group_id", Integer(), ForeignKey('groups.group_id'), nullable=False, unique=None, default=None)
+
+    users_group = relationship('UsersGroup')
+    permission = relationship('Permission')
+    group = relationship('RepoGroup')
 
 class Statistics(Base, BaseModel):
     __tablename__ = 'statistics'

rhodecode/model/forms.py

 from rhodecode.lib.exceptions import LdapImportError
 from rhodecode.model.user import UserModel
 from rhodecode.model.repo import RepoModel
-from rhodecode.model.db import User, UsersGroup, Group
+from rhodecode.model.db import User, UsersGroup, RepoGroup
 from rhodecode import BACKENDS
 
 log = logging.getLogger(__name__)
 
 
             if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None:
-                raise formencode.Invalid(_('Group name may only contain '
+                raise formencode.Invalid(_('RepoGroup name may only contain '
                                            'alphanumeric characters '
                                            'underscores, periods or dashes '
                                            'and must begin with alphanumeric '
 
             old_gname = None
             if edit:
-                old_gname = Group.get(
+                old_gname = RepoGroup.get(
                             old_data.get('group_id')).group_name
 
             if old_gname != group_name or not edit:
                 # check filesystem
-                gr = Group.query().filter(Group.group_name == slug)\
-                    .filter(Group.group_parent_id == group_parent_id).scalar()
+                gr = RepoGroup.query().filter(RepoGroup.group_name == slug)\
+                    .filter(RepoGroup.group_parent_id == group_parent_id).scalar()
 
                 if gr:
                     e_dict = {'group_name':_('This group already exists')}
 
 
             if value.get('repo_group'):
-                gr = Group.get(value.get('repo_group'))
+                gr = RepoGroup.get(value.get('repo_group'))
                 group_path = gr.full_path
                 # value needs to be aware of group name in order to check
                 # db key This is an actual just the name to store in the
                 # database
-                repo_name_full = group_path + Group.url_sep() + repo_name
+                repo_name_full = group_path + RepoGroup.url_sep() + repo_name
                 
             else:
                 group_path = ''
                                   gr.group_name}
                         raise formencode.Invalid('', value, state,
                                                  error_dict=e_dict)
-                elif Group.get_by_group_name(repo_name_full):
+                elif RepoGroup.get_by_group_name(repo_name_full):
                         e_dict = {'repo_name':_('There is a group with this'
                                                 ' name already "%s"') %
                                   repo_name_full}

rhodecode/model/permission.py

 from sqlalchemy.exc import DatabaseError
 
 from rhodecode.model import BaseModel
-from rhodecode.model.db import User, Permission, UserToPerm, RepoToPerm
+from rhodecode.model.db import User, Permission, UserToPerm, UserRepoToPerm
 from rhodecode.model.caching_query import FromCache
 
 log = logging.getLogger(__name__)
 
             #stage 2 update all default permissions for repos if checked
             if form_result['overwrite_default'] == True:
-                for r2p in self.sa.query(RepoToPerm)\
-                               .filter(RepoToPerm.user == perm_user).all():
+                for r2p in self.sa.query(UserRepoToPerm)\
+                               .filter(UserRepoToPerm.user == perm_user).all():
                     r2p.permission = self.get_permission_by_name(
                                          form_result['default_perm'])
                     self.sa.add(r2p)

rhodecode/model/repo.py

 
 from rhodecode.model import BaseModel
 from rhodecode.model.caching_query import FromCache
-from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \
-    Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, Group
+from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \
+    Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup
 from rhodecode.model.user import UserModel
 
 log = logging.getLogger(__name__)
             # update permissions
             for member, perm, member_type in form_data['perms_updates']:
                 if member_type == 'user':
-                    r2p = self.sa.query(RepoToPerm)\
-                            .filter(RepoToPerm.user == User.get_by_username(member))\
-                            .filter(RepoToPerm.repository == cur_repo)\
+                    r2p = self.sa.query(UserRepoToPerm)\
+                            .filter(UserRepoToPerm.user == User.get_by_username(member))\
+                            .filter(UserRepoToPerm.repository == cur_repo)\
                             .one()
 
                     r2p.permission = self.sa.query(Permission)\
             # set new permissions
             for member, perm, member_type in form_data['perms_new']:
                 if member_type == 'user':
-                    r2p = RepoToPerm()
+                    r2p = UserRepoToPerm()
                     r2p.repository = cur_repo
                     r2p.user = User.get_by_username(member)
 
                 elif k == 'repo_name':
                     pass
                 elif k == 'repo_group':
-                    cur_repo.group = Group.get(v)
+                    cur_repo.group = RepoGroup.get(v)
 
                 else:
                     setattr(cur_repo, k, v)
             self.sa.add(new_repo)
 
             #create default permission
-            repo_to_perm = RepoToPerm()
+            repo_to_perm = UserRepoToPerm()
             default = 'repository.read'
             for p in User.get_by_username('default').user_perms:
                 if p.permission.permission_name.startswith('repository.'):
 
     def delete_perm_user(self, form_data, repo_name):
         try:
-            self.sa.query(RepoToPerm)\
-                .filter(RepoToPerm.repository \
+            self.sa.query(UserRepoToPerm)\
+                .filter(UserRepoToPerm.repository \
                         == self.get_by_repo_name(repo_name))\
-                .filter(RepoToPerm.user_id == form_data['user_id']).delete()
+                .filter(UserRepoToPerm.user_id == form_data['user_id']).delete()
             self.sa.commit()
         except:
             log.error(traceback.format_exc())
         from rhodecode.lib.utils import is_valid_repo, is_valid_repos_group
 
         if new_parent_id:
-            paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
+            paths = RepoGroup.get(new_parent_id).full_path.split(RepoGroup.url_sep())
             new_parent_path = os.sep.join(paths)
         else:
             new_parent_path = ''

rhodecode/model/repo_permission.py

 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
-from rhodecode.model.db import BaseModel, RepoToPerm, Permission
+from rhodecode.model.db import BaseModel, UserRepoToPerm, Permission
 from rhodecode.model.meta import Session
 
 log = logging.getLogger(__name__)
 
 class RepositoryPermissionModel(BaseModel):
     def get_user_permission(self, repository, user):
-        return RepoToPerm.query() \
-                .filter(RepoToPerm.user == user) \
-                .filter(RepoToPerm.repository == repository) \
+        return UserRepoToPerm.query() \
+                .filter(UserRepoToPerm.user == user) \
+                .filter(UserRepoToPerm.repository == repository) \
                 .scalar()
 
     def update_user_permission(self, repository, user, permission):
             if not current.permission is permission:
                 current.permission = permission
         else:
-            p = RepoToPerm()
+            p = UserRepoToPerm()
             p.user = user
             p.repository = repository
             p.permission = permission

rhodecode/model/repos_group.py

 from vcs.utils.lazy import LazyProperty
 
 from rhodecode.model import BaseModel
-from rhodecode.model.caching_query import FromCache
-from rhodecode.model.db import Group, RhodeCodeUi
+from rhodecode.model.db import RepoGroup, RhodeCodeUi
 
 log = logging.getLogger(__name__)
 
         
         :param group: instance of group from database
         """
-        paths = group.full_path.split(Group.url_sep())
+        paths = group.full_path.split(RepoGroup.url_sep())
         paths = os.sep.join(paths)
 
         rm_path = os.path.join(self.repos_path, paths)
 
     def create(self, form_data):
         try:
-            new_repos_group = Group()
+            new_repos_group = RepoGroup()
             new_repos_group.group_description = form_data['group_description']
-            new_repos_group.parent_group = Group.get(form_data['group_parent_id'])
+            new_repos_group.parent_group = RepoGroup.get(form_data['group_parent_id'])
             new_repos_group.group_name = new_repos_group.get_new_name(form_data['group_name'])
 
             self.sa.add(new_repos_group)
     def update(self, repos_group_id, form_data):
 
         try:
-            repos_group = Group.get(repos_group_id)
+            repos_group = RepoGroup.get(repos_group_id)
             old_path = repos_group.full_path
                 
             # change properties
             repos_group.group_description = form_data['group_description']
-            repos_group.parent_group = Group.get(form_data['group_parent_id'])
+            repos_group.parent_group = RepoGroup.get(form_data['group_parent_id'])
             repos_group.group_name = repos_group.get_new_name(form_data['group_name'])
 
             new_path = repos_group.full_path
 
     def delete(self, users_group_id):
         try:
-            users_group = Group.get(users_group_id)
+            users_group = RepoGroup.get(users_group_id)
             self.sa.delete(users_group)
             self.__delete_group(users_group)
             self.sa.commit()

rhodecode/model/user.py

 from rhodecode.lib import safe_unicode
 from rhodecode.model import BaseModel
 from rhodecode.model.caching_query import FromCache
-from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \
+from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
     UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember
 from rhodecode.lib.exceptions import DefaultUserException, \
     UserOwnsReposException
         #======================================================================
         default_user = self.get_by_username('default', cache=True)
 
-        default_perms = self.sa.query(RepoToPerm, Repository, Permission)\
-            .join((Repository, RepoToPerm.repository_id ==
+        default_perms = self.sa.query(UserRepoToPerm, Repository, Permission)\
+            .join((Repository, UserRepoToPerm.repository_id ==
                    Repository.repo_id))\
-            .join((Permission, RepoToPerm.permission_id ==
+            .join((Permission, UserRepoToPerm.permission_id ==
                    Permission.permission_id))\
-            .filter(RepoToPerm.user == default_user).all()
+            .filter(UserRepoToPerm.user == default_user).all()
 
         if user.is_admin:
             #==================================================================
 
             for perm in default_perms:
                 p = 'repository.admin'
-                user.permissions['repositories'][perm.RepoToPerm.
+                user.permissions['repositories'][perm.UserRepoToPerm.
                                                  repository.repo_name] = p
 
         else:
                 else:
                     p = perm.Permission.permission_name
 
-                user.permissions['repositories'][perm.RepoToPerm.
+                user.permissions['repositories'][perm.UserRepoToPerm.
                                                  repository.repo_name] = p
 
             #==================================================================
                                                permission_name)
 
             #user repositories
-            user_repo_perms = self.sa.query(RepoToPerm, Permission,
+            user_repo_perms = self.sa.query(UserRepoToPerm, Permission,
                                             Repository)\
-                .join((Repository, RepoToPerm.repository_id ==
+                .join((Repository, UserRepoToPerm.repository_id ==
                        Repository.repo_id))\
-                .join((Permission, RepoToPerm.permission_id ==
+                .join((Permission, UserRepoToPerm.permission_id ==
                        Permission.permission_id))\
-                .filter(RepoToPerm.user_id == uid).all()
+                .filter(UserRepoToPerm.user_id == uid).all()
 
             for perm in user_repo_perms:
                 # set admin if owner
                     p = 'repository.admin'
                 else:
                     p = perm.Permission.permission_name
-                user.permissions['repositories'][perm.RepoToPerm.
+                user.permissions['repositories'][perm.UserRepoToPerm.
                                                  repository.repo_name] = p
 
             #==================================================================

rhodecode/templates/admin/repos_groups/repos_groups_show.html

                     <tr>
                         <th class="left"><a href="#">${_('Group name')}</a></th>
                         <th class="left"><a href="#">${_('Description')}</a></th>
-                        <th class="left"><a href="#">${_('Number of repositories')}</a></th>
+                        <th class="left"><a href="#">${_('Number of toplevel repositories')}</a></th>
                         <th class="left">${_('action')}</th>
                     </tr>
                 </thead>

rhodecode/tests/functional/test_admin_ldap_settings.py

 from rhodecode.tests import *
-from rhodecode.model.db import RhodeCodeSettings
+from rhodecode.model.db import RhodeCodeSetting
 from nose.plugins.skip import SkipTest
 
 skip_ldap_test = False
                     'ldap_attr_lastname':'tester',
                     'ldap_attr_email':'test@example.com' })
 
-        new_settings = RhodeCodeSettings.get_ldap_settings()
+        new_settings = RhodeCodeSetting.get_ldap_settings()
         self.assertEqual(new_settings['ldap_host'], u'dc.example.com',
                          'fail db write compare')
 

rhodecode/tests/functional/test_admin_settings.py

 # -*- coding: utf-8 -*-
 
 from rhodecode.lib.auth import get_crypt_password, check_password
-from rhodecode.model.db import User, RhodeCodeSettings
+from rhodecode.model.db import User, RhodeCodeSetting
 from rhodecode.tests import *
 
 class TestAdminSettingsController(TestController):
 
         self.checkSessionFlash(response, 'Updated application settings')
 
-        self.assertEqual(RhodeCodeSettings
+        self.assertEqual(RhodeCodeSetting
                          .get_app_settings()['rhodecode_ga_code'], new_ga_code)
 
         response = response.follow()
 
         self.assertTrue('Updated application settings' in
                         response.session['flash'][0][1])
-        self.assertEqual(RhodeCodeSettings
+        self.assertEqual(RhodeCodeSetting
                         .get_app_settings()['rhodecode_ga_code'], new_ga_code)
 
         response = response.follow()
                                                      ))
 
             self.checkSessionFlash(response, 'Updated application settings')
-            self.assertEqual(RhodeCodeSettings
+            self.assertEqual(RhodeCodeSetting
                              .get_app_settings()['rhodecode_title'],
                              new_title.decode('utf-8'))
 

rhodecode/tests/test_models.py

 
 from rhodecode.model.repos_group import ReposGroupModel
 from rhodecode.model.repo import RepoModel
-from rhodecode.model.db import Group, User
+from rhodecode.model.db import RepoGroup, User
 from sqlalchemy.exc import IntegrityError
 
 class TestReposGroups(unittest.TestCase):
     def __make_group(self, path, desc='desc', parent_id=None,
                      skip_if_exists=False):
 
-        gr = Group.get_by_group_name(path)
+        gr = RepoGroup.get_by_group_name(path)
         if gr and skip_if_exists:
             return gr
 
         sg1 = self.__make_group('deleteme')
         self.__delete_group(sg1.group_id)
 
-        self.assertEqual(Group.get(sg1.group_id), None)
+        self.assertEqual(RepoGroup.get(sg1.group_id), None)
         self.assertFalse(self.__check_path('deteteme'))
 
         sg1 = self.__make_group('deleteme', parent_id=self.g1.group_id)
         self.__delete_group(sg1.group_id)
 
-        self.assertEqual(Group.get(sg1.group_id), None)
+        self.assertEqual(RepoGroup.get(sg1.group_id), None)
         self.assertFalse(self.__check_path('test1', 'deteteme'))
 
 
 
         new_sg1 = self.__update_group(sg1.group_id, 'after')
         self.assertTrue(self.__check_path('after'))
-        self.assertEqual(Group.get_by_group_name('initial'), None)
+        self.assertEqual(RepoGroup.get_by_group_name('initial'), None)
 
 
     def test_update_group_parent(self):
 
         new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
         self.assertTrue(self.__check_path('test1', 'after'))
-        self.assertEqual(Group.get_by_group_name('test1/initial'), None)
+        self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None)
 
 
         new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
         self.assertTrue(self.__check_path('test3', 'after'))
-        self.assertEqual(Group.get_by_group_name('test3/initial'), None)
+        self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None)
 
 
         new_sg1 = self.__update_group(sg1.group_id, 'hello')
         self.assertTrue(self.__check_path('hello'))
 
-        self.assertEqual(Group.get_by_group_name('hello'), new_sg1)
+        self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1)