Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
allow to disable upload to lookup server, by default it is enabled
Signed-off-by: Bjoern Schiessle <[email protected]>
  • Loading branch information
schiessle committed Apr 7, 2017
commit 9afd160e66f2c060cb7d77d414d0c1d13ac0c3ad
11 changes: 11 additions & 0 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,4 +963,15 @@ public function isLookupServerQueriesEnabled() {
$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
return ($result === 'yes') ? true : false;
}


/**
* Check if it is allowed to publish user specific data to the lookup server
*
* @return bool
*/
public function isLookupServerUploadEnabled() {
$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
return ($result === 'yes') ? true : false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ($result === 'yes') part already results in a proper boolean value, no need for the ternary operator here 😉

We could even shorten this to

return $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely right, that's happen if you copy&paste methods and only replace the relevant parts 😉

I will not do the last step you suggested because I think this makes it harder to debug but will simplify the return statement

}
}
1 change: 1 addition & 0 deletions apps/federatedfilesharing/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getForm() {
'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(),
];

return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
Expand Down
10 changes: 9 additions & 1 deletion apps/federatedfilesharing/templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
<input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox"
value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> />
<label for="lookupServerEnabled">
<?php p($l->t('Search global and public address book for users'));?>
<?php p($l->t('Search global and public address book for users and let local users publish their data'));?>
</label><br/>
</p>
<p>
<input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox"
value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> />
<label for="lookupServerUploadEnabled">
<?php p($l->t('Allow users to publish their data to a global and public address book'));?>
</label><br/>
</p>

</div>
32 changes: 32 additions & 0 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,38 @@ public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected) {
);
}

/**
* @dataProvider dataTestFederatedSharingSettings
*
* @param string $isEnabled
* @param bool $expected
*/
public function testIsLookupServerQueriesEnabled($isEnabled, $expected) {
$this->config->expects($this->once())->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn($isEnabled);

$this->assertSame($expected,
$this->provider->isLookupServerQueriesEnabled()
);
}

/**
* @dataProvider dataTestFederatedSharingSettings
*
* @param string $isEnabled
* @param bool $expected
*/
public function testIsLookupServerUploadEnabled($isEnabled, $expected) {
$this->config->expects($this->once())->method('getAppValue')
->with('files_sharing', 'lookupServerUploadEnabled', 'yes')
->willReturn($isEnabled);

$this->assertSame($expected,
$this->provider->isLookupServerUploadEnabled()
);
}

public function dataTestFederatedSharingSettings() {
return [
['yes', true],
Expand Down
5 changes: 5 additions & 0 deletions apps/federatedfilesharing/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ public function testGetForm($state) {
->expects($this->once())
->method('isLookupServerQueriesEnabled')
->willReturn($state);
$this->federatedShareProvider
->expects($this->once())
->method('isLookupServerUploadEnabled')
->willReturn($state);

$params = [
'outgoingServer2serverShareEnabled' => $state,
'incomingServer2serverShareEnabled' => $state,
'lookupServerEnabled' => $state,
'lookupServerUploadEnabled' => $state
];
$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', $params, '');
$this->assertEquals($expected, $this->admin->getForm());
Expand Down
4 changes: 4 additions & 0 deletions settings/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
$tmpl->assign('showCertificates', $enableCertImport);
$tmpl->assign('urlGenerator', $urlGenerator);

$lookupServerUploadEnabled = $config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
$lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes';
$tmpl->assign('lookupServerUploadEnabled', $lookupServerUploadEnabled);

// Get array of group ids for this user
$groups = \OC::$server->getGroupManager()->getUserIdGroups(OC_User::getUser());
$groups2 = array_map(function($group) { return $group->getGID(); }, $groups);
Expand Down
9 changes: 8 additions & 1 deletion settings/templates/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
</div>
</div>
<span class="icon-checkmark hidden"/>
<?php if($_['lookupServerUploadEnabled']) { ?>
<input type="hidden" id="avatarscope" value="<?php p($_['avatarScope']) ?>">
<?php } ?>
</form>
</div>

Expand All @@ -86,7 +88,9 @@
<span><?php if(isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span>
<?php } ?>
<span class="icon-checkmark hidden"/>
<?php if($_['lookupServerUploadEnabled']) { ?>
<input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>">
<?php } ?>
</form>
</div>
<div class="personal-settings-setting-box">
Expand All @@ -107,9 +111,12 @@
<em><?php p($l->t('For password reset and notifications')); ?></em>
<?php } ?>
<span class="icon-checkmark hidden"/>
<?php if($_['lookupServerUploadEnabled']) { ?>
<input type="hidden" id="emailscope" value="<?php p($_['emailScope']) ?>">
<?php } ?>
</form>
</div>
<?php if($_['lookupServerUploadEnabled']) { ?>
<div class="personal-settings-setting-box">
<form id="phoneform" class="section">
<h2>
Expand Down Expand Up @@ -164,7 +171,7 @@
<input type="hidden" id="twitterscope" value="<?php p($_['twitterScope']) ?>">
</form>
</div>

<?php } ?>
<span class="msg"></span>
</div>
</div>
Expand Down