1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
<template>
<NcSettingsSection id="updatenotification" :title="t('updatenotification', 'Update')">
<div class="update">
<template v-if="isNewVersionAvailable">
<NcNoteCard v-if="versionIsEol" type="warning">
{{ t('updatenotification', 'The version you are running is not maintained anymore. Please make sure to update to a supported version as soon as possible.') }}
</NcNoteCard>
<p>
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-html="newVersionAvailableString" /><br>
<span v-if="!isListFetched" class="icon icon-loading-small" />
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-html="statusText" />
</p>
<template v-if="missingAppUpdates.length">
<h3 class="clickable" @click="toggleHideMissingUpdates">
{{ t('updatenotification', 'Apps missing compatible version') }}
<span v-if="!hideMissingUpdates" class="icon icon-triangle-n" />
<span v-if="hideMissingUpdates" class="icon icon-triangle-s" />
</h3>
<ul v-if="!hideMissingUpdates" class="applist">
<li v-for="(app, index) in missingAppUpdates" :key="index">
<a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{ app.appName }} ↗</a>
</li>
</ul>
</template>
<template v-if="availableAppUpdates.length">
<h3 class="clickable" @click="toggleHideAvailableUpdates">
{{ t('updatenotification', 'Apps with compatible version') }}
<span v-if="!hideAvailableUpdates" class="icon icon-triangle-n" />
<span v-if="hideAvailableUpdates" class="icon icon-triangle-s" />
</h3>
<ul v-if="!hideAvailableUpdates" class="applist">
<li v-for="(app, index) in availableAppUpdates" :key="index">
<a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{ app.appName }} ↗</a>
</li>
</ul>
</template>
<template v-if="!isWebUpdaterRecommended && updaterEnabled && webUpdaterEnabled">
<h3 class="warning">
{{ t('updatenotification', 'Please note that the web updater is not recommended with more than 100 users! Please use the command line updater instead!') }}
</h3>
</template>
<div>
<a v-if="updaterEnabled && webUpdaterEnabled"
href="#"
class="button primary"
@click="clickUpdaterButton">{{ t('updatenotification', 'Open updater') }}</a>
<a v-if="downloadLink"
:href="downloadLink"
class="button"
:class="{ hidden: !updaterEnabled }">{{ t('updatenotification', 'Download now') }}</a>
<span v-if="updaterEnabled && !webUpdaterEnabled">
{{ t('updatenotification', 'Please use the command line updater to update.') }}
</span>
<NcActions v-if="whatsNewData || changelogURL"
:force-menu="true"
:menu-title="t('updatenotification', 'What\'s new?')"
type="tertiary">
<template #icon>
<IconNewBox :size="20" />
</template>
<template #default>
<NcActionCaption v-for="changes,index in whatsNewData" :key="index" :title="changes" />
<NcActionLink v-if="changelogURL"
:href="changelogURL"
close-after-click
target="_blank">
{{ t('updatenotification', 'View changelog') }}
<template #icon>
<IconLink :size="20" />
</template>
</NcActionLink>
</template>
</NcActions>
</div>
</template>
<template v-else-if="!isUpdateChecked">
{{ t('updatenotification', 'The update check is not yet finished. Please refresh the page.') }}
</template>
<template v-else>
{{ t('updatenotification', 'Your version is up to date.') }}
<span :title="lastCheckedOnString" :aria-label="lastCheckedOnString" class="icon-info svg" />
</template>
<template v-if="!isDefaultUpdateServerURL">
<p class="topMargin">
<em>{{ t('updatenotification', 'A non-default update server is in use to be checked for updates:') }} <code>{{ updateServerURL }}</code></em>
</p>
</template>
</div>
<h3>{{ t('updatenotification', 'Update channel') }}</h3>
<p class="inlineblock">
{{ t('updatenotification', 'Changing the update channel also affects the apps management page. E.g. after switching to the beta channel, beta app updates will be offered to you in the apps management page.') }}
</p>
<div class="update-channel-selector">
<span>{{ t('updatenotification', 'Current update channel:') }}</span>
<NcActions :force-menu="true"
:menu-title="localizedChannelName"
type="tertiary">
<template #icon>
<IconChevronDown :size="20" />
</template>
<template #default>
<!-- TODO use NcActionRadio if it provides long text, e.g. subtitle -->
<NcActionButton v-for="channel,index in channelList"
:key="index"
:aria-checked="channel.active ? 'true' : 'false'"
:aria-label="channel.text"
:disabled="!!channel.disabled"
:icon="channel.icon"
:name="channel.text"
class="update-channel-action"
close-after-click
role="menuitemradio"
@click="channel.action">
{{ channel.longtext }}
</NcActionButton>
</template>
</NcActions>
</div>
<p>
<em>{{ t('updatenotification', 'You can always update to a newer version. But you can never downgrade to a more stable version.') }}</em><br>
<!-- eslint-disable-next-line vue/no-v-html -->
<em v-html="noteDelayedStableString" />
</p>
<h4>{{ t('updatenotification', 'Notify members of the following groups about available updates:') }}</h4>
<NcSelect v-model="notifyGroups"
:options="groups"
:multiple="true"
label="displayname"
:loading="loadingGroups"
:close-on-select="false"
@search="searchGroup">
<template #no-options>
{{ t('updatenotification', 'No groups') }}
</template>
</NcSelect>
<p>
<em v-if="currentChannel === 'daily' || currentChannel === 'git'">{{ t('updatenotification', 'Only notifications for app updates are available.') }}</em>
<em v-if="currentChannel === 'daily'">{{ t('updatenotification', 'The selected update channel makes dedicated notifications for the server obsolete.') }}</em>
<em v-else-if="currentChannel === 'git'">{{ t('updatenotification', 'The selected update channel does not support updates of the server.') }}</em>
</p>
</NcSettingsSection>
</template>
<script>
import { showSuccess } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { getLoggerBuilder } from '@nextcloud/logger'
import { generateUrl, getRootUrl, generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionCaption from '@nextcloud/vue/dist/Components/NcActionCaption.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
import IconChevronDown from 'vue-material-design-icons/ChevronDown.vue'
import IconLink from 'vue-material-design-icons/Link.vue'
import IconNewBox from 'vue-material-design-icons/NewBox.vue'
import debounce from 'debounce'
const logger = getLoggerBuilder()
.setApp('updatenotification')
.detectUser()
.build()
export default {
name: 'UpdateNotification',
components: {
IconChevronDown,
IconLink,
IconNewBox,
NcActions,
NcActionButton,
NcActionCaption,
NcActionLink,
NcNoteCard,
NcSelect,
NcSettingsSection,
},
data() {
return {
loadingGroups: false,
newVersionString: '',
lastCheckedDate: '',
isUpdateChecked: false,
webUpdaterEnabled: true,
isWebUpdaterRecommended: true,
updaterEnabled: true,
versionIsEol: false,
downloadLink: '',
isNewVersionAvailable: false,
hasValidSubscription: false,
updateServerURL: '',
changelogURL: '',
whatsNewData: [],
currentChannel: '',
channels: [],
notifyGroups: '',
groups: [],
isDefaultUpdateServerURL: true,
enableChangeWatcher: false,
availableAppUpdates: [],
missingAppUpdates: [],
appStoreFailed: false,
appStoreDisabled: false,
isListFetched: false,
hideMissingUpdates: false,
hideAvailableUpdates: true,
openedWhatsNew: false,
openedUpdateChannelMenu: false,
}
},
computed: {
newVersionAvailableString() {
return t('updatenotification', 'A new version is available: <strong>{newVersionString}</strong>', {
newVersionString: this.newVersionString,
})
},
noteDelayedStableString() {
return t('updatenotification', 'Note that after a new release the update only shows up after the first minor release or later. We roll out new versions spread out over time to our users and sometimes skip a version when issues are found. Learn more about updates and release channels at {link}')
.replace('{link}', '<a href="https://nextcloud.com/release-channels/">https://nextcloud.com/release-channels/</a>')
},
lastCheckedOnString() {
return t('updatenotification', 'Checked on {lastCheckedDate}', {
lastCheckedDate: this.lastCheckedDate,
})
},
statusText() {
if (!this.isListFetched) {
return t('updatenotification', 'Checking apps for compatible versions')
}
if (this.appStoreDisabled) {
return t('updatenotification', 'Please make sure your config.php does not set <samp>appstoreenabled</samp> to false.')
}
if (this.appStoreFailed) {
return t('updatenotification', 'Could not connect to the App Store or no updates have been returned at all. Search manually for updates or make sure your server has access to the internet and can connect to the App Store.')
}
return this.missingAppUpdates.length === 0
? t('updatenotification', '<strong>All</strong> apps have a compatible version for this Nextcloud version available.', this)
: n('updatenotification', '<strong>%n</strong> app has no compatible version for this Nextcloud version available.', '<strong>%n</strong> apps have no compatible version for this Nextcloud version available.', this.missingAppUpdates.length)
},
channelList() {
const channelList = []
channelList.push({
text: t('updatenotification', 'Enterprise'),
longtext: t('updatenotification', 'For enterprise use. Provides always the latest patch level, but will not update to the next major release immediately. That update happens once Nextcloud GmbH has done additional hardening and testing for large-scale and mission-critical deployments. This channel is only available to customers and provides the Nextcloud Enterprise package.'),
icon: 'icon-star',
active: this.currentChannel === 'enterprise',
disabled: !this.hasValidSubscription,
action: this.changeReleaseChannelToEnterprise,
})
channelList.push({
text: t('updatenotification', 'Stable'),
longtext: t('updatenotification', 'The most recent stable version. It is suited for regular use and will always update to the latest major version.'),
icon: 'icon-checkmark',
active: this.currentChannel === 'stable',
action: this.changeReleaseChannelToStable,
})
channelList.push({
text: t('updatenotification', 'Beta'),
longtext: t('updatenotification', 'A pre-release version only for testing new features, not for production environments.'),
icon: 'icon-category-customization',
active: this.currentChannel === 'beta',
action: this.changeReleaseChannelToBeta,
})
if (this.isNonDefaultChannel) {
channelList.push({
text: this.currentChannel,
icon: 'icon-rename',
active: true,
action: () => {},
})
}
return channelList
},
isNonDefaultChannel() {
return this.currentChannel !== 'enterprise' && this.currentChannel !== 'stable' && this.currentChannel !== 'beta'
},
localizedChannelName() {
switch (this.currentChannel) {
case 'enterprise':
return t('updatenotification', 'Enterprise')
case 'stable':
return t('updatenotification', 'Stable')
case 'beta':
return t('updatenotification', 'Beta')
default:
return this.currentChannel
}
},
},
watch: {
notifyGroups(selectedOptions) {
if (!this.enableChangeWatcher) {
// The first time is when loading the app
this.enableChangeWatcher = true
return
}
const groups = this.notifyGroups.map(group => {
return group.id
})
OCP.AppConfig.setValue('updatenotification', 'notify_groups', JSON.stringify(groups))
},
isNewVersionAvailable() {
if (!this.isNewVersionAvailable) {
return
}
axios.get(generateOcsUrl('apps/updatenotification/api/v1/applist/{newVersion}', {
newVersion: this.newVersion,
})).then(({ data }) => {
this.availableAppUpdates = data.ocs.data.available
this.missingAppUpdates = data.ocs.data.missing
this.isListFetched = true
this.appStoreFailed = false
}).catch(({ data }) => {
this.availableAppUpdates = []
this.missingAppUpdates = []
this.appStoreDisabled = data.ocs.data.appstore_disabled
this.isListFetched = true
this.appStoreFailed = true
})
},
},
beforeMount() {
// Parse server data
const data = loadState('updatenotification', 'data')
this.newVersion = data.newVersion
this.newVersionString = data.newVersionString
this.lastCheckedDate = data.lastChecked
this.isUpdateChecked = data.isUpdateChecked
this.webUpdaterEnabled = data.webUpdaterEnabled
this.isWebUpdaterRecommended = data.isWebUpdaterRecommended
this.updaterEnabled = data.updaterEnabled
this.downloadLink = data.downloadLink
this.isNewVersionAvailable = data.isNewVersionAvailable
this.updateServerURL = data.updateServerURL
this.currentChannel = data.currentChannel
this.channels = data.channels
this.notifyGroups = data.notifyGroups
this.isDefaultUpdateServerURL = data.isDefaultUpdateServerURL
this.versionIsEol = data.versionIsEol
this.hasValidSubscription = data.hasValidSubscription
if (data.changes && data.changes.changelogURL) {
this.changelogURL = data.changes.changelogURL
}
if (data.changes && data.changes.whatsNew) {
if (data.changes.whatsNew.admin) {
this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.admin)
}
this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.regular)
}
},
mounted() {
this.searchGroup()
},
methods: {
searchGroup: debounce(async function(query) {
this.loadingGroups = true
try {
const response = await axios.get(generateOcsUrl('cloud/groups/details'), {
search: query,
limit: 20,
offset: 0,
})
this.groups = response.data.ocs.data.groups.sort(function(a, b) {
return a.displayname.localeCompare(b.displayname)
})
} catch (err) {
logger.error('Could not fetch groups', err)
} finally {
this.loadingGroups = false
}
}, 500),
/**
* Creates a new authentication token and loads the updater URL
*/
clickUpdaterButton() {
axios.get(generateUrl('/apps/updatenotification/credentials'))
.then(({ data }) => {
// create a form to send a proper post request to the updater
const form = document.createElement('form')
form.setAttribute('method', 'post')
form.setAttribute('action', getRootUrl() + '/updater/')
const hiddenField = document.createElement('input')
hiddenField.setAttribute('type', 'hidden')
hiddenField.setAttribute('name', 'updater-secret-input')
hiddenField.setAttribute('value', data)
form.appendChild(hiddenField)
document.body.appendChild(form)
form.submit()
})
},
changeReleaseChannelToEnterprise() {
this.changeReleaseChannel('enterprise')
},
changeReleaseChannelToStable() {
this.changeReleaseChannel('stable')
},
changeReleaseChannelToBeta() {
this.changeReleaseChannel('beta')
},
changeReleaseChannel(channel) {
this.currentChannel = channel
axios.post(generateUrl('/apps/updatenotification/channel'), {
channel: this.currentChannel,
}).then(({ data }) => {
showSuccess(data.data.message)
})
this.openedUpdateChannelMenu = false
},
toggleHideMissingUpdates() {
this.hideMissingUpdates = !this.hideMissingUpdates
},
toggleHideAvailableUpdates() {
this.hideAvailableUpdates = !this.hideAvailableUpdates
},
},
}
</script>
<style lang="scss" scoped>
#updatenotification {
& > * {
max-width: 900px;
}
.topMargin {
margin-top: 15px;
}
div.update,
p:not(.inlineblock) {
margin-bottom: 25px;
}
h2.inlineblock {
margin-top: 25px;
}
h3 {
&.clickable {
cursor: pointer;
.icon {
cursor: pointer;
}
}
&:first-of-type {
margin-top: 0;
}
}
h4 {
margin-block-end: 0.7rem;
}
.update-channel-selector {
display: flex;
align-items: center;
gap: 12px;
}
.icon {
display: inline-block;
margin-bottom: -3px;
}
.icon-triangle-s, .icon-triangle-n {
opacity: 0.5;
}
.applist {
margin-bottom: 25px;
}
.update-menu {
position: relative;
cursor: pointer;
margin-left: 3px;
display: inline-block;
.icon-update-menu {
cursor: inherit;
.icon-triangle-s {
display: inline-block;
vertical-align: middle;
cursor: inherit;
opacity: 1;
}
}
}
}
</style>
<style lang="scss">
// Make current selected update channel visually visible, remove if NcActionRadio is used
.update-channel-action[aria-checked=true] {
border-inline-start: 4px solid var(--color-primary-element);
&:hover, &:focus-within {
background-color: var(--color-primary-element-light-hover);
}
button {
background-color: var(--color-primary-element-light);
color: var(--color-primary-element-light-text);
}
}
// Ensure outline for focus-visible works even with background color of selected channel
.update-channel-action[aria-checked] {
margin-block: 2px;
}
#updatenotification {
/* override needed to replace yellow hover state with a dark one */
.update-menu .icon-star:hover,
.update-menu .icon-star:focus {
background-image: var(--icon-starred);
}
}
</style>
|