fixed User::is_level... methods when anonymous

they where returning true in some cases (like when calling is_unactivated).
they now return false if anonymous.
This commit is contained in:
Parziphal 2013-12-06 05:13:03 -05:00
parent 12e3a57053
commit 272fc76629

View File

@ -494,8 +494,6 @@ class User extends Rails\ActiveRecord\Base
throw new Rails\ActiveRecord\Exception\RecordNotFoundException(); throw new Rails\ActiveRecord\Exception\RecordNotFoundException();
} }
// self::load_model('UserRecord');
if (UserRecord::where("user_id = ? AND is_positive = false AND reported_by IN (SELECT id FROM users WHERE level >= ?)", $invitee->id, CONFIG()->user_levels["Mod"])->exists() && !$this->is_admin()) { if (UserRecord::where("user_id = ? AND is_positive = false AND reported_by IN (SELECT id FROM users WHERE level >= ?)", $invitee->id, CONFIG()->user_levels["Mod"])->exists() && !$this->is_admin()) {
throw new User_HasNegativeRecord(); throw new User_HasNegativeRecord();
} }
@ -837,6 +835,11 @@ class User extends Rails\ActiveRecord\Base
private function parse_is_level_or($method) private function parse_is_level_or($method)
{ {
# For anonymous users
if (!$this->id) {
return false;
}
list($name, $operator) = explode('_or_', substr($method, 3)); list($name, $operator) = explode('_or_', substr($method, 3));
$name = ucfirst($name); $name = ucfirst($name);
$levels = CONFIG()->user_levels; $levels = CONFIG()->user_levels;
@ -856,6 +859,11 @@ class User extends Rails\ActiveRecord\Base
private function parse_is_level($method) private function parse_is_level($method)
{ {
# For anonymous users
if (!$this->id) {
return false;
}
$level_name = ucfirst(substr($method, 3)); $level_name = ucfirst(substr($method, 3));
$levels = CONFIG()->user_levels; $levels = CONFIG()->user_levels;
if (!isset($levels[$level_name])) { if (!isset($levels[$level_name])) {