Skip to content

Commit

Permalink
Merge pull request #556 from andrewandante/FEAT_add_individual_users_…
Browse files Browse the repository at this point in the history
…permissions_check

add check for specific user inherited permission
  • Loading branch information
GuySartorelli authored Jul 6, 2023
2 parents e57099b + 47fa6c6 commit 7605cda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 7605cda

Please sign in to comment.