Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for specific user inherited permission #556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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