|
12 | 12 | * @method DNProject Project() |
13 | 13 | * @method DataList Deployments() |
14 | 14 | * |
| 15 | + * @method ManyManyList Viewers() |
| 16 | + * @method ManyManyList ViewerGroups() |
15 | 17 | * @method ManyManyList Deployers() |
16 | 18 | * @method ManyManyList DeployerGroups() |
17 | 19 | * @method ManyManyList CanRestoreMembers() |
@@ -87,6 +89,8 @@ class DNEnvironment extends DataObject { |
87 | 89 | * @var array |
88 | 90 | */ |
89 | 91 | public static $many_many = array( |
| 92 | + "Viewers" => "Member", // Who can view this environment |
| 93 | + "ViewerGroups" => "Group", |
90 | 94 | "Deployers" => "Member", // Who can deploy to this environment |
91 | 95 | "DeployerGroups" => "Group", |
92 | 96 | "CanRestoreMembers" => "Member", // Who can restore archive files to this environment |
@@ -268,12 +272,23 @@ public function CanCancelPipeline() { |
268 | 272 | } |
269 | 273 |
|
270 | 274 | /** |
271 | | - * Environments are only viewable by people that can view the parent project |
| 275 | + * Environments are only viewable by people that can view the environment. |
272 | 276 | * |
273 | 277 | * @param Member $member |
274 | 278 | * @return boolean |
275 | 279 | */ |
276 | 280 | public function canView($member = null) { |
| 281 | + if(!$member) $member = Member::currentUser(); |
| 282 | + if(!$member) return false; // Must be logged in to check permissions |
| 283 | + |
| 284 | + if(Permission::checkMember($member, 'ADMIN')) return true; |
| 285 | + |
| 286 | + // if no Viewers or ViewerGroups defined, fallback to DNProject::canView permissions |
| 287 | + if($this->Viewers()->exists() || $this->ViewerGroups()->exists()) { |
| 288 | + return $this->Viewers()->byID($member->ID) |
| 289 | + || $member->inGroups($this->ViewerGroups()); |
| 290 | + } |
| 291 | + |
277 | 292 | return $this->Project()->canView($member); |
278 | 293 | } |
279 | 294 |
|
@@ -767,6 +782,12 @@ public function getCMSFields() { |
767 | 782 | )); |
768 | 783 |
|
769 | 784 | $fields->addFieldsToTab('Root.UserPermissions', array( |
| 785 | + // The viewers of the environment |
| 786 | + $this |
| 787 | + ->buildPermissionField('ViewerGroups', 'Viewers', $groups, $members) |
| 788 | + ->setTitle('Who can view this environment?') |
| 789 | + ->setDescription('Groups or Users who can view this environment'), |
| 790 | + |
770 | 791 | // The Main.Deployers |
771 | 792 | $this |
772 | 793 | ->buildPermissionField('DeployerGroups', 'Deployers', $groups, $members) |
|
0 commit comments