[2] | 1 | <%def name="render_select( current_actions, action_key, action, all_roles )"> |
---|
| 2 | <% |
---|
| 3 | import sets |
---|
| 4 | in_roles = sets.Set() |
---|
| 5 | for a in current_actions: |
---|
| 6 | if a.action == action.action: |
---|
| 7 | in_roles.add( a.role ) |
---|
| 8 | out_roles = filter( lambda x: x not in in_roles, all_roles ) |
---|
| 9 | %> |
---|
| 10 | <p> |
---|
| 11 | <b>${action.action}:</b> ${action.description} |
---|
| 12 | %if action == trans.app.security_agent.permitted_actions.DATASET_ACCESS: |
---|
| 13 | <br/> |
---|
| 14 | NOTE: Users must have every role associated with this dataset in order to access it |
---|
| 15 | %endif |
---|
| 16 | </p> |
---|
| 17 | <div style="width: 100%; white-space: nowrap;"> |
---|
| 18 | <div style="float: left; width: 50%;"> |
---|
| 19 | Roles associated:<br/> |
---|
| 20 | <select name="${action_key}_in" id="${action_key}_in_select" class="in_select" style="max-width: 98%; width: 98%; height: 150px; font-size: 100%;" multiple> |
---|
| 21 | %for role in in_roles: |
---|
| 22 | <option value="${role.id}">${role.name}</option> |
---|
| 23 | %endfor |
---|
| 24 | </select> <br/> |
---|
| 25 | <div style="width: 98%; text-align: right"><input type="submit" id="${action_key}_remove_button" class="role_remove_button" value=">>"/></div> |
---|
| 26 | </div> |
---|
| 27 | <div style="width: 50%;"> |
---|
| 28 | Roles not associated:<br/> |
---|
| 29 | <select name="${action_key}_out" id="${action_key}_out_select" style="max-width: 98%; width: 98%; height: 150px; font-size: 100%;" multiple> |
---|
| 30 | %for role in out_roles: |
---|
| 31 | <option value="${role.id}">${role.name}</option> |
---|
| 32 | %endfor |
---|
| 33 | </select> <br/> |
---|
| 34 | <input type="submit" id="${action_key}_add_button" class="role_add_button" value="<<"/> |
---|
| 35 | </div> |
---|
| 36 | </div> |
---|
| 37 | </%def> |
---|
| 38 | |
---|
| 39 | ## Any permission ( e.g., 'DATASET_ACCESS' ) included in the do_not_render param will not be rendered on the page. |
---|
| 40 | <%def name="render_permission_form( obj, obj_name, form_url, all_roles, do_not_render=[] )"> |
---|
| 41 | <% |
---|
| 42 | if isinstance( obj, trans.app.model.User ): |
---|
| 43 | current_actions = obj.default_permissions |
---|
| 44 | permitted_actions = trans.app.model.Dataset.permitted_actions.items() |
---|
| 45 | obj_str = 'user %s' % obj_name |
---|
| 46 | obj_type = 'dataset' |
---|
| 47 | elif isinstance( obj, trans.app.model.History ): |
---|
| 48 | current_actions = obj.default_permissions |
---|
| 49 | permitted_actions = trans.app.model.Dataset.permitted_actions.items() |
---|
| 50 | obj_str = 'history %s' % obj_name |
---|
| 51 | obj_type = 'dataset' |
---|
| 52 | elif isinstance( obj, trans.app.model.Dataset ): |
---|
| 53 | current_actions = obj.actions |
---|
| 54 | permitted_actions = trans.app.model.Dataset.permitted_actions.items() |
---|
| 55 | obj_str = obj_name |
---|
| 56 | obj_type = 'dataset' |
---|
| 57 | elif isinstance( obj, trans.app.model.LibraryDatasetDatasetAssociation ): |
---|
| 58 | current_actions = obj.actions + obj.dataset.actions |
---|
| 59 | permitted_actions = trans.app.model.Dataset.permitted_actions.items() + trans.app.model.Library.permitted_actions.items() |
---|
| 60 | obj_str = obj_name |
---|
| 61 | obj_type = 'dataset' |
---|
| 62 | elif isinstance( obj, trans.app.model.Library ): |
---|
| 63 | current_actions = obj.actions |
---|
| 64 | permitted_actions = trans.app.model.Library.permitted_actions.items() |
---|
| 65 | obj_str = 'library %s' % obj_name |
---|
| 66 | obj_type = 'library' |
---|
| 67 | elif isinstance( obj, trans.app.model.LibraryDataset ): |
---|
| 68 | current_actions = obj.actions |
---|
| 69 | permitted_actions = trans.app.model.Library.permitted_actions.items() |
---|
| 70 | obj_str = 'library dataset %s' % obj_name |
---|
| 71 | obj_type = 'library' |
---|
| 72 | elif isinstance( obj, trans.app.model.LibraryFolder ): |
---|
| 73 | current_actions = obj.actions |
---|
| 74 | permitted_actions = trans.app.model.Library.permitted_actions.items() |
---|
| 75 | obj_str = 'library folder %s' % obj_name |
---|
| 76 | obj_type = 'library' |
---|
| 77 | else: |
---|
| 78 | current_actions = [] |
---|
| 79 | permitted_actions = {}.items() |
---|
| 80 | obj_str = 'unknown object %s' %obj_name |
---|
| 81 | obj_type = '' |
---|
| 82 | %> |
---|
| 83 | <script type="text/javascript"> |
---|
| 84 | $( document ).ready( function () { |
---|
| 85 | $( '.role_add_button' ).click( function() { |
---|
| 86 | var action = this.id.substring( 0, this.id.lastIndexOf( '_add_button' ) ) |
---|
| 87 | var in_select = '#' + action + '_in_select'; |
---|
| 88 | var out_select = '#' + action + '_out_select'; |
---|
| 89 | return !$( out_select + ' option:selected' ).remove().appendTo( in_select ); |
---|
| 90 | }); |
---|
| 91 | $( '.role_remove_button' ).click( function() { |
---|
| 92 | var action = this.id.substring( 0, this.id.lastIndexOf( '_remove_button' ) ) |
---|
| 93 | var in_select = '#' + action + '_in_select'; |
---|
| 94 | var out_select = '#' + action + '_out_select'; |
---|
| 95 | return !$( in_select + ' option:selected' ).remove().appendTo( out_select ); |
---|
| 96 | }); |
---|
| 97 | $( 'form#edit_role_associations' ).submit( function() { |
---|
| 98 | $( '.in_select option' ).each(function( i ) { |
---|
| 99 | $( this ).attr( "selected", "selected" ); |
---|
| 100 | }); |
---|
| 101 | }); |
---|
| 102 | }); |
---|
| 103 | </script> |
---|
| 104 | <div class="toolForm"> |
---|
| 105 | <div class="toolFormTitle">Manage ${obj_type} permissions on ${obj_str}</div> |
---|
| 106 | <div class="toolFormBody"> |
---|
| 107 | <form name="edit_role_associations" id="edit_role_associations" action="${form_url}" method="post"> |
---|
| 108 | <div class="form-row"></div> |
---|
| 109 | %for k, v in permitted_actions: |
---|
| 110 | %if k not in do_not_render: |
---|
| 111 | <div class="form-row"> |
---|
| 112 | ${render_select( current_actions, k, v, all_roles )} |
---|
| 113 | </div> |
---|
| 114 | %endif |
---|
| 115 | %endfor |
---|
| 116 | <div class="form-row"> |
---|
| 117 | <input type="submit" name="update_roles_button" value="Save"/> |
---|
| 118 | </div> |
---|
| 119 | </form> |
---|
| 120 | </div> |
---|
| 121 | </div> |
---|
| 122 | <p/> |
---|
| 123 | </%def> |
---|