function getPermissions(&$record) { if (getUser()) { return Dataface_PermissionsTool::ALL(); } return null; }
/** * Returns permissions array. This method is called every time an action is * performed to make sure that the user has permission to perform the action. * @param record A Dataface_Record object (may be null) against which we check * permissions. * @see Dataface_PermissionsTool * @see Dataface_AuthenticationTool */ function getPermissions(&$record) { if (SweteTools::isAdmin()) { return Dataface_PermissionsTool::ALL(); } else { return Dataface_PermissionsTool::NO_ACCESS(); } }
function getPermissions(&$record) { // $record is a Dataface_Record object $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ($user) { return Dataface_PermissionsTool::ALL(); } return Dataface_PermissionsTool::NO_ACCESS(); }
function getPermissions($record) { if (SweteTools::isAdmin()) { $perms = Dataface_PermissionsTool::ALL(); $perms['edit'] = 0; $perms['new'] = 0; $perms['copy'] = 0; $perms['update'] = 0; $perms['update_set'] = 0; return $perms; } }
function getPermissions(&$record) { $app =& Dataface_Application::getInstance(); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); $query =& $app->getQuery(); if ($query['-action'] == 'new' and !isset($user)) { return Dataface_PermissionsTool::READ_EDIT(); } else { if ($user and isAdmin($user->val('role'))) { return Dataface_PermissionsTool::ALL(); } else { return Dataface_PermissionsTool::NO_ACCESS(); } } }
/** * Obtains the permissions for a particular record or for this table. * @param Dataface_Record record * @param string field * @param string relationship * @param boolean nobubble * @param array recordmask */ function getPermissions($params = array()) { // First let's try to load permissions from the cache $pt =& Dataface_PermissionsTool::getInstance(); $params['table'] = $this->tablename; if (isset($params['record'])) { $record =& $params['record']; } else { $record = null; } $cachedPermissions = $pt->getCachedPermissions($record, $params); if (isset($cachedPermissions)) { return $cachedPermissions; } $delegate =& $this->getDelegate(); $app =& Dataface_Application::getInstance(); $appDelegate =& $app->getDelegate(); $parent =& $this->getParent(); $recordmask = @$params['recordmask']; $methods = array(); if (isset($params['field'])) { $methods[] = array('object' => &$delegate, 'name' => $params['field'] . '__permissions', 'type' => 'permissions', 'partial' => 1); $methods[] = array('object' => &$delegate, 'name' => $params['field'] . '__roles', 'type' => 'roles', 'partial' => 1); $methods[] = array('object' => &$delegate, 'name' => '__field__permissions', 'type' => 'permissions', 'partial' => 1); $methods[] = array('object' => &$delegate, 'name' => '__field__roles', 'type' => 'roles', 'partial' => 1); if (isset($parent)) { $methods[] = array('object' => &$parent, 'name' => 'getPermissions', 'type' => 'Dataface_Table', 'partial' => 1); } if (@$params['recordmask']) { $methods[] = 'recordmask'; } if (@$params['nobubble']) { $methods[] = 'break'; } } else { if (isset($params['relationship'])) { if (isset($params['relationshipmask'])) { $rmask =& $params['relationshipmask']; } else { $rmask = array(); } $methods[] = array('object' => &$delegate, 'name' => 'rel_' . $params['relationship'] . '__permissions', 'type' => 'permissions', 'mask' => &$rmask, 'partial' => 1); $methods[] = array('object' => &$delegate, 'name' => 'rel_' . $params['relationship'] . '__roles', 'type' => 'roles', 'mask' => &$rmask, 'partial' => 1); if (isset($parent)) { $methods[] = array('object' => &$parent, 'name' => 'getPermissions', 'type' => 'Dataface_Table', 'partial' => 1); } if (@$params['nobubble']) { $methods[] = 'break'; } } } //if ( isset($params['recordmask']) ) $mask =& $params['recordmask']; //else $mask = array(); $methods[] = array('object' => &$delegate, 'name' => 'getPermissions', 'type' => 'permissions'); $methods[] = array('object' => &$delegate, 'name' => 'getRoles', 'type' => 'roles'); $methods[] = array('object' => &$appDelegate, 'name' => 'getPermissions', 'type' => 'permissions'); $methods[] = array('object' => &$appDelegate, 'name' => 'getRoles', 'type' => 'roles'); if (isset($parent)) { $methods[] = array('object' => &$parent, 'name' => 'getPermissions', 'type' => 'Dataface_Table'); } $perms = array(); foreach ($methods as $method) { if ($method == 'break') { return null; } if ($method == 'recordmask' and is_array($recordmask)) { // If a record mask has been supplied we apply that here // so that unspecified permissions in a field request will // be augmented with a specified recordmask $perms = array_merge($recordmask, $perms); continue; } if (isset($method['object']) and method_exists($method['object'], $method['name'])) { $name = $method['name']; if ($method['type'] == 'Dataface_Table') { $res = $method['object']->{$name}(array_merge($params, array('nobubble' => 1))); } else { $res = $method['object']->{$name}($record, $params); } if ($method['type'] == 'roles') { $res = $this->convertRolesToPermissions($res); } if (is_array($res)) { if (@$method['mask'] and is_array(@$method['mask'])) { $res = array_merge($method['mask'], $res); } $perms = array_merge($res, $perms); if (!@$method['partial']) { $pt->filterPermissions($record, $perms, $params); $pt->cachePermissions($record, $params, $perms); return $perms; } } } } $res = array_merge(Dataface_PermissionsTool::ALL(), $perms); $pt->filterPermissions($record, $res, $params); $pt->cachePermissions($record, $params, $res); return $res; }
function getPermissions(&$record) { return Dataface_PermissionsTool::ALL(); }
/** * @brief Builds a widget that can be added to a form. This will delegate * to the WidgetHandler::buildWidget() method if defined for the field's widget * type. * * @param Dataface_Record &$record The Dataface Record that this widget * is to be editing. * @param array &$field The field definition. * @param HTML_QuickForm The form to which the widget will be added. * @param string $formFieldName The name of the field on the form. * @returns HTML_QuickForm_element */ function &buildWidget($record, &$field, $form, $formFieldName, $new = false, $permissions = null) { $table =& $record->_table; $widget =& $field['widget']; if (!isset($permissions)) { //$permissions =& $record->getPermissions(array('field'=>$field['name'])); $permissions = Dataface_PermissionsTool::ALL(); // reference to widget descriptor array } $pt =& Dataface_PermissionsTool::getInstance(); // Reference to permissions tool to operate on $permissions $widgetHandler =& $this->getWidgetHandler($widget['type']); if (isset($widgetHandler) and method_exists($widgetHandler, 'buildWidget')) { $el =& $widgetHandler->buildWidget($record, $field, $form, $formFieldName, $new); } else { $factory =& Dataface_FormTool::factory(); // A dummy HTML_QuickForm used as a factory to create temporary elements. // Reference to the table object. $el =& $factory->addElement($widget['type'], $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $formFieldName)); } if (PEAR::isError($el)) { throw new Exception($el->toString(), E_USER_ERROR); } $el->setFieldDef($field); if (isset($record) && $record && $record->_table->hasField($field['name'])) { if ($link = $record->getLink($field['name'])) { $el->setProperty('link', $link); } $el->setProperty('record_url', $record->getURL()); } $atts = $el->getAttributes(); if (!is_array($atts)) { $atts = array(); } $atts = array_merge($atts, $field['widget']['atts']); foreach ($atts as $k => $v) { if (strpos($k, 'data-xf-override-') === 0) { $atts[substr($k, 17)] = $v; } } if (!isset($atts['data-xf-field'])) { $atts['data-xf-field'] = $field['name']; } $el->setAttributes($atts); if ($new and !$pt->checkPermission('new', $permissions)) { $el->freeze(); } else { if (!$new and !$pt->checkPermission('edit', $permissions)) { $el->freeze(); } } /* // Deal with permissions on this field. if ( $pt->view($permissions) and !$pt->edit($permissions) ){ if ( !($new && $pt->checkPermission('new', $permissions)) ){ $el->freeze(); } } */ $el->record =& $record; $form->addElement($el); /* * * If there are any validation options set for the field, we must add these rules to the quickform * element. * */ $validators = $field['validators']; foreach ($validators as $vname => $validator) { /* * * $validator['arg'] would be specified in the INI file. * Example ini file listing: * ------------------------- * [FirstName] * widget:label = First name * widget:description = Enter your first name * validators:regex = "/[0-9a-zA-Z/" * * This would result in $validator['arg'] = "/[0-9a-zA-Z/" in this section * and $vname == "regex". Hence it would mean that a regular expression validator * is being placed on this field so that only Alphanumeric characters are accepted. * Please see documentation for HTML_QuickForm PEAR class for more information * about QuickForm validators. * */ if ($vname == 'required' && $widget['type'] == 'file') { continue; } $form->addRule($formFieldName, $validator['message'], $vname, @$validator['arg'], $widget['type'] == 'htmlarea' ? null : 'client'); } $this->pullField($record, $field, $form, $formFieldName, $new); $el->_persistantFreeze = true; return $el; }
/** * * Build an HTML_QuickForm_element object to represent a field from the table. * * @param $field A field descriptor array for specific field. * @param $permissions An optional second argument to pass a permissions descriptor array * to define the current permissions. * */ function _buildWidget(&$field) { global $myctr; if (func_num_args() > 1) { /* * * A second argument is present. It must be a permissions array. * */ $permissions = func_get_arg(1); } else { /* * * No permissions were specified so we give Global permissions by default. * */ $permissions = Dataface_PermissionsTool::ALL(); } $formTool =& Dataface_FormTool::getInstance(); $el =& $formTool->buildWidget($this->_record, $field, $this, $field['name'], $this->_new, $permissions); return $el; }