Skip to content
Draft
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 apps/files_sharing/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getCapabilities() {
$res['api_enabled'] = true;

$public = [];
$public['enabled'] = $this->shareManager->shareApiAllowLinks();
$public['enabled'] = $this->shareManager->canUserCreateLinkShares();
if ($public['enabled']) {
$public['password'] = [];
$public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
Expand Down
54 changes: 42 additions & 12 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ protected function groupCreateChecks(IShare $share) {
*/
protected function linkCreateChecks(IShare $share) {
// Are link shares allowed?
if (!$this->shareApiAllowLinks()) {
if (!$this->canUserCreateLinkShares()) {
throw new \Exception($this->l->t('Link sharing is not allowed'));
}

Expand Down Expand Up @@ -1413,7 +1413,7 @@ public function getShareByToken($token) {
}
$share = null;
try {
if ($this->shareApiAllowLinks()) {
if ($this->isLinkSharingEnabled()) {
$provider = $this->factory->getProviderForType(IShare::TYPE_LINK);
$share = $provider->getShareByToken($token);
}
Expand Down Expand Up @@ -1740,27 +1740,57 @@ public function shareApiEnabled() {
}

/**
* Is public link sharing enabled
* Check if public link sharing is enabled globally
*
* @return bool
* @since 33.0.0
*/
public function shareApiAllowLinks() {
if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
public function isLinkSharingEnabled(): bool {
return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
}

/**
* Check if a specific user can create public link shares
*
* This considers both global settings and user-specific group restrictions
*
* @param string|null $userId The user ID to check, or null for current user
* @return bool
* @since 33.0.0
*/
public function canUserCreateLinkShares(?string $userId = null): bool {
if (!$this->isLinkSharingEnabled()) {
return false;
}

$user = $this->userSession->getUser();
if ($user) {
$excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]'));
if ($excludedGroups) {
$userGroups = $this->groupManager->getUserGroupIds($user);
return !(bool)array_intersect($excludedGroups, $userGroups);
}
$user = $userId ? $this->userManager->get($userId) : $this->userSession->getUser();
if (!$user) {
return true;
}

$excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]'));
if ($excludedGroups) {
$userGroups = $this->groupManager->getUserGroupIds($user);
return !(bool)array_intersect($excludedGroups, $userGroups);
}

return true;
}

/**
* Is public link sharing enabled
*
* @param bool $checkGroupExclusion Whether to check the current user's group exclusions
* @return bool
* @deprecated 33.0.0 Use isLinkSharingEnabled() or canUserCreateLinkShares() instead
*/
public function shareApiAllowLinks(bool $checkGroupExclusion = true) {
if ($checkGroupExclusion) {
return $this->canUserCreateLinkShares();
}
return $this->isLinkSharingEnabled();
}

/**
* Is password on public link requires
*
Expand Down
20 changes: 20 additions & 0 deletions lib/public/Share/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,31 @@ public function newShare();
*/
public function shareApiEnabled();

/**
* Check if public link sharing is enabled globally
*
* @return bool
* @since 33.0.0
*/
public function isLinkSharingEnabled(): bool;

/**
* Check if a specific user can create public link shares
*
* This considers both global settings and user-specific group restrictions
*
* @param string|null $userId The user ID to check, or null for current user
* @return bool
* @since 33.0.0
*/
public function canUserCreateLinkShares(?string $userId = null): bool;

/**
* Is public link sharing enabled
*
* @return bool
* @since 9.0.0
* @deprecated 33.0.0 Use isLinkSharingEnabled() or canUserCreateLinkShares() instead
*/
public function shareApiAllowLinks();

Expand Down
Loading