Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Feature: make user check case-insensitive
Since we're doing it for subreddits, we might as well for users, too.  It's an
easy mistake to make, so let's prevent it if we can.
  • Loading branch information
xiongchiamiov committed Oct 1, 2014
1 parent f41d0ad commit aac14d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions r2/r2/config/feature/state.py
Expand Up @@ -95,8 +95,8 @@ def is_enabled(self, user=None, subreddit=None):
if cfg.get('employee') and world.is_employee(user):
return True

users = cfg.get('users')
if users and user and user.name in users:
users = [u.lower() for u in cfg.get('users', [])]
if users and user and user.name.lower() in users:
return True

subreddits = [s.lower() for s in cfg.get('subreddits', [])]
Expand Down
7 changes: 6 additions & 1 deletion r2/r2/tests/unit/config/feature_test.py
Expand Up @@ -31,6 +31,7 @@

MockAccount = collections.namedtuple('Account', 'name')
gary = MockAccount(name='gary')
all_uppercase = MockAccount(name='ALL_UPPERCASE')


class TestFeature(unittest.TestCase):
Expand Down Expand Up @@ -126,10 +127,14 @@ def test_url_disabled(self):
self.assertFalse(feature_state.is_enabled(user=gary))

def test_user_in(self):
cfg = {'users': ['gary']}
cfg = {'users': ['Gary']}
feature_state = self._make_state(cfg)
self.assertTrue(feature_state.is_enabled(user=gary))

cfg = {'users': ['ALL_UPPERCASE']}
feature_state = self._make_state(cfg)
self.assertTrue(feature_state.is_enabled(user=all_uppercase))

cfg = {'users': ['dave', 'gary']}
feature_state = self._make_state(cfg)
self.assertTrue(feature_state.is_enabled(user=gary))
Expand Down

0 comments on commit aac14d4

Please sign in to comment.