wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.EditRightsController.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.EditRightsController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/presentation/class.Controller.php");
20 require_once(BASE."wcmf/lib/presentation/class.WCMFInifileParser.php");
21 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
22 require_once(BASE."wcmf/lib/security/class.RightsManager.php");
23 require_once(BASE."wcmf/lib/util/class.FormUtil.php");
24 require_once(BASE."wcmf/lib/util/class.ObjectFactory.php");
25 
26 /**
27  * @class EditRightsController
28  * @ingroup Controller
29  * @brief EditRightsController is used to edit rights on a resource.
30  *
31  * <b>Input actions:</b>
32  * - @em save Save changes right to the current resource
33  *
34  * <b>Output actions:</b>
35  * - @em ok In any case
36  *
37  * @param[in,out] oid The resource to set the right on
38  * @param[out] allroles An array of names of all roles
39  * @param[out] rights A 2-dimensional array of defined rights: rights[configFile][action]
40  * @param[out] rightnames An array of all right names
41  * @param[out] configfiles An array of all config filenames
42  *
43  * @author ingo herwig <ingo@wemove.com>
44  */
46 {
47  /**
48  * @see Controller::validate()
49  */
50  function validate()
51  {
52  if(strlen($this->_request->getValue('oid')) == 0)
53  {
54  $this->setErrorMsg("No 'oid' given in data.");
55  return false;
56  }
57  return true;
58  }
59  /**
60  * @see Controller::hasView()
61  */
62  function hasView()
63  {
64  return true;
65  }
66  /**
67  * Assign Node data to View.
68  * @return False (Stop action processing chain).
69  * @see Controller::executeKernel()
70  */
71  function executeKernel()
72  {
73  $objectFactory = &ObjectFactory::getInstance();
74  $userManager = &$objectFactory->createInstanceFromConfig('implementation', 'UserManager');
75  $rightsManager = &RightsManager::getInstance();
76 
77  $configFiles = WCMFInifileParser::getIniFiles();
78  $rightNames = array(ACTION_READ, ACTION_MODIFY, ACTION_DELETE, ACTION_CREATE);
79 
80  // process actions
81  if ($this->_request->getAction() == 'save')
82  {
83  $resource = $this->_request->getValue('oid');
84  $context = '';
85 
86  // for all configuration files do ...
87  foreach($configFiles as $configFile)
88  {
89  // for all actions files do ...
90  foreach ($rightNames as $action)
91  {
92  $existingRight = $rightsManager->getRight($configFile, $resource, $context, $action);
93 
94  // allow
95  $controlName = $action."_allow_".str_replace(".", "", $configFile);
96  $newAllowedRoles = $this->_request->getValue($controlName);
97  // add new
98  if (is_array($newAllowedRoles))
99  foreach ($newAllowedRoles as $role)
100  if (!is_array($existingRight['allow']) || !in_array($role, $existingRight['allow']))
101  $rightsManager->createPermission($configFile, $resource, $context, $action, $role, RIGHT_MODIFIER_ALLOW);
102  // remove old
103  if (is_array($existingRight['allow']))
104  foreach ($existingRight['allow'] as $role)
105  if (!is_array($newAllowedRoles) || !in_array($role, $this->_request->getValue($controlName)))
106  $rightsManager->removePermission($configFile, $resource, $context, $action, $role);
107 
108  // deny
109  $controlName = $action."_deny_".str_replace(".", "", $configFile);
110  $newDeniedRoles = $this->_request->getValue($controlName);
111  // add new
112  if (is_array($newDeniedRoles))
113  foreach ($newDeniedRoles as $role)
114  if (!is_array($existingRight['deny']) || !in_array($role, $existingRight['deny']))
115  $rightsManager->createPermission($configFile, $resource, $context, $action, $role, RIGHT_MODIFIER_DENY);
116  // remove old
117  if (is_array($existingRight['deny']))
118  foreach ($existingRight['deny'] as $role)
119  if (!is_array($newDeniedRoles) || !in_array($role, $this->_request->getValue($controlName)))
120  $rightsManager->removePermission($configFile, $resource, $context, $action, $role);
121  }
122  }
123  }
124 
125  // load model
126  $rights = array();
127  foreach($configFiles as $configFile)
128  foreach (array(ACTION_READ, ACTION_MODIFY, ACTION_DELETE, ACTION_CREATE) as $action)
129  {
130  $right = $rightsManager->getRight($configFile, $this->_request->getValue('oid'), '', $action);
131  // flatten role array for input control
132  foreach ($right as $name => $roles)
133  $right[$name] = join(',', $roles);
134  $rights[$configFile][$action] = $right;
135  }
136 
137  // assign model to view
138  $this->_response->setValue('oid', $this->_request->getValue('oid'));
139  $this->_response->setValue('allroles', join("|", $userManager->listRoles()));
140  $this->_response->setValue('rights', $rights);
141  $this->_response->setValue('rightnames', $rightNames);
142  $this->_response->setValue('configfiles', WCMFInifileParser::getIniFiles());
143 
144  // success
145  $this->_response->setAction('ok');
146  return false;
147  }
148 }
149 ?>
const ACTION_DELETE
const RIGHT_MODIFIER_ALLOW
EditRightsController is used to edit rights on a resource.
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
const ACTION_MODIFY
const RIGHT_MODIFIER_DENY
const ACTION_READ
const ACTION_CREATE