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

fix(files_sharing): Only enable mixed sharing types if there is at least one sharing type #46382

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export const action = new FileAction({

const node = nodes[0]
const ownerId = node?.attributes?.['owner-id']
const isMixed = Array.isArray(node.attributes?.['share-types'])
const shareTypes = node.attributes?.['share-types']
const isMixed = Array.isArray(shareTypes) && shareTypes.length > 0

// If the node is shared multiple times with
// different share types to the current user
Expand Down
26 changes: 26 additions & 0 deletions lib/private/CapabilitiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
use Psr\Log\LoggerInterface;

class CapabilitiesManager {
/**
* Anything above 0.1s to load the capabilities of an app qualifies for bad code
* and should be cached within the app.
*/
public const ACCEPTABLE_LOADING_TIME = 0.1;

/** @var \Closure[] */
private $capabilities = [];

Expand Down Expand Up @@ -51,7 +57,27 @@ public function getCapabilities(bool $public = false, bool $initialState = false
// that we would otherwise inject to every page load
continue;
}
$startTime = microtime(true);
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
$endTime = microtime(true);
$timeSpent = $endTime - $startTime;
if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) {
$logLevel = match (true) {
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => \OCP\ILogger::FATAL,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => \OCP\ILogger::ERROR,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => \OCP\ILogger::WARN,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => \OCP\ILogger::INFO,
default => \OCP\ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Capabilities of {className} took {duration} seconds to generate.',
[
'className' => get_class($c),
'duration' => round($timeSpent, 2),
]
);
}
}
} else {
throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface');
Expand Down