Skip to content

Commit

Permalink
Merge pull request joindin#386 from railto/JOINDIN-647
Browse files Browse the repository at this point in the history
Add ability to unlink an approved speaker from a talk #JOINDIN-647
  • Loading branch information
liam-wiltshire authored Jan 8, 2017
2 parents 55062c0 + b7537ac commit ea82716
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/src/Talk/TalkApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,18 @@ public function removeTalkFromTrack($removeTrackUri)

throw new Exception("Failed to remove talk from track: " . $message);
}

public function unlinkVerifiedSpeakerFromTalk($unlinkSpeakerUri)
{
list($status, $result, $headers) = $this->apiDelete($unlinkSpeakerUri, []);

if ($status == 204) {
return true;
}

$result = json_decode($result);
$message = $result[0];

throw new \Exception("Failed to unlink speaker from talk: " . $message);
}
}
37 changes: 37 additions & 0 deletions app/src/Talk/TalkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protected function defineRoutes(Slim $app)
->name('talk-by-id-web1')
->conditions(array('talkId' => '\d+'));
$app->post('/event/:eventSlug/:talkSlug/claim', array($this, 'claimTalk'))->name('talk-claim');
$app->get('/event/:eventSlug/:talkSlug/unlink/:username', array($this, 'unlinkSpeaker'))
->name('unlink-speaker');
}

public function index($eventSlug, $talkSlug)
Expand Down Expand Up @@ -442,6 +444,41 @@ public function reportComment($eventSlug, $talkSlug, $commentHash)
$this->application->redirect($url);
}

public function unlinkSpeaker($eventSlug, $talkSlug, $username)
{
$url = $this->application->urlFor('talk', ['eventSlug' => $eventSlug, 'talkSlug' => $talkSlug]);

if (!isset($_SESSION['user'])) {
$this->application->redirect(
$this->application->urlFor('not-allowed') . '?redirect=' . $url
);
}

$eventApi = $this->getEventApi();
$event = $eventApi->getByFriendlyUrl($eventSlug);
$eventUri = $event->getUri();

$talkApi = $this->getTalkApi();
$talk = $talkApi->getTalkBySlug($talkSlug, $eventUri);
$talkUri = $talk->getApiUri();

$userApi = $this->getUserApi();
$user = $userApi->getUserByUsername($username);
$userId = $user->getId();

$unlinkSpeakerUri = $talkUri . "/speakers/" . $userId;

try {
$talkApi->unlinkVerifiedSpeakerFromTalk($unlinkSpeakerUri);
} catch (Exception $e) {
$this->application->flash('error', $e->getMessage());
$this->application->redirect($url);
}

$this->application->flash('message', 'Speaker has been removed from this talk.');
$this->application->redirect($url);
}

/**
* @return CacheService
*/
Expand Down
8 changes: 8 additions & 0 deletions app/src/User/UserEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,12 @@ public function getAdmin()

return $this->data->admin;
}

public function getId()
{
$uri = $this->data->uri;
$parts = explode('/', $uri);

return $parts[5];
}
}
6 changes: 5 additions & 1 deletion app/templates/Talk/_common/talk_header.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
{% endif %}

{% if speaker.username %}
<a href="{{ urlFor('user-profile', {'username': speaker.username}) }}">{{ speaker.speaker_name }}</a>{{comma}}
<a href="{{ urlFor('user-profile', {'username': speaker.username}) }}">{{ speaker.speaker_name }}</a>
{% if canEditTalk %}
<a onclick="return confirm('Are you sure you want to unlink this speaker from this talk?')" href="{{ urlFor('unlink-speaker', {'eventSlug': event.getUrlFriendlyName, 'talkSlug': talk.getUrlFriendlyTalkTitle, 'username': speaker.username }) }}"><small>(unlink)</small></a>
{% endif %}
{{ comma }}
{% else %}
{{ speaker.speaker_name }}{{comma}}
{% endif %}
Expand Down

0 comments on commit ea82716

Please sign in to comment.