Merge lp:~wallyworld/launchpad/tri-state-sharee-picker-959784 into lp:launchpad

Proposed by Ian Booth on 2012-03-21
Status: Merged
Approved by: Ian Booth on 2012-03-21
Approved revision: no longer in the source branch.
Merged at revision: 14989
Proposed branch: lp:~wallyworld/launchpad/tri-state-sharee-picker-959784
Merge into: lp:launchpad
Diff against target: 592 lines (+226/-86)
6 files modified
lib/lp/registry/javascript/sharing/pillarsharingview.js (+10/-11)
lib/lp/registry/javascript/sharing/shareepicker.js (+101/-42)
lib/lp/registry/javascript/sharing/tests/test_pillarsharingview.js (+21/-8)
lib/lp/registry/javascript/sharing/tests/test_shareepicker.js (+73/-22)
lib/lp/registry/services/sharingservice.py (+10/-3)
lib/lp/registry/services/tests/test_sharingservice.py (+11/-0)
To merge this branch: bzr merge lp:~wallyworld/launchpad/tri-state-sharee-picker-959784
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code 2012-03-21 Approve on 2012-03-21
Review via email: mp+98556@code.launchpad.net

Commit Message

The permissions selection on the sharing picker now uses radio buttons to allow selection of 'All', 'Some' or 'Nothing'.

Description of the Change

== Implementation ==

The permissions selection on the sharing picker now uses radio buttons to allow selection of 'All', 'Some' or 'Nothing'. Adding a new sharee only shows 'All' or 'Nothing'.

The picker shows the radio buttons in the order 'All', 'Some', 'Nothing'.

The core picker changes were copied and adapted from the interactive mockup.

== Tests ==

Update pillarsharingview and shareepicker yui tests.
Add new test to check that getSharingPermissions() gives the permissions in the right order (All, Some, Nothing)

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/javascript/sharing/pillarsharingview.js
  lib/lp/registry/javascript/sharing/shareepicker.js
  lib/lp/registry/javascript/sharing/tests/test_pillarsharingview.js
  lib/lp/registry/javascript/sharing/tests/test_shareepicker.js
  lib/lp/registry/services/sharingservice.py
  lib/lp/registry/services/tests/test_sharingservice.py

To post a comment you must log in.
Steve Kowalik (stevenk) wrote :

184 + // Determine the selected permisios. data already contains the

What? :-)

433 + // (an no others).

As above.

587 + for x, permission in enumerate(expected_permissions):
588 + self.assertEqual(permissions[x]['value'], permission.name)

