ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 9854


Ignore:
Timestamp:
Jan 3, 2009, 12:40:00 PM (11 years ago)
Author:
ogawa
Message:

#3344:fixed publicFlag working correctly for direct accesses

Location:
OpenPNE3/plugins/opDiaryPlugin/trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/action/opDiaryPluginDiaryActions.class.php

    r9853 r9854  
    6262  public function executeShow(sfWebRequest $request)
    6363  {
     64    $this->forward404Unless($this->isViewable());
     65
    6466    $this->form = new DiaryCommentForm();
    6567  }
     
    7981  public function executeEdit(sfWebRequest $request)
    8082  {
    81     $this->forward404Unless($this->diary->getMemberId() === $this->getUser()->getMemberId());
     83    $this->forward404Unless($this->isAuthor());
     84
    8285    $this->form = new DiaryForm($this->diary);
    8386  }
     
    8588  public function executeUpdate(sfWebRequest $request)
    8689  {
    87     $this->forward404Unless($this->diary->getMemberId() === $this->getUser()->getMemberId());
     90    $this->forward404Unless($this->isAuthor());
     91
    8892    $this->form = new DiaryForm($this->diary);
    8993    $this->processForm($request, $this->form);
     
    107111  public function executeDelete(sfWebRequest $request)
    108112  {
    109     $diary = DiaryPeer::retrieveByPk($request->getParameter('id'));
    110     $this->forward404Unless($diary);
    111     $this->forward404Unless($diary->getMemberId() === $this->getUser()->getMemberId());
    112     $diary->delete();
     113    $this->forward404Unless($this->isAuthor());
     114
     115    $this->diary->delete();
    113116
    114117    $this->redirect('diary/list');
     
    117120  public function executePostComment(sfWebRequest $request)
    118121  {
     122    $this->forward404Unless($this->isViewable());
     123
    119124    $comment = new DiaryComment();
    120125    $comment->setDiary($this->diary);
     
    144149    $this->redirect($this->generateUrl('diary_show', $diaryComment->getDiary()));
    145150  }
     151
     152  protected function isAuthor()
     153  {
     154    if ($this->diary->getMemberId() === $this->getUser()->getMemberId())
     155    {
     156      return true;
     157    }
     158
     159    return false;
     160  }
     161
     162  protected function isViewable()
     163  {
     164    return DiaryPeer::isViewable($this->diary, $this->getUser()->getMemberId());
     165  }
    146166}
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/DiaryPeer.php

    r9852 r9854  
    9999  protected static function addPublicFlagCriteria(Criteria $c, $flag)
    100100  {
    101     $flags = array();
    102     switch ($flag)
     101    if ($flag === self::PUBLIC_FLAG_PRIVATE)
    103102    {
    104       case self::PUBLIC_FLAG_FRIEND:
    105         $flags[] = self::PUBLIC_FLAG_FRIEND;
    106       case self::PUBLIC_FLAG_SNS:
    107         $flags[] = self::PUBLIC_FLAG_SNS;
    108       case self::PUBLIC_FLAG_OPEN:
    109         $flags[] = self::PUBLIC_FLAG_OPEN;
    110         break;
    111 
    112       case self::PUBLIC_FLAG_PRIVATE:
    113       default:
    114         return $c;
     103      return $c;
    115104    }
    116105
     106    $flags = self::getViewablePublicFlags($flag);
    117107    if (1 === count($flags))
    118108    {
     
    149139    }
    150140  }
     141
     142  protected static function getViewablePublicFlags($flag)
     143  {
     144    $flags = array();
     145    switch ($flag)
     146    {
     147      case self::PUBLIC_FLAG_PRIVATE:
     148        $flags[] = self::PUBLIC_FLAG_PRIVATE;
     149      case self::PUBLIC_FLAG_FRIEND:
     150        $flags[] = self::PUBLIC_FLAG_FRIEND;
     151      case self::PUBLIC_FLAG_SNS:
     152        $flags[] = self::PUBLIC_FLAG_SNS;
     153      case self::PUBLIC_FLAG_OPEN:
     154        $flags[] = self::PUBLIC_FLAG_OPEN;
     155        break;
     156    }
     157
     158    return $flags;
     159  }
     160
     161  public static function isViewable(Diary $diary, $myMemberId)
     162  {
     163    $flags = self::getViewablePublicFlags(self::getPublicFlagByMemberId($diary->getMemberId(), $myMemberId));
     164
     165    return in_array($diary->getPublicFlag(), $flags);
     166  }
    151167}
Note: See TracChangeset for help on using the changeset viewer.