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

[feature] Fetch + create domain permissions from subscriptions nightly #3635

Merged

Conversation

tsmethurst
Copy link
Contributor

@tsmethurst tsmethurst commented Jan 6, 2025

Description

This pull request adds scheduling of domain permission creation from subscriptions, as well as functions to support that (dereference functions, functionality to let admins test domain permission subscriptions by doing a dummy fetch).

Closes #3

Screenshot from 2025-01-06 12-24-22

To make this work, I had to do some refactoring to extract the admin actions struct from the admin processor and put it in its own separate package, hence the many change lines.

The PR doesn't include logic for revoking permissions yet from a subscription, because this PR felt hefty enough without including that. I'll do that in a separate PR. The logic for that will not be very complicated.

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have not leveraged AI to create the proposed changes.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@tsmethurst tsmethurst marked this pull request as ready for review January 6, 2025 15:32

// Check for invalid characters
// after the punification process.
if strings.ContainsAny(domain, "*, \n") {
Copy link
Member

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this fully checks whether this is a valid domain or not. i think it might be worth replacing both util.Punify() and this check with, idna.Lookup.ToASCII(...) which should both convert to punycode and validate it too. it might even remove the need for dns.IsDomainName()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh we might just be able replace the util.Punify() definition to instead be idna.Lookup.ToASCII(...) so it does validation too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the currently idna profile we use doesn't do much validation at all:

	// Punycode is a Profile that does raw punycode processing with a minimum
	// of validation.
	Punycode *Profile = punycode

	// Lookup is the recommended profile for looking up domain names, according
	// to Section 5 of RFC 5891. The exact configuration of this profile may
	// change over time.
	Lookup *Profile = lookup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm I see what you mean. Would it be alright with you if we did this in a separate PR? There's a few places in the codebase where we could probably use better domain validation, and I'd rather switch everything over at once.

// Allow fallback in case target doesn't
// negotiate content type correctly.
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Accept", permSub.ContentType.String()+","+"*/*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm just thinking, instead of us storing an expected content-type and sticking to that, would it be worth just parsing the response dependent on returned content-type and we just have a series of expected content-types that we support parsing? or is there another reason for storing the content-type i'm not seeing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise at the moment we're quite rigid as to whether a subscription remains as a certain content-type or to whether we configure something as the correct content-type to begin with. when we could just support any of them concurrently just by removing that field, always sending the full list we support in "Accept: " and just having the response struct defined in this file return the set content-type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i didn't pick this up in one of the earlier PRs where you defined the gtsmodel.DomainPermissionSubscription{} type, it just didn't really twig in my brain until i saw it in action :p

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh this is a relatively larger change so feel free to make this as a PR afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the reasoning was that some platforms where you can host things (github intself, for example) only provide the content type "text/plain" even when serving a csv or json file. So I wanted to make things a bit easier for people hosting files, where they don't need to mess about ensuring that their webserver or hosting service serves the right content type. But indeed if we should change this I'd rather address it in a separate PR :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh github you bastard... in which case it seems we better leave it then :)

@NyaaaWhatsUpDoc
Copy link
Member

some comments, but looking real good otherwise 👀

@tsmethurst tsmethurst merged commit 451803b into main Jan 8, 2025
4 checks passed
@tsmethurst tsmethurst deleted the domain_permission_subscriptions_2_the_subscriptioning branch January 8, 2025 10:29
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.

[feature] Subscribe-able allowlists / denylists
2 participants