]> git.andy128k.dev Git - ipf.git/commitdiff
Trivial Model Permission for admin (view,change,add,delete)
authoravl <alex.litovchenko@gmail.com>
Mon, 8 Sep 2008 17:34:16 +0000 (20:34 +0300)
committeravl <alex.litovchenko@gmail.com>
Mon, 8 Sep 2008 17:34:16 +0000 (20:34 +0300)
ipf/admin/model.php
ipf/admin/templates/admin/change.html
ipf/admin/templates/admin/index.html
ipf/admin/templates/admin/items.html
ipf/admin/views.php
ipf/context.php

index e17e274da1cb55754bfe0c04769d72c3667b91e9..f6b06a4532a290a89d289b2f2a1f6d25a91d4569 100644 (file)
@@ -33,6 +33,10 @@ class IPF_Admin_Model{
     public function setUp(){
         $this->model = new $this->modelName;
     }
+
+    public function getPerms($request){
+        return array('view', 'add', 'change', 'delete');
+    }
     
     protected function setInlines(&$instance=null){
         $il = $this->inlines();
@@ -186,6 +190,7 @@ class IPF_Admin_Model{
             'form'=>$form,
             'inlineInstances'=>$this->inlineInstances,
             'lapp'=>$lapp,
+            'perms'=>$this->getPerms($request),
             'lmodel'=>$lmodel,
         );
         return IPF_Shortcuts::RenderToResponse('admin/change.html', $context, $request);
@@ -213,13 +218,13 @@ class IPF_Admin_Model{
         $this->ListItemsQuery();
         $this->qe = $this->q->execute();
         $this->ListItemsHeader();
-        //print_r($this->qe->getTable()->getIdentifier());
         $context = array(
             'page_title'=>$this->modelName.' List', 
             'header'=>$this->header,
             'classname'=>$this->modelName,
             'objects'=>$this->qe,
             'classname'=>$this->modelName,
+            'perms'=>$this->getPerms($request),
         );
         return IPF_Shortcuts::RenderToResponse('admin/items.html', $context, $request);
     }
index 9442bbf32c8085e5915821c56acdf86e7cc7a249..2877aac9dbb4bafb13fe4dfa633cf0a03929f67d 100644 (file)
@@ -37,7 +37,7 @@
     {/foreach}
 
     <div class="submit-row">
-        <p class="float-left"><a href="{url 'IPF_Admin_Views_DeleteItem', array($lapp, $lmodel, $object.id)}" class="deletelink">Delete</a></p>
+        {if array_search('delete',$perms)!==false}<p class="float-left"><a href="{url 'IPF_Admin_Views_DeleteItem', array($lapp, $lmodel, $object.id)}" class="deletelink">Delete</a></p>{/if}
         <input type="submit" value="Save" class="default" />
     </div>
     </form>    
index b1f05a638c63309aac6af9d53f8ac0d39b0dce35..b100e82ca40b5b027acefe41d73a40c52b7c6055 100644 (file)
@@ -12,8 +12,8 @@
             {foreach $app.models as $model}
             <tr>
                 <th><a href="{url 'IPF_Admin_Views_ListItems', array($app.path, $model.path)}">{$model.name}</a></th>
-                <td><a class="addlink" href="{url 'IPF_Admin_Views_AddItem', array($app.path, $model.path)}">{trans 'Add'}</a></td>
-                <td><a class="changelink" href="{url 'IPF_Admin_Views_ListItems', array($app.path, $model.path)}">{trans 'Change'}</a></td>
+                <td>{if array_search('add',$model['perms'])!==false}<a class="addlink" href="{url 'IPF_Admin_Views_AddItem', array($app.path, $model.path)}">{trans 'Add'}</a>{/if}</td>
+                <td>{if array_search('change',$model['perms'])!==false}<a class="changelink" href="{url 'IPF_Admin_Views_ListItems', array($app.path, $model.path)}">{trans 'Change'}</a>{/if}</td>
             </tr>
             {/foreach}
             </table>
index 85d1670f8d82984583001ef343a15191faaee487..e42317db340c376fa7fa3198ec282e078e5b1885 100644 (file)
@@ -7,7 +7,7 @@
 
 <div id="ipfcontent">
     <h1>{$page_title}</h1>
-    <ul class="object-tools"><li><a href="add/" class="addlink">Add {$classname}</a></li></ul>
+    <ul class="object-tools">{if array_search('add',$perms)!==false}<li><a href="add/" class="addlink">Add {$classname}</a></li>{/if}</ul>
     <div id="changelist">
         <table>
             <thead>
index 72fbce6230120a18c6caab09a8dae844ef000239..7fab61c90565add380ea6684ee2ec7ae3dc0c544 100644 (file)
@@ -24,9 +24,18 @@ function IPF_Admin_Views_Index($request, $match){
             $models = new IPF_Template_ContextVars();
             $models_found = false;
             foreach($app->modelList() as $m){
-                if (IPF_Admin_Model::isModelRegister($m)){
-                    $models[] = new IPF_Template_ContextVars(array('name'=>$m, 'path'=>strtolower($m)));
-                    $models_found = true;
+                
+                $ma = IPF_Admin_Model::getModelAdmin($m);
+                if ($ma!==null){
+                    $perms = $ma->getPerms($request);
+                    if (array_search('view', $perms)!==false){
+                        $models[] = new IPF_Template_ContextVars(array(
+                            'name'=>$m, 
+                            'path'=>strtolower($m),
+                            'perms'=>$perms,
+                        ));
+                        $models_found = true;
+                    }
                 }
             }
             if ($models_found){
index 86af69846435abc45fa366120aad02fff7da8d9e..370cfb995283a8e7fe6b6664c92a64bf81c2a7e6 100644 (file)
@@ -24,3 +24,8 @@ function IPF_Context_Upload($request)
 {
     return array('UPLOAD_URL' => IPF::get('upload_url'));
 }
+
+function IPF_Context_Current($request)
+{
+    return array('CURRENT_URL' => IPF_HTTP_URL::getAction());
+}