2011-04-03 23:48:36 +02:00
|
|
|
<?php
|
|
|
|
|
2012-08-08 21:25:11 +02:00
|
|
|
final class PhabricatorOwnersPackage extends PhabricatorOwnersDAO
|
|
|
|
implements PhabricatorPolicyInterface {
|
2011-04-03 23:48:36 +02:00
|
|
|
|
|
|
|
protected $name;
|
2012-06-14 05:52:10 +02:00
|
|
|
protected $originalName;
|
Add Basic Auditing Functionalities
Summary:
add basic auditing functionalities. For the related commits for a
package, we detect the following conditions which might be suspicious to the
owners of the package:
* no revision specified
* revision not found
* author not match
* reviewedby not match
* owners not involved
* commit author not recognized
The owners of the package can change the status of the audit entries by
accepting it or specify concern.
The owner can turn on/off the auditing for a package.
Test Plan:
* verified that non-owner cannot see the details of the audit and cannot modify
it
* verified that all the audit reasons can be detected
* tested dropdown filtering and package search
* verified really normal change not detected
* verified accept/concern a commit
* tested enable/disable a package for auditing
* verified one audit applies to all <commit, packages> to the packages the
auditor owns
* verified that re-parsing a commit won't have effect if there exists a
relationship for <commit, package> already
Reviewers: epriestley, nh
Reviewed By: epriestley
CC: aran, benmathews, btrahan, mpodobnik, prithvi, TomL, epriestley
Differential Revision: 1242
2011-12-18 00:52:54 +01:00
|
|
|
protected $auditingEnabled;
|
2011-04-03 23:48:36 +02:00
|
|
|
protected $description;
|
|
|
|
protected $primaryOwnerPHID;
|
|
|
|
|
2015-02-03 20:41:15 +01:00
|
|
|
private $unsavedOwners = self::ATTACHABLE;
|
|
|
|
private $unsavedPaths = self::ATTACHABLE;
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
private $actorPHID;
|
|
|
|
private $oldPrimaryOwnerPHID;
|
|
|
|
private $oldAuditingEnabled;
|
2011-04-04 07:03:27 +02:00
|
|
|
|
2012-08-08 21:25:11 +02:00
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return PhabricatorPolicies::POLICY_USER;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:47:05 +01:00
|
|
|
protected function getConfiguration() {
|
2011-04-03 23:48:36 +02:00
|
|
|
return array(
|
|
|
|
// This information is better available from the history table.
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2014-10-01 16:53:12 +02:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
Fix almost all remaining schemata issues
Summary:
Ref T1191. This fixes nearly every remaining blocker for utf8mb4 -- primarily, overlong keys.
Remaining issue is https://secure.phabricator.com/T1191#77467
Test Plan: I'll annotate inline.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley, hach-que
Maniphest Tasks: T6099, T6129, T6133, T6134, T6150, T6148, T6147, T6146, T6105, T1191
Differential Revision: https://secure.phabricator.com/D10601
2014-10-01 17:18:36 +02:00
|
|
|
'name' => 'text128',
|
2014-10-01 16:53:12 +02:00
|
|
|
'originalName' => 'text255',
|
|
|
|
'description' => 'text',
|
|
|
|
'primaryOwnerPHID' => 'phid?',
|
|
|
|
'auditingEnabled' => 'bool',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_phid' => null,
|
|
|
|
'phid' => array(
|
|
|
|
'columns' => array('phid'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'name' => array(
|
|
|
|
'columns' => array('name'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
),
|
2011-04-04 07:03:27 +02:00
|
|
|
) + parent::getConfiguration();
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2011-04-04 07:03:27 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID('OPKG');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachUnsavedOwners(array $owners) {
|
|
|
|
$this->unsavedOwners = $owners;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 20:41:15 +01:00
|
|
|
public function getUnsavedOwners() {
|
|
|
|
return $this->assertAttached($this->unsavedOwners);
|
|
|
|
}
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
public function attachUnsavedPaths(array $paths) {
|
|
|
|
$this->unsavedPaths = $paths;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 20:41:15 +01:00
|
|
|
public function getUnsavedPaths() {
|
|
|
|
return $this->assertAttached($this->unsavedPaths);
|
|
|
|
}
|
|
|
|
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
public function attachActorPHID($actor_phid) {
|
|
|
|
$this->actorPHID = $actor_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getActorPHID() {
|
|
|
|
return $this->actorPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOldPrimaryOwnerPHID($old_primary) {
|
|
|
|
$this->oldPrimaryOwnerPHID = $old_primary;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOldPrimaryOwnerPHID() {
|
|
|
|
return $this->oldPrimaryOwnerPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOldAuditingEnabled($auditing_enabled) {
|
|
|
|
$this->oldAuditingEnabled = $auditing_enabled;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOldAuditingEnabled() {
|
|
|
|
return $this->oldAuditingEnabled;
|
|
|
|
}
|
|
|
|
|
2012-06-14 05:52:10 +02:00
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
if (!$this->getID()) {
|
|
|
|
$this->originalName = $name;
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-04-04 07:03:27 +02:00
|
|
|
public function loadOwners() {
|
|
|
|
if (!$this->getID()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new PhabricatorOwnersOwner())->loadAllWhere(
|
|
|
|
'packageID = %d',
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadPaths() {
|
|
|
|
if (!$this->getID()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new PhabricatorOwnersPath())->loadAllWhere(
|
|
|
|
'packageID = %d',
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
2011-04-04 08:23:36 +02:00
|
|
|
public static function loadAffectedPackages(
|
|
|
|
PhabricatorRepository $repository,
|
|
|
|
array $paths) {
|
|
|
|
|
|
|
|
if (!$paths) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-12-07 02:23:56 +01:00
|
|
|
return self::loadPackagesForPaths($repository, $paths);
|
2011-04-12 06:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function loadOwningPackages($repository, $path) {
|
|
|
|
if (empty($path)) {
|
|
|
|
return array();
|
2011-04-04 08:23:36 +02:00
|
|
|
}
|
|
|
|
|
2012-12-07 02:23:56 +01:00
|
|
|
return self::loadPackagesForPaths($repository, array($path), 1);
|
2011-04-12 06:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static function loadPackagesForPaths(
|
|
|
|
PhabricatorRepository $repository,
|
|
|
|
array $paths,
|
|
|
|
$limit = 0) {
|
2012-12-07 02:23:56 +01:00
|
|
|
|
|
|
|
$fragments = array();
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
foreach (self::splitPath($path) as $fragment) {
|
|
|
|
$fragments[$fragment][$path] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-04 08:23:36 +02:00
|
|
|
$package = new PhabricatorOwnersPackage();
|
|
|
|
$path = new PhabricatorOwnersPath();
|
2011-04-12 06:51:36 +02:00
|
|
|
$conn = $package->establishConnection('r');
|
|
|
|
|
2012-07-09 19:51:46 +02:00
|
|
|
$repository_clause = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'AND p.repositoryPHID = %s',
|
2011-04-12 06:51:36 +02:00
|
|
|
$repository->getPHID());
|
|
|
|
|
2012-07-09 19:51:46 +02:00
|
|
|
// NOTE: The list of $paths may be very large if we're coming from
|
|
|
|
// the OwnersWorker and processing, e.g., an SVN commit which created a new
|
|
|
|
// branch. Break it apart so that it will fit within 'max_allowed_packet',
|
|
|
|
// and then merge results in PHP.
|
|
|
|
|
2012-12-07 02:23:56 +01:00
|
|
|
$rows = array();
|
|
|
|
foreach (array_chunk(array_keys($fragments), 128) as $chunk) {
|
|
|
|
$rows[] = queryfx_all(
|
2012-07-09 19:51:46 +02:00
|
|
|
$conn,
|
2012-12-07 02:23:56 +01:00
|
|
|
'SELECT pkg.id, p.excluded, p.path
|
2012-07-09 19:51:46 +02:00
|
|
|
FROM %T pkg JOIN %T p ON p.packageID = pkg.id
|
|
|
|
WHERE p.path IN (%Ls) %Q',
|
|
|
|
$package->getTableName(),
|
|
|
|
$path->getTableName(),
|
|
|
|
$chunk,
|
|
|
|
$repository_clause);
|
2011-04-12 06:51:36 +02:00
|
|
|
}
|
2012-12-07 02:23:56 +01:00
|
|
|
$rows = array_mergev($rows);
|
|
|
|
|
|
|
|
$ids = self::findLongestPathsPerPackage($rows, $fragments);
|
2011-04-12 06:51:36 +02:00
|
|
|
|
2012-07-09 19:51:46 +02:00
|
|
|
if (!$ids) {
|
2011-04-12 06:51:36 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-07-09 19:51:46 +02:00
|
|
|
arsort($ids);
|
|
|
|
if ($limit) {
|
|
|
|
$ids = array_slice($ids, 0, $limit, $preserve_keys = true);
|
2011-04-12 06:51:36 +02:00
|
|
|
}
|
2012-07-09 19:51:46 +02:00
|
|
|
$ids = array_keys($ids);
|
2011-04-12 06:51:36 +02:00
|
|
|
|
2012-07-25 21:38:32 +02:00
|
|
|
$packages = $package->loadAllWhere('id in (%Ld)', $ids);
|
|
|
|
$packages = array_select_keys($packages, $ids);
|
2011-04-12 06:51:36 +02:00
|
|
|
|
2011-04-15 01:17:39 +02:00
|
|
|
return $packages;
|
2011-04-04 08:23:36 +02:00
|
|
|
}
|
|
|
|
|
2013-04-24 15:07:26 +02:00
|
|
|
public static function loadPackagesForRepository($repository) {
|
|
|
|
$package = new PhabricatorOwnersPackage();
|
|
|
|
$ids = ipull(
|
|
|
|
queryfx_all(
|
|
|
|
$package->establishConnection('r'),
|
|
|
|
'SELECT DISTINCT packageID FROM %T WHERE repositoryPHID = %s',
|
|
|
|
id(new PhabricatorOwnersPath())->getTableName(),
|
|
|
|
$repository->getPHID()),
|
|
|
|
'packageID');
|
|
|
|
|
|
|
|
return $package->loadAllWhere('id in (%Ld)', $ids);
|
|
|
|
}
|
|
|
|
|
2012-12-07 02:23:56 +01:00
|
|
|
public static function findLongestPathsPerPackage(array $rows, array $paths) {
|
|
|
|
$ids = array();
|
|
|
|
|
|
|
|
foreach (igroup($rows, 'id') as $id => $package_paths) {
|
|
|
|
$relevant_paths = array_select_keys(
|
|
|
|
$paths,
|
|
|
|
ipull($package_paths, 'path'));
|
|
|
|
|
|
|
|
// For every package, remove all excluded paths.
|
|
|
|
$remove = array();
|
|
|
|
foreach ($package_paths as $package_path) {
|
|
|
|
if ($package_path['excluded']) {
|
2014-04-15 20:12:42 +02:00
|
|
|
$remove += idx($relevant_paths, $package_path['path'], array());
|
2012-12-07 02:23:56 +01:00
|
|
|
unset($relevant_paths[$package_path['path']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($remove) {
|
|
|
|
foreach ($relevant_paths as $fragment => $fragment_paths) {
|
|
|
|
$relevant_paths[$fragment] = array_diff_key($fragment_paths, $remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$relevant_paths = array_filter($relevant_paths);
|
|
|
|
if ($relevant_paths) {
|
|
|
|
$ids[$id] = max(array_map('strlen', array_keys($relevant_paths)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:51:36 +02:00
|
|
|
private static function splitPath($path) {
|
2012-12-07 02:23:56 +01:00
|
|
|
$result = array('/');
|
2011-04-12 06:51:36 +02:00
|
|
|
$trailing_slash = preg_match('@/$@', $path) ? '/' : '';
|
|
|
|
$path = trim($path, '/');
|
|
|
|
$parts = explode('/', $path);
|
|
|
|
while (count($parts)) {
|
2012-12-07 02:23:56 +01:00
|
|
|
$result[] = '/'.implode('/', $parts).$trailing_slash;
|
2011-04-12 06:51:36 +02:00
|
|
|
$trailing_slash = '/';
|
|
|
|
array_pop($parts);
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2011-04-03 23:48:36 +02:00
|
|
|
}
|