# HG changeset patch # User Marcin Kuzminski # Date 2012-08-28 23:07:21 # Node ID c61c2ccea2b43432e1a90a0638eeb75df7ec1116 # Parent dc4709e7da51dd659b10d71fe7ffb8476b904ade #538 form for permissions can handle multiple users at once diff --git a/docs/changelog.rst b/docs/changelog.rst --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -39,6 +39,9 @@ news - Import remote svn repositories to mercurial using hgsubversion - Fixed #508 RhodeCode now has a option to explicitly set forking permissions - RhodeCode can use alternative server for generating avatar icons +- implemented repositories locking. Pull locks, push unlocks. Also can be done + via API calls +- #538 form for permissions can handle multiple users at once fixes +++++ diff --git a/rhodecode/lib/utils2.py b/rhodecode/lib/utils2.py --- a/rhodecode/lib/utils2.py +++ b/rhodecode/lib/utils2.py @@ -273,7 +273,6 @@ def engine_from_config(configuration, pr context._query_start_time = time.time() log.info(color_sql(">>>>> STARTING QUERY >>>>>")) - def after_cursor_execute(conn, cursor, statement, parameters, context, executemany): total = time.time() - context._query_start_time diff --git a/rhodecode/model/validators.py b/rhodecode/model/validators.py --- a/rhodecode/model/validators.py +++ b/rhodecode/model/validators.py @@ -5,6 +5,7 @@ import os import re import formencode import logging +from collections import defaultdict from pylons.i18n.translation import _ from webhelpers.pylonslib.secure_form import authentication_token @@ -12,6 +13,7 @@ from formencode.validators import ( UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set, NotEmpty ) +from rhodecode.lib.compat import OrderedSet from rhodecode.lib.utils import repo_name_slug from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User,\ ChangesetStatus @@ -477,20 +479,34 @@ def ValidPerms(type_='repo'): } def to_python(self, value, state): - perms_update = [] - perms_new = [] + perms_update = OrderedSet() + perms_new = OrderedSet() # build a list of permission to update and new permission to create - for k, v in value.items(): - # means new added member to permissions + + #CLEAN OUT ORG VALUE FROM NEW MEMBERS, and group them using + new_perms_group = defaultdict(dict) + for k, v in value.copy().iteritems(): if k.startswith('perm_new_member'): - new_perm = value.get('perm_new_member', False) - new_member = value.get('perm_new_member_name', False) - new_type = value.get('perm_new_member_type') + del value[k] + _type, part = k.split('perm_new_member_') + args = part.split('_') + if len(args) == 1: + new_perms_group[args[0]]['perm'] = v + elif len(args) == 2: + _key, pos = args + new_perms_group[pos][_key] = v - if new_member and new_perm: - if (new_member, new_perm, new_type) not in perms_new: - perms_new.append((new_member, new_perm, new_type)) - elif k.startswith('u_perm_') or k.startswith('g_perm_'): + # fill new permissions in order of how they were added + for k in sorted(map(int, new_perms_group.keys())): + perm_dict = new_perms_group[str(k)] + new_member = perm_dict['name'] + new_perm = perm_dict['perm'] + new_type = perm_dict['type'] + if new_member and new_perm and new_type: + perms_new.add((new_member, new_perm, new_type)) + + for k, v in value.iteritems(): + if k.startswith('u_perm_') or k.startswith('g_perm_'): member = k[7:] t = {'u': 'user', 'g': 'users_group' @@ -500,10 +516,10 @@ def ValidPerms(type_='repo'): # set none for default when updating to # private repo v = EMPTY_PERM - perms_update.append((member, v, t)) + perms_update.add((member, v, t)) - value['perms_updates'] = perms_update - value['perms_new'] = perms_new + value['perms_updates'] = list(perms_update) + value['perms_new'] = list(perms_new) # update permissions for k, v, t in perms_new: diff --git a/rhodecode/public/js/rhodecode.js b/rhodecode/public/js/rhodecode.js --- a/rhodecode/public/js/rhodecode.js +++ b/rhodecode/public/js/rhodecode.js @@ -908,7 +908,7 @@ var readNotification = function(url, not /** MEMBERS AUTOCOMPLETE WIDGET **/ -var MembersAutoComplete = function (users_list, groups_list) { +var MembersAutoComplete = function (divid, cont, users_list, groups_list) { var myUsers = users_list; var myGroups = groups_list; @@ -970,7 +970,7 @@ var MembersAutoComplete = function (user }; // Instantiate AutoComplete for perms - var membersAC = new YAHOO.widget.AutoComplete("perm_new_member_name", "perm_container", memberDS); + var membersAC = new YAHOO.widget.AutoComplete(divid, cont, memberDS); membersAC.useShadow = false; membersAC.resultTypeList = false; membersAC.animVert = false; @@ -1055,7 +1055,7 @@ var MembersAutoComplete = function (user ownerAC.formatResult = custom_formatter; var myHandler = function (sType, aArgs) { - + var nextId = divid.split('perm_new_member_name_')[1]; var myAC = aArgs[0]; // reference back to the AC instance var elLI = aArgs[1]; // reference to the selected LI element var oData = aArgs[2]; // object literal of selected item's result data @@ -1063,11 +1063,11 @@ var MembersAutoComplete = function (user if (oData.nname != undefined) { //users myAC.getInputEl().value = oData.nname; - YUD.get('perm_new_member_type').value = 'user'; + YUD.get('perm_new_member_type_'+nextId).value = 'user'; } else { //groups myAC.getInputEl().value = oData.grname; - YUD.get('perm_new_member_type').value = 'users_group'; + YUD.get('perm_new_member_type_'+nextId).value = 'users_group'; } }; @@ -1602,6 +1602,25 @@ var linkSort = function(a, b, desc, fiel return compState; } +var addPermAction = function(_html, users_list, groups_list){ + var elmts = YUD.getElementsByClassName('last_new_member'); + var last_node = elmts[elmts.length-1]; + if (last_node){ + var next_id = (YUD.getElementsByClassName('new_members')).length; + _html = _html.format(next_id); + last_node.innerHTML = _html; + YUD.setStyle(last_node, 'display', ''); + YUD.removeClass(last_node, 'last_new_member'); + MembersAutoComplete("perm_new_member_name_"+next_id, + "perm_container_"+next_id, users_list, groups_list); + //create new last NODE + var el = document.createElement('tr'); + el.id = 'add_perm_input'; + YUD.addClass(el,'last_new_member'); + YUD.addClass(el,'new_members'); + YUD.insertAfter(el, last_node); + } +} /* Multi selectors */ diff --git a/rhodecode/templates/admin/repos/repo_edit_perms.html b/rhodecode/templates/admin/repos/repo_edit_perms.html --- a/rhodecode/templates/admin/repos/repo_edit_perms.html +++ b/rhodecode/templates/admin/repos/repo_edit_perms.html @@ -60,20 +60,23 @@ %endfor - - ${h.radio('perm_new_member','repository.none')} - ${h.radio('perm_new_member','repository.read')} - ${h.radio('perm_new_member','repository.write')} - ${h.radio('perm_new_member','repository.admin')} - -
- ${h.text('perm_new_member_name',class_='yui-ac-input')} - ${h.hidden('perm_new_member_type')} -
-
- - - + <% + _tmpl = h.literal("""' \ + \ + \ + \ + \ + \ +
\ + \ + \ +
\ +
\ + \ + '""") + %> + ## ADD HERE DYNAMICALLY NEW INPUTS FROM THE '_tmpl' + @@ -118,11 +121,8 @@ YUE.onDOMReady(function () { YUD.setStyle('add_perm_input', 'display', 'none'); } YAHOO.util.Event.addListener('add_perm', 'click', function () { - YUD.setStyle('add_perm_input', 'display', ''); - YUD.setStyle('add_perm', 'opacity', '0.6'); - YUD.setStyle('add_perm', 'cursor', 'default'); + addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n}); }); - MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n}); }); diff --git a/rhodecode/templates/admin/repos_groups/repos_group_edit_perms.html b/rhodecode/templates/admin/repos_groups/repos_group_edit_perms.html --- a/rhodecode/templates/admin/repos_groups/repos_group_edit_perms.html +++ b/rhodecode/templates/admin/repos_groups/repos_group_edit_perms.html @@ -44,20 +44,23 @@ %endfor - - ${h.radio('perm_new_member','group.none')} - ${h.radio('perm_new_member','group.read')} - ${h.radio('perm_new_member','group.write')} - ${h.radio('perm_new_member','group.admin')} - -
- ${h.text('perm_new_member_name',class_='yui-ac-input')} - ${h.hidden('perm_new_member_type')} -
-
- - - +<% + _tmpl = h.literal("""' \ + \ + \ + \ + \ + \ +
\ + \ + \ +
\ +
\ + \ + '""") + %> + ## ADD HERE DYNAMICALLY NEW INPUTS FROM THE '_tmpl' + @@ -102,11 +105,8 @@ YUE.onDOMReady(function () { YUD.setStyle('add_perm_input', 'display', 'none'); } YAHOO.util.Event.addListener('add_perm', 'click', function () { - YUD.setStyle('add_perm_input', 'display', ''); - YUD.setStyle('add_perm', 'opacity', '0.6'); - YUD.setStyle('add_perm', 'cursor', 'default'); + addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n}); }); - MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n}); });