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

Fix audit log overwrite transformer #1716

Merged
merged 6 commits into from Oct 22, 2022

Conversation

NeloBlivion
Copy link
Member

Summary

A bit of a niche issue I encountered in help channels, but worth fixing nonetheless.
When fetching audit_logs from a guild, each AuditLogEntry can have before/after attributes showing the changes in the target. Some Audit Log Actions can have an overwrites attribute if it deals with permissions, e.g. channel creation/deletion. When forming this attribute, the data from Discord goes through the below transformer to resolve the User/Role objects.

def _transform_overwrites(
entry: AuditLogEntry, data: list[PermissionOverwritePayload]
) -> list[tuple[Object, PermissionOverwrite]]:
overwrites = []
for elem in data:
allow = Permissions(int(elem["allow"]))
deny = Permissions(int(elem["deny"]))
ow = PermissionOverwrite.from_pair(allow, deny)
ow_type = elem["type"]
ow_id = int(elem["id"])
target = None
if ow_type == "0":
target = entry.guild.get_role(ow_id)
elif ow_type == "1":
target = entry._get_member(ow_id)
if target is None:
target = Object(id=ow_id)
overwrites.append((target, ow))
return overwrites

However, in the Overwrite structuer "type" is an integer; as such, the above code will always result in target = None, so the object is never resolved. This PR adjusts them to compare to ints instead.

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.

@codecov
Copy link

codecov bot commented Oct 20, 2022

Codecov Report

Merging #1716 (5e00ce0) into master (1aafeb8) will not change coverage.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1716   +/-   ##
=======================================
  Coverage   33.19%   33.19%           
=======================================
  Files          96       96           
  Lines       18414    18414           
=======================================
  Hits         6113     6113           
  Misses      12301    12301           
Flag Coverage Δ
pytest 33.19% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
discord/audit_logs.py 28.52% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1aafeb8...5e00ce0. Read the comment docs.

@BobDotCom BobDotCom enabled auto-merge (squash) October 20, 2022 21:44
@BobDotCom BobDotCom requested review from a team, FrostByte266, plun1331 and WhoIsConch and removed request for a team October 21, 2022 15:17
@Lulalaby Lulalaby enabled auto-merge (squash) October 21, 2022 19:24
@Lulalaby Lulalaby enabled auto-merge (squash) October 22, 2022 02:39
@Lulalaby Lulalaby merged commit 982c476 into Pycord-Development:master Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants