1818import Cookies from 'js-cookie'
1919import message from 'ant-design-vue/es/message'
2020import notification from 'ant-design-vue/es/notification'
21+ import semver from 'semver'
2122
2223import { vueProps } from '@/vue-app'
2324import router from '@/router'
2425import store from '@/store'
2526import { oauthlogin , login , logout , api } from '@/api'
2627import { i18n } from '@/locales'
28+ import { axios } from '../../utils/request'
29+ import { getParsedVersion } from '@/utils/util'
2730
2831import {
2932 ACCESS_TOKEN ,
3033 CURRENT_PROJECT ,
3134 DEFAULT_THEME ,
3235 APIS ,
3336 ZONES ,
37+ SHOW_SECURTIY_GROUPS ,
3438 TIMEZONE_OFFSET ,
3539 USE_BROWSER_TIMEZONE ,
3640 HEADER_NOTICES ,
3741 DOMAIN_STORE ,
3842 DARK_MODE ,
3943 CUSTOM_COLUMNS ,
4044 OAUTH_DOMAIN ,
41- OAUTH_PROVIDER
45+ OAUTH_PROVIDER ,
46+ LATEST_CS_VERSION
4247} from '@/store/mutation-types'
4348
4449const user = {
@@ -120,6 +125,10 @@ const user = {
120125 state . zones = zones
121126 vueProps . $localStorage . set ( ZONES , zones )
122127 } ,
128+ SET_SHOW_SECURITY_GROUPS : ( state , show ) => {
129+ state . showSecurityGroups = show
130+ vueProps . $localStorage . set ( SHOW_SECURTIY_GROUPS , show )
131+ } ,
123132 SET_DOMAIN_STORE ( state , domainStore ) {
124133 state . domainStore = domainStore
125134 vueProps . $localStorage . set ( DOMAIN_STORE , domainStore )
@@ -167,6 +176,12 @@ const user = {
167176 } ,
168177 SET_OAUTH_PROVIDER_USED_TO_LOGIN : ( state , provider ) => {
169178 vueProps . $localStorage . set ( OAUTH_PROVIDER , provider )
179+ } ,
180+ SET_LATEST_VERSION : ( state , version ) => {
181+ if ( version ?. fetchedTs > 0 ) {
182+ vueProps . $localStorage . set ( LATEST_CS_VERSION , version )
183+ state . latestVersion = version
184+ }
170185 }
171186 } ,
172187
@@ -212,6 +227,8 @@ const user = {
212227 commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
213228 commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
214229 commit ( 'SET_LOGIN_FLAG' , false )
230+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
231+ commit ( 'SET_LATEST_VERSION' , latestVersion )
215232 notification . destroy ( )
216233
217234 resolve ( )
@@ -259,6 +276,8 @@ const user = {
259276 commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
260277 commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
261278 commit ( 'SET_LOGIN_FLAG' , false )
279+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
280+ commit ( 'SET_LATEST_VERSION' , latestVersion )
262281 notification . destroy ( )
263282
264283 resolve ( )
@@ -276,14 +295,18 @@ const user = {
276295 const cachedUseBrowserTimezone = vueProps . $localStorage . get ( USE_BROWSER_TIMEZONE , false )
277296 const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
278297 const domainStore = vueProps . $localStorage . get ( DOMAIN_STORE , { } )
298+ const cachedShowSecurityGroups = vueProps . $localStorage . get ( SHOW_SECURTIY_GROUPS , false )
279299 const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
300+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
280301 const hasAuth = Object . keys ( cachedApis ) . length > 0
281302
282303 commit ( 'SET_DOMAIN_STORE' , domainStore )
283304 commit ( 'SET_DARK_MODE' , darkMode )
305+ commit ( 'SET_LATEST_VERSION' , latestVersion )
284306 if ( hasAuth ) {
285307 console . log ( 'Login detected, using cached APIs' )
286308 commit ( 'SET_ZONES' , cachedZones )
309+ commit ( 'SET_SHOW_SECURITY_GROUPS' , cachedShowSecurityGroups )
287310 commit ( 'SET_APIS' , cachedApis )
288311 commit ( 'SET_TIMEZONE_OFFSET' , cachedTimezoneOffset )
289312 commit ( 'SET_USE_BROWSER_TIMEZONE' , cachedUseBrowserTimezone )
@@ -294,6 +317,7 @@ const user = {
294317 const result = response . listusersresponse . user [ 0 ]
295318 commit ( 'SET_INFO' , result )
296319 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
320+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
297321 resolve ( cachedApis )
298322 } ) . catch ( error => {
299323 reject ( error )
@@ -314,7 +338,10 @@ const user = {
314338 const apiName = api . name
315339 apis [ apiName ] = {
316340 params : api . params ,
317- response : api . response
341+ response : api . response ,
342+ isasync : api . isasync ,
343+ since : api . since ,
344+ description : api . description
318345 }
319346 }
320347 commit ( 'SET_APIS' , apis )
@@ -329,16 +356,54 @@ const user = {
329356 } ) . catch ( error => {
330357 reject ( error )
331358 } )
359+
360+ api ( 'listNetworks' , { restartrequired : true , forvpc : false } ) . then ( response => {
361+ if ( response . listnetworksresponse . count > 0 ) {
362+ store . dispatch ( 'AddHeaderNotice' , {
363+ key : 'NETWORK_RESTART_REQUIRED' ,
364+ title : i18n . global . t ( 'label.network.restart.required' ) ,
365+ description : i18n . global . t ( 'message.network.restart.required' ) ,
366+ path : '/guestnetwork/' ,
367+ query : { restartrequired : true , forvpc : false } ,
368+ status : 'done' ,
369+ timestamp : new Date ( )
370+ } )
371+ }
372+ } ) . catch ( ignored => { } )
373+
374+ api ( 'listVPCs' , { restartrequired : true } ) . then ( response => {
375+ if ( response . listvpcsresponse . count > 0 ) {
376+ store . dispatch ( 'AddHeaderNotice' , {
377+ key : 'VPC_RESTART_REQUIRED' ,
378+ title : i18n . global . t ( 'label.vpc.restart.required' ) ,
379+ description : i18n . global . t ( 'message.vpc.restart.required' ) ,
380+ path : '/vpc/' ,
381+ query : { restartrequired : true } ,
382+ status : 'done' ,
383+ timestamp : new Date ( )
384+ } )
385+ }
386+ } ) . catch ( ignored => { } )
332387 }
333388
334389 api ( 'listUsers' , { username : Cookies . get ( 'username' ) } ) . then ( response => {
335390 const result = response . listusersresponse . user [ 0 ]
336391 commit ( 'SET_INFO' , result )
337392 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
393+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
338394 } ) . catch ( error => {
339395 reject ( error )
340396 } )
341397
398+ api (
399+ 'listNetworkServiceProviders' ,
400+ { name : 'SecurityGroupProvider' , state : 'Enabled' }
401+ ) . then ( response => {
402+ const showSecurityGroups = response . listnetworkserviceprovidersresponse . count > 0
403+ commit ( 'SET_SHOW_SECURITY_GROUPS' , showSecurityGroups )
404+ } ) . catch ( ignored => {
405+ } )
406+
342407 api ( 'listCapabilities' ) . then ( response => {
343408 const result = response . listcapabilitiesresponse . capability
344409 commit ( 'SET_FEATURES' , result )
@@ -348,6 +413,9 @@ const user = {
348413 if ( result && result . customhypervisordisplayname ) {
349414 commit ( 'SET_CUSTOM_HYPERVISOR_NAME' , result . customhypervisordisplayname )
350415 }
416+ if ( result && result . securitygroupsenabled ) {
417+ commit ( 'SET_SHOW_SECURITY_GROUPS' , result . securitygroupsenabled )
418+ }
351419 } ) . catch ( error => {
352420 reject ( error )
353421 } )
@@ -364,6 +432,8 @@ const user = {
364432 commit ( 'SET_CLOUDIAN' , cloudian )
365433 } ) . catch ( ignored => {
366434 } )
435+ } ) . catch ( error => {
436+ console . error ( error )
367437 } )
368438 } ,
369439
@@ -485,6 +555,29 @@ const user = {
485555 SetDomainStore ( { commit } , domainStore ) {
486556 commit ( 'SET_DOMAIN_STORE' , domainStore )
487557 } ,
558+ SetCsLatestVersion ( { commit } , rolename ) {
559+ const lastFetchTs = store . getters . latestVersion ?. fetchedTs ? store . getters . latestVersion . fetchedTs : 0
560+ if ( rolename === 'Root Admin' && ( + new Date ( ) - lastFetchTs ) > 24 * 60 * 60 * 1000 ) {
561+ axios . get (
562+ 'https://api.github.com/repos/apache/cloudstack/releases'
563+ ) . then ( response => {
564+ let latestReleaseVersion = getParsedVersion ( response [ 0 ] . tag_name )
565+ let latestTag = response [ 0 ] . tag_name
566+
567+ for ( const release of response ) {
568+ if ( release . tag_name . toLowerCase ( ) . includes ( 'rc' ) ) {
569+ continue
570+ }
571+ const parsedVersion = getParsedVersion ( release . tag_name )
572+ if ( semver . gte ( parsedVersion , latestReleaseVersion ) ) {
573+ latestReleaseVersion = parsedVersion
574+ latestTag = release . tag_name
575+ commit ( 'SET_LATEST_VERSION' , { version : latestTag , fetchedTs : ( + new Date ( ) ) } )
576+ }
577+ }
578+ } ) . catch ( ignored => { } )
579+ }
580+ } ,
488581 SetDarkMode ( { commit } , darkMode ) {
489582 commit ( 'SET_DARK_MODE' , darkMode )
490583 } ,
@@ -497,4 +590,4 @@ const user = {
497590 }
498591}
499592
500- export default user
593+ export default user
0 commit comments