mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
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
This commit is contained in:
parent
f146f4577e
commit
fe40be7fc9
2 changed files with 75 additions and 22 deletions
|
@ -111,7 +111,7 @@ final class ConpherenceUpdateController
|
|||
break;
|
||||
}
|
||||
$person_phid = $request->getStr('remove_person');
|
||||
if ($person_phid && $person_phid == $user->getPHID()) {
|
||||
if ($person_phid) {
|
||||
$xactions[] = id(new ConpherenceTransaction())
|
||||
->setTransactionType(
|
||||
ConpherenceTransaction::TYPE_PARTICIPANTS)
|
||||
|
@ -321,38 +321,83 @@ final class ConpherenceUpdateController
|
|||
ConpherenceThread $conpherence) {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
$viewer = $request->getUser();
|
||||
$remove_person = $request->getStr('remove_person');
|
||||
$participants = $conpherence->getParticipants();
|
||||
|
||||
$message = pht('Are you sure you want to leave this room?');
|
||||
$removed_user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($remove_person))
|
||||
->executeOne();
|
||||
if (!$removed_user) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$is_self = ($viewer->getPHID() == $removed_user->getPHID());
|
||||
$is_last = (count($participants) == 1);
|
||||
|
||||
$test_conpherence = clone $conpherence;
|
||||
$test_conpherence->attachParticipants(array());
|
||||
if (!PhabricatorPolicyFilter::hasCapability(
|
||||
$user,
|
||||
$still_visible = PhabricatorPolicyFilter::hasCapability(
|
||||
$removed_user,
|
||||
$test_conpherence,
|
||||
PhabricatorPolicyCapability::CAN_VIEW)) {
|
||||
if (count($participants) == 1) {
|
||||
$message .= ' '.pht('The room will be inaccessible forever and ever.');
|
||||
PhabricatorPolicyCapability::CAN_VIEW);
|
||||
|
||||
$body = array();
|
||||
|
||||
if ($is_self) {
|
||||
$title = pht('Leave Room');
|
||||
$body[] = pht(
|
||||
'Are you sure you want to leave this room?');
|
||||
} else {
|
||||
$title = pht('Banish User');
|
||||
$body[] = pht(
|
||||
'Banish %s from the realm?',
|
||||
phutil_tag('strong', array(), $removed_user->getUsername()));
|
||||
}
|
||||
|
||||
if ($still_visible) {
|
||||
if ($is_self) {
|
||||
$body[] = pht(
|
||||
'You will be able to rejoin the room later.');
|
||||
} else {
|
||||
$message .= ' '.pht('Someone else in the room can add you back later.');
|
||||
$body[] = pht(
|
||||
'This user will be able to rejoin the room later.');
|
||||
}
|
||||
} else {
|
||||
if ($is_self) {
|
||||
if ($is_last) {
|
||||
$body[] = pht(
|
||||
'You are the last member, so you will never be able to rejoin '.
|
||||
'the room.');
|
||||
} else {
|
||||
$body[] = pht(
|
||||
'You will not be able to rejoin the room on your own, but '.
|
||||
'someone else can invite you later.');
|
||||
}
|
||||
} else {
|
||||
$body[] = pht(
|
||||
'This user will not be able to rejoin the room unless invited '.
|
||||
'again.');
|
||||
}
|
||||
}
|
||||
$body = phutil_tag(
|
||||
'p',
|
||||
array(),
|
||||
$message);
|
||||
|
||||
require_celerity_resource('conpherence-update-css');
|
||||
return id(new AphrontDialogView())
|
||||
->setTitle(pht('Leave Room'))
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setTitle($title)
|
||||
->addHiddenInput('action', 'remove_person')
|
||||
->addHiddenInput('remove_person', $remove_person)
|
||||
->addHiddenInput(
|
||||
'latest_transaction_id',
|
||||
$request->getInt('latest_transaction_id'))
|
||||
->addHiddenInput('__continue__', true)
|
||||
->appendChild($body);
|
||||
->addHiddenInput('__continue__', true);
|
||||
|
||||
foreach ($body as $paragraph) {
|
||||
$dialog->appendParagraph($paragraph);
|
||||
}
|
||||
|
||||
return $dialog;
|
||||
}
|
||||
|
||||
private function renderMetadataDialogue(
|
||||
|
|
|
@ -5,11 +5,11 @@ final class ConpherencePeopleWidgetView extends ConpherenceWidgetView {
|
|||
public function render() {
|
||||
$conpherence = $this->getConpherence();
|
||||
$widget_data = $conpherence->getWidgetData();
|
||||
$user = $this->getUser();
|
||||
$conpherence = $this->getConpherence();
|
||||
$viewer = $this->getUser();
|
||||
|
||||
$participants = $conpherence->getParticipants();
|
||||
$handles = $conpherence->getHandles();
|
||||
$head_handles = array_select_keys($handles, array($user->getPHID()));
|
||||
$head_handles = array_select_keys($handles, array($viewer->getPHID()));
|
||||
$handle_list = mpull($handles, 'getName');
|
||||
natcasesort($handle_list);
|
||||
$handles = mpull($handles, null, 'getName');
|
||||
|
@ -17,11 +17,16 @@ final class ConpherencePeopleWidgetView extends ConpherenceWidgetView {
|
|||
$head_handles = mpull($head_handles, null, 'getName');
|
||||
$handles = $head_handles + $handles;
|
||||
|
||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
$conpherence,
|
||||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$body = array();
|
||||
foreach ($handles as $handle) {
|
||||
$user_phid = $handle->getPHID();
|
||||
$remove_html = '';
|
||||
if ($user_phid == $user->getPHID()) {
|
||||
|
||||
if (($user_phid == $viewer->getPHID()) || $can_edit) {
|
||||
$icon = id(new PHUIIconView())
|
||||
->setIcon('fa-times lightbluetext');
|
||||
$remove_html = javelin_tag(
|
||||
|
@ -35,7 +40,10 @@ final class ConpherencePeopleWidgetView extends ConpherenceWidgetView {
|
|||
),
|
||||
),
|
||||
$icon);
|
||||
} else {
|
||||
$remove_html = null;
|
||||
}
|
||||
|
||||
$body[] = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
|
|
Loading…
Reference in a new issue