-
Notifications
You must be signed in to change notification settings - Fork 30
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
Rsvp form token field #522
Conversation
…event to respond to changes
@mauteri I am throwing this pr up here as this is as far as I got. It includes most of the heavy lifting we need to do here. I have a tight week and off to AZ for a week. So I figured maybe someone could work on it in case I can't get back to it until I return next week. |
@@ -251,7 +251,7 @@ protected function events_list_route(): array { | |||
* @return bool True if the parameter is a valid RSVP status, false otherwise. | |||
*/ | |||
public function validate_rsvp_status( $param ): bool { | |||
return ( 'attend' === $param || 'attending' === $param || 'not_attending' === $param ); | |||
return ( 'attend' === $param || 'attending' === $param || 'not_attending' === $param || 'remove' === $param ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of remove
when I was working on anonymous feature. I ended up just going with attend
so we don't have to add another status. This can be confusing though for removal.
I think we can update things a bit and remove attend
and remove
and replace it with no_status
. I think that word can be used in both cases without confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to update this #525
@@ -646,6 +647,10 @@ public function update_rsvp( WP_REST_Request $request ): WP_REST_Response { | |||
} | |||
} | |||
|
|||
if ( $status === 'remove') { | |||
$event->rsvp->remove( $user_id, $responses ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be just $event->rsvp->remove( $user_id );
In the database user id and post id are the 2 unique fields to remove an RSVP. When the RSVP class is instantiated here, it is done so by an event, so you have that in the object that you can use. This will also be faster so you don't need to loop through the responses.
includes/core/classes/class-rsvp.php
Outdated
* @param int $user_id The ID of the user to remove the RSVP for. | ||
* @param array $responses Array of RSVP responses containing the entry to remove. | ||
*/ | ||
public function remove( int $user_id, array $responses ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments above. Remove responses. Let's have this return boolean
based on success.
public function remove( int $user_id ): bool {
includes/core/classes/class-rsvp.php
Outdated
*/ | ||
public function remove( int $user_id, array $responses ) { | ||
if ( ! current_user_can( 'edit_posts' ) ) { | ||
return $responses; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false;
includes/core/classes/class-rsvp.php
Outdated
$result = $wpdb->delete( $table, array( 'user_id' => $value['id'] ) ); | ||
} | ||
} | ||
return $responses; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 143 to 150 can simply be something like...
global $wpdb;
$table = sprintf( static::TABLE_FORMAT, $wpdb->prefix );
return $wpdb->delete( $table, array( 'post_id' => $this->event->ID, 'user_id' => $user_id ) );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mauteri wpdb->delete will return an int on success, not boolean. Might have to check the $result if false, otherwise return true. Also, this is in a loop of responses. So adding a return in here will kill the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/blocks/rsvp-response/edit.js
Outdated
<BlockControls> | ||
<ToolbarGroup> | ||
<ToolbarButton | ||
label="Edit Attendees" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to just Edit
. Make sure to add to translation function. {__('Edit', 'gatherpress')}
. Super important we do this. We already have the plugin translated to 3 languages and we'll need to update when this feature goes out to ensure text is translated.
src/blocks/rsvp-response/edit.js
Outdated
label="Edit Attendees" | ||
text={ | ||
editMode | ||
? 'Preview Attendees' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to Preview
. Add translation function.
src/blocks/rsvp-response/edit.js
Outdated
text={ | ||
editMode | ||
? 'Preview Attendees' | ||
: 'Edit Attendees' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to Edit
. Add translation function.
src/components/RsvpResponse.js
Outdated
if (!items.some((item) => item.value === rsvpStatus)) { | ||
setRsvpStatus(defaultStatus); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this file got messed up. These changes should remain. Think something happened when you updated from main
after I pushed code. Looks like the file can just be reverted to what's on main
.
includes/core/classes/class-rsvp.php
Outdated
* @param array $responses Array of RSVP responses containing the entry to remove. | ||
* @return bool True if the RSVP was removed, false otherwise. | ||
*/ | ||
public function remove( int $user_id, array $responses ): bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to pass $responses
just pass $user_id
. The only 2 pieces of data you need to remove someone is their user ID and the post ID. The object knows the post ID.
@@ -620,6 +620,7 @@ public function update_rsvp( WP_REST_Request $request ): WP_REST_Response { | |||
$guests = intval( $params['guests'] ); | |||
$anonymous = intval( $params['anonymous'] ); | |||
$event = new Event( $post_id ); | |||
$responses = $event->rsvp->responses(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need $responses
can remove this.
@@ -641,7 +642,7 @@ public function update_rsvp( WP_REST_Request $request ): WP_REST_Response { | |||
if ( | |||
$user_id && | |||
is_user_member_of_blog( $user_id ) && | |||
! $event->has_event_past() | |||
! $event->has_event_past() && ( 'remove' !== $status ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change remove
to no_status
@@ -650,6 +651,10 @@ public function update_rsvp( WP_REST_Request $request ): WP_REST_Response { | |||
} | |||
} | |||
|
|||
if ( 'remove' !== $status ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change remove
to no_status
includes/core/classes/class-rsvp.php
Outdated
$result = $wpdb->delete( $table, array( 'user_id' => $value['id'] ) ); | ||
} | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lines 144-151
can just be
global $wpdb;
$table = sprintf( static::TABLE_FORMAT, $wpdb->prefix );
return $wpdb->delete( $table, array( 'post_id' => $this->event->ID, 'user_id' => $user_id ) );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mauteri I just removed the remove
function and wrapped it all in with the save
function.
includes/core/classes/class-rsvp.php
Outdated
$result = $wpdb->delete( $table, array( 'user_id' => $value['id'] ) ); | ||
} | ||
} | ||
return $responses; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description of the Change
Administrators can now add/remove attendees to events.
Closes #485
How to test the Change
Changelog Entry
Credits
Props @linusx @jmarx @mauteri
Checklist: