From 219c89223942fdae8d44a53095c378abbc0e912c Mon Sep 17 00:00:00 2001 From: avl Date: Mon, 8 Sep 2008 20:34:16 +0300 Subject: [PATCH] Trivial Model Permission for admin (view,change,add,delete) --- ipf/admin/model.php | 7 ++++++- ipf/admin/templates/admin/change.html | 2 +- ipf/admin/templates/admin/index.html | 4 ++-- ipf/admin/templates/admin/items.html | 2 +- ipf/admin/views.php | 15 ++++++++++++--- ipf/context.php | 5 +++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ipf/admin/model.php b/ipf/admin/model.php index e17e274..f6b06a4 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -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); } diff --git a/ipf/admin/templates/admin/change.html b/ipf/admin/templates/admin/change.html index 9442bbf..2877aac 100644 --- a/ipf/admin/templates/admin/change.html +++ b/ipf/admin/templates/admin/change.html @@ -37,7 +37,7 @@ {/foreach}
-

Delete

+ {if array_search('delete',$perms)!==false}

Delete

{/if}
diff --git a/ipf/admin/templates/admin/index.html b/ipf/admin/templates/admin/index.html index b1f05a6..b100e82 100644 --- a/ipf/admin/templates/admin/index.html +++ b/ipf/admin/templates/admin/index.html @@ -12,8 +12,8 @@ {foreach $app.models as $model} {$model.name} - {trans 'Add'} - {trans 'Change'} + {if array_search('add',$model['perms'])!==false}{trans 'Add'}{/if} + {if array_search('change',$model['perms'])!==false}{trans 'Change'}{/if} {/foreach} diff --git a/ipf/admin/templates/admin/items.html b/ipf/admin/templates/admin/items.html index 85d1670..e42317d 100644 --- a/ipf/admin/templates/admin/items.html +++ b/ipf/admin/templates/admin/items.html @@ -7,7 +7,7 @@

{$page_title}

- +
diff --git a/ipf/admin/views.php b/ipf/admin/views.php index 72fbce6..7fab61c 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -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){ diff --git a/ipf/context.php b/ipf/context.php index 86af698..370cfb9 100644 --- a/ipf/context.php +++ b/ipf/context.php @@ -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()); +} -- 2.49.0