Skip to content

Commit 22d454e

Browse files
committed
fixup! feat(files_sharing): show Account menu on public pages
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 4729c87 commit 22d454e

5 files changed

Lines changed: 45 additions & 32 deletions

File tree

apps/files_sharing/lib/DefaultPublicShareTemplateProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ public function renderPage(IShare $share, string $token, string $path): Template
104104
Util::addInitScript(Application::APP_ID, 'init');
105105
Util::addInitScript(Application::APP_ID, 'init-public');
106106
Util::addScript('files', 'main');
107+
Util::addScript(Application::APP_ID, 'public-file-request');
107108

108109
// Add file-request script if needed
109110
$attributes = $share->getAttributes();
110111
$isFileRequest = $attributes?->getAttribute('fileRequest', 'enabled') === true;
111-
if ($isFileRequest) {
112-
Util::addScript(Application::APP_ID, 'public-file-request');
113-
}
112+
$this->initialState->provideInitialState('isFileRequest', $isFileRequest);
114113

115114
// Load Viewer scripts
116115
if (class_exists(LoadViewer::class)) {

apps/files_sharing/lib/Listener/LoadPublicFileRequestAuthListener.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCA\Files_Sharing\AppInfo\Application;
1111
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
1212
use OCP\AppFramework\Http\TemplateResponse;
13+
use OCP\AppFramework\Services\IInitialState;
1314
use OCP\EventDispatcher\Event;
1415
use OCP\EventDispatcher\IEventListener;
1516
use OCP\Share\IManager;
@@ -19,6 +20,7 @@
1920
class LoadPublicFileRequestAuthListener implements IEventListener {
2021
public function __construct(
2122
private IManager $shareManager,
23+
private IInitialState $initialState,
2224
) {
2325
}
2426

@@ -51,9 +53,10 @@ public function handle(Event $event): void {
5153
// Ignore, this is not a file request or the share does not exist
5254
}
5355

54-
if ($isFileRequest) {
55-
// Add the script to the public page
56-
Util::addScript(Application::APP_ID, 'public-file-request');
57-
}
56+
Util::addScript(Application::APP_ID, 'public-file-request');
57+
58+
// Add file-request script if needed
59+
$attributes = $share->getAttributes();
60+
$this->initialState->provideInitialState('isFileRequest', $isFileRequest);
5861
}
5962
}

apps/files_sharing/src/public-file-request.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { getBuilder } from '@nextcloud/browser-storage'
7-
import { getGuestNickname, getGuestUser } from '@nextcloud/auth'
7+
import { getGuestNickname, getGuestUser, type NextcloudUser } from '@nextcloud/auth'
88
import { getUploader } from '@nextcloud/upload'
99
import { loadState } from '@nextcloud/initial-state'
1010
import { showGuestUserPrompt } from '@nextcloud/dialogs'
@@ -15,29 +15,29 @@ import { subscribe } from '@nextcloud/event-bus'
1515

1616
const storage = getBuilder('files_sharing').build()
1717

18-
/**
19-
* Setup file-request nickname header for the uploader
20-
* @param nickname The nickname
21-
*/
22-
function registerFileRequestHeader(nickname: string) {
18+
// Setup file-request nickname header for the uploader
19+
const registerFileRequestHeader = (nickname: string) => {
2320
const uploader = getUploader()
2421
uploader.setCustomHeader('X-NC-Nickname', encodeURIComponent(nickname))
2522
logger.debug('Nickname header registered for uploader', { headers: uploader.customHeaders })
2623
}
2724

28-
/**
29-
* Callback when a nickname was chosen
30-
*/
31-
function onUpdatedNickname(): void {
32-
// Register header for uploader
33-
registerFileRequestHeader(getGuestUser().displayName ?? '')
25+
// Callback when a nickname was chosen
26+
const onUserInfoChanged = (guest: NextcloudUser) => {
27+
logger.debug('User info changed', { guest })
28+
registerFileRequestHeader(guest.displayName ?? '')
3429
}
35-
subscribe('user:info:changed', onUpdatedNickname)
30+
31+
// Monitor nickname changes
32+
subscribe('user:info:changed', onUserInfoChanged)
3633

3734
window.addEventListener('DOMContentLoaded', () => {
3835
const nickname = getGuestNickname() ?? ''
3936
const dialogShown = storage.getItem('public-auth-prompt-shown') !== null
4037

38+
// Check if a nickname is mandatory
39+
const isFileRequest = loadState('files_sharing', 'isFileRequest', false)
40+
4141
const owner = loadState('files_sharing', 'owner', '')
4242
const ownerDisplayName = loadState('files_sharing', 'ownerDisplayName', '')
4343
const label = loadState('files_sharing', 'label', '')
@@ -64,12 +64,23 @@ window.addEventListener('DOMContentLoaded', () => {
6464
options.subtitle = t('files_sharing', '{ownerDisplayName} shared a folder with you.', { ownerDisplayName })
6565
}
6666

67-
// If we don't have a nickname or the public auth prompt hasn't been shown yet, show it
68-
// We still show the prompt if the user has a nickname to double check
69-
if (!nickname || !dialogShown) {
70-
showGuestUserPrompt(options)
71-
} else {
72-
logger.debug('Public auth prompt already shown.', { nickname })
73-
registerFileRequestHeader(nickname)
67+
// If this is a file request, then we need a nickname
68+
if (isFileRequest) {
69+
// If we don't have a nickname or the public auth prompt hasn't been shown yet, show it
70+
// We still show the prompt if the user has a nickname to double check
71+
if (!nickname || !dialogShown) {
72+
logger.debug('Showing public auth prompt.', { nickname })
73+
showGuestUserPrompt(options)
74+
}
75+
return
76+
}
77+
78+
if (!dialogShown && !nickname) {
79+
logger.debug('Public auth prompt not shown yet but nickname is not mandatory.', { nickname })
80+
return
7481
}
82+
83+
// Else, we just register the nickname header if any.
84+
logger.debug('Public auth prompt already shown.', { nickname })
85+
registerFileRequestHeader(nickname)
7586
})

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@chenfengyuan/vue-qrcode": "^1.0.2",
4444
"@mdi/js": "^7.4.47",
4545
"@mdi/svg": "^7.4.47",
46-
"@nextcloud/auth": "^2.5.0",
46+
"@nextcloud/auth": "^2.5.1",
4747
"@nextcloud/axios": "^2.5.1",
4848
"@nextcloud/browser-storage": "^0.4.0",
4949
"@nextcloud/browserslist-config": "^3.0.1",

0 commit comments

Comments
 (0)