1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Conpherence - add storage for view / edit / join policy

Summary: Ref T7582. Also adds the basic logic for "rooms" implementation. Also makes sure we use the initializeNewThread method as appropriate.

Test Plan: made a new conpherence and it worked!

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7582

Differential Revision: https://secure.phabricator.com/D12103
This commit is contained in:
Bob Trahan 2015-03-17 17:04:44 -07:00
parent 441112c8e2
commit 85de4419a5
3 changed files with 60 additions and 5 deletions

View file

@ -0,0 +1,17 @@
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread
ADD viewPolicy VARBINARY(64) NOT NULL AFTER recentParticipantPHIDs;
UPDATE {$NAMESPACE}_conpherence.conpherence_thread
SET viewPolicy = 'users' WHERE viewPolicy = '';
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread
ADD editPolicy VARBINARY(64) NOT NULL AFTER viewPolicy;
UPDATE {$NAMESPACE}_conpherence.conpherence_thread
SET editPolicy = 'users' WHERE editPolicy = '';
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread
ADD joinPolicy VARBINARY(64) NOT NULL AFTER editPolicy;
UPDATE {$NAMESPACE}_conpherence.conpherence_thread
SET joinPolicy = 'users' WHERE joinPolicy = '';

View file

@ -20,10 +20,7 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
$message, $message,
PhabricatorContentSource $source) { PhabricatorContentSource $source) {
$conpherence = id(new ConpherenceThread()) $conpherence = ConpherenceThread::initializeNewThread($creator);
->attachParticipants(array())
->attachFilePHIDs(array())
->setMessageCount(0);
$files = array(); $files = array();
$errors = array(); $errors = array();
if (empty($participant_phids)) { if (empty($participant_phids)) {

View file

@ -8,6 +8,9 @@ final class ConpherenceThread extends ConpherenceDAO
protected $messageCount; protected $messageCount;
protected $recentParticipantPHIDs = array(); protected $recentParticipantPHIDs = array();
protected $mailKey; protected $mailKey;
protected $viewPolicy;
protected $editPolicy;
protected $joinPolicy;
private $participants = self::ATTACHABLE; private $participants = self::ATTACHABLE;
private $transactions = self::ATTACHABLE; private $transactions = self::ATTACHABLE;
@ -19,7 +22,24 @@ final class ConpherenceThread extends ConpherenceDAO
public static function initializeNewThread(PhabricatorUser $sender) { public static function initializeNewThread(PhabricatorUser $sender) {
return id(new ConpherenceThread()) return id(new ConpherenceThread())
->setMessageCount(0) ->setMessageCount(0)
->setTitle(''); ->setTitle('')
->attachParticipants(array())
->attachFilePHIDs(array())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_USER)
->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
}
public static function initializeNewRoom(PhabricatorUser $creator) {
return id(new ConpherenceThread())
->setIsRoom(1)
->setMessageCount(0)
->setTitle('')
->attachParticipants(array())
->attachFilePHIDs(array())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy($creator->getPHID())
->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
} }
protected function getConfiguration() { protected function getConfiguration() {
@ -33,6 +53,7 @@ final class ConpherenceThread extends ConpherenceDAO
'isRoom' => 'bool', 'isRoom' => 'bool',
'messageCount' => 'uint64', 'messageCount' => 'uint64',
'mailKey' => 'text20', 'mailKey' => 'text20',
'joinPolicy' => 'policy',
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
'key_room' => array( 'key_room' => array(
@ -190,10 +211,21 @@ final class ConpherenceThread extends ConpherenceDAO
return array( return array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
PhabricatorPolicyCapability::CAN_JOIN,
); );
} }
public function getPolicy($capability) { public function getPolicy($capability) {
if ($this->getIsRoom()) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
case PhabricatorPolicyCapability::CAN_JOIN:
return $this->getJoinPolicy();
}
}
return PhabricatorPolicies::POLICY_NOONE; return PhabricatorPolicies::POLICY_NOONE;
} }
@ -202,6 +234,15 @@ final class ConpherenceThread extends ConpherenceDAO
if (!$this->getID()) { if (!$this->getID()) {
return true; return true;
} }
if ($this->getIsRoom()) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_EDIT:
case PhabricatorPolicyCapability::CAN_JOIN:
return false;
}
}
$participants = $this->getParticipants(); $participants = $this->getParticipants();
return isset($participants[$user->getPHID()]); return isset($participants[$user->getPHID()]);
} }