mirror of
https://github.com/nextcloud/server.git
synced 2026-04-05 17:16:55 -04:00
Add Share API settings to admin page
This commit is contained in:
parent
2aac6f02a0
commit
9cd55508c3
6 changed files with 97 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
@ -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());
|
||||
});
|
||||
});
|
||||
|
|
@ -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'>
|
||||
|
|
|
|||
Loading…
Reference in a new issue