00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 class FormLayoutSecurityUtil
00041 {
00042
00050 public static function resolveElementForEditableRender($model, & $elementInformation, $user)
00051 {
00052 assert('$model instanceof RedBeanModel || $model instanceof CModel');
00053 assert('is_array($elementInformation)');
00054 assert('$user instanceof User && $user->id > 0');
00055 $elementclassname = $elementInformation['type'] . 'Element';
00056 $attributeName = $elementInformation['attributeName'];
00057 if (is_subclass_of($elementclassname, 'ModelElement'))
00058 {
00059 $editableActionType = $elementclassname::getEditableActionType();
00060 if (!ActionSecurityUtil::canUserPerformAction(
00061 $editableActionType, $model->$attributeName, $user))
00062 {
00063 $elementInformation['attributeName'] = null;
00064 $elementInformation['type'] = 'Null';
00065
00066
00067 }
00068
00069
00070
00071 elseif ($editableActionType == 'ModalList' &&
00072 $model->{$attributeName} != null &&
00073 $model->{$attributeName} instanceof RedBeanModel &
00074 $model->{$attributeName}->id > 0 &&
00075 !ActionSecurityUtil::canUserPerformAction('Details', $model->{$attributeName}, $user))
00076 {
00077 $elementInformation['attributeName'] = null;
00078 $elementInformation['type'] = 'Null';
00079 }
00080 }
00081 if (is_subclass_of($elementclassname, 'ModelsElement'))
00082 {
00083 $actionType = $elementclassname::getEditableActionType();
00084 if ($actionType != null)
00085 {
00086 $actionSecurity = ActionSecurityFactory::createRightsOnlyActionSecurityFromActionType($actionType, $user);
00087 if (!$actionSecurity->canUserPerformAction())
00088 {
00089 $elementInformation['attributeName'] = null;
00090 $elementInformation['type'] = 'Null';
00091
00092
00093 }
00094 }
00095 }
00096 }
00097
00098
00106 public static function resolveElementForNonEditableRender($model, & $elementInformation, $user)
00107 {
00108 assert('$model instanceof RedBeanModel || $model instanceof CModel');
00109 assert('is_array($elementInformation)');
00110 assert('$user instanceof User && $user->id > 0');
00111 $elementclassname = $elementInformation['type'] . 'Element';
00112 $attributeName = $elementInformation['attributeName'];
00113 if (is_subclass_of($elementclassname, 'ModelElement'))
00114 {
00115 $moduleId = $elementclassname::getModuleId();
00116 $moduleClassName = get_class(Yii::app()->getModule($moduleId));
00117 assert('is_string($moduleClassName)');
00118 $userCanAccess = RightsUtil::canUserAccessModule($moduleClassName, $user);
00119 $userCanReadItem = ActionSecurityUtil::canUserPerformAction(
00120 $elementclassname::getNonEditableActionType(), $model->$attributeName, $user);
00121 if ($userCanAccess && $userCanReadItem)
00122 {
00123 return;
00124 }
00125 elseif (!$userCanAccess && $userCanReadItem)
00126 {
00127 if ($model->$attributeName->id < 0)
00128 {
00129 $elementInformation['attributeName'] = null;
00130 $elementInformation['type'] = 'Null';
00131 }
00132 else
00133 {
00134 $elementInformation['noLink'] = true;
00135 }
00136 }
00137 else
00138 {
00139 $elementInformation['attributeName'] = null;
00140 $elementInformation['type'] = 'Null';
00141 }
00142 }
00143 elseif (is_subclass_of($elementclassname, 'ExplicitReadWriteModelPermissionsElement'))
00144 {
00145 if (ActionSecurityUtil::canUserPerformAction('Edit', $model, $user))
00146 {
00147 return;
00148 }
00149 else
00150 {
00151 $elementInformation['type'] = 'Null';
00152 }
00153 }
00154 }
00155 }
00156 ?>