]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add Share API settings to admin page
authorMichael Gapczynski <mtgap@owncloud.com>
Tue, 28 Aug 2012 00:36:34 +0000 (20:36 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Tue, 28 Aug 2012 00:39:31 +0000 (20:39 -0400)
apps/files_sharing/js/share.js
lib/public/share.php
settings/admin.php
settings/css/settings.css
settings/js/admin.js
settings/templates/admin.php

index 8754b16b061328be05c66f4fbdc85ac98d463aa3..79ab4adebac392f1a6908c156c7def71d318eed3 100644 (file)
@@ -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
index 964394d75db105dc872800834675b0e7b86f71ad..165e3df452f763414f9f4bee9adee8ac15c192ec 100644 (file)
@@ -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') {
index 6909e02d14f5bd14d5acf1e05e44cd18981c3136..8788de940b385e10537d4a5767c91a3ace66dda1 100755 (executable)
@@ -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);
index 5a0f5bbde9ed0f238b0040e174f26763310c7c8b..49274103ca87293767642d1c401ee0b79c9a2d11 100644 (file)
@@ -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
index 57a67b54998add335d578f5ed771fa1e9da39265..8b1494881a544f25259272e58ede8d39a697e97b 100644 (file)
@@ -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
index 1306d90f402f8d6100750d95b4a38d8f707bd1ce..b701b0e839a7e08493d8b3c29c00b8088faf5c6d 100755 (executable)
@@ -35,6 +35,34 @@ if(!$_['htaccessworking']) {
        <label for="backgroundjobs_cron" title="<?php echo $l->t("use systems cron service"); ?>">Cron</label><br />
 </fieldset>
 
+<fieldset class="personalblock" id="shareAPI">
+       <legend><strong><?php echo $l->t('Share API');?></strong></legend>
+       <table class="shareAPI nostyle">
+               <tr>
+                       <td id="enable">
+                               <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" value="1" <?php if ($_['shareAPIEnabled'] == 'yes') echo 'checked="checked"'; ?> />
+                               <label for="shareAPIEnabled"><?php echo $l->t('Enable Share API');?></label><br />
+                               <em><?php echo $l->t('Allow apps to use the Share API'); ?></em>
+                       </td>
+                       <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+                               <input type="checkbox" name="shareapi_allow_links" id="allowLinks" value="1" <?php if ($_['allowLinks'] == 'yes') echo 'checked="checked"'; ?> />
+                               <label for="allowLinks"><?php echo $l->t('Allow links');?></label><br />
+                               <em><?php echo $l->t('Allow users to share items to the public with links'); ?></em>
+                       </td>
+                       <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+                               <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" value="1" <?php if ($_['allowResharing'] == 'yes') echo 'checked="checked"'; ?> />
+                               <label for="allowResharing"><?php echo $l->t('Allow resharing');?></label><br />
+                               <em><?php echo $l->t('Allow users to share items shared with them again'); ?></em>
+                       <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+                               <input type="radio" name="shareapi_share_policy" id="sharePolicyGlobal" value="global" <?php if ($_['sharePolicy'] == 'global') echo 'checked="checked"'; ?> />
+                               <label for="sharePolicyGlobal"><?php echo $l->t('Allow users to share with anyone'); ?></label><br />
+                               <input type="radio" name="shareapi_share_policy" id="sharePolicyGroupsOnly" value="groups_only" <?php if ($_['sharePolicy'] == 'groups_only') echo 'checked="checked"'; ?> />
+                               <label for="sharePolicyGroupsOnly"><?php echo $l->t('Allow users to only share with users in their groups');?></label><br />
+                       </td>
+               </tr>
+       </table>
+</fieldset>
+
 <fieldset class="personalblock">
        <legend><strong><?php echo $l->t('Log');?></strong></legend>
        Log level: <select name='loglevel' id='loglevel'>