2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
2012-08-09 02:10:10 +02:00
|
|
|
final class PhabricatorProject extends PhabricatorProjectDAO
|
2013-10-25 21:52:00 +02:00
|
|
|
implements
|
|
|
|
PhabricatorFlaggableInterface,
|
|
|
|
PhabricatorPolicyInterface {
|
2011-02-21 03:41:23 +01:00
|
|
|
|
|
|
|
protected $name;
|
2012-02-07 23:59:38 +01:00
|
|
|
protected $status = PhabricatorProjectStatus::STATUS_ACTIVE;
|
2011-02-21 03:41:23 +01:00
|
|
|
protected $authorPHID;
|
2011-07-19 20:50:15 +02:00
|
|
|
protected $subprojectPHIDs = array();
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
protected $phrictionSlug;
|
2011-07-19 20:50:15 +02:00
|
|
|
|
2012-08-11 16:05:01 +02:00
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
|
|
|
protected $joinPolicy;
|
|
|
|
|
2012-08-08 03:02:05 +02:00
|
|
|
private $subprojectsNeedUpdate;
|
2013-09-03 15:02:14 +02:00
|
|
|
private $memberPHIDs = self::ATTACHABLE;
|
|
|
|
private $sparseMembers = self::ATTACHABLE;
|
2013-10-07 02:07:20 +02:00
|
|
|
private $profile = self::ATTACHABLE;
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2012-08-09 02:10:10 +02:00
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
2012-08-11 16:05:01 +02:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN,
|
2012-08-09 02:10:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
2012-08-11 16:05:01 +02:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
|
|
|
return $this->getJoinPolicy();
|
|
|
|
}
|
2012-08-09 02:10:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
2012-08-11 16:05:01 +02:00
|
|
|
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
if ($this->isUserMember($viewer->getPHID())) {
|
|
|
|
// Project members can always view a project.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
break;
|
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
|
|
|
$can_edit = PhabricatorPolicyCapability::CAN_EDIT;
|
|
|
|
if (PhabricatorPolicyFilter::hasCapability($viewer, $this, $can_edit)) {
|
|
|
|
// Project editors can always join a project.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-09 02:10:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return pht("Members of a project can always view it.");
|
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
|
|
|
return pht("Users who can edit a project can always join it.");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-08-11 16:05:01 +02:00
|
|
|
public function isUserMember($user_phid) {
|
2013-09-03 15:02:14 +02:00
|
|
|
return $this->assertAttachedKey($this->sparseMembers, $user_phid);
|
2012-08-11 16:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsUserMember($user_phid, $is_member) {
|
2013-09-03 15:02:14 +02:00
|
|
|
if ($this->sparseMembers === self::ATTACHABLE) {
|
|
|
|
$this->sparseMembers = array();
|
|
|
|
}
|
2012-08-11 16:05:01 +02:00
|
|
|
$this->sparseMembers[$user_phid] = $is_member;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2011-07-19 20:50:15 +02:00
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'subprojectPHIDs' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
2011-02-21 03:41:23 +01:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2011-03-03 03:58:21 +01:00
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2013-07-22 18:26:26 +02:00
|
|
|
PhabricatorProjectPHIDTypeProject::TYPECONST);
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
|
2013-10-07 02:07:20 +02:00
|
|
|
public function getProfile() {
|
|
|
|
return $this->assertAttached($this->profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachProfile(PhabricatorProjectProfile $profile) {
|
|
|
|
$this->profile = $profile;
|
|
|
|
return $this;
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 03:02:05 +02:00
|
|
|
public function attachMemberPHIDs(array $phids) {
|
|
|
|
$this->memberPHIDs = $phids;
|
|
|
|
return $this;
|
2012-08-07 20:55:00 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 03:02:05 +02:00
|
|
|
public function getMemberPHIDs() {
|
2013-09-03 15:02:14 +02:00
|
|
|
return $this->assertAttached($this->memberPHIDs);
|
2012-01-18 01:29:35 +01:00
|
|
|
}
|
|
|
|
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
public function setPhrictionSlug($slug) {
|
|
|
|
|
|
|
|
// NOTE: We're doing a little magic here and stripping out '/' so that
|
|
|
|
// project pages always appear at top level under projects/ even if the
|
|
|
|
// display name is "Hack / Slash" or similar (it will become
|
|
|
|
// 'hack_slash' instead of 'hack/slash').
|
|
|
|
|
|
|
|
$slug = str_replace('/', ' ', $slug);
|
2012-04-10 23:18:20 +02:00
|
|
|
$slug = PhabricatorSlug::normalize($slug);
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
$this->phrictionSlug = $slug;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-18 01:43:37 +02:00
|
|
|
public function getFullPhrictionSlug() {
|
|
|
|
$slug = $this->getPhrictionSlug();
|
|
|
|
return 'projects/'.$slug;
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|