Page MenuHomePhabricator

D12632.id30327.diff
No OneTemporary

D12632.id30327.diff

diff --git a/resources/sql/autopatches/20150430.calendar.1.policies.sql b/resources/sql/autopatches/20150430.calendar.1.policies.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150430.calendar.1.policies.sql
@@ -0,0 +1,11 @@
+ALTER TABLE {$NAMESPACE}_calendar.calendar_event
+ ADD viewPolicy varbinary(64) NOT NULL;
+
+ALTER TABLE {$NAMESPACE}_calendar.calendar_event
+ ADD editPolicy varbinary(64) NOT NULL;
+
+UPDATE {$NAMESPACE}_calendar.calendar_event
+ SET viewPolicy = 'users' WHERE viewPolicy = '';
+
+UPDATE {$NAMESPACE}_calendar.calendar_event
+ SET editPolicy = userPHID;
diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
--- a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
+++ b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
@@ -33,7 +33,9 @@
->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY);
if ($this->isCreate()) {
- $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($user);
+ $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($user)
+ ->setViewPolicy($user_phid)
+ ->setEditPolicy($user_phid);
$end_value = $end_time->readValueFromRequest($request);
$start_value = $start_time->readValueFromRequest($request);
$submit_label = pht('Create');
@@ -138,6 +140,14 @@
PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION)
->setNewValue($description);
+ $xactions[] = id(new PhabricatorCalendarEventTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
+ ->setNewValue($request->getStr('viewPolicy'));
+
+ $xactions[] = id(new PhabricatorCalendarEventTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
+ ->setNewValue($request->getStr('editPolicy'));
+
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($user)
->setContentSourceFromRequest($request)
@@ -179,6 +189,23 @@
->setName('description')
->setValue($event->getDescription());
+ $curren_policies = id(new PhabricatorPolicyQuery())
+ ->setViewer($user)
+ ->setObject($event)
+ ->execute();
+ $view_policies = id(new AphrontFormPolicyControl())
+ ->setUser($user)
+ ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
+ ->setPolicyObject($event)
+ ->setPolicies($curren_policies)
+ ->setName('viewPolicy');
+ $edit_policies = id(new AphrontFormPolicyControl())
+ ->setUser($user)
+ ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
+ ->setPolicyObject($event)
+ ->setPolicies($curren_policies)
+ ->setName('editPolicy');
+
$subscribers = id(new AphrontFormTokenizerControl())
->setLabel(pht('Subscribers'))
->setName('subscribers')
@@ -199,10 +226,13 @@
->appendChild($status_select)
->appendChild($start_time)
->appendChild($end_time)
+ ->appendControl($view_policies)
+ ->appendControl($edit_policies)
->appendControl($subscribers)
->appendControl($invitees)
->appendChild($description);
+
$submit = id(new AphrontFormSubmitControl())
->setValue($submit_label);
if ($this->isCreate()) {
diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
--- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php
+++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php
@@ -18,6 +18,9 @@
protected $description;
protected $isCancelled;
+ protected $viewPolicy;
+ protected $editPolicy;
+
private $invitees = self::ATTACHABLE;
const STATUS_AWAY = 1;
@@ -32,6 +35,8 @@
return id(new PhabricatorCalendarEvent())
->setUserPHID($actor->getPHID())
->setIsCancelled(0)
+ ->setViewPolicy($actor->getPHID())
+ ->setEditPolicy($actor->getPHID())
->attachInvitees(array());
}
@@ -224,18 +229,39 @@
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
- return PhabricatorPolicies::getMostOpenPolicy();
+ return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
- return $this->getUserPHID();
+ return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ // The owner of a task can always view and edit it.
+ $user_phid = $this->getUserPHID();
+ if ($user_phid) {
+ $viewer_phid = $viewer->getPHID();
+ if ($viewer_phid == $user_phid) {
+ return true;
+ }
+ }
+
+ if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
+ $status = $this->getUserInviteStatus($viewer->getPHID());
+ if ($status == PhabricatorCalendarEventInvitee::STATUS_INVITED ||
+ $status == PhabricatorCalendarEventInvitee::STATUS_ATTENDING ||
+ $status == PhabricatorCalendarEventInvitee::STATUS_DECLINED) {
+ return true;
+ }
+ } else {
+ return false;
+ }
+
return false;
}
public function describeAutomaticCapability($capability) {
- return null;
+ return pht('The owner of an event can always view and edit it,
+ and invitees can always view it.');
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 7, 1:22 PM (21 h, 59 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6679418
Default Alt Text
D12632.id30327.diff (5 KB)

Event Timeline