diff --git a/resources/sql/autopatches/20150317.conpherence.policy.sql b/resources/sql/autopatches/20150317.conpherence.policy.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20150317.conpherence.policy.sql @@ -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 = ''; diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php --- a/src/applications/conpherence/editor/ConpherenceEditor.php +++ b/src/applications/conpherence/editor/ConpherenceEditor.php @@ -20,10 +20,7 @@ $message, PhabricatorContentSource $source) { - $conpherence = id(new ConpherenceThread()) - ->attachParticipants(array()) - ->attachFilePHIDs(array()) - ->setMessageCount(0); + $conpherence = ConpherenceThread::initializeNewThread($creator); $files = array(); $errors = array(); if (empty($participant_phids)) { diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php --- a/src/applications/conpherence/storage/ConpherenceThread.php +++ b/src/applications/conpherence/storage/ConpherenceThread.php @@ -8,6 +8,9 @@ protected $messageCount; protected $recentParticipantPHIDs = array(); protected $mailKey; + protected $viewPolicy; + protected $editPolicy; + protected $joinPolicy; private $participants = self::ATTACHABLE; private $transactions = self::ATTACHABLE; @@ -19,7 +22,24 @@ public static function initializeNewThread(PhabricatorUser $sender) { return id(new ConpherenceThread()) ->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() { @@ -33,6 +53,7 @@ 'isRoom' => 'bool', 'messageCount' => 'uint64', 'mailKey' => 'text20', + 'joinPolicy' => 'policy', ), self::CONFIG_KEY_SCHEMA => array( 'key_room' => array( @@ -190,10 +211,21 @@ return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, + PhabricatorPolicyCapability::CAN_JOIN, ); } 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; } @@ -202,6 +234,15 @@ if (!$this->getID()) { return true; } + + if ($this->getIsRoom()) { + switch ($capability) { + case PhabricatorPolicyCapability::CAN_EDIT: + case PhabricatorPolicyCapability::CAN_JOIN: + return false; + } + } + $participants = $this->getParticipants(); return isset($participants[$user->getPHID()]); }