/** * test custom field acl * * - add custom field * - remove grants * - cf should no longer be returned */ public function testCustomFieldAcl() { $createdCustomField = $this->_instance->addCustomField($this->_getCustomField()); $this->_objects[] = $createdCustomField; $this->_instance->setGrants($createdCustomField); $application = Tinebase_Application::getInstance()->getApplicationByName('Tinebase'); $appCustomFields = $this->_instance->getCustomFieldsForApplication($application->getId()); $this->assertEquals(0, count($appCustomFields)); }
/** * testAddressbookCustomFieldAcl * * @see 0007630: Customfield read access to all users */ public function testAddressbookCustomFieldAcl() { $createdCustomField = $this->_instance->addCustomField(self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact'))); $anotherCustomField = $this->_instance->addCustomField(self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact'))); $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'testcontact', 'container_id' => Tinebase_Container::getInstance()->getSharedContainer(Tinebase_Core::getUser(), 'Addressbook', Tinebase_Model_Grants::GRANT_READ)->getFirstRecord()->getId()))); $cfValue = array($createdCustomField->name => 'test value', $anotherCustomField->name => 'test value 2'); $contact->customfields = $cfValue; $contact = Addressbook_Controller_Contact::getInstance()->update($contact); $this->assertEquals($cfValue, $contact->customfields, 'cf not saved: ' . print_r($contact->toArray(), TRUE)); // create group and only give acl to this group $group = Tinebase_Group::getInstance()->getDefaultAdminGroup(); $this->_instance->setGrants($createdCustomField, array(Tinebase_Model_CustomField_Grant::GRANT_READ, Tinebase_Model_CustomField_Grant::GRANT_WRITE), Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP, $group->getId()); $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId()); $this->assertEquals(2, count($contact->customfields)); // change user and check cfs $this->_user = Tinebase_Core::getUser(); $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever'); Tinebase_Core::set(Tinebase_Core::USER, $sclever); $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId()); $this->assertEquals(array($anotherCustomField->name => 'test value 2'), $contact->customfields, 'cf should be hidden: ' . print_r($contact->customfields, TRUE)); }