Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sopel/builtins/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UrlSection(types.StaticSection):
"""A list of regular expressions to match URLs for which the title should not be shown."""
exclude_required_access = types.ChoiceAttribute(
'exclude_required_access',
choices=privileges.__all__,
choices=[level.name for level in privileges.AccessLevel],
default='OP',
)
"""Minimum channel access level required to edit ``exclude`` list using chat commands."""
Expand Down Expand Up @@ -168,7 +168,7 @@ def _user_can_change_excludes(bot: SopelWrapper, trigger: Trigger) -> bool:
channel = bot.channels[trigger.sender]
user_access = channel.privileges[trigger.nick]

if user_access >= getattr(privileges, required_access):
if user_access >= getattr(privileges.AccessLevel, required_access):
return True

return False
Expand Down
43 changes: 43 additions & 0 deletions test/builtins/test_builtins_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ def callback(bot, trigger, match):
return sopel


PRELOADED_CONFIG = """
[core]
owner = testnick
nick = TestBot
enable =
coretasks
url
"""


@pytest.fixture
def preloadedbot(configfactory, botfactory):
tmpconfig = configfactory('preloaded.cfg', PRELOADED_CONFIG)
return botfactory.preloaded(tmpconfig, ['url'])


@pytest.mark.parametrize("site", INVALID_URLS)
def test_find_title_invalid(site):
# All local for invalid ones
Expand Down Expand Up @@ -114,3 +130,30 @@ def test_url_triggers_rules_and_auto_title(mockbot):
labels = sorted(result[0].get_rule_label() for result in results)
expected = ['handle_urls_https', 'title_auto']
assert labels == expected


@pytest.mark.parametrize('level, result', (
('NOTHING', False),
('VOICE', False),
('HALFOP', False),
('OP', True),
('ADMIN', True),
('OWNER', True),
))
def test_url_ban_privilege(preloadedbot, ircfactory, triggerfactory, level, result):
"""Make sure the urlban command privilege check functions correctly."""
irc = ircfactory(preloadedbot)
irc.channel_joined('#test', [
'Unothing', 'Uvoice', 'Uhalfop', 'Uop', 'Uadmin', 'Uowner'])
irc.mode_set('#test', '+vhoaq', [
'Uvoice', 'Uhalfop', 'Uop', 'Uadmin', 'Uowner'])

nick = f'U{level.title()}'
user = level.lower()
line = f':{nick}!{user}@example.com PRIVMSG #test :.urlban *'
wrapper = triggerfactory.wrapper(preloadedbot, line)
match = triggerfactory(preloadedbot, line)

# parameter matrix assumes the default `url.exclude_required_access` config
# value, which was 'OP' at the time of test creation
assert url._user_can_change_excludes(wrapper, match) == result
Loading