Browse Source

improve toobar buttons show/hide according to current user rights.

Damien Accorsi 10 years ago
parent
commit
4a5ca1664a

+ 1 - 1
pboard/pboard/controllers/root.py View File

@@ -141,7 +141,7 @@ class RootController(BaseController):
141 141
         except Exception as e:
142 142
           flash(_('Document not found'), 'error')
143 143
 
144
-        user_specific_group_rights = pld.PODStaticController.getUserDedicatedGroupRightsOnNode(node_id)
144
+        user_specific_group_rights = pld.PODStaticController.getUserDedicatedGroupRightsOnNode(loCurrentNode)
145 145
 
146 146
         current_user_rights = None
147 147
         for right in user_specific_group_rights:

+ 9 - 7
pboard/pboard/lib/dbapi.py View File

@@ -141,15 +141,17 @@ class PODStaticController(object):
141 141
     return groupRightsOnNodeCustomSelect
142 142
 
143 143
   @classmethod
144
-  def getUserDedicatedGroupRightsOnNode(cls, piNodeId: int) -> pbmd.DIRTY_GroupRightsOnNode:
144
+  def getUserDedicatedGroupRightsOnNode(cls, node: pbmd.PBNode) -> pbmd.DIRTY_GroupRightsOnNode:
145 145
 
146
-    groupRightsOnNodeCustomSelect = pbm.DBSession\
147
-        .query(pbmd.DIRTY_GroupRightsOnNode)\
148
-        .from_statement(pbmd.DIRTY_UserDedicatedGroupRightOnNodeSqlQuery)\
149
-        .params(node_id=piNodeId)\
150
-        .all()
146
+    group_rights_on_node = []
147
+    if node:
148
+        group_rights_on_node = pbm.DBSession\
149
+            .query(pbmd.DIRTY_GroupRightsOnNode)\
150
+            .from_statement(pbmd.DIRTY_UserDedicatedGroupRightOnNodeSqlQuery)\
151
+            .params(node_id=node.node_id)\
152
+            .all()
151 153
 
152
-    return groupRightsOnNodeCustomSelect
154
+    return group_rights_on_node
153 155
 
154 156
 
155 157
 

+ 4 - 3
pboard/pboard/templates/document-widgets-tabs.mak View File

@@ -11,7 +11,7 @@
11 11
   </ul>
12 12
 </%def>
13 13
 
14
-<%def name="AccessManagementTab(poNode)">
14
+<%def name="AccessManagementTab(poNode, user_rights, user)">
15 15
   ######
16 16
   ##
17 17
   ## THIS WIDGET IS INTENDED TO BE USED ONE TIME ONLY IN A PAGE
@@ -87,11 +87,13 @@
87 87
 ##    % endif
88 88
 ##  </p>
89 89
   <!-- Button to trigger modal -->
90
+% if user.user_id==poNode.owner_id or (user_rights and user_rights.hasWriteAccess()):
90 91
   <a href="#edit-document-share-properties" role="button" class="btn btn-success" data-toggle="modal">
91 92
     <i class="fa fa-edit"></i>
92 93
     ${_('Edit share options')}
93 94
   </a>
94
-     
95
+% endif
96
+
95 97
   <!-- Modal -->
96 98
   <div
97 99
     id="edit-document-share-properties"
@@ -413,7 +415,6 @@
413 415
         <p style="list-style-type:none;">
414 416
           <i class="fa-fw ${subnode.getIconClass()}"></i>
415 417
             <a href="${tg.url('/document/%i'%subnode.node_id)}">
416
-              ${subnode.data_label}<i class="${subnode.getIconClass()}"></i>
417 418
             ${subnode.data_label}
418 419
             <span class="label ${subnode.getStatus().css} pull-right" title="${subnode.getStatus().label}">
419 420
               <i class="${subnode.getStatus().icon}"></i>

+ 10 - 6
pboard/pboard/templates/document-widgets.mak View File

@@ -40,12 +40,15 @@
40 40
 </%def>
41 41
 
42 42
         
43
-<%def name="Toolbar(poNode, plNodeStatusList, plRootNodes, psDivId)">
43
+<%def name="Toolbar(poNode, plNodeStatusList, plRootNodes, psDivId, user_rights, user)">
44 44
   <div id="${psDivId}">
45
+
46
+##
47
+## TOOLBAR ITEMS ARE SHOWN ACCORDING TO THE R/W PERMISSIONS GRANTED TO THE USER
48
+##
49
+% if user.user_id==poNode.owner_id or (user_rights and user_rights.hasWriteAccess()):
45 50
     <div class="btn-group">
46
-	% if current_user_rights and current_user_rights.hasWriteAccess():
47 51
       ${POD.EditButton('current-document-content-edit-button', True)}
48
-	% endif
49 52
 
50 53
       <button class="btn btn-small"  data-toggle="dropdown" href="#"> 
51 54
         <i class="fa  fa-signal"></i>
@@ -75,7 +78,8 @@
75 78
       % endfor
76 79
       </ul>
77 80
     </div>
78
-    
81
+% endif
82
+
79 83
     <div class="btn-group">
80 84
       <button class="btn btn-small btn-success"  data-toggle="dropdown" href="#">
81 85
         <i class="fa fa-plus"></i> ${_('Add')}
@@ -106,7 +110,7 @@
106 110
         <li><p class="pod-grey"><i class="fa fa-danger"></i> coming soon!</p></li>
107 111
       </ul>
108 112
     </div>
109
-
113
+% if user.user_id==poNode.owner_id or (user_rights and user_rights.hasWriteAccess()):
110 114
     <div class="btn-group pull-right">
111 115
       <button class="btn btn-small btn-link"  data-toggle="dropdown" href="#">
112 116
         ${_('more ...')}
@@ -121,9 +125,9 @@
121 125
 ##
122 126
         ${ToolbarMenuItemModal(h.ID.MoveDocumentModalForm(current_node), 'fa fa-arrows', _('Move'), 'btn-warning')}
123 127
         ${ToolbarMenuItemLink(tg.url('/api/edit_status', dict(node_id=poNode.node_id, node_status='deleted')), 'fa fa-trash-o', _('Delete'), 'btn-danger', _('Delete the current document'), 'return confirm(\'{0}\');'.format('Delete current document?'))}
124
-
125 128
       </ul>
126 129
     </div>
130
+% endif
127 131
   </div>
128 132
 </%def>
129 133
 

+ 6 - 3
pboard/pboard/templates/document.mak View File

@@ -130,7 +130,10 @@
130 130
             nodes = $('#mypodtree .jstree-node');
131 131
             console.log("nodes = "+nodes.length);
132 132
             if (nodes.length<=0) {
133
-              $("#mypodtree").append( "<p class='pod-grey'>${_('There is no content yet.')|n}</p>" );
133
+              $("#mypodtree").append( "<p class='pod-grey'>${_('There is no content yet.')|n}" );
134
+              $("#mypodtree").append( "<p><a class=\"btn btn-success\" data-toggle=\"modal\" role=\"button\" href=\"#add-document-modal-form\"><i class=\"fa fa-plus\"></i> ${_('Create a topic')}</a></p>" );
135
+              
136
+              
134 137
             }
135 138
           });
136 139
         });
@@ -157,7 +160,7 @@
157 160
             ##
158 161
             ## The Toolbar is a div with a specific id
159 162
             ##
160
-            ${DOC.Toolbar(current_node, node_status_list, root_node_list_for_select_field, 'current-document-toobar')}
163
+            ${DOC.Toolbar(current_node, node_status_list, root_node_list_for_select_field, 'current-document-toobar', current_user_rights, current_user)}
161 164
             ${DOC.ShowTitle(current_node, keywords, 'current-document-title')}
162 165
             ${DOC.ShowContent(current_node, keywords)}
163 166
           </div>
@@ -196,7 +199,7 @@
196 199
               <div class="tab-pane active" id="comments">${DOCTABS.CommentTabContent(current_user, current_node)}</div>
197 200
               <div class="tab-pane" id="files">${DOCTABS.FileTabContent(current_node)}</div>
198 201
               <div class="tab-pane" id="history">${DOCTABS.HistoryTabContent(current_node)}</div>
199
-              <div class="tab-pane" id="accessmanagement">${DOCTABS.AccessManagementTab(current_node)}</div>
202
+              <div class="tab-pane" id="accessmanagement">${DOCTABS.AccessManagementTab(current_node, current_user_rights, current_user)}</div>
200 203
             </div>
201 204
           </div>
202 205
         </div>