##// 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 - Import remote svn repositories to mercurial using hgsubversion
39 - Import remote svn repositories to mercurial using hgsubversion
40 - Fixed #508 RhodeCode now has a option to explicitly set forking permissions
40 - Fixed #508 RhodeCode now has a option to explicitly set forking permissions
41 - RhodeCode can use alternative server for generating avatar icons
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 fixes
46 fixes
44 +++++
47 +++++
@@ -273,7 +273,6 b' def engine_from_config(configuration, pr'
273 context._query_start_time = time.time()
273 context._query_start_time = time.time()
274 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
274 log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
275
275
276
277 def after_cursor_execute(conn, cursor, statement,
276 def after_cursor_execute(conn, cursor, statement,
278 parameters, context, executemany):
277 parameters, context, executemany):
279 total = time.time() - context._query_start_time
278 total = time.time() - context._query_start_time
@@ -5,6 +5,7 b' import os'
5 import re
5 import re
6 import formencode
6 import formencode
7 import logging
7 import logging
8 from collections import defaultdict
8 from pylons.i18n.translation import _
9 from pylons.i18n.translation import _
9 from webhelpers.pylonslib.secure_form import authentication_token
10 from webhelpers.pylonslib.secure_form import authentication_token
10
11
@@ -12,6 +13,7 b' from formencode.validators import ('
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
13 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
13 NotEmpty
14 NotEmpty
14 )
15 )
16 from rhodecode.lib.compat import OrderedSet
15 from rhodecode.lib.utils import repo_name_slug
17 from rhodecode.lib.utils import repo_name_slug
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User,\
18 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User,\
17 ChangesetStatus
19 ChangesetStatus
@@ -477,20 +479,34 b" def ValidPerms(type_='repo'):"
477 }
479 }
478
480
479 def to_python(self, value, state):
481 def to_python(self, value, state):
480 perms_update = []
482 perms_update = OrderedSet()
481 perms_new = []
483 perms_new = OrderedSet()
482 # build a list of permission to update and new permission to create
484 # build a list of permission to update and new permission to create
483 for k, v in value.items():
485
484 # means new added member to permissions
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 if k.startswith('perm_new_member'):
489 if k.startswith('perm_new_member'):
486 new_perm = value.get('perm_new_member', False)
490 del value[k]
487 new_member = value.get('perm_new_member_name', False)
491 _type, part = k.split('perm_new_member_')
488 new_type = value.get('perm_new_member_type')
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:
499 # fill new permissions in order of how they were added
491 if (new_member, new_perm, new_type) not in perms_new:
500 for k in sorted(map(int, new_perms_group.keys())):
492 perms_new.append((new_member, new_perm, new_type))
501 perm_dict = new_perms_group[str(k)]
493 elif k.startswith('u_perm_') or k.startswith('g_perm_'):
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 member = k[7:]
510 member = k[7:]
495 t = {'u': 'user',
511 t = {'u': 'user',
496 'g': 'users_group'
512 'g': 'users_group'
@@ -500,10 +516,10 b" def ValidPerms(type_='repo'):"
500 # set none for default when updating to
516 # set none for default when updating to
501 # private repo
517 # private repo
502 v = EMPTY_PERM
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
521 value['perms_updates'] = list(perms_update)
506 value['perms_new'] = perms_new
522 value['perms_new'] = list(perms_new)
507
523
508 # update permissions
524 # update permissions
509 for k, v, t in perms_new:
525 for k, v, t in perms_new:
@@ -908,7 +908,7 b' var readNotification = function(url, not'
908
908
909 /** MEMBERS AUTOCOMPLETE WIDGET **/
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 var myUsers = users_list;
912 var myUsers = users_list;
913 var myGroups = groups_list;
913 var myGroups = groups_list;
914
914
@@ -970,7 +970,7 b' var MembersAutoComplete = function (user'
970 };
970 };
971
971
972 // Instantiate AutoComplete for perms
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 membersAC.useShadow = false;
974 membersAC.useShadow = false;
975 membersAC.resultTypeList = false;
975 membersAC.resultTypeList = false;
976 membersAC.animVert = false;
976 membersAC.animVert = false;
@@ -1055,7 +1055,7 b' var MembersAutoComplete = function (user'
1055 ownerAC.formatResult = custom_formatter;
1055 ownerAC.formatResult = custom_formatter;
1056
1056
1057 var myHandler = function (sType, aArgs) {
1057 var myHandler = function (sType, aArgs) {
1058
1058 var nextId = divid.split('perm_new_member_name_')[1];
1059 var myAC = aArgs[0]; // reference back to the AC instance
1059 var myAC = aArgs[0]; // reference back to the AC instance
1060 var elLI = aArgs[1]; // reference to the selected LI element
1060 var elLI = aArgs[1]; // reference to the selected LI element
1061 var oData = aArgs[2]; // object literal of selected item's result data
1061 var oData = aArgs[2]; // object literal of selected item's result data
@@ -1063,11 +1063,11 b' var MembersAutoComplete = function (user'
1063 if (oData.nname != undefined) {
1063 if (oData.nname != undefined) {
1064 //users
1064 //users
1065 myAC.getInputEl().value = oData.nname;
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 } else {
1067 } else {
1068 //groups
1068 //groups
1069 myAC.getInputEl().value = oData.grname;
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 return compState;
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 /* Multi selectors */
1625 /* Multi selectors */
1607
1626
@@ -60,20 +60,23 b''
60 </td>
60 </td>
61 </tr>
61 </tr>
62 %endfor
62 %endfor
63 <tr id="add_perm_input">
63 <%
64 <td>${h.radio('perm_new_member','repository.none')}</td>
64 _tmpl = h.literal("""' \
65 <td>${h.radio('perm_new_member','repository.read')}</td>
65 <td><input type="radio" value="repository.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
66 <td>${h.radio('perm_new_member','repository.write')}</td>
66 <td><input type="radio" value="repository.read" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
67 <td>${h.radio('perm_new_member','repository.admin')}</td>
67 <td><input type="radio" value="repository.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
68 <td class='ac'>
68 <td><input type="radio" value="repository.admin" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
69 <div class="perm_ac" id="perm_ac">
69 <td class="ac"> \
70 ${h.text('perm_new_member_name',class_='yui-ac-input')}
70 <div class="perm_ac" id="perm_ac_{0}"> \
71 ${h.hidden('perm_new_member_type')}
71 <input class="yui-ac-input" id="perm_new_member_name_{0}" name="perm_new_member_name_{0}" value="" type="text"> \
72 <div id="perm_container"></div>
72 <input id="perm_new_member_type_{0}" name="perm_new_member_type_{0}" value="" type="hidden"> \
73 </div>
73 <div id="perm_container_{0}"></div> \
74 </td>
74 </div> \
75 <td></td>
75 </td> \
76 </tr>
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 <tr>
80 <tr>
78 <td colspan="6">
81 <td colspan="6">
79 <span id="add_perm" class="add_icon" style="cursor: pointer;">
82 <span id="add_perm" class="add_icon" style="cursor: pointer;">
@@ -118,11 +121,8 b' YUE.onDOMReady(function () {'
118 YUD.setStyle('add_perm_input', 'display', 'none');
121 YUD.setStyle('add_perm_input', 'display', 'none');
119 }
122 }
120 YAHOO.util.Event.addListener('add_perm', 'click', function () {
123 YAHOO.util.Event.addListener('add_perm', 'click', function () {
121 YUD.setStyle('add_perm_input', 'display', '');
124 addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n});
122 YUD.setStyle('add_perm', 'opacity', '0.6');
123 YUD.setStyle('add_perm', 'cursor', 'default');
124 });
125 });
125 MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n});
126 });
126 });
127
127
128 </script>
128 </script>
@@ -44,20 +44,23 b''
44 </td>
44 </td>
45 </tr>
45 </tr>
46 %endfor
46 %endfor
47 <tr id="add_perm_input">
47 <%
48 <td>${h.radio('perm_new_member','group.none')}</td>
48 _tmpl = h.literal("""' \
49 <td>${h.radio('perm_new_member','group.read')}</td>
49 <td><input type="radio" value="group.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
50 <td>${h.radio('perm_new_member','group.write')}</td>
50 <td><input type="radio" value="group.read" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
51 <td>${h.radio('perm_new_member','group.admin')}</td>
51 <td><input type="radio" value="group.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
52 <td class='ac'>
52 <td><input type="radio" value="group.admin" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \
53 <div class="perm_ac" id="perm_ac">
53 <td class="ac"> \
54 ${h.text('perm_new_member_name',class_='yui-ac-input')}
54 <div class="perm_ac" id="perm_ac_{0}"> \
55 ${h.hidden('perm_new_member_type')}
55 <input class="yui-ac-input" id="perm_new_member_name_{0}" name="perm_new_member_name_{0}" value="" type="text"> \
56 <div id="perm_container"></div>
56 <input id="perm_new_member_type_{0}" name="perm_new_member_type_{0}" value="" type="hidden"> \
57 </div>
57 <div id="perm_container_{0}"></div> \
58 </td>
58 </div> \
59 <td></td>
59 </td> \
60 </tr>
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 <tr>
64 <tr>
62 <td colspan="6">
65 <td colspan="6">
63 <span id="add_perm" class="add_icon" style="cursor: pointer;">
66 <span id="add_perm" class="add_icon" style="cursor: pointer;">
@@ -102,11 +105,8 b' YUE.onDOMReady(function () {'
102 YUD.setStyle('add_perm_input', 'display', 'none');
105 YUD.setStyle('add_perm_input', 'display', 'none');
103 }
106 }
104 YAHOO.util.Event.addListener('add_perm', 'click', function () {
107 YAHOO.util.Event.addListener('add_perm', 'click', function () {
105 YUD.setStyle('add_perm_input', 'display', '');
108 addPermAction(${_tmpl}, ${c.users_array|n}, ${c.users_groups_array|n});
106 YUD.setStyle('add_perm', 'opacity', '0.6');
107 YUD.setStyle('add_perm', 'cursor', 'default');
108 });
109 });
109 MembersAutoComplete(${c.users_array|n}, ${c.users_groups_array|n});
110 });
110 });
111
111
112 </script>
112 </script>
General Comments 0
You need to be logged in to leave comments. Login now