You seem to be allergic to list comprehensions -- fix this one if you want, I don't mind.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/javascript/sharing/pillarsharingview.js'
2--- lib/lp/registry/javascript/sharing/pillarsharingview.js 2012-03-16 23:46:20 +0000
3+++ lib/lp/registry/javascript/sharing/pillarsharingview.js 2012-03-21 03:22:20 +0000
4@@ -86,9 +86,10 @@
5 zIndex: 1000,
6 visible: false,
7 information_types: LP.cache.information_types,
8+ sharing_permissions: LP.cache.sharing_permissions,
9 save: function(result) {
10 self.save_sharing_selection(
11- result.api_uri, result.sharing_permissions);
12+ result.api_uri, result.selected_permissions);
13 }
14 });
15 var ns = Y.lp.registry.sharing.shareepicker;
16@@ -347,31 +348,29 @@
17 * @param person_name
18 */
19 update_sharee_interaction: function(update_link, person_uri, person_name) {
20- var information_types_by_value =
21- this.get('information_types_by_value');
22 var sharee_data = LP.cache.sharee_data;
23- var selected_permissions = [];
24+ var sharee_permissions = {};
25 Y.Array.some(sharee_data, function(sharee) {
26 var full_person_uri = Y.lp.client.normalize_uri(person_uri);
27 full_person_uri = Y.lp.client.get_absolute_uri(full_person_uri);
28 if (sharee.self_link !== full_person_uri) {
29 return false;
30 }
31- Y.each(sharee.permissions, function(permission, info_type_value) {
32- //we only support ALL for now
33- if ('ALL' === permission) {
34- selected_permissions.push(info_type_value);
35- }
36- });
37+ sharee_permissions = sharee.permissions;
38 return true;
39 });
40+ var allowed_permissions = [];
41+ Y.Array.each(LP.cache.sharing_permissions, function(permission) {
42+ allowed_permissions.push(permission.value);
43+ });
44 this.get('sharee_picker').show({
45 first_step: 2,
46 sharee: {
47 person_uri: person_uri,
48 person_name: person_name
49 },
50- selected_permissions: selected_permissions
51+ sharee_permissions: sharee_permissions,
52+ allowed_permissions: allowed_permissions
53 });
54 }
55 });
56
57=== modified file 'lib/lp/registry/javascript/sharing/shareepicker.js'
58--- lib/lp/registry/javascript/sharing/shareepicker.js 2012-03-15 08:54:40 +0000
59+++ lib/lp/registry/javascript/sharing/shareepicker.js 2012-03-21 03:22:20 +0000
60@@ -27,6 +27,9 @@
61 information_types: {
62 value: []
63 },
64+ sharing_permissions: {
65+ value: []
66+ },
67 // Override for testing
68 anim_duration: {
69 value: 1
70@@ -38,15 +41,20 @@
71 initializer: function(config) {
72 ShareePicker.superclass.initializer.apply(this, arguments);
73 var information_types = [];
74+ var sharing_permissions = [];
75 if (config !== undefined) {
76 if (config.information_types !== undefined) {
77 information_types = config.information_types;
78 }
79+ if (config.sharing_permissions !== undefined) {
80+ sharing_permissions = config.sharing_permissions;
81+ }
82 }
83 this.set('information_types', information_types);
84+ this.set('sharing_permissions', sharing_permissions);
85 var self = this;
86 this.subscribe('save', function (e) {
87- e.preventDefault();
88+ e.halt();
89 // The step number indicates which picker step has just fired.
90 var step_nr = e.details[1];
91 if (!Y.Lang.isNumber(step_nr)) {
92@@ -122,34 +130,54 @@
93 step_two_content.one('a.prev').remove(true);
94 } else {
95 step_two_content.one('a.prev').on('click', function(e) {
96- e.preventDefault();
97+ e.halt();
98 self._display_step_one();
99 });
100 }
101 // Wire up the next (ie submit) links.
102 step_two_content.all('.next').on('click', function(e) {
103- e.preventDefault();
104+ e.halt();
105 // Only submit if at least one info type is selected.
106 if (!self._all_info_choices_unticked(step_two_content)) {
107 self.fire('save', data, 2);
108 }
109 });
110+ // By default, we only show All or Nothing.
111+ var allowed_permissions = ['ALL', 'NOTHING'];
112+ if (Y.Lang.isValue(data.allowed_permissions)) {
113+ allowed_permissions = data.allowed_permissions;
114+ }
115+ var sharing_permissions = [];
116+ Y.Array.each(this.get('sharing_permissions'),
117+ function(permission) {
118+ if (Y.Array.indexOf(
119+ allowed_permissions, permission.value) >=0) {
120+ sharing_permissions.push(permission);
121+ }
122+ });
123+ var policy_selector = self._make_policy_selector(
124+ sharing_permissions);
125 step_two_content.one('div.step-links')
126- .insert(self._make_policy_selector(), 'before');
127+ .insert(policy_selector, 'before');
128 step_one_content.insert(step_two_content, 'after');
129- step_two_content.all('input[name=field.visibility]')
130+ step_two_content.all('input[name^=field.permission]')
131 .on('click', function(e) {
132 self._disable_select_if_all_info_choices_unticked(
133 step_two_content);
134 });
135 }
136- // If we have been given values for the information_type data, ensure
137- // the relevant checkboxes are ticked.
138- if (Y.Lang.isArray(data.information_types)) {
139- Y.Array.each(data.information_types, function(info_type) {
140+ // Initially set all radio buttons to Nothing.
141+ step_two_content.all('input[name^=field.permission][value=NOTHING]')
142+ .each(function(radio_button) {
143+ radio_button.set('checked', true);
144+ });
145+ // Ensure the correct radio buttons are ticked according to the
146+ // sharee_permissions.
147+ if (Y.Lang.isObject(data.sharee_permissions)) {
148+ Y.each(data.sharee_permissions, function(perm, type) {
149 var cb = step_two_content.one(
150- 'input[name=field.visibility]' +
151- '[value="' + info_type + '"]');
152+ 'input[name=field.permission.'+type+']' +
153+ '[value="' + perm + '"]');
154 if (Y.Lang.isValue(cb)) {
155 cb.set('checked', true);
156 }
157@@ -160,16 +188,18 @@
158 },
159
160 /**
161- * Are all the info type checkboxes unticked?
162+ * Are all the radio buttons set to Nothing?
163 * @param content
164 * @return {Boolean}
165 * @private
166 */
167 _all_info_choices_unticked: function(content) {
168 var all_unticked = true;
169- content.all('input[name=field.visibility]')
170+ content.all('input[name^=field.permission]')
171 .each(function(info_node) {
172- all_unticked &= !info_node.get('checked');
173+ if (info_node.get('value') !== 'NOTHING') {
174+ all_unticked &= !info_node.get('checked');
175+ }
176 });
177 return all_unticked;
178 },
179@@ -191,50 +221,78 @@
180 },
181
182 _publish_result: function(data) {
183- // Determine the chosen information type. data already contains the
184+ // Determine the selected permissions. 'data' already contains the
185 // selected person due to the base picker behaviour.
186 var contentBox = this.get('contentBox');
187- var sharing_permissions = {};
188- contentBox.all('input[name=field.visibility]')
189- .each(function(node) {
190- var permission = 'NOTHING';
191+ var selected_permissions = {};
192+ Y.Array.each(this.get('information_types'), function(info_type) {
193+ contentBox.all('input[name=field.permission.'+info_type.value+']')
194+ .each(function(node) {
195 if (node.get('checked')) {
196- permission = 'ALL';
197+ selected_permissions[info_type.value] = node.get('value');
198 }
199- sharing_permissions[node.get('value')] = permission;
200 });
201- data.sharing_permissions = sharing_permissions;
202+ });
203+ data.selected_permissions = selected_permissions;
204 // Publish the result with step_nr 0 to indicate we have finished.
205 this.fire('save', data, 0);
206 },
207
208- _make_policy_selector: function() {
209+ _sharing_permission_template: function() {
210+ return [
211+ '<table class="radio-button-widget"><tbody>',
212+ '{{#permissions}}',
213+ '<tr>',
214+ ' <input type="radio"',
215+ ' value="{{value}}"',
216+ ' name="field.permission.{{info_type}}"',
217+ ' id="field.permission.{{info_type}}.{{index}}"',
218+ ' class="radioType">',
219+ ' <label for="field.permission.{{info_type}}"',
220+ ' title="{{description}}">',
221+ ' {{title}}',
222+ ' </label>',
223+ '</tr>',
224+ '{{/permissions}}',
225+ '</tbody></table>'
226+ ].join('');
227+ },
228+
229+ _make_policy_selector: function(allowed_permissions) {
230 // The policy selector is a set of radio buttons.
231+ var sharing_permissions_template = this._sharing_permission_template();
232 var html = Y.lp.mustache.to_html([
233 '<div class="selection-choices">',
234- '<table class="radio-button-widget"><tbody>',
235+ '<table><tbody>',
236 '{{#policies}}',
237- ' <tr>',
238- ' <td rowspan="2"><input type="checkbox"',
239- ' value="{{value}}"',
240- ' name="field.visibility"',
241- ' id="field.visibility.{{index}}"',
242- ' class="checkboxType">',
243- ' </td>',
244- ' <td><label for="field.visibility.{{index}}">',
245+ '<tr>',
246+ ' <td><strong>',
247 ' <span class="accessPolicy{{value}}">{{title}}',
248- ' </span></label>',
249- ' </td>',
250- ' </tr>',
251- ' <tr>',
252- ' <td class="formHelp">',
253- ' {{description}}',
254- ' </td>',
255- ' </tr>',
256+ ' </span>',
257+ ' </strong></td>',
258+ '</tr>',
259+ '<tr>',
260+ ' <td>',
261+ ' {{#sharing_permissions}} {{/sharing_permissions}}',
262+ ' </td>',
263+ '</tr>',
264+ '<tr>',
265+ ' <td class="formHelp">',
266+ ' {{description}}',
267+ ' </td>',
268+ '</tr>',
269 '{{/policies}}',
270 '</tbody></table></div>'
271 ].join(''), {
272- policies: this.get('information_types')
273+ policies: this.get('information_types'),
274+ sharing_permissions: function() {
275+ return function(text, render) {
276+ return Y.lp.mustache.to_html(sharing_permissions_template, {
277+ permissions: allowed_permissions,
278+ info_type: render('{{value}}')
279+ });
280+ };
281+ }
282 });
283 return Y.Node.create(html);
284 },
285@@ -273,7 +331,8 @@
286 var data = {
287 title: config.sharee.person_name,
288 api_uri: config.sharee.person_uri,
289- information_types: config.selected_permissions,
290+ sharee_permissions: config.sharee_permissions,
291+ allowed_permissions: config.allowed_permissions,
292 back_enabled: false
293 };
294 this._display_step_two(data);
295
296=== modified file 'lib/lp/registry/javascript/sharing/tests/test_pillarsharingview.js'
297--- lib/lp/registry/javascript/sharing/tests/test_pillarsharingview.js 2012-03-16 08:18:37 +0000
298+++ lib/lp/registry/javascript/sharing/tests/test_pillarsharingview.js 2012-03-21 03:22:20 +0000
299@@ -20,19 +20,19 @@
300 {'name': 'fred', 'display_name': 'Fred Bloggs',
301 'role': '(Maintainer)', web_link: '~fred',
302 'self_link': '~fred',
303- 'permissions': {'P1': 'ALL', 'P2': 's2'}},
304+ 'permissions': {'P1': 'ALL', 'P2': 'SOME'}},
305 {'name': 'john', 'display_name': 'John Smith',
306 'role': '', web_link: '~john',
307 'self_link': 'file:///api/devel/~john',
308- 'permissions': {'P1': 'ALL', 'P3': 's3'}}
309+ 'permissions': {'P1': 'ALL', 'P3': 'SOME'}}
310 ],
311 sharing_permissions: [
312 {'value': 'ALL', 'title': 'All',
313 'description': 'Everything'},
314 {'value': 'NOTHING', 'title': 'Nothing',
315 'description': 'Nothing'},
316- {'value': 's2', 'title': 'S2',
317- 'description': 'Sharing 2'}
318+ {'value': 'SOME', 'title': 'Some',
319+ 'description': 'Some'}
320 ],
321 information_types: [
322 {index: '0', value: 'P1', title: 'Policy 1',
323@@ -123,8 +123,12 @@
324 Y.Assert.areEqual(2, config.first_step);
325 Y.Assert.areEqual('~john', config.sharee.person_uri);
326 Y.Assert.areEqual('John', config.sharee.person_name);
327+ Y.Assert.areEqual(2, Y.Object.size(config.sharee_permissions));
328+ Y.Assert.areEqual('ALL', config.sharee_permissions.P1);
329+ Y.Assert.areEqual('SOME', config.sharee_permissions.P3);
330 Y.ArrayAssert.itemsAreEqual(
331- ['P1'], config.selected_permissions);
332+ ['ALL', 'NOTHING', 'SOME'],
333+ config.allowed_permissions);
334 show_picker_called = true;
335 };
336 var update_link =
337@@ -278,7 +282,16 @@
338 '.yui3-picker-results li:nth-child(1)').simulate('click');
339 var cb = sharee_picker.get('contentBox');
340 var step_two_content = cb.one('.picker-content-two');
341- step_two_content.one('input[value="P2"]').simulate('click');
342+ // All sharing permissions should initially be set to nothing.
343+ step_two_content.all('input[name^=field.permission]')
344+ .each(function(radio_button) {
345+ if (radio_button.get('checked')) {
346+ Y.Assert.areEqual('NOTHING', radio_button.get('value'));
347+ }
348+ });
349+ step_two_content
350+ .one('input[name=field.permission.P2][value="ALL"]')
351+ .simulate('click');
352 var select_link = step_two_content.one('a.next');
353 select_link.simulate('click');
354 // Selection made using the picker, now check the results.
355@@ -328,7 +341,7 @@
356 Y.one('#sharee-table span[id=P1-permission-fred] a');
357 permission_popup.simulate('click');
358 var permission_choice = Y.one(
359- '.yui3-ichoicelist-content a[href=#s2]');
360+ '.yui3-ichoicelist-content a[href=#SOME]');
361 permission_choice.simulate('click');
362
363 // Selection made, now check the results.
364@@ -345,7 +358,7 @@
365 expected_url = Y.lp.client.append_qs(
366 expected_url, 'sharee', person_uri);
367 expected_url = Y.lp.client.append_qs(
368- expected_url, 'permissions', 'Policy 1,S2');
369+ expected_url, 'permissions', 'Policy 1,Some');
370 Y.Assert.areEqual(expected_url, mockio.last_request.config.data);
371 mockio.last_request.successJSON({
372 'name': 'fred',
373
374=== modified file 'lib/lp/registry/javascript/sharing/tests/test_shareepicker.js'
375--- lib/lp/registry/javascript/sharing/tests/test_shareepicker.js 2012-03-15 08:54:40 +0000
376+++ lib/lp/registry/javascript/sharing/tests/test_shareepicker.js 2012-03-21 03:22:20 +0000
377@@ -25,6 +25,14 @@
378 description: 'Policy 2 description'},
379 {index: '2', value: 'P3', title: 'Policy 3',
380 description: 'Policy 3 description'}];
381+ this.sharing_permissions = [
382+ {'index': 0, 'value': 'ALL', 'title': 'All',
383+ 'description': 'Everything'},
384+ {'index': 1, 'value': 'NOTHING', 'title': 'Nothing',
385+ 'description': 'Nothing'},
386+ {'index': 2, 'value': 'SOME', 'title': 'Some',
387+ 'description': 'Some'}
388+ ];
389 },
390
391 tearDown: function () {
392@@ -54,7 +62,8 @@
393 "with whom to share",
394 zIndex: 1000,
395 visible: false,
396- information_types: this.information_types
397+ information_types: this.information_types,
398+ sharing_permissions: this.sharing_permissions
399 };
400 if (overrides !== undefined) {
401 config = Y.merge(config, overrides);
402@@ -109,11 +118,14 @@
403 var step_two_content = cb.one('.picker-content-two');
404 Y.Assert.isFalse(step_two_content.hasClass('unseen'));
405 // The second step ui should contain input buttons for each access
406- // policy type.
407+ // policy type for each sharing permission.
408 Y.Array.each(this.information_types, function(info_type) {
409- var rb = step_two_content.one(
410- 'input[value="' + info_type.value + '"]');
411- Y.Assert.isNotNull(rb);
412+ Y.Array.each(this.sharing_permissions, function(permission) {
413+ var rb = step_two_content.one(
414+ 'input[name=field.permission.' + info_type.value +
415+ '][value="' + permission.value + '"]');
416+ Y.Assert.isNotNull(rb);
417+ });
418 });
419 // There should be a link back to previous step.
420 Y.Assert.isNotNull(step_two_content.one('a.prev'));
421@@ -157,21 +169,34 @@
422 person_uri: '~/fred',
423 person_name: 'Fred'
424 },
425- selected_permissions: ['P1']
426+ sharee_permissions: {'P1': 'ALL'}
427 });
428 var cb = this.picker.get('contentBox');
429 var steptitle = cb.one('.contains-steptitle h2').getContent();
430 Y.Assert.areEqual(
431 'Select sharing policies for Fred', steptitle);
432+ // By default, selections only for ALL and NOTHING are available
433+ // (and no others).
434+ Y.Assert.isNotNull(cb.one('input[value=ALL]'));
435+ Y.Assert.isNotNull(cb.one('input[value=NOTHING]'));
436+ Y.Assert.isNull(cb.one('input[value=SOME]'));
437 // Selected permission checkboxes should be ticked.
438- cb.all('input[name=field.visibility]')
439- .each(function(node) {
440+ cb.all('input[name=field.permission.P1]')
441+ .each(function(node) {
442+ if (node.get('checked')) {
443+ Y.Assert.areEqual('ALL', node.get('value'));
444+ } else {
445+ Y.Assert.areEqual('NOTHING', node.get('value'));
446+ }
447+ });
448+ Y.Array.each(['P2', 'P3'], function(info_type) {
449+ cb.all('input[name=field.permission.' + info_type + ']')
450+ .each(function(node) {
451 if (node.get('checked')) {
452- Y.Assert.areEqual('P1', node.get('value'));
453- } else {
454- Y.Assert.areNotEqual('P1', node.get('value'));
455+ Y.Assert.areEqual('NOTHING', node.get('value'));
456 }
457 });
458+ });
459 // Back link should not he shown
460 var back_link = cb.one('a.prev');
461 Y.Assert.isNull(back_link);
462@@ -181,6 +206,27 @@
463 Y.Assert.areEqual('~/fred', selected_result.api_uri);
464 },
465
466+ // Test that show() can be used to open the second picker screen and
467+ // that we can filter what permissions are shown.
468+ test_filtered_permissions: function() {
469+ this.picker = this._create_picker();
470+ // Select a person to trigger transition to next step.
471+ this.picker.set('results', this.vocabulary);
472+ this.picker.render();
473+ this.picker.show({
474+ first_step: 2,
475+ sharee: {
476+ person_uri: '~/fred',
477+ person_name: 'Fred'
478+ },
479+ allowed_permissions: ['SOME']
480+ });
481+ var cb = this.picker.get('contentBox');
482+ Y.Assert.isNull(cb.one('input[value=ALL]'));
483+ Y.Assert.isNull(cb.one('input[value=NOTHING]'));
484+ Y.Assert.isNotNull(cb.one('input[value=SOME]'));
485+ },
486+
487 // Test that the back link goes back to step one when step two is
488 // active.
489 test_second_step_back_link: function() {
490@@ -226,17 +272,19 @@
491 var cb = this.picker.get('contentBox');
492 var step_two_content = cb.one('.picker-content-two');
493 // Select an access policy.
494- step_two_content.one('input[value="P2"]').simulate('click');
495+ step_two_content
496+ .one('input[name=field.permission.P2][value="ALL"]')
497+ .simulate('click');
498 var select_link = step_two_content.one('a.next');
499 select_link.simulate('click');
500 Y.Assert.areEqual(
501- 3, Y.Object.size(selected_result.sharing_permissions));
502- Y.Assert.areEqual(
503- selected_result.sharing_permissions.P1, 'NOTHING');
504- Y.Assert.areEqual(
505- selected_result.sharing_permissions.P2, 'ALL');
506- Y.Assert.areEqual(
507- selected_result.sharing_permissions.P3, 'NOTHING');
508+ 3, Y.Object.size(selected_result.selected_permissions));
509+ Y.Assert.areEqual(
510+ selected_result.selected_permissions.P1, 'NOTHING');
511+ Y.Assert.areEqual(
512+ selected_result.selected_permissions.P2, 'ALL');
513+ Y.Assert.areEqual(
514+ selected_result.selected_permissions.P3, 'NOTHING');
515 Y.Assert.areEqual('~/fred', selected_result.api_uri);
516 },
517
518@@ -268,19 +316,22 @@
519 select_link.simulate('click');
520 Y.Assert.isFalse(save_called);
521 // Select one info type and check submit links are enabled.
522- cb.one('input[name=field.visibility]').simulate('click');
523+ cb.one('input[name=field.permission.P1][value=ALL]')
524+ .simulate('click');
525 cb.all('a.next', function(link) {
526 Y.Assert.isFalse(link.hasClass('invalid-link'));
527 });
528 // De-select info type and submit links are disabled again.
529- cb.one('input[name=field.visibility]').simulate('click');
530+ cb.one('input[name=field.permission.P1][value=NOTHING]')
531+ .simulate('click');
532 cb.all('a.next', function(link) {
533 Y.Assert.isTrue(link.hasClass('invalid-link'));
534 });
535 select_link.simulate('click');
536 Y.Assert.isFalse(save_called);
537 // Once at least one info type is selected, save is called.
538- cb.one('input[name=field.visibility]').simulate('click');
539+ cb.one('input[name=field.permission.P1][value=ALL]')
540+ .simulate('click');
541 select_link.simulate('click');
542 Y.Assert.isTrue(save_called);
543 }
544
545=== modified file 'lib/lp/registry/services/sharingservice.py'
546--- lib/lp/registry/services/sharingservice.py 2012-03-19 05:53:39 +0000
547+++ lib/lp/registry/services/sharingservice.py 2012-03-21 03:22:20 +0000
548@@ -76,12 +76,19 @@
549
550 def getSharingPermissions(self):
551 """See `ISharingService`."""
552+ # We want the permissions displayed in the following order.
553+ ordered_permissions = [
554+ SharingPermission.ALL,
555+ SharingPermission.SOME,
556+ SharingPermission.NOTHING
557+ ]
558 sharing_permissions = []
559- for permission in SharingPermission:
560+ for x, permission in enumerate(ordered_permissions):
561 item = dict(
562- value=permission.token,
563+ index=x,
564+ value=permission.name,
565 title=permission.title,
566- description=permission.value.description
567+ description=permission.description
568 )
569 sharing_permissions.append(item)
570 return sharing_permissions
571
572=== modified file 'lib/lp/registry/services/tests/test_sharingservice.py'
573--- lib/lp/registry/services/tests/test_sharingservice.py 2012-03-16 08:28:51 +0000
574+++ lib/lp/registry/services/tests/test_sharingservice.py 2012-03-21 03:22:20 +0000
575@@ -71,6 +71,17 @@
576 sharee_data['permissions'] = permissions
577 return sharee_data
578
579+ def test_getSharingPermissions(self):
580+ # test_getSharingPermissions returns permissions in the right order.
581+ permissions = self.service.getSharingPermissions()
582+ expected_permissions = [
583+ SharingPermission.ALL,
584+ SharingPermission.SOME,
585+ SharingPermission.NOTHING
586+ ]
587+ for x, permission in enumerate(expected_permissions):
588+ self.assertEqual(permissions[x]['value'], permission.name)
589+
590 def _test_getInformationTypes(self, pillar, expected_policies):
591 policy_data = self.service.getInformationTypes(pillar)
592 expected_data = []