diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php --- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php @@ -166,6 +166,7 @@ } $availability_select->setDropdownMenu($dropdown); + $availability_select->setDisabled($event->isImportedEvent()); $header->addActionLink($availability_select); } @@ -629,6 +630,7 @@ ->setIcon('fa-times grey') ->setHref($this->getApplicationURI("/event/decline/{$id}/")) ->setWorkflow(true) + ->setDisabled($event->isImportedEvent()) ->setText(pht('Decline')); $accept_button = id(new PHUIButtonView()) @@ -636,6 +638,7 @@ ->setIcon('fa-check green') ->setHref($this->getApplicationURI("/event/accept/{$id}/")) ->setWorkflow(true) + ->setDisabled($event->isImportedEvent()) ->setText(pht('Accept')); return array($decline_button, $accept_button); diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -207,10 +207,17 @@ $events = null; } + // Verified emails of the Calendar uploader. + $author_verified_emails = id(new PhabricatorUserEmail())->loadAllWhere( + 'userPHID = %s AND isVerified = 1', + $import->getAuthorPHID()); + $author_verified_emails = mpull($author_verified_emails, 'getAddress'); + $xactions = array(); $update_map = array(); $invitee_map = array(); - $attendee_map = array(); + $attendee_name_map = array(); // [eventUID][email from] = Attendee + $attendee_user_map = array(); // [eventUID][userPHID ] = Attendee foreach ($node_map as $full_uid => $node) { $event = idx($events, $full_uid); if (!$event) { @@ -227,7 +234,7 @@ $xactions[$full_uid] = $this->newUpdateTransactions($event, $node); $update_map[$full_uid] = $event; - $attendee_map[$full_uid] = array(); + $attendee_name_map[$full_uid] = array(); $attendees = $node->getAttendees(); $private_index = 1; foreach ($attendees as $attendee) { @@ -236,8 +243,19 @@ // of the product. $name = $attendee->getName(); if (preg_match('/@/', $name)) { - $name = new PhutilEmailAddress($name); - $name = $name->getDisplayName(); + $attendee_mail = new PhutilEmailAddress($name); + $name = $attendee_mail->getDisplayName(); + $address = $attendee_mail->getAddress(); + + // Skip creation of dummy "Private User" if this Attendee is just + // a verified email owned by the Calendar uploader. + if ($address) { + if (in_array($address, $author_verified_emails, true)) { + $attendee_user_map[$full_uid][$import->getAuthorPHID()] = + $attendee; + continue; + } + } } // If we don't have a name or the name still looks like it's an @@ -247,12 +265,12 @@ $private_index++; } - $attendee_map[$full_uid][$name] = $attendee; + $attendee_name_map[$full_uid][$name] = $attendee; } } $attendee_names = array(); - foreach ($attendee_map as $full_uid => $event_attendees) { + foreach ($attendee_name_map as $full_uid => $event_attendees) { foreach ($event_attendees as $name => $attendee) { $attendee_names[$name] = $attendee; } @@ -356,13 +374,22 @@ // We're just forcing attendees to the correct values here because // transactions intentionally don't let you RSVP for other users. This // might need to be turned into a special type of transaction eventually. - $attendees = $attendee_map[$full_uid]; + $attendees_name = $attendee_name_map[$full_uid]; + $attendees_user = idx($attendee_user_map, $full_uid, array()); $old_map = $event->getInvitees(); $old_map = mpull($old_map, null, 'getInviteePHID'); + $phid_invitees = array(); + foreach ($attendees_name as $name => $attendee) { + $attendee_phid = $external_invitees[$name]->getPHID(); + $phid_invitees[$attendee_phid] = $attendee; + } + foreach ($attendees_user as $attendee_user_phid => $attendee) { + $phid_invitees[$attendee_user_phid] = $attendee; + } + $new_map = array(); - foreach ($attendees as $name => $attendee) { - $phid = $external_invitees[$name]->getPHID(); + foreach ($phid_invitees as $phid => $attendee) { $invitee = idx($old_map, $phid); if (!$invitee) { @@ -381,7 +408,11 @@ break; case PhutilCalendarUserNode::STATUS_INVITED: default: - $status = PhabricatorCalendarEventInvitee::STATUS_INVITED; + if ($phid === $import->getAuthorPHID()) { + $status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; + } else { + $status = PhabricatorCalendarEventInvitee::STATUS_INVITED; + } break; } $invitee->setStatus($status);