You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateNotification.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div id="updatenotification" class="followupsection">
  3. <div class="update">
  4. <template v-if="isNewVersionAvailable">
  5. <p v-if="versionIsEol">
  6. <span class="warning">
  7. <span class="icon icon-error-white" />
  8. {{ t('updatenotification', 'The version you are running is not maintained anymore. Please make sure to update to a supported version as soon as possible.') }}
  9. </span>
  10. </p>
  11. <p>
  12. <span v-html="newVersionAvailableString" /><br>
  13. <span v-if="!isListFetched" class="icon icon-loading-small" />
  14. <span v-html="statusText" />
  15. </p>
  16. <template v-if="missingAppUpdates.length">
  17. <h3 @click="toggleHideMissingUpdates">
  18. {{ t('updatenotification', 'Apps missing updates') }}
  19. <span v-if="!hideMissingUpdates" class="icon icon-triangle-n" />
  20. <span v-if="hideMissingUpdates" class="icon icon-triangle-s" />
  21. </h3>
  22. <ul v-if="!hideMissingUpdates" class="applist">
  23. <li v-for="(app, index) in missingAppUpdates" :key="index">
  24. <a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{ app.appName }} ↗</a>
  25. </li>
  26. </ul>
  27. </template>
  28. <template v-if="availableAppUpdates.length">
  29. <h3 @click="toggleHideAvailableUpdates">
  30. {{ t('updatenotification', 'Apps with available updates') }}
  31. <span v-if="!hideAvailableUpdates" class="icon icon-triangle-n" />
  32. <span v-if="hideAvailableUpdates" class="icon icon-triangle-s" />
  33. </h3>
  34. <ul v-if="!hideAvailableUpdates" class="applist">
  35. <li v-for="(app, index) in availableAppUpdates" :key="index">
  36. <a :href="'https://apps.nextcloud.com/apps/' + app.appId" :title="t('settings', 'View in store')">{{ app.appName }} ↗</a>
  37. </li>
  38. </ul>
  39. </template>
  40. <div>
  41. <a v-if="updaterEnabled"
  42. href="#"
  43. class="button primary"
  44. @click="clickUpdaterButton">{{ t('updatenotification', 'Open updater') }}</a>
  45. <a v-if="downloadLink"
  46. :href="downloadLink"
  47. class="button"
  48. :class="{ hidden: !updaterEnabled }">{{ t('updatenotification', 'Download now') }}</a>
  49. <div v-if="whatsNew" class="whatsNew">
  50. <div class="toggleWhatsNew">
  51. <a v-click-outside="hideMenu" class="button" @click="toggleMenu">{{ t('updatenotification', 'What\'s new?') }}</a>
  52. <div class="popovermenu" :class="{ 'menu-center': true, open: openedWhatsNew }">
  53. <PopoverMenu :menu="whatsNew" />
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <template v-else-if="!isUpdateChecked">
  60. {{ t('updatenotification', 'The update check is not yet finished. Please refresh the page.') }}
  61. </template>
  62. <template v-else>
  63. {{ t('updatenotification', 'Your version is up to date.') }}
  64. <span v-tooltip.auto="lastCheckedOnString" class="icon-info svg" />
  65. </template>
  66. <template v-if="!isDefaultUpdateServerURL">
  67. <p class="topMargin">
  68. <em>{{ t('updatenotification', 'A non-default update server is in use to be checked for updates:') }} <code>{{ updateServerURL }}</code></em>
  69. </p>
  70. </template>
  71. </div>
  72. <h3 class="update-channel-selector">
  73. {{ t('updatenotification', 'Update channel:') }}
  74. <div v-click-outside="closeUpdateChannelMenu" class="update-menu">
  75. <span class="icon-update-menu" @click="toggleUpdateChannelMenu">
  76. {{ localizedChannelName }}
  77. <span class="icon-triangle-s" />
  78. </span>
  79. <div class="popovermenu menu menu-center" :class="{ 'show-menu': openedUpdateChannelMenu}">
  80. <PopoverMenu :menu="channelList" />
  81. </div>
  82. </div>
  83. </h3>
  84. <span id="channel_save_msg" class="msg" /><br>
  85. <p>
  86. <em>{{ t('updatenotification', 'You can always update to a newer version. But you can never downgrade to a more stable version.') }}</em><br>
  87. <em>{{ t('updatenotification', 'Note that after a new release it can take some time before it shows up here. We roll out new versions spread out over time to our users and sometimes skip a version when issues are found.') }}</em>
  88. </p>
  89. <p id="oca_updatenotification_groups">
  90. {{ t('updatenotification', 'Notify members of the following groups about available updates:') }}
  91. <Multiselect v-model="notifyGroups"
  92. :options="availableGroups"
  93. :multiple="true"
  94. label="label"
  95. track-by="value"
  96. :tag-width="75" /><br>
  97. <em v-if="currentChannel === 'daily' || currentChannel === 'git'">{{ t('updatenotification', 'Only notification for app updates are available.') }}</em>
  98. <em v-if="currentChannel === 'daily'">{{ t('updatenotification', 'The selected update channel makes dedicated notifications for the server obsolete.') }}</em>
  99. <em v-if="currentChannel === 'git'">{{ t('updatenotification', 'The selected update channel does not support updates of the server.') }}</em>
  100. </p>
  101. </div>
  102. </template>
  103. <script>
  104. import { PopoverMenu, Multiselect } from '@nextcloud/vue'
  105. import { VTooltip } from 'v-tooltip'
  106. import ClickOutside from 'vue-click-outside'
  107. VTooltip.options.defaultHtml = false
  108. export default {
  109. name: 'UpdateNotification',
  110. components: {
  111. Multiselect,
  112. PopoverMenu,
  113. },
  114. directives: {
  115. ClickOutside,
  116. tooltip: VTooltip,
  117. },
  118. data: function() {
  119. return {
  120. newVersionString: '',
  121. lastCheckedDate: '',
  122. isUpdateChecked: false,
  123. updaterEnabled: true,
  124. versionIsEol: false,
  125. downloadLink: '',
  126. isNewVersionAvailable: false,
  127. hasValidSubscription: false,
  128. updateServerURL: '',
  129. changelogURL: '',
  130. whatsNewData: [],
  131. currentChannel: '',
  132. channels: [],
  133. notifyGroups: '',
  134. availableGroups: [],
  135. isDefaultUpdateServerURL: true,
  136. enableChangeWatcher: false,
  137. availableAppUpdates: [],
  138. missingAppUpdates: [],
  139. appStoreFailed: false,
  140. appStoreDisabled: false,
  141. isListFetched: false,
  142. hideMissingUpdates: false,
  143. hideAvailableUpdates: true,
  144. openedWhatsNew: false,
  145. openedUpdateChannelMenu: false,
  146. }
  147. },
  148. _$el: null,
  149. _$notifyGroups: null,
  150. computed: {
  151. newVersionAvailableString: function() {
  152. return t('updatenotification', 'A new version is available: <strong>{newVersionString}</strong>', {
  153. newVersionString: this.newVersionString,
  154. })
  155. },
  156. lastCheckedOnString: function() {
  157. return t('updatenotification', 'Checked on {lastCheckedDate}', {
  158. lastCheckedDate: this.lastCheckedDate,
  159. })
  160. },
  161. statusText: function() {
  162. if (!this.isListFetched) {
  163. return t('updatenotification', 'Checking apps for compatible updates')
  164. }
  165. if (this.appStoreDisabled) {
  166. return t('updatenotification', 'Please make sure your config.php does not set <samp>appstoreenabled</samp> to false.')
  167. }
  168. if (this.appStoreFailed) {
  169. return t('updatenotification', 'Could not connect to the appstore or the appstore returned no updates at all. Search manually for updates or make sure your server has access to the internet and can connect to the appstore.')
  170. }
  171. return this.missingAppUpdates.length === 0
  172. ? t('updatenotification', '<strong>All</strong> apps have an update for this version available', this)
  173. : n('updatenotification', '<strong>%n</strong> app has no update for this version available', '<strong>%n</strong> apps have no update for this version available', this.missingAppUpdates.length)
  174. },
  175. whatsNew: function() {
  176. if (this.whatsNewData.length === 0) {
  177. return null
  178. }
  179. const whatsNew = []
  180. for (const i in this.whatsNewData) {
  181. whatsNew[i] = { icon: 'icon-checkmark', longtext: this.whatsNewData[i] }
  182. }
  183. if (this.changelogURL) {
  184. whatsNew.push({
  185. href: this.changelogURL,
  186. text: t('updatenotification', 'View changelog'),
  187. icon: 'icon-link',
  188. target: '_blank',
  189. action: '',
  190. })
  191. }
  192. return whatsNew
  193. },
  194. channelList: function() {
  195. const channelList = []
  196. channelList.push({
  197. text: t('updatenotification', 'Enterprise'),
  198. 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.'),
  199. icon: 'icon-star',
  200. active: this.currentChannel === 'enterprise',
  201. disabled: !this.hasValidSubscription,
  202. action: this.changeReleaseChannelToEnterprise,
  203. })
  204. channelList.push({
  205. text: t('updatenotification', 'Stable'),
  206. longtext: t('updatenotification', 'The most recent stable version. It is suited for regular use and will always update to the latest major version.'),
  207. icon: 'icon-checkmark',
  208. active: this.currentChannel === 'stable',
  209. action: this.changeReleaseChannelToStable,
  210. })
  211. channelList.push({
  212. text: t('updatenotification', 'Beta'),
  213. longtext: t('updatenotification', 'A pre-release version only for testing new features, not for production environments.'),
  214. icon: 'icon-category-customization',
  215. active: this.currentChannel === 'beta',
  216. action: this.changeReleaseChannelToBeta,
  217. })
  218. if (this.isNonDefaultChannel) {
  219. channelList.push({
  220. text: this.currentChannel,
  221. icon: 'icon-rename',
  222. active: true,
  223. })
  224. }
  225. return channelList
  226. },
  227. isNonDefaultChannel: function() {
  228. return this.currentChannel !== 'enterprise' && this.currentChannel !== 'stable' && this.currentChannel !== 'beta'
  229. },
  230. localizedChannelName: function() {
  231. switch (this.currentChannel) {
  232. case 'enterprise':
  233. return t('updatenotification', 'Enterprise')
  234. case 'stable':
  235. return t('updatenotification', 'Stable')
  236. case 'beta':
  237. return t('updatenotification', 'Beta')
  238. default:
  239. return this.currentChannel
  240. }
  241. },
  242. },
  243. watch: {
  244. notifyGroups: function(selectedOptions) {
  245. if (!this.enableChangeWatcher) {
  246. return
  247. }
  248. const selectedGroups = []
  249. _.each(selectedOptions, function(group) {
  250. selectedGroups.push(group.value)
  251. })
  252. OCP.AppConfig.setValue('updatenotification', 'notify_groups', JSON.stringify(selectedGroups))
  253. },
  254. isNewVersionAvailable: function() {
  255. if (!this.isNewVersionAvailable) {
  256. return
  257. }
  258. $.ajax({
  259. url: OC.linkToOCS('apps/updatenotification/api/v1/applist', 2) + this.newVersion,
  260. type: 'GET',
  261. beforeSend: function(request) {
  262. request.setRequestHeader('Accept', 'application/json')
  263. },
  264. success: function(response) {
  265. this.availableAppUpdates = response.ocs.data.available
  266. this.missingAppUpdates = response.ocs.data.missing
  267. this.isListFetched = true
  268. this.appStoreFailed = false
  269. }.bind(this),
  270. error: function(xhr) {
  271. this.availableAppUpdates = []
  272. this.missingAppUpdates = []
  273. this.appStoreDisabled = xhr.responseJSON.ocs.data.appstore_disabled
  274. this.isListFetched = true
  275. this.appStoreFailed = true
  276. }.bind(this),
  277. })
  278. },
  279. },
  280. beforeMount: function() {
  281. // Parse server data
  282. const data = JSON.parse($('#updatenotification').attr('data-json'))
  283. this.newVersion = data.newVersion
  284. this.newVersionString = data.newVersionString
  285. this.lastCheckedDate = data.lastChecked
  286. this.isUpdateChecked = data.isUpdateChecked
  287. this.updaterEnabled = data.updaterEnabled
  288. this.downloadLink = data.downloadLink
  289. this.isNewVersionAvailable = data.isNewVersionAvailable
  290. this.updateServerURL = data.updateServerURL
  291. this.currentChannel = data.currentChannel
  292. this.channels = data.channels
  293. this.notifyGroups = data.notifyGroups
  294. this.isDefaultUpdateServerURL = data.isDefaultUpdateServerURL
  295. this.versionIsEol = data.versionIsEol
  296. this.hasValidSubscription = data.hasValidSubscription
  297. if (data.changes && data.changes.changelogURL) {
  298. this.changelogURL = data.changes.changelogURL
  299. }
  300. if (data.changes && data.changes.whatsNew) {
  301. if (data.changes.whatsNew.admin) {
  302. this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.admin)
  303. }
  304. this.whatsNewData = this.whatsNewData.concat(data.changes.whatsNew.regular)
  305. }
  306. },
  307. mounted: function() {
  308. this._$el = $(this.$el)
  309. this._$notifyGroups = this._$el.find('#oca_updatenotification_groups_list')
  310. this._$notifyGroups.on('change', function() {
  311. this.$emit('input')
  312. }.bind(this))
  313. $.ajax({
  314. url: OC.linkToOCS('cloud', 2) + '/groups',
  315. dataType: 'json',
  316. success: function(data) {
  317. const results = []
  318. $.each(data.ocs.data.groups, function(i, group) {
  319. results.push({ value: group, label: group })
  320. })
  321. this.availableGroups = results
  322. this.enableChangeWatcher = true
  323. }.bind(this),
  324. })
  325. },
  326. methods: {
  327. /**
  328. * Creates a new authentication token and loads the updater URL
  329. */
  330. clickUpdaterButton: function() {
  331. $.ajax({
  332. url: OC.generateUrl('/apps/updatenotification/credentials'),
  333. }).success(function(token) {
  334. // create a form to send a proper post request to the updater
  335. const form = document.createElement('form')
  336. form.setAttribute('method', 'post')
  337. form.setAttribute('action', OC.getRootPath() + '/updater/')
  338. const hiddenField = document.createElement('input')
  339. hiddenField.setAttribute('type', 'hidden')
  340. hiddenField.setAttribute('name', 'updater-secret-input')
  341. hiddenField.setAttribute('value', token)
  342. form.appendChild(hiddenField)
  343. document.body.appendChild(form)
  344. form.submit()
  345. })
  346. },
  347. changeReleaseChannelToEnterprise: function() {
  348. this.changeReleaseChannel('enterprise')
  349. },
  350. changeReleaseChannelToStable: function() {
  351. this.changeReleaseChannel('stable')
  352. },
  353. changeReleaseChannelToBeta: function() {
  354. this.changeReleaseChannel('beta')
  355. },
  356. changeReleaseChannel: function(channel) {
  357. this.currentChannel = channel
  358. $.ajax({
  359. url: OC.generateUrl('/apps/updatenotification/channel'),
  360. type: 'POST',
  361. data: {
  362. 'channel': this.currentChannel,
  363. },
  364. success: function(data) {
  365. OC.msg.finishedAction('#channel_save_msg', data)
  366. },
  367. })
  368. this.openedUpdateChannelMenu = false
  369. },
  370. toggleUpdateChannelMenu: function() {
  371. this.openedUpdateChannelMenu = !this.openedUpdateChannelMenu
  372. },
  373. toggleHideMissingUpdates: function() {
  374. this.hideMissingUpdates = !this.hideMissingUpdates
  375. },
  376. toggleHideAvailableUpdates: function() {
  377. this.hideAvailableUpdates = !this.hideAvailableUpdates
  378. },
  379. toggleMenu: function() {
  380. this.openedWhatsNew = !this.openedWhatsNew
  381. },
  382. closeUpdateChannelMenu: function() {
  383. this.openedUpdateChannelMenu = false
  384. },
  385. hideMenu: function() {
  386. this.openedWhatsNew = false
  387. },
  388. },
  389. }
  390. </script>
  391. <style lang="scss" scoped>
  392. #updatenotification {
  393. margin-top: -25px;
  394. margin-bottom: 200px;
  395. div.update,
  396. p:not(.inlineblock) {
  397. margin-bottom: 25px;
  398. }
  399. h2.inlineblock {
  400. margin-top: 25px;
  401. }
  402. h3 {
  403. cursor: pointer;
  404. .icon {
  405. cursor: pointer;
  406. }
  407. &:first-of-type {
  408. margin-top: 0;
  409. }
  410. &.update-channel-selector {
  411. display: inline-block;
  412. cursor: inherit;
  413. }
  414. }
  415. .icon {
  416. display: inline-block;
  417. margin-bottom: -3px;
  418. }
  419. .icon-triangle-s, .icon-triangle-n {
  420. opacity: 0.5;
  421. }
  422. .whatsNew {
  423. display: inline-block;
  424. }
  425. .toggleWhatsNew {
  426. position: relative;
  427. }
  428. .popovermenu {
  429. p {
  430. margin-bottom: 0;
  431. width: 100%;
  432. }
  433. margin-top: 5px;
  434. width: 300px;
  435. }
  436. .applist {
  437. margin-bottom: 25px;
  438. }
  439. .update-menu {
  440. position: relative;
  441. cursor: pointer;
  442. margin-left: 3px;
  443. display: inline-block;
  444. .icon-update-menu {
  445. cursor: inherit;
  446. .icon-triangle-s {
  447. display: inline-block;
  448. vertical-align: middle;
  449. cursor: inherit;
  450. opacity: 1;
  451. }
  452. }
  453. .popovermenu {
  454. display: none;
  455. top: 28px;
  456. &.show-menu {
  457. display: block;
  458. }
  459. }
  460. }
  461. }
  462. </style>
  463. <style lang="scss">
  464. /* override needed to make menu wider */
  465. #updatenotification .popovermenu {
  466. p {
  467. margin-top: 5px;
  468. width: 100%;
  469. }
  470. margin-top: 5px;
  471. width: 300px;
  472. }
  473. /* override needed to replace yellow hover state with a dark one */
  474. #updatenotification .update-menu .icon-star:hover,
  475. #updatenotification .update-menu .icon-star:focus {
  476. background-image: var(--icon-star-000);
  477. }
  478. #updatenotification .topMargin {
  479. margin-top: 15px;
  480. }
  481. </style>