Skip to content

Commit

Permalink
Merge pull request #240 from WordPress/remove-attendees
Browse files Browse the repository at this point in the history
Remove attendees
  • Loading branch information
trymebytes committed May 9, 2024
2 parents 3224564 + 9756a24 commit be69147
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 6 deletions.
23 changes: 17 additions & 6 deletions assets/css/translation-events.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
margin: 0;
}

.event-details-stats table {
margin: 1rem;
}

.event-details-stats table {
width: 100%;
table-layout: fixed;
Expand All @@ -64,6 +60,7 @@
.event-details-stats table td {
padding: 1em;
text-align: center;
vertical-align: middle;
}

.event-details-stats table td:first-child {
Expand Down Expand Up @@ -244,6 +241,7 @@ span.active-events-before-translation-table a {

.event-page-wrapper {
margin: 0 auto;
padding: 1em 0;
width: 80%;
}

Expand All @@ -256,7 +254,6 @@ input[type="submit"].remove-as-host,
input[type="submit"].convert-to-host {
text-align: center;
display: inline;
margin-top: 1em;
font-weight: bold;
}

Expand Down Expand Up @@ -384,7 +381,7 @@ ul#translation-links li {
}

ul.event-attendees-filter {
padding-left: 1rem;
margin-left: 0;
}

ul.event-attendees-filter li {
Expand Down Expand Up @@ -424,13 +421,27 @@ a.active-filter {
}

#quick-add {
margin-top: -1em;
padding: 0 .5em;
border-left: #d9d8d8 thin solid;
border-bottom: #d9d8d8 thin solid;
max-height: 8em;
overflow: auto;
}

a.remove-attendee.button {
background-color: var(--gp-color-btn-danger-bg);
color: var(--gp-color-btn-danger-text);
border-color: var(----gp-color-btn-danger-border);
margin-left: .1em;
}

a.remove-attendee.button:hover {
background-color: var(--gp-color-btn-danger-hover-bg);
color: var(--gp-color-btn-danger-hover-text);
border-color: var(----gp-color-btn-danger-hover-border);
}

/* show the event-details-right below instead of on the right on mobile */
@media (max-width: 768px) {

Expand Down
2 changes: 2 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
require_once __DIR__ . '/includes/project/project-repository.php';
require_once __DIR__ . '/includes/translation/translation-repository.php';
require_once __DIR__ . '/includes/event-text-snippet.php';
require_once __DIR__ . '/includes/routes/attendee/list.php';
require_once __DIR__ . '/includes/routes/attendee/remove.php';
13 changes: 13 additions & 0 deletions includes/attendee/attendee-repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public function remove_attendee( int $event_id, int $user_id ): void {
'%d',
),
);

$wpdb->delete(
"{$gp_table_prefix}event_actions",
array(
'event_id' => $event_id,
'user_id' => $user_id,
),
array(
'%d',
'%d',
),
);

// phpcs:enable
}

Expand Down
61 changes: 61 additions & 0 deletions includes/routes/attendee/remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Wporg\TranslationEvents\Routes\Attendee;

use Wporg\TranslationEvents\Attendee\Attendee;
use Wporg\TranslationEvents\Attendee\Attendee_Repository;
use Wporg\TranslationEvents\Event\Event_Repository_Interface;
use Wporg\TranslationEvents\Routes\Route;
use Wporg\TranslationEvents\Translation_Events;
use Wporg\TranslationEvents\Urls;

/**
* Remove an attendee from an event.
*/
class Remove_Attendee_Route extends Route {
private Event_Repository_Interface $event_repository;
private Attendee_Repository $attendee_repository;

/**
* Remove_Attendee_Route constructor.
*/
public function __construct() {
parent::__construct();
$this->event_repository = Translation_Events::get_event_repository();
$this->attendee_repository = Translation_Events::get_attendee_repository();
}

/**
* Handle the request to remove an attendee from an event.
*
* @param int $event_id The event slug.
* @param int $user_id The user ID.
* @return void
*/
public function handle( int $event_id, int $user_id ): void {
global $wp;
if ( ! is_user_logged_in() ) {
wp_safe_redirect( wp_login_url( home_url( $wp->request ) ) );
exit;
}

$event = $this->event_repository->get_event( $event_id );
if ( ! $event ) {
$this->die_with_404();
}
if ( ! current_user_can( 'edit_translation_event_attendees', $event->id() ) ) {
$this->die_with_error( esc_html__( 'You do not have permission to edit this event.', 'gp-translation-events' ), 403 );
}

$attendee = $this->attendee_repository->get_attendee( $event->id(), $user_id );
if ( $attendee instanceof Attendee ) {
if ( ! current_user_can( 'edit_translation_event_attendees', $event->id() ) ) {
$this->die_with_error( esc_html__( 'You do not have permission to remove this attendee.', 'gp-translation-events' ), 400 );
}
$this->attendee_repository->remove_attendee( $event->id(), $user_id );
}

wp_safe_redirect( Urls::event_attendees( $event->id() ) );
exit;
}
}
4 changes: 4 additions & 0 deletions includes/urls.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public static function my_events(): string {
public static function event_attendees( int $event_id ): string {
return self::event_details( $event_id ) . 'attendees/';
}

public static function event_remove_attendee( int $event_id, int $user_id ): string {
return gp_url( "/events/$event_id/attendees/remove/$user_id" );
}
}
3 changes: 3 additions & 0 deletions templates/events-attendees.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<?php else : ?>
<input type="submit" class="button is-secondary convert-to-host" value="<?php echo esc_attr__( 'Make co-host', 'gp-translation-events' ); ?>"/>
<?php endif; ?>
<?php if ( ! $attendee->is_host() ) : ?>
<a href="<?php echo esc_url( Urls::event_remove_attendee( $event->id(), $attendee->user_id() ) ); ?>" class="button remove-attendee"><?php esc_html_e( 'Remove', 'gp-translation-events' ); ?></a>
<?php endif; ?>
</form>
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions wporg-gp-translation-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function gp_init() {
GP::$router->add( "/events/$slug/translations/$locale", array( 'Wporg\TranslationEvents\Routes\Event\Translations_Route', 'handle' ) );
GP::$router->add( "/events/$slug", array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) );
GP::$router->add( "/events/$slug/attendees", array( 'Wporg\TranslationEvents\Routes\Attendee\List_Route', 'handle' ) );
GP::$router->add( "/events/$id/attendees/remove/$id", array( 'Wporg\TranslationEvents\Routes\Attendee\Remove_Attendee_Route', 'handle' ) );

$stats_listener = new Stats_Listener(
self::get_event_repository(),
Expand Down

0 comments on commit be69147

Please sign in to comment.