浏览代码

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

Damien Accorsi 11 年前
父节点
当前提交
4a5ca1664a

+ 1 - 1
pboard/pboard/controllers/root.py 查看文件

141
         except Exception as e:
141
         except Exception as e:
142
           flash(_('Document not found'), 'error')
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
         current_user_rights = None
146
         current_user_rights = None
147
         for right in user_specific_group_rights:
147
         for right in user_specific_group_rights:

+ 9 - 7
pboard/pboard/lib/dbapi.py 查看文件

141
     return groupRightsOnNodeCustomSelect
141
     return groupRightsOnNodeCustomSelect
142
 
142
 
143
   @classmethod
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 查看文件

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

+ 10 - 6
pboard/pboard/templates/document-widgets.mak 查看文件

40
 </%def>
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
   <div id="${psDivId}">
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
     <div class="btn-group">
50
     <div class="btn-group">
46
-	% if current_user_rights and current_user_rights.hasWriteAccess():
47
       ${POD.EditButton('current-document-content-edit-button', True)}
51
       ${POD.EditButton('current-document-content-edit-button', True)}
48
-	% endif
49
 
52
 
50
       <button class="btn btn-small"  data-toggle="dropdown" href="#"> 
53
       <button class="btn btn-small"  data-toggle="dropdown" href="#"> 
51
         <i class="fa  fa-signal"></i>
54
         <i class="fa  fa-signal"></i>
75
       % endfor
78
       % endfor
76
       </ul>
79
       </ul>
77
     </div>
80
     </div>
78
-    
81
+% endif
82
+
79
     <div class="btn-group">
83
     <div class="btn-group">
80
       <button class="btn btn-small btn-success"  data-toggle="dropdown" href="#">
84
       <button class="btn btn-small btn-success"  data-toggle="dropdown" href="#">
81
         <i class="fa fa-plus"></i> ${_('Add')}
85
         <i class="fa fa-plus"></i> ${_('Add')}
106
         <li><p class="pod-grey"><i class="fa fa-danger"></i> coming soon!</p></li>
110
         <li><p class="pod-grey"><i class="fa fa-danger"></i> coming soon!</p></li>
107
       </ul>
111
       </ul>
108
     </div>
112
     </div>
109
-
113
+% if user.user_id==poNode.owner_id or (user_rights and user_rights.hasWriteAccess()):
110
     <div class="btn-group pull-right">
114
     <div class="btn-group pull-right">
111
       <button class="btn btn-small btn-link"  data-toggle="dropdown" href="#">
115
       <button class="btn btn-small btn-link"  data-toggle="dropdown" href="#">
112
         ${_('more ...')}
116
         ${_('more ...')}
121
 ##
125
 ##
122
         ${ToolbarMenuItemModal(h.ID.MoveDocumentModalForm(current_node), 'fa fa-arrows', _('Move'), 'btn-warning')}
126
         ${ToolbarMenuItemModal(h.ID.MoveDocumentModalForm(current_node), 'fa fa-arrows', _('Move'), 'btn-warning')}
123
         ${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?'))}
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
       </ul>
128
       </ul>
126
     </div>
129
     </div>
130
+% endif
127
   </div>
131
   </div>
128
 </%def>
132
 </%def>
129
 
133
 

+ 6 - 3
pboard/pboard/templates/document.mak 查看文件

130
             nodes = $('#mypodtree .jstree-node');
130
             nodes = $('#mypodtree .jstree-node');
131
             console.log("nodes = "+nodes.length);
131
             console.log("nodes = "+nodes.length);
132
             if (nodes.length<=0) {
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
             ##
160
             ##
158
             ## The Toolbar is a div with a specific id
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
             ${DOC.ShowTitle(current_node, keywords, 'current-document-title')}
164
             ${DOC.ShowTitle(current_node, keywords, 'current-document-title')}
162
             ${DOC.ShowContent(current_node, keywords)}
165
             ${DOC.ShowContent(current_node, keywords)}
163
           </div>
166
           </div>
196
               <div class="tab-pane active" id="comments">${DOCTABS.CommentTabContent(current_user, current_node)}</div>
199
               <div class="tab-pane active" id="comments">${DOCTABS.CommentTabContent(current_user, current_node)}</div>
197
               <div class="tab-pane" id="files">${DOCTABS.FileTabContent(current_node)}</div>
200
               <div class="tab-pane" id="files">${DOCTABS.FileTabContent(current_node)}</div>
198
               <div class="tab-pane" id="history">${DOCTABS.HistoryTabContent(current_node)}</div>
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
             </div>
203
             </div>
201
           </div>
204
           </div>
202
         </div>
205
         </div>