diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 8754b16b061..79ab4adebac 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -1,6 +1,6 @@ $(document).ready(function() { - if (typeof FileActions !== 'undefined') { + if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined') { OC.Share.loadIcons('file'); FileActions.register('all', 'Share', FileActions.PERMISSION_READ, function(filename) { // Return the correct sharing icon diff --git a/lib/public/share.php b/lib/public/share.php index 964394d75db..165e3df452f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -67,15 +67,31 @@ class Share { * @return Returns true if backend is registered or false if error */ public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) { - if (!isset(self::$backendTypes[$itemType])) { - self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions); - if(count(self::$backendTypes) === 1) { - \OC_Util::addScript('core', 'share'); - \OC_Util::addStyle('core', 'share'); + if (self::isEnabled()) { + if (!isset(self::$backendTypes[$itemType])) { + self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions); + if(count(self::$backendTypes) === 1) { + \OC_Util::addScript('core', 'share'); + \OC_Util::addStyle('core', 'share'); + } + return true; } + \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN); + } + return false; + } + + /** + * @brief Check if the Share API is enabled + * @return Returns true if enabled or false + * + * The Share API is enabled by default if not configured + * + */ + public static function isEnabled() { + if (\OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes') == 'yes') { return true; } - \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN); return false; } @@ -168,11 +184,13 @@ class Share { \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } - $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); - if (empty($inGroup)) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; - \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); - throw new \Exception($message); + if (\OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global') == 'groups_only') { + $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); + if (empty($inGroup)) { + $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { @@ -210,13 +228,19 @@ class Share { $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else if ($shareType === self::SHARE_TYPE_LINK) { - // Generate hash of password - same method as user passwords - if (isset($shareWith)) { - $forcePortable = (CRYPT_BLOWFISH != 1); - $hasher = new \PasswordHash(8, $forcePortable); - $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); + if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { + // Generate hash of password - same method as user passwords + if (isset($shareWith)) { + $forcePortable = (CRYPT_BLOWFISH != 1); + $hasher = new \PasswordHash(8, $forcePortable); + $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); + } + return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); } - return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); + $message = 'Sharing '.$itemSource.' failed, because sharing with links is not allowed'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + return false; } else if ($shareType === self::SHARE_TYPE_CONTACT) { if (!\OC_App::isEnabled('contacts')) { $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; @@ -436,6 +460,13 @@ class Share { * */ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) { + if (!self::isEnabled()) { + if ($limit == 1 || (isset($uidOwner) && isset($item))) { + return false; + } else { + return array(); + } + } $backend = self::getBackend($itemType); // Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache if ($itemType == 'file' || $itemType == 'folder') { diff --git a/settings/admin.php b/settings/admin.php index 6909e02d14f..8788de940b3 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -30,6 +30,10 @@ $tmpl->assign('entries',$entries); $tmpl->assign('entriesremain', $entriesremain); $tmpl->assign('htaccessworking',$htaccessworking); $tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax')); +$tmpl->assign('shareAPIEnabled', OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes')); +$tmpl->assign('allowLinks', OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes')); +$tmpl->assign('allowResharing', OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes')); +$tmpl->assign('sharePolicy', OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global')); $tmpl->assign('forms',array()); foreach($forms as $form){ $tmpl->append('forms',$form); diff --git a/settings/css/settings.css b/settings/css/settings.css index 5a0f5bbde9e..49274103ca8 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -64,4 +64,5 @@ span.version { margin-left:3em; margin-right:3em; color:#555; } span.securitywarning {color:#C33; font-weight:bold; } h3.settingsNotice { font-size: 1.2em; } .settingsNotice { font-weight:bold; padding: 0.5em 0; } -#backgroundjobs input[type=radio] { width:1em; } +input[type=radio] { width:1em; } +table.shareAPI td { padding-right: 2em; } \ No newline at end of file diff --git a/settings/js/admin.js b/settings/js/admin.js index 57a67b54998..8b1494881a5 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -13,4 +13,18 @@ $(document).ready(function(){ } } }); + + $('#shareAPIEnabled').change(function() { + $('.shareAPI td:not(#enable)').toggle(); + }); + + $('#shareAPI input').change(function() { + if ($(this).attr('type') == 'radio') { + console.log('radio'); + } + if ($(this).attr('type') == 'checkbox') { + console.log('checked'); + } + OC.AppConfig.setValue('core', 'shareapi_', $(this).val()); + }); }); \ No newline at end of file diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 1306d90f402..b701b0e839a 100755 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -35,6 +35,34 @@ if(!$_['htaccessworking']) {
+
+ t('Share API');?> + + + + + + +
+ /> +
+ t('Allow apps to use the Share API'); ?> +
> + /> +
+ t('Allow users to share items to the public with links'); ?> +
> + /> +
+ t('Allow users to share items shared with them again'); ?> +
> + /> +
+ /> +
+
+
+
t('Log');?> Log level: