Skip to content

Commit

Permalink
Cache isSharingDisabledForUser
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Feb 2, 2015
1 parent d4a6901 commit 25d5f67
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions lib/private/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,28 @@ public static function isPublicLinkPasswordRequired() {
* @return boolean
*/
public static function isSharingDisabledForUser() {
if (\OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$user = \OCP\User::getUser();
$groupsList = \OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = explode(',', $groupsList);
$usersGroups = \OC_Group::getUserGroups($user);
if (!empty($usersGroups)) {
$remainingGroups = array_diff($usersGroups, $excludedGroups);
// if the user is only in groups which are disabled for sharing then
// sharing is also disabled for the user
if (empty($remainingGroups)) {
return true;
static $disabled;
if (isset($disabled)) {
return $disabled;
} else {
if (\OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$user = \OCP\User::getUser();
$groupsList = \OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = explode(',', $groupsList);
$usersGroups = \OC_Group::getUserGroups($user);
if (!empty($usersGroups)) {
$remainingGroups = array_diff($usersGroups, $excludedGroups);
// if the user is only in groups which are disabled for sharing then
// sharing is also disabled for the user
if (empty($remainingGroups)) {
$disabled = true;
return true;
}
}
}
$disabled = false;
return false;
}
return false;
}

/**
Expand Down Expand Up @@ -197,9 +204,9 @@ public static function getUserQuota($user) {
if ($userQuota === 'default') {
$userQuota = $config->getAppValue('files', 'default_quota', 'none');
}
if($userQuota === 'none') {
if ($userQuota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
}else{
} else {
return OC_Helper::computerFileSize($userQuota);
}
}
Expand Down Expand Up @@ -612,7 +619,7 @@ public static function checkServer(\OCP\IConfig $config) {
}
}

foreach($missingDependencies as $missingDependency) {
foreach ($missingDependencies as $missingDependency) {
$errors[] = array(
'error' => $l->t('PHP module %s not installed.', array($missingDependency)),
'hint' => $moduleHint
Expand Down Expand Up @@ -959,7 +966,7 @@ public static function getInstanceId() {
$id = OC_Config::getValue('instanceid', null);
if (is_null($id)) {
// We need to guarantee at least one letter in instanceid so it can be used as the session_name
$id = 'oc' . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
$id = 'oc' . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
OC_Config::$object->setValue('instanceid', $id);
}
return $id;
Expand Down Expand Up @@ -1197,7 +1204,7 @@ public static function obEnd() {
* @deprecated Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
*/
public static function generateRandomBytes($length = 30) {
return \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
return \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS);
}

/**
Expand All @@ -1212,6 +1219,7 @@ public static function secureRNGAvailable() {

/**
* Get URL content
*
* @param string $url Url to get content
* @deprecated Use \OC::$server->getHTTPHelper()->getUrlContent($url);
* @throws Exception If the URL does not start with http:// or https://
Expand Down

0 comments on commit 25d5f67

Please sign in to comment.