##// END OF EJS Templates
#538 form for permissions can handle multiple users at once
marcink -
r2759:c61c2cce beta
parent child Browse files
Show More
@@ -39,6 +39,9 b' news'
39 39 - Import remote svn repositories to mercurial using hgsubversion
40 40 - Fixed #508 RhodeCode now has a option to explicitly set forking permissions
41 41 - RhodeCode can use alternative server for generating avatar icons
42 - implemented repositories locking. Pull locks, push unlocks. Also can be done
43 via API calls
44 - #538 form for permissions can handle multiple users at once
42 45
43 46 fixes
44 47 +++++
@@ -273,7 +273,6 b' def engine_from_config(configuration, pr'
273 273 context._query_start_time = time.time()
274 274 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
275 275
276
277 276 def after_cursor_execute(conn, cursor, statement,
278 277 parameters, context, executemany):
279 278 total = time.time() - context._query_start_time
@@ -5,6 +5,7 b' import os'
5 5 import re
6 6 import formencode
7 7 import logging
8 from collections import defaultdict
8 9 from pylons.i18n.translation import _
9 10 from webhelpers.pylonslib.secure_form import authentication_token
10 11
@@ -12,6 +13,7 b' from formencode.validators import ('
12 13 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
13 14 NotEmpty
14 15 )
16 from rhodecode.lib.compat import OrderedSet
15 17 from rhodecode.lib.utils import repo_name_slug
16 18 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User,\
17 19 ChangesetStatus
@@ -477,20 +479,34 b" def ValidPerms(type_='repo'):"
477 479 }
478 480
479 481 def to_python(self, value, state):
480 perms_update = []
481 perms_new = []
482 perms_update = OrderedSet()
483 perms_new = OrderedSet()
482 484 # build a list of permission to update and new permission to create
483 for k, v in value.items():
484 # means new added member to permissions
485
486 #CLEAN OUT ORG VALUE FROM NEW MEMBERS, and group them using
487 new_perms_group = defaultdict(dict)
488 for k, v in value.copy().iteritems():
485 489 if k.startswith('perm_new_member'):
486 new_perm = value.get('perm_new_member', False)
487 new_member = value.get('perm_new_member_name', False)
488 new_type = value.get('perm_new_member_type')
490 del value[k]
491 _type, part = k.split('perm_new_member_')
492 args = part.split('_')
493 if len(args) == 1:
494 new_perms_group[args[0]]['perm'] = v
495 elif len(args) == 2:
496 _key, pos = args
497 new_perms_group[pos][_key] = v
489 498
490 if new_member and new_perm:
491 if (new_member, new_perm, new_type) not in perms_new:
492 perms_new.append((new_member, new_perm, new_type))
493 elif k.startswith('u_perm_') or k.startswith('g_perm_'):
499 # fill new permissions in order of how they were added
500 for k in sorted(map(int, new_perms_group.keys())):
501 perm_dict = new_perms_group[str(k)]
502 new_member = perm_dict['name']
503 new_perm = perm_dict['perm']
504 new_type = perm_dict['type']
505 if new_member and new_perm and new_type:
506 perms_new.add((new_member, new_perm, new_type))
507
508 for k, v in value.iteritems():
509 if k.startswith('u_perm_') or k.startswith('g_perm_'):
494 510 member = k[7:]
495 511 t = {'u': 'user',
496 512 'g': 'users_group'
@@ -500,10 +516,10 b" def ValidPerms(type_='repo'):"
500 516 # set none for default when updating to
501 517 # private repo
502 518 v = EMPTY_PERM
503 perms_update.append((member, v, t))
519 perms_update.add((member, v, t))
504 520
505 value['perms_updates'] = perms_update
506 value['perms_new'] = perms_new
521 value['perms_updates'] = list(perms_update)
522 value['perms_new'] = list(perms_new)
507 523
508 524 # update permissions
509 525 for k, v, t in perms_new:
@@ -908,7 +908,7 b' var readNotification = function(url, not'
908 908
909 909 /** MEMBERS AUTOCOMPLETE WIDGET **/
910 910
911 var MembersAutoComplete = function (users_list, groups_list) {
911 var MembersAutoComplete = function (divid, cont, users_list, groups_list) {
912 912 var myUsers = users_list;
913 913 var myGroups = groups_list;
914 914
@@ -970,7 +970,7 b' var MembersAutoComplete = function (user'
970 970 };
971 971
972 972 // Instantiate AutoComplete for perms
973 var membersAC = new YAHOO.widget.AutoComplete("perm_new_member_name", "perm_container", memberDS);
973 var membersAC = new YAHOO.widget.AutoComplete(divid, cont, memberDS);
974 974 membersAC.useShadow = false;
975 975 membersAC.resultTypeList = false;
976 976 membersAC.animVert = false;
@@ -1055,7 +1055,7 b' var MembersAutoComplete = function (user'
1055 1055 ownerAC.formatResult = custom_formatter;
1056 1056
1057 1057 var myHandler = function (sType, aArgs) {
1058
1058 var nextId = divid.split('perm_new_member_name_')[1];
1059 1059 var myAC = aArgs[0]; // reference back to the AC instance
1060 1060 var elLI = aArgs[1]; // reference to the selected LI element
1061 1061 var oData = aArgs[2]; // object literal of selected item's result data
@@ -1063,11 +1063,11 b' var MembersAutoComplete = function (user'
1063 1063 if (oData.nname != undefined) {
1064 1064 //users
1065 1065 myAC.getInputEl().value = oData.nname;
1066 YUD.get('perm_new_member_type').value = 'user';
1066 YUD.get('perm_new_member_type_'+nextId).value = 'user';
1067 1067 } else {
1068 1068 //groups
1069 1069 myAC.getInputEl().value = oData.grname;
1070 YUD.get('perm_new_member_type').value = 'users_group';
1070 YUD.get('perm_new_member_type_'+nextId).value = 'users_group';
1071 1071 }
1072 1072 };
1073 1073
@@ -1602,6 +1602,25 b' var linkSort = function(a, b, desc, fiel'
1602 1602 return compState;
1603 1603 }
1604 1604
1605 var addPermAction = function(_html, users_list, groups_list){
1606 var elmts = YUD.getElementsByClassName('last_new_member');
1607 var last_node = elmts[elmts.length-1];
1608 if (last_node){
1609 var next_id = (YUD.getElementsByClassName('new_members')).length;
1610 _html = _html.format(next_id);
1611 last_node.innerHTML = _html;
1612 YUD.setStyle(last_node, 'display', '');
1613 YUD.removeClass(last_node, 'last_new_member');
1614 MembersAutoComplete("perm_new_member_name_"+next_id,
1615 "perm_container_"+next_id, users_list, groups_list);
1616 //create new last NODE
1617 var el = document.createElement('tr');
1618 el.id = 'add_perm_input';
1619 YUD.addClass(el,'last_new_member');
1620 YUD.addClass(el,'new_members');
1621 YUD.insertAfter(el, last_node);
1622 }
1623 }
1605 1624
1606 1625 /* Multi selectors */
1607 1626
@@ -60,20 +60,23 b''
60 60 </td>
61 61 </tr>
62 62 %endfor
63 <tr id="add_perm_input">
64 <td>${h.radio('perm_new_member','repository.none')}</td>
65 <td>${h.radio('perm_new_member','repository.read')}</td>
66 <td>${h.radio('perm_new_member','repository.write')}</td>
67 <td>${h.radio('perm_new_member','repository.admin')}</td>
68 <td class='ac'>
69 <div class="perm_ac" id="perm_ac">
70 ${h.text('perm_new_member_name',class_='yui-ac-input')}
71 ${h.hidden('perm_new_member_type')}
72 <div id="perm_container"></div>
73 </div>
74 </td>
75 <td></td>
76 </tr>
63 <%
64 _tmpl = h.literal("""' \
65 <td><input type="radio" value="repository.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
66 <td><input type="radio" value="repository.read" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
67 <td><input type="radio" value="repository.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
68 <td><input type="radio" value="repository.admin" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
69 <td class="ac"> \
70 <div class="perm_ac" id="perm_ac_{0}"> \
71 <input class="yui-ac-input" id="perm_new_member_name_{0}" name="perm_new_member_name_{0}" value="" type="text"> \
72 <input id="perm_new_member_type_{0}" name="perm_new_member_type_{0}" value="" type="hidden"> \
73 <div id="perm_container_{0}"></div> \
74 </div> \
75 </td> \
76 <td></td>'""")
77 %>
78 ## ADD HERE DYNAMICALLY NEW INPUTS FROM THE '_tmpl'
79 <tr class="new_members last_new_member" id="add_perm_input"></tr>
77 80 <tr>
78 81 <td colspan="6">
79 82 <span id="add_perm" class="add_icon" style="cursor: pointer;">
@@ -118,11 +121,8 b' YUE.onDOMReady(function () {'
118 121 YUD.setStyle('add_perm_input', 'display', 'none');
119 122 }
120 123 YAHOO.util.Event.addListener('add_perm', 'click', function () {
121 YUD.setStyle('add_perm_input', 'display', '');
122 YUD.setStyle('add_perm', 'opacity', '0.6');
123 YUD.setStyle('add_perm', 'cursor', 'default');
124 addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n});
124 125 });
125 MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n});
126 126 });
127 127
128 128 </script>
@@ -44,20 +44,23 b''
44 44 </td>
45 45 </tr>
46 46 %endfor
47 <tr id="add_perm_input">
48 <td>${h.radio('perm_new_member','group.none')}</td>
49 <td>${h.radio('perm_new_member','group.read')}</td>
50 <td>${h.radio('perm_new_member','group.write')}</td>
51 <td>${h.radio('perm_new_member','group.admin')}</td>
52 <td class='ac'>
53 <div class="perm_ac" id="perm_ac">
54 ${h.text('perm_new_member_name',class_='yui-ac-input')}
55 ${h.hidden('perm_new_member_type')}
56 <div id="perm_container"></div>
57 </div>
58 </td>
59 <td></td>
60 </tr>
47 <%
48 _tmpl = h.literal("""' \
49 <td><input type="radio" value="group.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
50 <td><input type="radio" value="group.read" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
51 <td><input type="radio" value="group.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
52 <td><input type="radio" value="group.admin" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
53 <td class="ac"> \
54 <div class="perm_ac" id="perm_ac_{0}"> \
55 <input class="yui-ac-input" id="perm_new_member_name_{0}" name="perm_new_member_name_{0}" value="" type="text"> \
56 <input id="perm_new_member_type_{0}" name="perm_new_member_type_{0}" value="" type="hidden"> \
57 <div id="perm_container_{0}"></div> \
58 </div> \
59 </td> \
60 <td></td>'""")
61 %>
62 ## ADD HERE DYNAMICALLY NEW INPUTS FROM THE '_tmpl'
63 <tr class="new_members last_new_member" id="add_perm_input"></tr>
61 64 <tr>
62 65 <td colspan="6">
63 66 <span id="add_perm" class="add_icon" style="cursor: pointer;">
@@ -102,11 +105,8 b' YUE.onDOMReady(function () {'
102 105 YUD.setStyle('add_perm_input', 'display', 'none');
103 106 }
104 107 YAHOO.util.Event.addListener('add_perm', 'click', function () {
105 YUD.setStyle('add_perm_input', 'display', '');
106 YUD.setStyle('add_perm', 'opacity', '0.6');
107 YUD.setStyle('add_perm', 'cursor', 'default');
108 addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n});
108 109 });
109 MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n});
110 110 });
111 111
112 112 </script>
General Comments 0
You need to be logged in to leave comments. Login now