Пример #1
0
 /**
  * Create new ParseACL from existing permissions.
  *
  * @param array $data represents permissions.
  *
  * @return ParseACL
  * @throws \Exception
  * @ignore
  */
 public static function _createACLFromJSON($data)
 {
     $acl = new ParseACL();
     foreach ($data as $id => $permissions) {
         if (!is_string($id)) {
             throw new \Exception('Tried to create an ACL with an invalid userId.');
         }
         foreach ($permissions as $accessType => $value) {
             if ($accessType !== 'read' && $accessType !== 'write') {
                 throw new \Exception('Tried to create an ACL with an invalid permission type.');
             }
             if (!is_bool($value)) {
                 throw new \Exception('Tried to create an ACL with an invalid permission value.');
             }
             $acl->setAccess($accessType, $id, $value);
         }
     }
     return $acl;
 }
Пример #2
0
 public function createACL()
 {
     $newACL = new ParseACL();
     $newACL->setPublicReadAccess(true);
     $newACL->setRoleReadAccessWithName('Admin', true);
     $newACL->setRoleWriteAccessWithName('Admin', true);
     $newACL->setRoleReadAccessWithName('Master', true);
     $newACL->setRoleWriteAccessWithName('Master', true);
     return $newACL;
 }
Пример #3
0
 /**
  * Get the defaultACL.
  *
  * @return ParseACL
  */
 public static function _getDefaultACL()
 {
     if (self::$defaultACLUsesCurrentUser && self::$defaultACL) {
         $last = self::$lastCurrentUser ? clone self::$lastCurrentUser : null;
         if (!ParseUser::getCurrentUser()) {
             return self::$defaultACL;
         }
         if ($last != ParseUser::getCurrentUser()) {
             self::$defaultACLWithCurrentUser = clone self::$defaultAC;
             self::$defaultACLWithCurrentUser->_setShared(true);
             self::$defaultACLWithCurrentUser->setUserReadAccess(ParseUser::getCurrentUser(), true);
             self::$defaultACLWithCurrentUser->setUserWriteAccess(ParseUser::getCurrentUser(), true);
             self::$lastCurrentUser = clone ParseUser::getCurrentUser();
         }
         return self::$defaultACLWithCurrentUser;
     }
     return self::$defaultACL;
 }
Пример #4
0
 public function aclPublic()
 {
     $acl = new ParseACL();
     $acl->setPublicReadAccess(true);
     $acl->setPublicWriteAccess(true);
     return $acl;
 }
Пример #5
0
 /**
  * Handle merging of special fields for the object.
  *
  * @param array &$data Data received from server.
  */
 public function _mergeMagicFields(&$data)
 {
     if (isset($data['objectId'])) {
         $this->objectId = $data['objectId'];
         unset($data['objectId']);
     }
     if (isset($data['createdAt'])) {
         $this->createdAt = new \DateTime($data['createdAt']);
         unset($data['createdAt']);
     }
     if (isset($data['updatedAt'])) {
         $this->updatedAt = new \DateTime($data['updatedAt']);
         unset($data['updatedAt']);
     }
     if (isset($data['ACL'])) {
         $acl = ParseACL::_createACLFromJSON($data['ACL']);
         $this->serverData['ACL'] = $acl;
         unset($data['ACL']);
     }
 }
Пример #6
0
 /**
  * Handle merging of special fields for the object.
  *
  * @param array &$data Data received from server.
  */
 public function _mergeMagicFields(&$data)
 {
     date_default_timezone_set('America/Chicago');
     if (isset($data['objectId'])) {
         $this->objectId = $data['objectId'];
         unset($data['objectId']);
     }
     if (isset($data['createdAt'])) {
         $this->createdAt = new \DateTime($data['createdAt']);
         unset($data['createdAt']);
     }
     if (isset($data['updatedAt'])) {
         $this->updatedAt = new \DateTime($data['updatedAt']);
         unset($data['updatedAt']);
     }
     if (isset($data['ACL'])) {
         $acl = ParseACL::_createACLFromJSON($data['ACL']);
         $this->serverData['ACL'] = $acl;
         unset($data['ACL']);
     }
 }
Пример #7
0
 public function testIncludedObjectsGetACLWithDefaultACL()
 {
     Helper::clearClass("Test");
     Helper::clearClass("Related");
     $defaultACL = new ParseACL();
     $defaultACL->setPublicReadAccess(true);
     $defaultACL->setPublicWriteAccess(true);
     ParseACL::setDefaultACL($defaultACL, true);
     $object = ParseObject::create('Test');
     $acl = new ParseACL();
     $acl->setPublicReadAccess(true);
     $object->setACL($acl);
     $object->save();
     $this->assertTrue($object->getACL()->getPublicReadAccess());
     $related = ParseObject::create('Related');
     $related->set('test', $object);
     $related->save();
     $query = new ParseQuery('Related');
     $query->includeKey('test');
     $objectAgain = $query->first()->get('test');
     $this->assertTrue($objectAgain->getACL()->getPublicReadAccess());
     $this->assertFalse($objectAgain->getACL()->getPublicWriteAccess());
 }
Пример #8
0
 if (empty($roleName) != true) {
     $query = new ParseQuery("_Role");
     $query->equalTo('name', $roleName);
     $role = $query->first();
     if ($role != NULL) {
         if ($roleGenerateType != 'new') {
             $role->getUsers()->add($user);
             $role->save();
         }
         $saveRole = true;
     }
 }
 if ($roleGenerateType != 'exist' && $saveRole != true) {
     // 新しくロールを追加
     if (empty($roleName) != true) {
         $roleACL = new ParseACL();
         $roleACL->setPublicWriteAccess(true);
         $roleACL->setPublicReadAccess(true);
         $role = ParseRole::createRole($roleName, $roleACL);
         $role->getUsers()->add($user);
         $role->save();
         $saveRole = true;
     }
 }
 if ($saveRole == true) {
     $hasChangeAcceptRole = false;
     foreach ($acceptRoleNames as $acceptRoleName) {
         $query = new ParseQuery("_Role");
         $query->equalTo('name', $acceptRoleName);
         $acceptRole = $query->first();
         if ($acceptRole != NULL) {