Exemplo n.º 1
0
 /**
  * Override to process the note as a social item when needed.
  * (non-PHPdoc)
  * @see ZurmoBaseController::actionAfterSuccessfulModelSave()
  */
 protected function actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams = null)
 {
     assert('$model instanceof Note');
     if (ArrayUtil::getArrayValue(PostUtil::getData(), 'postToProfile')) {
         $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($model);
         $socialItem = new SocialItem();
         $socialItem->note = $model;
         $saved = $socialItem->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
         ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($socialItem, $explicitReadWriteModelPermissions);
     }
     parent::actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams);
 }
 /**
  * @param DemoDataHelper $demoDataHelper
  */
 public function makeAll(&$demoDataHelper)
 {
     assert('$demoDataHelper instanceof DemoDataHelper');
     assert('$demoDataHelper->isSetRange("User")');
     assert('$demoDataHelper->isSetRange("Account")');
     $socialItems = array();
     $data = self::getSocialItemData();
     shuffle($data);
     foreach ($data as $randomSocialItemData) {
         $postData = array();
         $socialItem = new SocialItem();
         $socialItem->setScenario('importModel');
         $socialItem->owner = $demoDataHelper->getRandomByModelName('User');
         $socialItem->createdByUser = $socialItem->owner;
         //check if we should connect to a note
         if (isset($randomSocialItemData['noteDescription'])) {
             $note = new Note();
             $account = $demoDataHelper->getRandomByModelName('Account');
             $note->description = $randomSocialItemData['noteDescription'];
             $note->owner = $socialItem->owner;
             $note->activityItems->add($account);
             $this->populateModel($note);
             $saved = $note->save();
             assert('$saved');
             $socialItem->note = $note;
         } else {
             $socialItem->description = $randomSocialItemData['description'];
         }
         //Add some comments
         foreach ($randomSocialItemData['comments'] as $commentDescription) {
             $comment = new Comment();
             $comment->setScenario('importModel');
             $comment->createdByUser = $demoDataHelper->getRandomByModelName('User');
             $comment->description = $commentDescription;
             $socialItem->comments->add($comment);
         }
         $socialItem->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
         $saved = $socialItem->save();
         assert('$saved');
         $socialItems[] = $socialItem->id;
     }
     $demoDataHelper->setRangeByModelName('SocialItem', $socialItems[0], $socialItems[count($socialItems) - 1]);
 }
 public function actionDeleteViaAjax($id)
 {
     $socialItem = SocialItem::getById(intval($id));
     if (!$socialItem->canUserDelete(Yii::app()->user->userModel) && $socialItem->owner->id != Yii::app()->user->userModel->id && $socialItem->toUser->id != Yii::app()->user->userModel->id) {
         $messageView = new AccessFailureAjaxView();
         $view = new AjaxPageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $deleted = $socialItem->delete();
     if (!$deleted) {
         throw new FailedToDeleteModelException();
     }
 }
Exemplo n.º 4
0
 public function testAddingNoteAndDeletingNoteAndThenTheSocialItemsAreRemoved()
 {
     $super = User::getByUsername('super');
     $this->assertEquals(0, SocialItem::getCount());
     $accounts = Account::getByName('anAccount');
     $note = NoteTestHelper::createNoteWithOwnerAndRelatedAccount('aNote', $super, $accounts[0]);
     $socialItem = new SocialItem();
     $socialItem->description = 'My test description';
     $socialItem->note = $note;
     $saved = $socialItem->save();
     $this->assertTrue($saved);
     $socialItemId = $socialItem->id;
     $noteId = $note->id;
     $note->forget();
     $this->assertEquals(1, SocialItem::getCount());
     $note = Note::getById($noteId);
     $deleted = $note->delete();
     $this->assertTrue($deleted);
     $this->assertEquals(0, SocialItem::getCount());
 }
 /**
  * @depends testPostGameNotificationToProfile
  */
 public function testPostingAnNoteCarriesPermissionsCorrectly()
 {
     if (!SECURITY_OPTIMIZED) {
         return;
     }
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $socialItems = SocialItem::getAll();
     $this->assertEquals(2, count($socialItems));
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $activityItemPostData = array('Account' => array('id' => $superAccountId));
     $this->setGetArray(array('redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'postToProfile' => true, 'Note' => array('description' => 'a note that is promoted')));
     $content = $this->runControllerWithRedirectExceptionAndGetContent('notes/default/inlineCreateSave');
     $notes = Note::getAll();
     $this->assertEquals(1, count($notes));
     $socialItems = SocialItem::getAll();
     $this->assertEquals(3, count($socialItems));
     $this->assertEquals($notes[0]->id, $socialItems[2]->note->id);
     $this->assertNull($socialItems[2]->description);
 }