Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: .urlban privilege check is broken #2649

Closed
dgw opened this issue Jan 24, 2025 · 2 comments · Fixed by #2650
Closed

url: .urlban privilege check is broken #2649

dgw opened this issue Jan 24, 2025 · 2 comments · Fixed by #2650
Labels
Bug Things to squish; generally used for issues
Milestone

Comments

@dgw
Copy link
Member

dgw commented Jan 24, 2025

Description

Non-admin users hit a broken channel-privilege check if they try to use .urlban, which throws an uncaught exception.

Reproduction steps

  1. Be a non-admin user, i.e. not listed in Sopel's core.admins or core.owner settings
  2. Do .urlban *
  3. Sopel spits out an unexpected AttributeError

Expected behavior

Use of the .urlban command by non-admins should be correctly allowed or denied based on their channel privilege level and the bot's url.exclude_required_access setting.

Relevant logs

[2025-01-24 02:51:44,490] sopel.bot            ERROR    - Unexpected AttributeError (module 'sopel.privileges' has no attribute 'OP') from msv. Message was: .urlban *
Traceback (most recent call last):
  File "/home/sopel/.local/lib/python3.12/site-packages/sopel/bot.py", line 698, in call_rule
    rule.execute(sopel, trigger)
  File "/home/sopel/.local/lib/python3.12/site-packages/sopel/plugins/rules.py", line 1273, in execute
    exit_code = self._handler(bot, trigger)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sopel/.local/lib/python3.12/site-packages/sopel/builtins/url.py", line 183, in url_ban
    if not _user_can_change_excludes(bot, trigger):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sopel/.local/lib/python3.12/site-packages/sopel/builtins/url.py", line 162, in _user_can_change_excludes
    if user_access >= getattr(privileges, required_access):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'sopel.privileges' has no attribute 'OP'

Notes

Someone reported this bug on our IRC last night. @SnoopJ correctly deduced that it was related to the switch to privileges.AccessLevel. We can safely say #2540 was responsible for this breakage; as is often the case, it was my fault. I forgot about #2352 when making that change.

sopel.privileges.names is a new shortcut to sopel.privileges.AccessLevel._member_names_, which is quite a mouthful. (I wanted to create sopel.privileges.AccessLevel.names as a @property, but that doesn't work and I don't want to monkeypatch our subclass of enum.IntFlag too much.)

Sopel version

8.0.1, master

Installation method

pip install

Python version

3.12.7

Operating system

No response

IRCd

No response

Relevant plugins

url

@dgw dgw added the Bug Things to squish; generally used for issues label Jan 24, 2025
@dgw dgw added this to the 8.0.2 milestone Jan 24, 2025
@dgw
Copy link
Member Author

dgw commented Jan 24, 2025

Note: I started working on this in the privilege-names branch.

The solution there is adding a sopel.privileges.names attribute as a shortcut to sopel.privileges.AccessLevel._member_names_, though using the AccessLevel attr directly would obviously work without the shortcut.

I'm holding off on opening a PR because of unresolved CI issues, though. See #2647.

@dgw
Copy link
Member Author

dgw commented Jan 30, 2025

Fixed by #2650, just not correctly linked/closed automatically.

@dgw dgw closed this as completed Jan 30, 2025
@dgw dgw linked a pull request Jan 30, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant