Skip to content

Commit

Permalink
ENH add check for specific user inherited permission
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewandante committed Jul 6, 2023
1 parent 981dd3b commit 47fa6c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -20,7 +20,7 @@
],
"require": {
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/framework": "^5.1",
"silverstripe/vendor-plugin": "^2",
"symfony/filesystem": "^6.1",
"intervention/image": "^2.7.2",
Expand Down
16 changes: 14 additions & 2 deletions src/File.php
Expand Up @@ -397,6 +397,14 @@ public function canView($member = null)
return $member->inGroups($this->ViewerGroups());
}

// Specific users can view this file
if ($this->CanViewType === InheritedPermissions::ONLY_THESE_MEMBERS) {
if (!$member) {
return false;
}
return $this->ViewerMembers()->filter('ID', $member->ID)->count() > 0;
}

// Check default root level permissions
return $this->getPermissionChecker()->canView($this->ID, $member);
}
Expand All @@ -423,7 +431,7 @@ public function canEdit($member = null)
}

// Delegate to parent if inheriting permissions
if ($this->CanEditType === 'Inherit' && $this->ParentID) {
if ($this->CanEditType === InheritedPermissions::INHERIT && $this->ParentID) {
return $this->getPermissionChecker()->canEdit($this->ParentID, $member);
}

Expand Down Expand Up @@ -518,7 +526,11 @@ private function hasRestrictedPermissions(File $file): bool
$id = $file->ID;
$parentID = $file->ParentID;
$canViewType = $file->CanViewType;
if (in_array($canViewType, [InheritedPermissions::LOGGED_IN_USERS, InheritedPermissions::ONLY_THESE_USERS])) {
if (in_array($canViewType, [
InheritedPermissions::LOGGED_IN_USERS,
InheritedPermissions::ONLY_THESE_USERS,
InheritedPermissions::ONLY_THESE_MEMBERS,
])) {
self::$has_restricted_permissions_cache[$id] = true;
return true;
}
Expand Down

0 comments on commit 47fa6c6

Please sign in to comment.