Skip to content

Commit

Permalink
Dev Fixing template permissions - work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Apr 1, 2013
1 parent 807cb29 commit c81e859
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/templates.php
Expand Up @@ -467,7 +467,7 @@ public function delete($templatename)
}

Template::model()->deleteAllByAttributes(array('folder' => $templatename));
Templates_rights::model()->deleteAllByAttributes(array('folder' => $templatename));
Permission::model()->deleteAllByAttributes(array('permission' => $templatename,'entity' => 'template'));

Yii::app()->session['flashmessage'] = sprintf($clang->gT("Template '%s' was successfully deleted."), $templatename);
}
Expand Down
30 changes: 16 additions & 14 deletions application/controllers/admin/useraction.php
Expand Up @@ -105,7 +105,7 @@ function adduser()

if ($iNewUID) {
// add default template to template rights for user
Templates_rights::model()->insertRecords(array('uid' => $iNewUID, 'folder' => Yii::app()->getConfig("defaulttemplate"), 'use' => '1'));
Permission::model()->insertRecords(array('uid' => $iNewUID, 'permission' => Yii::app()->getConfig("defaulttemplate"), 'entity'=>$template, 'read_p' => 1));

// add new user to userlist
$sresult = User::model()->getAllRecords(array('uid' => $iNewUID));
Expand Down Expand Up @@ -500,14 +500,15 @@ function setusertemplates()
$aData['postuserid'] = $postuserid;
$aData['postfull_name'] = Yii::app()->request->getPost("full_name");
$this->_refreshtemplates();
$templaterights=array();
foreach (getUserList() as $usr)
{
if ($usr['uid'] == $postuserid)
{
$trights = Templates_rights::model()->findAllByAttributes(array('uid' => $usr['uid']));
$trights = Permission::model()->findAllByAttributes(array('uid' => $usr['uid'],'entity'=>'template'));
foreach ($trights as $srow)
{
$templaterights[$srow["folder"]] = array("use"=>$srow["use"]);
$templaterights[$srow["permission"]] = array("use"=>$srow["read_p"]);
}
$templates = Template::model()->findAll();
$aData['list'][] = array('templaterights'=>$templaterights,'templates'=>$templates);
Expand All @@ -523,27 +524,28 @@ function usertemplates()

// SUPERADMINS AND MANAGE_TEMPLATE USERS CAN SET THESE RIGHTS
if (Permission::model()->hasGlobalPermission('superadmin','read') || Permission::model()->hasGlobalPermission('templates','update')) {
$templaterights = array();
$aTemplatePermissions = array();
$tresult = Template::model()->findAll();
$postvalue= array_flip($_POST);
foreach ($tresult as $trow)
{
if (isset($postvalue[$trow["folder"] . "_use"]))
$templaterights[$trow["folder"]] = 1;
$aTemplatePermissions[$trow["folder"]] = 1;
else
$templaterights[$trow["folder"]] = 0;
$aTemplatePermissions[$trow["folder"]] = 0;
}
foreach ($templaterights as $key => $value)
foreach ($aTemplatePermissions as $key => $value)
{
$rights = Templates_rights::model()->findByPk(array('folder' => $key, 'uid' => $postuserid));
if (empty($rights))
$oPermission = Permission::model()->findByPk(array('permission' => $key, 'uid' => $postuserid, 'entity'=>'template'));
if (empty($oPermission))
{
$rights = new Templates_rights;
$rights->uid = $postuserid;
$rights->folder = $key;
$oPermission = new Permission;
$oPermission->uid = $postuserid;
$oPermission->permission = $key;
$oPermission->entity='template';
}
$rights->use = $value;
$uresult = $rights->save();
$oPermission->read_p = $value;
$uresult = $oPermission->save();
}
if ($uresult !== false) {
$aViewUrls['mboxwithredirect'][] = $this->_messageBoxWithRedirect($clang->gT("Set template permissions"), $clang->gT("Template permissions were updated successfully."), "successheader");
Expand Down

0 comments on commit c81e859

Please sign in to comment.