Skip to content

Commit

Permalink
Add a setting to disable files and public sharing integration
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 8, 2019
1 parent ef2f4e6 commit 2475dad
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 51 deletions.
82 changes: 41 additions & 41 deletions js/admin/general-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/admin/general-settings.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions lib/Controller/FilesIntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\AppFramework\OCSController;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ISession;
Expand All @@ -57,6 +58,8 @@ class FilesIntegrationController extends OCSController {
private $talkSession;
/** @var Util */
private $util;
/** @var IConfig */
private $config;
/** @var IL10N */
private $l;

Expand All @@ -69,6 +72,7 @@ public function __construct(
IUserSession $userSession,
TalkSession $talkSession,
Util $util,
IConfig $config,
IL10N $l10n
) {
parent::__construct($appName, $request);
Expand All @@ -78,6 +82,7 @@ public function __construct(
$this->userSession = $userSession;
$this->talkSession = $talkSession;
$this->util = $util;
$this->config = $config;
$this->l = $l10n;
}

Expand Down Expand Up @@ -112,6 +117,10 @@ public function __construct(
* @throws OCSNotFoundException
*/
public function getRoomByFileId(string $fileId): DataResponse {
if ($this->config->getAppValue('spreed', 'conversations_files', '1') !== '1') {
throw new OCSException($this->l->t('File is not shared, or shared but not with the user'), Http::STATUS_UNAUTHORIZED);
}

$currentUser = $this->userSession->getUser();
if (!$currentUser instanceof IUser) {
throw new OCSException($this->l->t('File is not shared, or shared but not with the user'), Http::STATUS_UNAUTHORIZED);
Expand Down Expand Up @@ -180,6 +189,11 @@ public function getRoomByFileId(string $fileId): DataResponse {
* or "404 Not found" if the given share token was invalid.
*/
public function getRoomByShareToken(string $shareToken): DataResponse {
if ($this->config->getAppValue('spreed', 'conversations_files', '1') !== '1' ||
$this->config->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

try {
$share = $this->shareManager->getShareByToken($shareToken);
if ($share->getPassword() !== null) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Files/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class TemplateLoader {

public static function register(EventDispatcherInterface $dispatcher): void {
$dispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
self::loadTalkSidebarForFilesApp();
if (\OC::$server->getConfig()->getAppValue('spreed', 'conversations_files', '1') === '1') {
self::loadTalkSidebarForFilesApp();
}
});
}

Expand Down
8 changes: 6 additions & 2 deletions lib/PublicShare/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class TemplateLoader {

public static function register(EventDispatcherInterface $dispatcher): void {
$listener = function() {
self::loadTalkSidebarUi();
$config = \OC::$server->getConfig();
if ($config->getAppValue('spreed', 'conversations_files', '1') === '1' &&
$config->getAppValue('spreed', 'conversations_files_public_shares', '1') === '1') {
self::loadTalkSidebarUi();
}
};
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', $listener);
}
Expand All @@ -49,7 +53,7 @@ public static function register(EventDispatcherInterface $dispatcher): void {
* This method should be called when loading additional scripts for the
* public share page of the server.
*/
public static function loadTalkSidebarUi() {
public static function loadTalkSidebarUi(): void {
Util::addStyle('spreed', 'merged-public-share');
Util::addScript('spreed', 'merged-public-share');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Settings/Admin/GeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function __construct(IConfig $config,
*/
public function getForm(): TemplateResponse {
$this->initialStateService->provideInitialState('talk', 'start_calls', (int) $this->config->getAppValue('spreed', 'start_calls', '0'));
$this->initialStateService->provideInitialState('talk', 'conversations_files', (int) $this->config->getAppValue('spreed', 'conversations_files', '1'));
$this->initialStateService->provideInitialState('talk', 'conversations_files_public_shares', (int) $this->config->getAppValue('spreed', 'conversations_files_public_shares', '1'));
return new TemplateResponse('spreed', 'settings/admin/general-settings', [], '');
}

Expand Down
73 changes: 67 additions & 6 deletions vue/src/views/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,36 @@
:options="startCallOptions"
label="label"
track-by="value"
@input="saveChanges" />
:disabled="loading || loadingStartCalls"
@input="saveStartCalls" />
</p>
<p>
<em>{{ t('spreed', 'When a call has started, everyone with access to the conversation can join the call.') }}</em>
</p>

<h3>{{ t('spreed', 'Integration into other apps') }}</h3>

<p>
<input id="conversations_files"
v-model="conversationsFiles"
type="checkbox"
name="conversations_files"
class="checkbox"
:disabled="loading || loadingConversationsFiles"
@change="saveConversationsFiles">
<label for="conversations_files">{{ t('spreed', 'Allow conversations on files') }}</label>
</p>

<p>
<input id="conversations_files_public_shares"
v-model="conversationsFilesPublicShares"
type="checkbox"
name="conversations_files_public_shares"
class="checkbox"
:disabled="loading || loadingConversationsFiles || !conversationsFiles"
@change="saveConversationsFilesPublicShares">
<label for="conversations_files_public_shares">{{ t('spreed', 'Allow conversations on public shares for files') }}</label>
</p>
</div>
</template>

Expand All @@ -56,25 +81,61 @@ export default {
data() {
return {
loading: false,
loading: true,
loadingStartCalls: false,
loadingConversationsFiles: false,
startCallOptions,
startCalls: startCallOptions[0]
startCalls: startCallOptions[0],
conversationsFiles: true,
conversationsFilesPublicShares: true
}
},
mounted() {
this.loading = true
this.startCalls = startCallOptions[parseInt(OCP.InitialState.loadState('talk', 'start_calls'))]
this.conversationsFiles = parseInt(OCP.InitialState.loadState('talk', 'conversations_files')) === 1
this.conversationsFilesPublicShares = parseInt(OCP.InitialState.loadState('talk', 'conversations_files_public_shares')) === 1
this.loading = false
},
methods: {
saveChanges() {
this.loading = true
saveStartCalls() {
this.loadingStartCalls = true
OCP.AppConfig.setValue('spreed', 'start_calls', this.startCalls.value, {
success: function() {
this.loading = false
this.loadingStartCalls = false
}.bind(this)
})
},
saveConversationsFiles() {
this.loadingConversationsFiles = true
OCP.AppConfig.setValue('spreed', 'conversations_files', this.conversationsFiles ? '1' : '0', {
success: function() {
if (!this.conversationsFiles) {
// When the file integration is disabled, the share integration is also disabled
OCP.AppConfig.setValue('spreed', 'conversations_files_public_shares', '0', {
success: function() {
this.conversationsFilesPublicShares = false
this.loadingConversationsFiles = false
}.bind(this)
})
} else {
this.loadingConversationsFiles = false
}
}.bind(this)
})
},
saveConversationsFilesPublicShares() {
this.loadingConversationsFiles = true
OCP.AppConfig.setValue('spreed', 'conversations_files_public_shares', this.conversationsFilesPublicShares ? '1' : '0', {
success: function() {
this.loadingConversationsFiles = false
}.bind(this)
})
}
Expand Down

0 comments on commit 2475dad

Please sign in to comment.