Skip to content

Commit fe40be7

Browse files
author
epriestley
committed
Allow users to be banished from Conpherence rooms
Summary: Fixes T9348. If you have edit permission, you can kick people out of a room. Test Plan: - Kicked people out of a room. - As an unprivileged user, wasn't able to kick people out of a room. - Hit most (all?) of the various weird dialog sub-cases. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9348 Differential Revision: https://secure.phabricator.com/D15728
1 parent f146f45 commit fe40be7

File tree

2 files changed

+75
-22
lines changed

2 files changed

+75
-22
lines changed

src/applications/conpherence/controller/ConpherenceUpdateController.php

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function handleRequest(AphrontRequest $request) {
111111
break;
112112
}
113113
$person_phid = $request->getStr('remove_person');
114-
if ($person_phid && $person_phid == $user->getPHID()) {
114+
if ($person_phid) {
115115
$xactions[] = id(new ConpherenceTransaction())
116116
->setTransactionType(
117117
ConpherenceTransaction::TYPE_PARTICIPANTS)
@@ -321,38 +321,83 @@ private function renderRemovePersonDialogue(
321321
ConpherenceThread $conpherence) {
322322

323323
$request = $this->getRequest();
324-
$user = $request->getUser();
324+
$viewer = $request->getUser();
325325
$remove_person = $request->getStr('remove_person');
326326
$participants = $conpherence->getParticipants();
327327

328-
$message = pht('Are you sure you want to leave this room?');
328+
$removed_user = id(new PhabricatorPeopleQuery())
329+
->setViewer($viewer)
330+
->withPHIDs(array($remove_person))
331+
->executeOne();
332+
if (!$removed_user) {
333+
return new Aphront404Response();
334+
}
335+
336+
$is_self = ($viewer->getPHID() == $removed_user->getPHID());
337+
$is_last = (count($participants) == 1);
338+
329339
$test_conpherence = clone $conpherence;
330340
$test_conpherence->attachParticipants(array());
331-
if (!PhabricatorPolicyFilter::hasCapability(
332-
$user,
341+
$still_visible = PhabricatorPolicyFilter::hasCapability(
342+
$removed_user,
333343
$test_conpherence,
334-
PhabricatorPolicyCapability::CAN_VIEW)) {
335-
if (count($participants) == 1) {
336-
$message .= ' '.pht('The room will be inaccessible forever and ever.');
344+
PhabricatorPolicyCapability::CAN_VIEW);
345+
346+
$body = array();
347+
348+
if ($is_self) {
349+
$title = pht('Leave Room');
350+
$body[] = pht(
351+
'Are you sure you want to leave this room?');
352+
} else {
353+
$title = pht('Banish User');
354+
$body[] = pht(
355+
'Banish %s from the realm?',
356+
phutil_tag('strong', array(), $removed_user->getUsername()));
357+
}
358+
359+
if ($still_visible) {
360+
if ($is_self) {
361+
$body[] = pht(
362+
'You will be able to rejoin the room later.');
337363
} else {
338-
$message .= ' '.pht('Someone else in the room can add you back later.');
364+
$body[] = pht(
365+
'This user will be able to rejoin the room later.');
366+
}
367+
} else {
368+
if ($is_self) {
369+
if ($is_last) {
370+
$body[] = pht(
371+
'You are the last member, so you will never be able to rejoin '.
372+
'the room.');
373+
} else {
374+
$body[] = pht(
375+
'You will not be able to rejoin the room on your own, but '.
376+
'someone else can invite you later.');
377+
}
378+
} else {
379+
$body[] = pht(
380+
'This user will not be able to rejoin the room unless invited '.
381+
'again.');
339382
}
340383
}
341-
$body = phutil_tag(
342-
'p',
343-
array(),
344-
$message);
345384

346385
require_celerity_resource('conpherence-update-css');
347-
return id(new AphrontDialogView())
348-
->setTitle(pht('Leave Room'))
386+
387+
$dialog = id(new AphrontDialogView())
388+
->setTitle($title)
349389
->addHiddenInput('action', 'remove_person')
350390
->addHiddenInput('remove_person', $remove_person)
351391
->addHiddenInput(
352392
'latest_transaction_id',
353393
$request->getInt('latest_transaction_id'))
354-
->addHiddenInput('__continue__', true)
355-
->appendChild($body);
394+
->addHiddenInput('__continue__', true);
395+
396+
foreach ($body as $paragraph) {
397+
$dialog->appendParagraph($paragraph);
398+
}
399+
400+
return $dialog;
356401
}
357402

358403
private function renderMetadataDialogue(

src/applications/conpherence/view/ConpherencePeopleWidgetView.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ final class ConpherencePeopleWidgetView extends ConpherenceWidgetView {
55
public function render() {
66
$conpherence = $this->getConpherence();
77
$widget_data = $conpherence->getWidgetData();
8-
$user = $this->getUser();
9-
$conpherence = $this->getConpherence();
8+
$viewer = $this->getUser();
9+
1010
$participants = $conpherence->getParticipants();
1111
$handles = $conpherence->getHandles();
12-
$head_handles = array_select_keys($handles, array($user->getPHID()));
12+
$head_handles = array_select_keys($handles, array($viewer->getPHID()));
1313
$handle_list = mpull($handles, 'getName');
1414
natcasesort($handle_list);
1515
$handles = mpull($handles, null, 'getName');
1616
$handles = array_select_keys($handles, $handle_list);
1717
$head_handles = mpull($head_handles, null, 'getName');
1818
$handles = $head_handles + $handles;
1919

20+
$can_edit = PhabricatorPolicyFilter::hasCapability(
21+
$viewer,
22+
$conpherence,
23+
PhabricatorPolicyCapability::CAN_EDIT);
24+
2025
$body = array();
2126
foreach ($handles as $handle) {
2227
$user_phid = $handle->getPHID();
23-
$remove_html = '';
24-
if ($user_phid == $user->getPHID()) {
28+
29+
if (($user_phid == $viewer->getPHID()) || $can_edit) {
2530
$icon = id(new PHUIIconView())
2631
->setIcon('fa-times lightbluetext');
2732
$remove_html = javelin_tag(
@@ -35,7 +40,10 @@ public function render() {
3540
),
3641
),
3742
$icon);
43+
} else {
44+
$remove_html = null;
3845
}
46+
3947
$body[] = phutil_tag(
4048
'div',
4149
array(

0 commit comments

Comments
 (0)