Changeset - cf78d302d441
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 14 years ago 2011-05-23 02:46:43
marcin@python-works.com
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
4 files changed with 43 insertions and 12 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos_groups.py
Show inline comments
 
@@ -109,12 +109,33 @@ class ReposGroupsController(BaseControll
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('repos_group', id=ID),
 
        #           method='delete')
 
        # url('repos_group', id=ID)
 

	
 
        repos_group_model = ReposGroupModel()
 
        gr = Group.get(id)
 
        repos = gr.repositories.all()
 
        if repos:
 
            h.flash(_('This group contains %s repositores and cannot be '
 
                      'deleted' % len(repos)),
 
                    category='error')
 
            return redirect(url('repos_groups'))
 

	
 

	
 
        try:
 
            repos_group_model.delete(id)
 
            h.flash(_('removed repos group %s' % gr.group_name), category='success')
 
            #TODO: in futureaction_logger(, '', '', '', self.sa)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            h.flash(_('error occurred during deletion of repos group %s' % gr.group_name),
 
                    category='error')
 

	
 
        return redirect(url('repos_groups'))
 

	
 
    def show(self, id, format='html'):
 
        """GET /repos_groups/id: Show a specific item"""
 
        # url('repos_group', id=ID)
 

	
 
        c.group = Group.get(id)
 
        if c.group:
rhodecode/model/db.py
Show inline comments
 
@@ -317,12 +317,17 @@ class Group(Base):
 
        self.parent_group = parent_group
 

	
 
    def __repr__(self):
 
        return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
 
                                  self.group_name)
 

	
 

	
 
    @classmethod
 
    def url_sep(cls):
 
        return '/'
 

	
 
    @property
 
    def parents(self):
 
        groups = []
 
        if self.parent_group is None:
 
            return groups
 
        cur_gr = self.parent_group
 
@@ -335,13 +340,13 @@ class Group(Base):
 
            groups.insert(0, gr)
 
        return groups
 

	
 

	
 
    @property
 
    def full_path(self):
 
        return '/'.join([g.group_name for g in self.parents] +
 
        return Group.url_sep().join([g.group_name for g in self.parents] +
 
                        [self.group_name])
 

	
 
    @property
 
    def repositories(self):
 
        return Session.query(Repository).filter(Repository.group == self)
 

	
rhodecode/model/forms.py
Show inline comments
 
@@ -234,15 +234,15 @@ def ValidRepoName(edit, old_data):
 
                raise formencode.Invalid('', value, state, error_dict=e_dict)
 

	
 

	
 
            if value.get('repo_group'):
 
                gr = Group.get(value.get('repo_group'))
 
                group_path = gr.full_path
 
                # value needs to be aware of group name
 
                # it has to use '/'
 
                repo_name_full = group_path + '/' + repo_name
 
                # value needs to be aware of group name in order to check
 
                # db key
 
                repo_name_full = group_path + Group.url_sep() + repo_name
 
            else:
 
                group_path = ''
 
                repo_name_full = repo_name
 

	
 

	
 
            value['repo_name_full'] = repo_name_full
rhodecode/model/repos_group.py
Show inline comments
 
@@ -55,18 +55,18 @@ class ReposGroupModel(BaseModel):
 

	
 
        :param repo_name:
 
        :param parent_id:
 
        """
 

	
 
        if parent_id:
 
            parent_group_name = Group.get(parent_id).group_name
 
            paths = Group.get(parent_id).full_path.split(Group.url_sep())
 
            parent_path = os.sep.join(paths)
 
        else:
 
            parent_group_name = ''
 
            parent_path = ''
 

	
 
        create_path = os.path.join(self.repos_path, parent_group_name,
 
                                   group_name)
 
        create_path = os.path.join(self.repos_path, parent_path, group_name)
 
        log.debug('creating new group in %s', create_path)
 

	
 
        if os.path.isdir(create_path):
 
            raise Exception('That directory already exists !')
 

	
 

	
 
@@ -78,19 +78,23 @@ class ReposGroupModel(BaseModel):
 
        Renames a group on filesystem
 
        
 
        :param group_name:
 
        """
 
        pass
 

	
 
    def __delete_group(self, group_name):
 
    def __delete_group(self, group):
 
        """
 
        Deletes a group from a filesystem
 
        
 
        :param group_name:
 
        :param group: instance of group from database
 
        """
 
        pass
 
        paths = group.full_path.split(Group.url_sep())
 
        paths = os.sep.join(paths)
 

	
 
        rm_path = os.path.join(self.repos_path, paths)
 
        os.rmdir(rm_path)
 

	
 
    def create(self, form_data):
 
        try:
 
            new_repos_group = Group()
 
            new_repos_group.group_name = form_data['repos_group_name']
 
            new_repos_group.group_description = \
 
@@ -121,13 +125,14 @@ class ReposGroupModel(BaseModel):
 
            log.error(traceback.format_exc())
 
            self.sa.rollback()
 
            raise
 

	
 
    def delete(self, users_group_id):
 
        try:
 
            users_group = self.get(users_group_id, cache=False)
 
            users_group = Group.get(users_group_id)
 
            self.sa.delete(users_group)
 
            self.__delete_group(users_group)
 
            self.sa.commit()
 
        except:
 
            log.error(traceback.format_exc())
 
            self.sa.rollback()
 
            raise
0 comments (0 inline, 0 general)