瀏覽代碼

[zookeeper] Readonly for non superuser

At some point we can add fine grained permissions.
Romain Rigaux 11 年之前
父節點
當前提交
e4757b6
共有 2 個文件被更改,包括 23 次插入6 次删除
  1. 12 2
      apps/zookeeper/src/zookeeper/templates/tree.mako
  2. 11 4
      apps/zookeeper/src/zookeeper/views.py

+ 12 - 2
apps/zookeeper/src/zookeeper/templates/tree.mako

@@ -50,10 +50,16 @@ ${ shared.header(_breadcrumbs, clusters, False) }
         % if len(children) == 0:
           <li class="white">${ _('No children available') }</li>
         % endif
+        % if user.is_superuser:
         <li class="white">
-          <button class="btn" onclick="location.href='${url('zookeeper:create', id=cluster['id'], path=path)}'"><i class="fa fa-plus-circle"></i> ${ _('Add') }</button>
-          <button id="removeBtn" class="btn btn-danger disable-feedback" data-msg="${_('Are you sure you want to delete %s?' % path)}" data-url="${url('zookeeper:delete', id=cluster['id'], path=path)}"><i class="fa fa-times-circle"></i> ${ _('Remove current ZNode') }</button>
+          <button class="btn" onclick="location.href='${url('zookeeper:create', id=cluster['id'], path=path)}'">
+            <i class="fa fa-plus-circle"></i> ${ _('Add') }
+          </button>
+          <button id="removeBtn" class="btn btn-danger disable-feedback" data-msg="${_('Are you sure you want to delete %s?' % path)}" data-url="${url('zookeeper:delete', id=cluster['id'], path=path)}">
+            <i class="fa fa-times-circle"></i> ${ _('Remove current ZNode') }
+          </button>
         </li>
+        % endif
       </ul>
     </div>
   </div>
@@ -71,11 +77,15 @@ ${ shared.header(_breadcrumbs, clusters, False) }
       %if znode.get('dataLength', 0) != 0:
       <div class="tab-pane active" id="text">
         <textarea id="textareaText" rows="25" readonly="readonly"></textarea>
+        % if user.is_superuser:
         <a href="${url('zookeeper:edit_as_text', id=cluster['id'], path=path)}" class="btn"><i class="fa fa-pencil"></i> ${_('Edit as Text')}</a>
+        % endif
       </div>      
       <div class="tab-pane" id="base64">
         <textarea id="textarea64" rows="25" readonly="readonly">${znode.get('data64', '')}</textarea>
+        % if user.is_superuser:
         <a href="${url('zookeeper:edit_as_base64', id=cluster['id'], path=path)}" class="btn"><i class="fa fa-pencil"></i> ${_('Edit as Base64')}</a>
+        % endif
       </div>
       <div class="tab-pane" id="stats">
       %else:

+ 11 - 4
apps/zookeeper/src/zookeeper/views.py

@@ -15,11 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-try:
-  import json
-except ImportError:
-  import simplejson as json
 
+import json
 import logging
 
 from django.http import Http404, HttpResponse
@@ -123,7 +120,10 @@ def tree(request, id, path):
 
 
 def delete(request, id, path):
+  if not request.user.is_superuser:
+    raise PopupException(_('You are not a superuser'))
   cluster = get_cluster_or_404(id)
+
   redir = {}
   if request.method == 'POST':
     zk = ZooKeeper(cluster['rest_url'])
@@ -134,10 +134,13 @@ def delete(request, id, path):
     redir = {
       'redirect': reverse('zookeeper:tree', kwargs={'id':id, 'path': path[:path.rindex('/')] or '/'})
     }
+
   return HttpResponse(json.dumps(redir), mimetype="application/json")
 
 
 def create(request, id, path):
+  if not request.user.is_superuser:
+    raise PopupException(_('You are not a superuser'))
   cluster = get_cluster_or_404(id)
 
   if request.method == 'POST':
@@ -161,6 +164,8 @@ def edit_as_base64(request, id, path):
   node = zk.get(path)
 
   if request.method == 'POST':
+    if not request.user.is_superuser:
+      raise PopupException(_('You are not a superuser'))
     form = EditZNodeForm(request.POST)
     if form.is_valid():
       # TODO is valid base64 string?
@@ -182,6 +187,8 @@ def edit_as_text(request, id, path):
   node = zk.get(path)
 
   if request.method == 'POST':
+    if not request.user.is_superuser:
+      raise PopupException(_('You are not a superuser'))
     form = EditZNodeForm(request.POST)
     if form.is_valid():
       zk.set(path, form.cleaned_data['data'])