Skip to content

Commit

Permalink
Merge pull request #2283 from nextcloud/feature/2280/allow-to-disable…
Browse files Browse the repository at this point in the history
…-file-rooms

Allow to disable file rooms
  • Loading branch information
nickvergessen authored Oct 21, 2019
2 parents ab47d7d + 5ab5ff4 commit 293650b
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 11 deletions.
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') {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

$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_BAD_REQUEST);
}

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

public static function register(EventDispatcherInterface $dispatcher): void {
$dispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
$dispatcher->addListener('OCA\Files::loadAdditionalScripts', static function() {
self::loadTalkSidebarForFilesApp();
});
}
Expand All @@ -44,6 +44,11 @@ public static function register(EventDispatcherInterface $dispatcher): void {
* Files app.
*/
public static function loadTalkSidebarForFilesApp(): void {
$config = \OC::$server->getConfig();
if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1') {
return;
}

Util::addStyle('spreed', 'merged-files');
Util::addScript('spreed', 'merged-files');
}
Expand Down
13 changes: 9 additions & 4 deletions lib/PublicShare/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
class TemplateLoader {

public static function register(EventDispatcherInterface $dispatcher): void {
$listener = function() {
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', static function() {
self::loadTalkSidebarUi();
};
$dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', $listener);
});
}

/**
Expand All @@ -49,7 +48,13 @@ 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 {
$config = \OC::$server->getConfig();
if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1' ||
$config->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') {
return;
}

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 src/views/AdminSettings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,36 @@
:placeholder="t('spreed', 'Who can start a call?')"
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 @@ -57,25 +82,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 293650b

Please sign in to comment.