router.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var misc = require('utils/misc');
  19. var App = require('app');
  20. App.WizardRoute = Em.Route.extend({
  21. gotoStep0: Em.Router.transitionTo('step0'),
  22. gotoStep1: Em.Router.transitionTo('step1'),
  23. gotoStep2: Em.Router.transitionTo('step2'),
  24. gotoStep3: Em.Router.transitionTo('step3'),
  25. gotoStep4: Em.Router.transitionTo('step4'),
  26. gotoStep5: Em.Router.transitionTo('step5'),
  27. gotoStep6: Em.Router.transitionTo('step6'),
  28. gotoStep7: Em.Router.transitionTo('step7'),
  29. gotoStep8: Em.Router.transitionTo('step8'),
  30. gotoStep9: Em.Router.transitionTo('step9'),
  31. gotoStep10: Em.Router.transitionTo('step10'),
  32. isRoutable: function() {
  33. return (typeof this.get('route') === 'string' && App.router.get('loggedIn'));
  34. }.property('App.router.loggedIn')
  35. });
  36. App.Router = Em.Router.extend({
  37. enableLogging: true,
  38. isFwdNavigation: true,
  39. backBtnForHigherStep: false,
  40. transitionInProgress: false,
  41. /**
  42. * Path for local login page. This page will be always accessible without
  43. * redirect to auth server different from ambari-server. Used in some types of
  44. * authorizations like knox sso.
  45. *
  46. * @type {string}
  47. */
  48. localUserAuthUrl: '/login/local',
  49. /**
  50. * LocalStorage property <code>redirectsCount</code> from <code>tmp</code> namespace
  51. * will be incremented by each redirect action performed by UI and reset on success login.
  52. * <code>redirectsLimitCount</code> determines maximum redirect tries. When redirects count overflow
  53. * then something goes wrong and we have to inform user about the problem.
  54. *
  55. * @type {number}
  56. */
  57. redirectsLimitCount: 0,
  58. /**
  59. * Is true, if cluster.provisioning_state is equal to 'INSTALLED'
  60. * @type {Boolean}
  61. */
  62. clusterInstallCompleted: false,
  63. /**
  64. * user prefered path to route
  65. */
  66. preferedPath: null,
  67. setNavigationFlow: function (step) {
  68. var matches = step.match(/\d+$/);
  69. var newStep;
  70. if (matches) {
  71. newStep = parseInt(matches[0]);
  72. }
  73. var previousStep = parseInt(this.getInstallerCurrentStep());
  74. this.set('isFwdNavigation', newStep >= previousStep);
  75. },
  76. clearAllSteps: function () {
  77. this.get('installerController').clear();
  78. this.get('addHostController').clear();
  79. this.get('addServiceController').clear();
  80. this.get('backgroundOperationsController').clear();
  81. for (var i = 1; i < 11; i++) {
  82. this.set('wizardStep' + i + 'Controller.hasSubmitted', false);
  83. this.set('wizardStep' + i + 'Controller.isDisabled', true);
  84. }
  85. },
  86. /**
  87. * Temporary fix for getting cluster name
  88. * @return {*}
  89. */
  90. getClusterName: function () {
  91. return App.router.get('clusterController').get('clusterName');
  92. },
  93. /**
  94. * Get current step of Installer wizard
  95. * @return {*}
  96. */
  97. getInstallerCurrentStep: function () {
  98. return this.getWizardCurrentStep('installer');
  99. },
  100. /**
  101. * Get current step for <code>wizardType</code> wizard
  102. * @param wizardType one of <code>installer</code>, <code>addHost</code>, <code>addServices</code>
  103. */
  104. getWizardCurrentStep: function (wizardType) {
  105. var currentStep = App.db.getWizardCurrentStep(wizardType);
  106. if (!currentStep) {
  107. currentStep = wizardType === 'installer' ? '0' : '1';
  108. }
  109. return currentStep;
  110. },
  111. /**
  112. * @type {boolean}
  113. */
  114. loggedIn: App.db.getAuthenticated(),
  115. loginName: function() {
  116. return this.getLoginName();
  117. }.property('loggedIn'),
  118. getAuthenticated: function () {
  119. var dfd = $.Deferred();
  120. var self = this;
  121. var auth = App.db.getAuthenticated();
  122. App.ajax.send({
  123. name: 'router.login.clusters',
  124. sender: this,
  125. success: 'onAuthenticationSuccess',
  126. error: 'onAuthenticationError'
  127. }).complete(function (xhr) {
  128. if (xhr.isResolved()) {
  129. // if server knows the user and user authenticated by UI
  130. if (auth) {
  131. dfd.resolve(self.get('loggedIn'));
  132. // if server knows the user but UI don't, check the response header
  133. // and try to authorize
  134. } else if (xhr.getResponseHeader('User')) {
  135. var user = xhr.getResponseHeader('User');
  136. App.ajax.send({
  137. name: 'router.login',
  138. sender: self,
  139. data: {
  140. usr: user,
  141. loginName: encodeURIComponent(user)
  142. },
  143. success: 'loginSuccessCallback',
  144. error: 'loginErrorCallback'
  145. });
  146. } else {
  147. self.setAuthenticated(false);
  148. dfd.resolve(false);
  149. }
  150. } else {
  151. //if provisioning state unreachable then consider user as unauthenticated
  152. self.setAuthenticated(false);
  153. dfd.resolve(false);
  154. }
  155. });
  156. return dfd.promise();
  157. },
  158. /**
  159. * Response for <code>/clusters?fields=Clusters/provisioning_state</code>
  160. * @type {null|object}
  161. */
  162. clusterData: null,
  163. onAuthenticationSuccess: function (data) {
  164. if (App.db.getAuthenticated() === true) {
  165. this.set('clusterData', data);
  166. this.setAuthenticated(true);
  167. if (data.items.length) {
  168. this.setClusterInstalled(data);
  169. }
  170. }
  171. },
  172. /**
  173. * If authentication failed, need to check for jwt auth url
  174. * and redirect user if current location is not <code>localUserAuthUrl</code>
  175. *
  176. * @param {?object} data
  177. */
  178. onAuthenticationError: function (data) {
  179. if (data.status === 403) {
  180. try {
  181. var responseJson = JSON.parse(data.responseText);
  182. if (responseJson.jwtProviderUrl && this.get('location.lastSetURL') !== this.get('localUserAuthUrl')) {
  183. this.redirectByURL(responseJson.jwtProviderUrl + encodeURIComponent(this.getCurrentLocationUrl()));
  184. }
  185. } catch (e) {
  186. } finally {
  187. this.setAuthenticated(false);
  188. }
  189. } else if (data.status >= 500) {
  190. this.setAuthenticated(false);
  191. this.loginErrorCallback(data);
  192. }
  193. },
  194. setAuthenticated: function (authenticated) {
  195. App.db.setAuthenticated(authenticated);
  196. this.set('loggedIn', authenticated);
  197. },
  198. getLoginName: function () {
  199. return App.db.getLoginName();
  200. },
  201. setLoginName: function (loginName) {
  202. App.db.setLoginName(loginName);
  203. },
  204. /**
  205. * Set user model to local storage
  206. * @param user
  207. */
  208. setUser: function (user) {
  209. App.db.setUser(user);
  210. },
  211. /**
  212. * Get user model from local storage
  213. * @return {*}
  214. */
  215. getUser: function () {
  216. return App.db.getUser();
  217. },
  218. setUserLoggedIn: function(userName) {
  219. this.setAuthenticated(true);
  220. this.setLoginName(userName);
  221. this.setUser(App.User.find().findProperty('id', userName));
  222. App.db.set('tmp', 'redirectsCount', 0);
  223. },
  224. /**
  225. * Set `clusterInstallCompleted` property based on cluster info response.
  226. *
  227. * @param {Object} clusterObject
  228. **/
  229. setClusterInstalled: function(clusterObject) {
  230. this.set('clusterInstallCompleted', clusterObject.items[0].Clusters.provisioning_state === 'INSTALLED')
  231. },
  232. login: function () {
  233. var controller = this.get('loginController');
  234. var loginName = controller.get('loginName');
  235. controller.set('loginName', loginName);
  236. var hash = misc.utf8ToB64(loginName + ":" + controller.get('password'));
  237. var usr = '';
  238. if (App.get('testMode')) {
  239. if (loginName === "admin" && controller.get('password') === 'admin') {
  240. usr = 'admin';
  241. } else if (loginName === 'user' && controller.get('password') === 'user') {
  242. usr = 'user';
  243. }
  244. }
  245. App.ajax.send({
  246. name: 'router.login',
  247. sender: this,
  248. data: {
  249. auth: "Basic " + hash,
  250. usr: usr,
  251. loginName: encodeURIComponent(loginName)
  252. },
  253. beforeSend: 'authBeforeSend',
  254. success: 'loginSuccessCallback',
  255. error: 'loginErrorCallback'
  256. });
  257. },
  258. authBeforeSend: function(opt, xhr, data) {
  259. xhr.setRequestHeader("Authorization", data.auth);
  260. },
  261. loginSuccessCallback: function(data, opt, params) {
  262. var self = this;
  263. App.router.set('loginController.isSubmitDisabled', false);
  264. App.usersMapper.map({"items": [data]});
  265. this.setUserLoggedIn(decodeURIComponent(params.loginName));
  266. var requestData = {
  267. loginName: params.loginName,
  268. loginData: data
  269. };
  270. App.router.get('clusterController').loadAuthorizations().complete(function() {
  271. // no need to load cluster data if it's already loaded
  272. if (self.get('clusterData')) {
  273. self.loginGetClustersSuccessCallback(self.get('clusterData'), {}, requestData);
  274. }
  275. else {
  276. App.ajax.send({
  277. name: 'router.login.clusters',
  278. sender: self,
  279. data: requestData,
  280. success: 'loginGetClustersSuccessCallback'
  281. });
  282. }
  283. });
  284. },
  285. loginErrorCallback: function(request) {
  286. var controller = this.get('loginController');
  287. this.setAuthenticated(false);
  288. if (request.status > 400) {
  289. var responseMessage = request.responseText;
  290. try{
  291. responseMessage = JSON.parse(request.responseText).message;
  292. }catch(e){}
  293. }
  294. if (request.status == 403) {
  295. controller.postLogin(true, false, responseMessage);
  296. } else if (request.status == 500) {
  297. controller.postLogin(false, false, responseMessage);
  298. } else {
  299. controller.postLogin(false, false, null);
  300. }
  301. },
  302. /**
  303. * success callback of login request
  304. * @param {object} clustersData
  305. * @param {object} opt
  306. * @param {object} params
  307. */
  308. loginGetClustersSuccessCallback: function (clustersData, opt, params) {
  309. var privileges = params.loginData.privileges || [];
  310. var router = this;
  311. var isAdmin = privileges.mapProperty('PrivilegeInfo.permission_name').contains('AMBARI.ADMINISTRATOR');
  312. App.set('isAdmin', isAdmin);
  313. if (clustersData.items.length) {
  314. var clusterPermissions = privileges.
  315. filterProperty('PrivilegeInfo.cluster_name', clustersData.items[0].Clusters.cluster_name).
  316. mapProperty('PrivilegeInfo.permission_name');
  317. //cluster installed
  318. router.setClusterInstalled(clustersData);
  319. if (clusterPermissions.contains('CLUSTER.ADMINISTRATOR')) {
  320. App.setProperties({
  321. isAdmin: true,
  322. isOperator: true
  323. });
  324. }
  325. if (isAdmin || clusterPermissions.contains('CLUSTER.USER') || clusterPermissions.contains('CLUSTER.ADMINISTRATOR')) {
  326. router.transitionToApp();
  327. } else {
  328. router.transitionToViews();
  329. }
  330. } else {
  331. if (isAdmin) {
  332. router.transitionToAdminView();
  333. } else {
  334. router.transitionToViews();
  335. }
  336. }
  337. App.set('isPermissionDataLoaded', true);
  338. App.router.get('userSettingsController').dataLoading();
  339. },
  340. /**
  341. * redirect user to Admin View
  342. * @returns {$.ajax}
  343. */
  344. transitionToAdminView: function() {
  345. return App.ajax.send({
  346. name: 'ambari.service.load_server_version',
  347. sender: this,
  348. success: 'adminViewInfoSuccessCallback',
  349. error: 'adminViewInfoErrorCallback'
  350. });
  351. },
  352. /**
  353. * redirect user to application Dashboard
  354. */
  355. transitionToApp: function () {
  356. var router = this;
  357. if (!router.restorePreferedPath()) {
  358. router.getSection(function (route) {
  359. router.transitionTo(route);
  360. });
  361. }
  362. },
  363. /**
  364. * redirect user to application Views
  365. */
  366. transitionToViews: function() {
  367. App.router.get('mainViewsController').loadAmbariViews();
  368. this.transitionTo('main.views.index');
  369. },
  370. adminViewInfoSuccessCallback: function(data) {
  371. var components = Em.get(data,'components');
  372. if (Em.isArray(components)) {
  373. var mappedVersions = components.map(function(component) {
  374. if (Em.get(component, 'RootServiceComponents.component_version')) {
  375. return Em.get(component, 'RootServiceComponents.component_version');
  376. }
  377. }),
  378. sortedMappedVersions = mappedVersions.sort(),
  379. latestVersion = sortedMappedVersions[sortedMappedVersions.length-1];
  380. window.location.replace('/views/ADMIN_VIEW/' + latestVersion + '/INSTANCE/#/');
  381. }
  382. },
  383. adminViewInfoErrorCallback: function() {
  384. this.transitionToViews();
  385. },
  386. getSection: function (callback) {
  387. if (App.get('testMode')) {
  388. if (App.alwaysGoToInstaller) {
  389. callback('installer');
  390. } else {
  391. callback('main.dashboard.index');
  392. }
  393. } else {
  394. if (this.get('clusterInstallCompleted')) {
  395. App.router.get('wizardWatcherController').getUser().complete(function() {
  396. App.clusterStatus.updateFromServer(false).complete(function () {
  397. var route = 'main.dashboard.index';
  398. var clusterStatusOnServer = App.clusterStatus.get('value');
  399. if (clusterStatusOnServer) {
  400. var wizardControllerRoutes = require('data/controller_route');
  401. var wizardControllerRoute = wizardControllerRoutes.findProperty('wizardControllerName', clusterStatusOnServer.wizardControllerName);
  402. if (wizardControllerRoute && !App.router.get('wizardWatcherController').get('isNonWizardUser')) {
  403. route = wizardControllerRoute.route;
  404. }
  405. }
  406. if (wizardControllerRoute && wizardControllerRoute.wizardControllerName === 'mainAdminStackAndUpgradeController') {
  407. var clusterController = App.router.get('clusterController');
  408. clusterController.loadClusterName().done(function(){
  409. clusterController.restoreUpgradeState().done(function(){
  410. callback(route);
  411. });
  412. });
  413. } else {
  414. callback(route);
  415. }
  416. });
  417. });
  418. } else {
  419. callback('installer');
  420. }
  421. }
  422. },
  423. logOff: function (context) {
  424. var self = this;
  425. $('title').text(Em.I18n.t('app.name'));
  426. App.router.get('mainController').stopPolling();
  427. // App.db.cleanUp() must be called before router.clearAllSteps().
  428. // otherwise, this.set('installerController.currentStep, 0) would have no effect
  429. // since it's a computed property but we are not setting it as a dependent of App.db.
  430. App.db.cleanUp();
  431. App.setProperties({
  432. isAdmin: false,
  433. auth: null,
  434. isOperator: false,
  435. isPermissionDataLoaded: false
  436. });
  437. this.set('loggedIn', false);
  438. this.clearAllSteps();
  439. this.set('loginController.loginName', '');
  440. this.set('loginController.password', '');
  441. // When logOff is called by Sign Out button, context contains event object. As it is only case we should send logoff request, we are checking context below.
  442. if (!App.get('testMode') && context) {
  443. App.ajax.send({
  444. name: 'router.logoff',
  445. sender: this,
  446. success: 'logOffSuccessCallback',
  447. error: 'logOffErrorCallback'
  448. }).complete(function() {
  449. self.logoffRedirect(context);
  450. });
  451. } else {
  452. this.logoffRedirect();
  453. }
  454. },
  455. logOffSuccessCallback: function () {
  456. var applicationController = App.router.get('applicationController');
  457. applicationController.set('isPollerRunning', false);
  458. },
  459. logOffErrorCallback: function () {
  460. },
  461. /**
  462. * Redirect function on sign off request.
  463. *
  464. * @param {$.Event} [context=undefined] - triggered event context
  465. */
  466. logoffRedirect: function(context) {
  467. if (App.router.get('clusterController.isLoaded')) {
  468. window.location.reload();
  469. } else {
  470. this.transitionTo('login', context);
  471. }
  472. },
  473. /**
  474. * save prefered path
  475. * @param {string} path
  476. * @param {string} key
  477. */
  478. savePreferedPath: function(path, key) {
  479. if (key) {
  480. if (path.contains(key)) {
  481. this.set('preferedPath', path.slice(path.indexOf(key) + key.length));
  482. }
  483. } else {
  484. this.set('preferedPath', path);
  485. }
  486. },
  487. /**
  488. * If path exist route to it, otherwise return false
  489. * @returns {boolean}
  490. */
  491. restorePreferedPath: function() {
  492. var preferredPath = this.get('preferedPath');
  493. var isRestored = false;
  494. if (preferredPath) {
  495. // If the preferred path is relative, allow a redirect to it.
  496. // If the path is not relative, silently ignore it - if the path is an absolute URL, the user
  497. // may be routed to a different server where the possibility exists for a phishing attack.
  498. if ((preferredPath.startsWith('/') || preferredPath.startsWith('#')) && !preferredPath.contains('#/login')) {
  499. window.location = preferredPath;
  500. isRestored = true;
  501. }
  502. // Unset preferedPath
  503. this.set('preferedPath', null);
  504. }
  505. return isRestored;
  506. },
  507. /**
  508. * initialize isAdmin if user is administrator
  509. */
  510. initAdmin: function(){
  511. if (App.db) {
  512. var user = App.db.getUser();
  513. if (user) {
  514. if (user.admin) {
  515. App.set('isAdmin', true);
  516. }
  517. if (user.operator) {
  518. App.set('isOperator', true);
  519. }
  520. App.set('isPermissionDataLoaded', true);
  521. }
  522. }
  523. },
  524. /**
  525. * initialize Auth for user
  526. */
  527. initAuth: function(){
  528. if (App.db) {
  529. var auth = App.db.getAuth();
  530. if(auth)
  531. App.set('auth', auth);
  532. }
  533. },
  534. /**
  535. * Increment redirect count if <code>redirected</code> parameter passed.
  536. */
  537. handleUIRedirect: function() {
  538. if (/(\?|&)redirected=/.test(location.hash)) {
  539. var redirectsCount = App.db.get('tmp', 'redirectsCount') || 0;
  540. App.db.set('tmp', 'redirectsCount', ++redirectsCount);
  541. }
  542. },
  543. /**
  544. * <code>window.location</code> setter. Will add query param which determines that we redirect user
  545. * @param {string} url - url to navigate
  546. */
  547. redirectByURL: function(url) {
  548. var suffix = "?redirected=true";
  549. var redirectsCount = App.db.get('tmp', 'redirectsCount') || 0;
  550. if (redirectsCount > this.get('redirectsLimitCount')) {
  551. this.showRedirectIssue();
  552. return;
  553. }
  554. // skip adding redirected parameter if added
  555. if (/(\?|&)redirected=/.test(location.hash)) {
  556. this.setLocationUrl(url);
  557. return;
  558. }
  559. // detect if query params were assigned and replace "?" with "&" for suffix param
  560. if (/\?\w+=/.test(location.hash)) {
  561. suffix = suffix.replace('?', '&');
  562. }
  563. this.setLocationUrl(url + suffix);
  564. },
  565. /**
  566. * Convenient method to set <code>window.location</code>.
  567. * Useful for faking url manipulation in tests.
  568. *
  569. * @param {string} url
  570. */
  571. setLocationUrl: function(url) {
  572. window.location = url;
  573. },
  574. /**
  575. * Convenient method to get current <code>window.location</code>.
  576. * Useful for faking url manipulation in tests.
  577. */
  578. getCurrentLocationUrl: function() {
  579. return window.location.href;
  580. },
  581. /**
  582. * Inform user about redirect issue in modal popup.
  583. *
  584. * @returns {App.ModalPopup}
  585. */
  586. showRedirectIssue: function() {
  587. var bodyMessage = Em.I18n.t('app.redirectIssuePopup.body').format(location.origin + '/#' + this.get('localUserAuthUrl'));
  588. var popupHeader = Em.I18n.t('app.redirectIssuePopup.header');
  589. var popup = App.showAlertPopup(popupHeader, bodyMessage);
  590. popup.set('encodeBody', false);
  591. return popup;
  592. },
  593. root: Em.Route.extend({
  594. index: Em.Route.extend({
  595. route: '/',
  596. redirectsTo: 'login'
  597. }),
  598. enter: function(router){
  599. router.initAdmin();
  600. router.initAuth();
  601. router.handleUIRedirect();
  602. },
  603. login: Em.Route.extend({
  604. route: '/login:suffix',
  605. /**
  606. * If the user is already logged in, redirect to where the user was previously
  607. */
  608. enter: function (router, context) {
  609. var location = router.location.location.hash;
  610. router.getAuthenticated().done(function (loggedIn) {
  611. if (loggedIn) {
  612. Ember.run.next(function () {
  613. router.getSection(function (route) {
  614. router.transitionTo(route, context);
  615. });
  616. });
  617. } else {
  618. //key to parse URI for prefered path to route
  619. router.savePreferedPath(location, '?targetURI=');
  620. }
  621. });
  622. },
  623. connectOutlets: function (router, context) {
  624. $('title').text(Em.I18n.t('app.name'));
  625. router.get('applicationController').connectOutlet('login');
  626. },
  627. serialize: function(router, context) {
  628. // check for login/local hash
  629. var location = router.get('location.location.hash');
  630. return {
  631. suffix: location === '#' + router.get('localUserAuthUrl') ? '/local' : ''
  632. };
  633. }
  634. }),
  635. installer: require('routes/installer'),
  636. main: require('routes/main'),
  637. adminView: Em.Route.extend({
  638. route: '/adminView',
  639. enter: function (router) {
  640. if (!router.get('loggedIn') || !App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK')) {
  641. Em.run.next(function () {
  642. router.transitionTo('login');
  643. });
  644. } else {
  645. App.ajax.send({
  646. name: 'ambari.service.load_server_version',
  647. sender: router,
  648. success: 'adminViewInfoSuccessCallback'
  649. });
  650. }
  651. }
  652. }),
  653. experimental: Em.Route.extend({
  654. route: '/experimental',
  655. enter: function (router, context) {
  656. if (App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK')) {
  657. Em.run.next(function () {
  658. if (router.get('clusterInstallCompleted')) {
  659. router.transitionTo("main.dashboard.widgets");
  660. } else {
  661. router.route("installer");
  662. }
  663. });
  664. } else if (!App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK')) {
  665. Em.run.next(function () {
  666. router.transitionTo("main.views.index");
  667. });
  668. }
  669. },
  670. connectOutlets: function (router, context) {
  671. if (App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK')) {
  672. App.router.get('experimentalController').loadSupports().complete(function () {
  673. $('title').text(Em.I18n.t('app.name.subtitle.experimental'));
  674. router.get('applicationController').connectOutlet('experimental');
  675. });
  676. }
  677. }
  678. }),
  679. logoff: function (router, context) {
  680. router.logOff(context);
  681. }
  682. })
  683. });