mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +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:
parent
441112c8e2
commit
85de4419a5
3 changed files with 60 additions and 5 deletions
17
resources/sql/autopatches/20150317.conpherence.policy.sql
Normal file
17
resources/sql/autopatches/20150317.conpherence.policy.sql
Normal 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 = '';
|
|
@ -20,10 +20,7 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
|||
$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)) {
|
||||
|
|
|
@ -8,6 +8,9 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
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 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
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 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
'isRoom' => 'bool',
|
||||
'messageCount' => 'uint64',
|
||||
'mailKey' => 'text20',
|
||||
'joinPolicy' => 'policy',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_room' => array(
|
||||
|
@ -190,10 +211,21 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
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 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
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()]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue