changeset 2749:3ed4dae499d0 beta

Recursive set locking on all children of a group.
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 28 Aug 2012 00:17:42 +0200
parents dfb15c8ee63f
children 30cafecb2630
files rhodecode/controllers/admin/repos_groups.py rhodecode/model/db.py rhodecode/model/forms.py rhodecode/model/repos_group.py rhodecode/templates/admin/repos_groups/repos_groups_edit.html
diffstat 5 files changed, 42 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/repos_groups.py	Mon Aug 27 23:33:43 2012 +0200
+++ b/rhodecode/controllers/admin/repos_groups.py	Tue Aug 28 00:17:42 2012 +0200
@@ -74,11 +74,8 @@
         :param group_id:
         """
         self.__load_defaults()
-
         repo_group = RepoGroup.get_or_404(group_id)
-
         data = repo_group.get_dict()
-
         data['group_name'] = repo_group.name
 
         # fill repository users
@@ -179,7 +176,7 @@
             h.flash(_('error occurred during update of repos group %s') \
                     % request.POST.get('group_name'), category='error')
 
-        return redirect(url('repos_groups'))
+        return redirect(url('edit_repos_group', id=id))
 
     @HasPermissionAnyDecorator('hg.admin')
     def delete(self, id):
@@ -202,10 +199,11 @@
         try:
             ReposGroupModel().delete(id)
             Session().commit()
-            h.flash(_('removed repos group %s') % gr.group_name, category='success')
+            h.flash(_('removed repos group %s') % gr.group_name,
+                    category='success')
             #TODO: in future action_logger(, '', '', '', self.sa)
         except IntegrityError, e:
-            if e.message.find('groups_group_parent_id_fkey') != -1:
+            if str(e.message).find('groups_group_parent_id_fkey') != -1:
                 log.error(traceback.format_exc())
                 h.flash(_('Cannot delete this group it still contains '
                           'subgroups'),
--- a/rhodecode/model/db.py	Mon Aug 27 23:33:43 2012 +0200
+++ b/rhodecode/model/db.py	Tue Aug 28 00:17:42 2012 +0200
@@ -994,6 +994,7 @@
     group_name = Column("group_name", String(255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
     group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
     group_description = Column("group_description", String(10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
+    enable_locking = Column("enable_locking", Boolean(), nullable=False, unique=None, default=False)
 
     repo_group_to_perm = relationship('UserRepoGroupToPerm', cascade='all', order_by='UserRepoGroupToPerm.group_to_perm_id')
     users_group_to_perm = relationship('UsersGroupRepoGroupToPerm', cascade='all')
@@ -1100,6 +1101,24 @@
 
         return cnt + children_count(self)
 
+    def recursive_groups_and_repos(self):
+        """
+        Recursive return all groups, with repositories in those groups
+        """
+        all_ = []
+
+        def _get_members(root_gr):
+            for r in root_gr.repositories:
+                all_.append(r)
+            childs = root_gr.children.all()
+            if childs:
+                for gr in childs:
+                    all_.append(gr)
+                    _get_members(gr)
+
+        _get_members(self)
+        return [self] + all_
+
     def get_new_name(self, group_name):
         """
         returns new full group name based on parent and new name
--- a/rhodecode/model/forms.py	Mon Aug 27 23:33:43 2012 +0200
+++ b/rhodecode/model/forms.py	Tue Aug 28 00:17:42 2012 +0200
@@ -127,7 +127,7 @@
         group_parent_id = v.OneOf(available_groups, hideList=False,
                                         testValueList=True,
                                         if_missing=None, not_empty=False)
-
+        enable_locking = v.StringBoolean(if_missing=False)
         chained_validators = [v.ValidReposGroup(edit, old_data),
                               v.ValidPerms('group')]
 
--- a/rhodecode/model/repos_group.py	Mon Aug 27 23:33:43 2012 +0200
+++ b/rhodecode/model/repos_group.py	Tue Aug 28 00:17:42 2012 +0200
@@ -183,11 +183,20 @@
             repos_group.group_description = form_data['group_description']
             repos_group.parent_group = RepoGroup.get(form_data['group_parent_id'])
             repos_group.group_parent_id = form_data['group_parent_id']
+            repos_group.enable_locking = form_data['enable_locking']
             repos_group.group_name = repos_group.get_new_name(form_data['group_name'])
             new_path = repos_group.full_path
 
             self.sa.add(repos_group)
 
+            # iterate over all members of this groups and set the locking !
+            # this can be potentially heavy operation
+
+            for obj in repos_group.recursive_groups_and_repos():
+                #set the value from it's parent
+                obj.enable_locking = repos_group.enable_locking
+                self.sa.add(obj)
+
             # we need to get all repositories from this new group and
             # rename them accordingly to new group path
             for r in repos_group.repositories:
--- a/rhodecode/templates/admin/repos_groups/repos_groups_edit.html	Mon Aug 27 23:33:43 2012 +0200
+++ b/rhodecode/templates/admin/repos_groups/repos_groups_edit.html	Tue Aug 28 00:17:42 2012 +0200
@@ -60,8 +60,16 @@
                 <div class="input">
                     <%include file="repos_group_edit_perms.html"/>
                 </div>
-
             </div>
+            <div class="field">
+                <div class="label label-checkbox">
+                    <label for="enable_locking">${_('Enable locking')}:</label>
+                </div>
+                <div class="checkboxes">
+                    ${h.checkbox('enable_locking',value="True")}
+                    <span class="help-block">${_('Enable lock-by-pulling on group. This option will be applied to all other groups and repositories inside')}</span>
+                </div>
+            </div>    
             <div class="buttons">
               ${h.submit('save',_('Save'),class_="ui-btn large")}
               ${h.reset('reset',_('Reset'),class_="ui-btn large")}