From bae2bd84b3d5204c8e32509a18e8bd30d1c3b148 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sat, 12 Apr 2014 18:42:33 +0200 Subject: [PATCH 1/4] fixes map location validation is limited to ([0-90],[0-90]) #249 --- app/Model/AppModel.php | 21 +++++++++++ app/Model/User.php | 10 +++--- app/Test/Case/Model/UserTest.php | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 09e1112ac..8f639527a 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -137,4 +137,25 @@ protected function _setting($name) { throw new UnexpectedValueException; } + /** + * Inclusive Validation::range() + * + * @param array $check + * @param float $lower + * @param float $upper + * @return bool + * @see https://github.com/cakephp/cakephp/issues/3304 + */ + public function inRange($check, $lower = null, $upper = null) { + $check = reset($check); + if (!is_numeric($check)) { + return false; + } + if (isset($lower) && isset($upper)) { + return ($check >= $lower && $check <= $upper); + } + // fallback to 'parent' + return Validation::range($check, $lower, $upper); + } + } \ No newline at end of file diff --git a/app/Model/User.php b/app/Model/User.php index d977460de..69d4ff220 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -115,16 +115,16 @@ class User extends AppModel { 'message' => '*' ], 'user_place_lat' => [ - 'numeric' => ['rule' => 'numeric', 'allowEmpty' => true], - 'roundedGeoFormat' => ['rule' => '/^\d{1,2}(\.\d{0,4})?$/'] + 'validLatitude' => ['rule' => ['inRange', -90, 90], + 'allowEmpty' => true], ], 'user_place_lng' => [ - 'numeric' => ['rule' => 'numeric', 'allowEmpty' => true], - 'roundedGeoFormat' => ['rule' => '/^\d{1,2}(\.\d{0,4})?$/'] + 'validLongitude' => ['rule' => ['inRange', -180, 180], + 'allowEmpty' => true], ], 'user_place_zoom' => [ 'numeric' => ['rule' => ['naturalNumber', 0], 'allowEmpty' => true], - 'between' => ['rule' => ['between', 0, 25]] + 'between' => ['rule' => ['inRange', 0, 25]] ], 'user_color_actual_posting' => ['rule' => '/^#?[a-f0-9]{0,6}$/i'] ]; diff --git a/app/Test/Case/Model/UserTest.php b/app/Test/Case/Model/UserTest.php index 77938aa81..80d03fe87 100755 --- a/app/Test/Case/Model/UserTest.php +++ b/app/Test/Case/Model/UserTest.php @@ -268,6 +268,67 @@ public function testSetPassword() { $this->assertTrue($result); } + public function testSetPlace() { + $this->User->id = 3; + $success = $this->User->save([ + 'User' => [ + 'user_place' => 'Island', + 'user_place_lat' => -90.0000, + 'user_place_lng' => -180.0000, + 'user_place_zoom' => 1 + ] + ]); + $this->assertNotEmpty($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save([ + 'User' => [ + 'user_place' => 'Island', + 'user_place_lat' => 90.0000, + 'user_place_lng' => 180.0000 + ] + ]); + $this->assertNotEmpty($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save([ + 'User' => [ + 'user_place' => 'Island', + 'user_place_lat' => 90.0001, + 'user_place_log' => 180.0001 + ] + ]); + $this->assertFalse($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save(['User' => ['user_place_lat' => -90.0001]]); + $this->assertFalse($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save(['User' => ['user_place_lng' => -180.0001]]); + $this->assertFalse($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save(['User' => ['user_place_lat' => -180.0001]]); + $this->assertFalse($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save(['User' => ['user_place_zoom' => -1]]); + $this->assertFalse($success); + $this->User->clear(); + + $this->User->id = 3; + $success = $this->User->save(['User' => ['user_place_zoom' => 26]]); + $this->assertFalse($success); + $this->User->clear(); + } + public function testSetUsername() { $User = $this->getMockForModel('User', ['_dispatchEvent']); $User->id = 1; From 45f7a4a914d48b52c43eb9c971bee2d4a541f2e4 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sat, 12 Apr 2014 19:01:40 +0200 Subject: [PATCH 2/4] fixes link to /users/map in /users/* area even if maps are not activated #245 --- .../Case/Controller/UsersControllerTest.php | 22 +++++++++++++++++++ app/View/Elements/users/menu.ctp | 14 +++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/Test/Case/Controller/UsersControllerTest.php b/app/Test/Case/Controller/UsersControllerTest.php index c268f15c6..4a11d79c4 100755 --- a/app/Test/Case/Controller/UsersControllerTest.php +++ b/app/Test/Case/Controller/UsersControllerTest.php @@ -363,6 +363,24 @@ public function testViewSanitation() { $this->assertTextNotContains('<&Username', $result); } + public function testMapLinkInMenu() { + $this->generate('Users'); + $this->_loginUser(3); + + // not enabled, no link + $result = $this->testAction('/users/view/2', ['return' => 'contents']); + $this->assertTextNotContains('/users/map', $result); + $result = $this->testAction('/users/index', ['return' => 'contents']); + $this->assertTextNotContains('/users/map', $result); + + // not enabled, link + Configure::write('Saito.Settings.map_enabled', 1); + $result = $this->testAction('/users/view/2', ['return' => 'contents']); + $this->assertTextContains('/users/map', $result); + $result = $this->testAction('/users/index', ['return' => 'contents']); + $this->assertTextContains('/users/map', $result); + } + public function testMapDisabled() { $this->generate('Users'); $this->_loginUser(3); @@ -370,6 +388,10 @@ public function testMapDisabled() { $this->assertTextNotContains('class="saito-usermap"', $result); $this->assertTextNotContains(static::MAPQUEST, $result); + $result = $this->testAction('/users/view/3', ['return' => 'contents']); + $this->assertTextNotContains('class="saito-usermap"', $result); + $this->assertTextNotContains(static::MAPQUEST, $result); + $result = $this->testAction('/users/map', ['return' => 'view']); $this->assertTextNotContains('class="saito-usermap"', $result); $this->assertRedirectedTo(); diff --git a/app/View/Elements/users/menu.ctp b/app/View/Elements/users/menu.ctp index df261496c..16d729fe8 100644 --- a/app/View/Elements/users/menu.ctp +++ b/app/View/Elements/users/menu.ctp @@ -5,13 +5,15 @@ 'url' => '/users/index', 'title' => __d('page_titles', 'users/index'), 'icon' => 'users' - ], - 'map' => [ + ] + ]; + if (Configure::read('Saito.Settings.map_enabled')) { + $userMenu['map'] = [ 'url' => '/users/map', 'title' => __d('page_titles', 'users/map'), 'icon' => 'map-marker' - ] - ]; + ]; + } foreach ($userMenu as $m) { if (strpos($this->here, $m['url']) !== false) { continue; @@ -21,5 +23,7 @@ $m['url'], ['position' => 'right', 'escape' => false]); } - echo implode($menu); + if (!empty($menu)) { + echo implode($menu); + } $this->end(); From 11fee27da24ce21d33dd0e723947c3da6adc6142 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Sat, 12 Apr 2014 19:05:20 +0200 Subject: [PATCH 3/4] bumps version string --- app/Config/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/version.php b/app/Config/version.php index 4b4308659..cdc2f635c 100644 --- a/app/Config/version.php +++ b/app/Config/version.php @@ -1,4 +1,4 @@ Date: Sat, 12 Apr 2014 19:15:32 +0200 Subject: [PATCH 4/4] removes C&P duplicate --- app/Test/Case/Model/UserTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Test/Case/Model/UserTest.php b/app/Test/Case/Model/UserTest.php index 80d03fe87..48a0944b7 100755 --- a/app/Test/Case/Model/UserTest.php +++ b/app/Test/Case/Model/UserTest.php @@ -313,11 +313,6 @@ public function testSetPlace() { $this->assertFalse($success); $this->User->clear(); - $this->User->id = 3; - $success = $this->User->save(['User' => ['user_place_lat' => -180.0001]]); - $this->assertFalse($success); - $this->User->clear(); - $this->User->id = 3; $success = $this->User->save(['User' => ['user_place_zoom' => -1]]); $this->assertFalse($success);