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

Receiving Vouches #181

Merged
merged 8 commits into from
Sep 4, 2018
Merged

Receiving Vouches #181

merged 8 commits into from
Sep 4, 2018

Conversation

dshanske
Copy link
Collaborator

@dshanske dshanske commented Jul 1, 2018

This PR adds in the ability to add domains to the whitelist from the comment admin, as well as preliminary support for receiving vouches.

For now, the code, if there is a vouch parameter, verifies it. If it fails verification, it rejects the webmention. If it passes, it adds a parameter noting it passed. It also stores the vouch. It uses the approved domains list to determine acceptable sites for vouching, but I'd like to expand verification in future.

The next piece would be to add an admin setting to decide whether or not a successful vouch should be auto-approved, and to start getting some vouched webmentions.

@pfefferle
Copy link
Owner

pfefferle commented Jul 4, 2018

Vouch is very experimental and (as you said) there are only few who really send vouches, so I am not sure if we sould add this in such an early state. This might cause errors on verifications and might result in timeouts, because of the extra site that has to be parsed. I would prefer implementing async Webmentions first and/or implementing Vouch as a feature plugin or behind a feature toggle (so users can enable it using for example a constant).

@dshanske
Copy link
Collaborator Author

dshanske commented Jul 4, 2018

I am happy to put this behind a toggle and to merely start storing the vouch url by default.

@pfefferle
Copy link
Owner

Cool. I think the best way to do so, is to encapsulate all in a class-webmention-vouch.php file. With all the hooks and settings (if needed). So that we simply can enable/disable vouch via:

if ( WEBMENTION_VOUCH === true ) {
    require_once dirname( __FILE__ ) . '/includes/class-webmention-vouch.php';
}

What do you think?

@dshanske
Copy link
Collaborator Author

@pfefferle How is this?

@pfefferle
Copy link
Owner

pfefferle commented Jul 11, 2018

nice, thanks! can you rename the vouch method to a more descriptive one? For example verify or verify_vouch. So that we can differ between sending and verifying...

@dshanske
Copy link
Collaborator Author

@pfefferle Done if you want to review

@@ -96,6 +133,15 @@ public static function register_meta() {
'show_in_rest' => true,
);
register_meta( 'comment', 'webmention_response_code', $args );

// Purpose of this is to store a vouch URL
Copy link
Owner

Choose a reason for hiding this comment

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

Can you move this to the vouch class, otherwise it will load, if vouch is enabled or not...

Copy link
Collaborator Author

@dshanske dshanske Aug 5, 2018

Choose a reason for hiding this comment

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

I'd like to store the vouch URL whether or not vouch is enabled or not, in the event it becomes stable in future. Is that fine, or do you feel strongly it shouldn't store it unless enabled?

if ( ! $url ) {
return;
}
$whitelist = get_option( 'webmention_approve_domains' );
Copy link
Owner

Choose a reason for hiding this comment

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

can you encapsulate this in some functions? For example get_webmention_approve_domains and add_webmention_approve_domains... (just example names, feel free to change them to a better/more readable version)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do.

$whitelist = explode( "\n", $whitelist );
$host = wp_parse_url( $url, PHP_URL_HOST );

// strip leading www, if any
Copy link
Owner

Choose a reason for hiding this comment

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

see comment above

@@ -387,6 +438,39 @@ public static function post( $request ) {
return new WP_REST_Response( $return, 200 );
}

/**
Copy link
Owner

Choose a reason for hiding this comment

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

should be also part of the vouch class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Back to the question I asked re storage.

Copy link
Owner

Choose a reason for hiding this comment

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

OK, will think about that, but then I have one more question: Why not directly set the comment-meta in line 318 and following and move it above the commentdata setter in line 316?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because there might not be a vouch parameter? It is optional.

Copy link
Owner

Choose a reason for hiding this comment

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

But this is what you also check in line 318...

Copy link
Owner

@pfefferle pfefferle Aug 5, 2018

Choose a reason for hiding this comment

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

why not:

if ( isset( $params['vouch'] ) ) {
	$comment_meta['vouch'] = esc_url_raw( urldecode( $params['vouch'] ) );
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I misunderstood...you are right.

Copy link
Owner

Choose a reason for hiding this comment

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

@dshanske
Copy link
Collaborator Author

@pfefferle Requesting a re-review

@dshanske
Copy link
Collaborator Author

dshanske commented Sep 1, 2018

@pfefferle Can you merge and do a release then?

@pfefferle pfefferle merged commit f596bcc into pfefferle:master Sep 4, 2018
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

2 participants