Skip to content

Commit bf5a8bf

Browse files
committed
feat(user-settings): introduce iframe for user settings
Signed-off-by: codewithvk <[email protected]>
1 parent c962471 commit bf5a8bf

File tree

5 files changed

+69
-10
lines changed

5 files changed

+69
-10
lines changed

lib/Settings/Personal.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace OCA\Richdocuments\Settings;
88

9+
use OCA\Richdocuments\AppConfig;
910
use OCA\Richdocuments\Service\CapabilitiesService;
1011
use OCA\Richdocuments\Service\InitialStateService;
1112
use OCP\AppFramework\Http\TemplateResponse;
@@ -15,6 +16,7 @@
1516
class Personal implements ISettings {
1617
public function __construct(
1718
private IConfig $config,
19+
private AppConfig $appConfig,
1820
private CapabilitiesService $capabilitiesService,
1921
private InitialStateService $initialState,
2022
private ?string $userId,
@@ -39,7 +41,8 @@ public function getForm() {
3941
'documentSigningKey' => $this->config->getUserValue($this->userId, 'richdocuments', 'documentSigningKey', ''),
4042
'documentSigningCa' => $this->config->getUserValue($this->userId, 'richdocuments', 'documentSigningCa', ''),
4143
'hasZoteroSupport' => $this->capabilitiesService->hasZoteroSupport(),
42-
'zoteroAPIKey' => $this->config->getUserValue($this->userId, 'richdocuments', 'zoteroAPIKey', '')
44+
'zoteroAPIKey' => $this->config->getUserValue($this->userId, 'richdocuments', 'zoteroAPIKey', ''),
45+
'publicWopiUrl' => $this->appConfig->getCollaboraUrlPublic(),
4346
],
4447
'blank'
4548
);

src/components/AdminSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div id="admin-cool-frame-section" class="section">
1919
<h2>{{ t('richdocuments', 'Collabora Admin Settings') }}</h2>
2020
<CoolFrame v-if="tokenGenerated"
21-
:endpoint="'/cool/adminIntegratorSettings'"
21+
:iframe-type="'admin'"
2222
:public-wopi-url="settings.public_wopi_url"
2323
:access-token="accessToken"
2424
:access-token-t-t-l="accessTokenTTL"

src/components/CoolFrame.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<input type="hidden" name="access_token" :value="accessToken">
99
<input type="hidden" name="access_token_ttl" :value="accessTokenTTL">
1010
<input type="hidden" name="wopi_setting_base_url" :value="wopiSettingBaseUrl">
11+
<input type="hidden" name="iframe_type" :value="iframeType">
1112
<!-- TODO: Include any other necessary hidden inputs -->
1213
</form>
1314
<iframe :id="iframeName"
@@ -26,10 +27,6 @@ import { getCoolServerUrl } from '../helpers/url.js'
2627
export default {
2728
name: 'CoolFrame',
2829
props: {
29-
endpoint: {
30-
type: String,
31-
required: true,
32-
},
3330
publicWopiUrl: {
3431
type: String,
3532
required: true,
@@ -46,6 +43,10 @@ export default {
4643
type: String,
4744
required: true,
4845
},
46+
iframeType: {
47+
type: String,
48+
required: true,
49+
},
4950
},
5051
data() {
5152
return {

src/components/PersonalSettings.vue

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
</em>
3535
</p>
3636

37+
<!-- user settings iframe -->
38+
<div id="user-cool-frame-section" class="section">
39+
<h2>{{ t('richdocuments', 'Collabora User Settings') }}</h2>
40+
<CoolFrame v-if="tokenGenerated"
41+
:iframe-type="'user'"
42+
:public-wopi-url="public_wopi_url"
43+
:access-token="accessToken"
44+
:access-token-t-t-l="accessTokenTTL"
45+
:wopi-setting-base-url="wopiSettingBaseUrl" />
46+
</div>
47+
3748
<!-- Zotero -->
3849
<div class="zotero-section">
3950
<p><strong>{{ t('richdocuments', 'Zotero') }}</strong></p>
@@ -114,14 +125,21 @@
114125
</template>
115126

116127
<script>
117-
import { generateFilePath } from '@nextcloud/router'
128+
import { generateFilePath, generateUrl } from '@nextcloud/router'
118129
import { showError, showSuccess } from '@nextcloud/dialogs'
119130
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
120131
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
121132
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
122133
import DocSigningField from './DocSigningField.vue'
123134
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
124135
import axios from '@nextcloud/axios'
136+
import {
137+
getCurrentUser,
138+
} from '@nextcloud/auth'
139+
140+
import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public'
141+
import { getConfigFileUrl } from '../helpers/url.js'
142+
import CoolFrame from './CoolFrame.vue'
125143
126144
export default {
127145
name: 'PersonalSettings',
@@ -131,6 +149,7 @@ export default {
131149
NcButton,
132150
DocSigningField,
133151
DeleteIcon,
152+
CoolFrame,
134153
},
135154
props: {
136155
initial: {
@@ -147,9 +166,46 @@ export default {
147166
documentSigningCert: this.initial.documentSigningCert || '',
148167
documentSigningKey: this.initial.documentSigningKey || '',
149168
documentSigningCa: this.initial.documentSigningCa || '',
169+
tokenGenerated: false,
170+
accessToken: '',
171+
accessTokenTTL: '',
172+
userId: '',
173+
wopiSettingBaseUrl: '',
174+
public_wopi_url: this.initial.publicWopiUrl || '',
175+
}
176+
},
177+
computed: {
178+
shareToken() {
179+
return getSharingToken()
180+
},
181+
},
182+
async mounted() {
183+
const currentUser = getCurrentUser()
184+
if (currentUser && currentUser.uid) {
185+
this.userId = currentUser.uid
186+
await this.generateAccessToken()
187+
if (this.accessToken) {
188+
this.wopiSettingBaseUrl = getConfigFileUrl()
189+
console.debug('wopiSettingBaseUrl', this.wopiSettingBaseUrl)
190+
this.tokenGenerated = true
191+
}
192+
} else {
193+
console.error('User not authenticated')
150194
}
151195
},
152196
methods: {
197+
async generateAccessToken() {
198+
const { data } = await axios.get(generateUrl('/apps/richdocuments/settings/generateToken/user'))
199+
if (data.token) {
200+
this.accessToken = data.token
201+
this.accessTokenTTL = data.token_ttl
202+
console.debug('Admin settings WOPI token generated:', this.accessToken, this.accessTokenTTL)
203+
} else if (data.federatedUrl) {
204+
console.error('Federated URL returned, not expected for admin settings.')
205+
} else {
206+
console.error('Failed to generate token for admin settings')
207+
}
208+
},
153209
setZoteroAPIKey(newVal) {
154210
this.zoteroAPIKey = newVal
155211
},

src/helpers/url.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ export const getCoolServerUrl = (collaboraBaseUrl) => {
9393
// todo fix wopi Url
9494
const wopiurl = getCallbackBaseUrl() + '/index.php/apps/richdocuments/wopi/files/-1'
9595

96-
const AdminSettingsUrl = collaboraBaseUrl + '/browser/dist/admin/adminIntegratorSettings.html?'
97-
98-
return AdminSettingsUrl
96+
return collaboraBaseUrl
97+
+ '/browser/dist/admin/adminIntegratorSettings.html?'
9998
+ 'WOPISrc=' + encodeURIComponent(wopiurl)
10099
}
101100

0 commit comments

Comments
 (0)