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
 
@@ -112,6 +112,27 @@ class ReposGroupsController(BaseControll
 
        #           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)
rhodecode/model/db.py
Show inline comments
 
@@ -320,6 +320,11 @@ class Group(Base):
 
        return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
 
                                  self.group_name)
 

	
 

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

	
 
    @property
 
    def parents(self):
 
        groups = []
 
@@ -338,7 +343,7 @@ class Group(Base):
 

	
 
    @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
rhodecode/model/forms.py
Show inline comments
 
@@ -237,9 +237,9 @@ def ValidRepoName(edit, old_data):
 
            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
rhodecode/model/repos_group.py
Show inline comments
 
@@ -58,12 +58,12 @@ class ReposGroupModel(BaseModel):
 
        """
 

	
 
        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):
 
@@ -81,13 +81,17 @@ class ReposGroupModel(BaseModel):
 
        """
 
        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:
 
@@ -124,8 +128,9 @@ class ReposGroupModel(BaseModel):
 

	
 
    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())
0 comments (0 inline, 0 general)