Skip to content

Commit

Permalink
Merge pull request #1140 from ManageIQ/revert-1133-redux-3
Browse files Browse the repository at this point in the history
Revert "Add support for Redux"
  • Loading branch information
chriskacerguis authored Oct 24, 2017
2 parents cfdbf62 + 3a476b0 commit 2b9ba12
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 237 deletions.
9 changes: 0 additions & 9 deletions client/app/actions/token.js

This file was deleted.

3 changes: 0 additions & 3 deletions client/app/constants/token.js

This file was deleted.

91 changes: 91 additions & 0 deletions client/app/core/authorization.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,94 @@ export function authConfig ($httpProvider) {
}
}
}

/** @ngInject */
export function authInit ($rootScope, $state, $log, Session, $sessionStorage, Language, ApplianceInfo, $window, RBAC) {
$rootScope.$on('$stateChangeStart', changeStart)
$rootScope.$on('$stateChangeError', changeError)
$rootScope.$on('$stateChangeSuccess', changeSuccess)

$sessionStorage.$sync() // needed when called right on reload
if ($sessionStorage.token) {
syncSession()
}

function changeStart (event, toState, toParams, _fromState, _fromParams) {
if (angular.isDefined(toState.data)) {
if (angular.isDefined(toState.data.authorization) && !toState.data.authorization) {
event.preventDefault()
$state.transitionTo('dashboard')

return
}
if (!toState.data.requireUser) {
return
}
}
if (Session.active()) {
return
}

// user is required and session not active - not going anywhere right away
event.preventDefault()
$sessionStorage.$sync() // needed when called right on reload
if (!$sessionStorage.token) {
// no saved token, go directly to login
$state.transitionTo('login')

return
}
syncSession().then(rbacReloadOrLogin(toState, toParams)).catch(badUser)
}

function syncSession () {
return new Promise(function (resolve, reject) {
// trying saved token..
Session.setAuthToken($sessionStorage.token)
Session.setGroup($sessionStorage.miqGroup)

Session.loadUser()
.then(function (response) {
if (angular.isDefined(response)) {
Language.onReload(response)
ApplianceInfo.set(response)
RBAC.setRole(response.identity.role)
}
resolve()
})
.catch(badUser)
})
}

function rbacReloadOrLogin (toState, toParams) {
return function () {
if (RBAC.suiAuthorized()) {
$state.go(toState, toParams)
} else {
Session.privilegesError = true
$window.location.href = $state.href('login')
}
}
}

function badUser (error) {
$log.error(__('Error retrieving user info'), [error])
$window.location.href = $state.href('login')
}

function changeError (event, toState, _toParams, _fromState, _fromParams, error) {
// If a 401 is encountered during a state change, then kick the user back to the login
if (401 || error.status === 403) {
event.preventDefault()
if (Session.active()) {
$state.transitionTo('logout')
} else if (toState.name !== 'login') {
$state.transitionTo('login')
}
}
}

function changeSuccess () {
angular.element('html, body').animate({scrollTop: 0}, 200)
}
}
84 changes: 0 additions & 84 deletions client/app/core/authorization.run.js

This file was deleted.

13 changes: 1 addition & 12 deletions client/app/core/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint angular/window-service: "off" */
import { RootReducer } from '../reducers'
import { autoRehydrate } from 'redux-persist'

var DEVEL_DOMAINS = [
'localhost',
Expand All @@ -9,23 +7,14 @@ var DEVEL_DOMAINS = [
]

var isDevel = window._.includes(DEVEL_DOMAINS, window.location.hostname)
const hasDevTools = angular.isDefined(window.__REDUX_DEVTOOLS_EXTENSION__)

/** @ngInject */
export function configure ($logProvider, $compileProvider, $qProvider, $ngReduxProvider) {
export function configure ($logProvider, $compileProvider, $qProvider) {
$logProvider.debugEnabled(isDevel)
$compileProvider.debugInfoEnabled(isDevel)

// TODO: Remove following line as per: https://docs.angularjs.org/guide/migration#migrate1.5to1.6-ng-services-$compile
$compileProvider.preAssignBindingsEnabled(true)

$qProvider.errorOnUnhandledRejections(false)

const storeEnhancers = [
autoRehydrate()
]
if (hasDevTools) {
storeEnhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__())
}
$ngReduxProvider.createStoreWith(RootReducer, [], storeEnhancers)
}
11 changes: 5 additions & 6 deletions client/app/core/core.module.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* global _:false, ActionCable:false, $:false, sprintf: false, moment: false */
/* eslint-disable sort-imports */
import { authConfig } from './authorization.config.js'
import { authInit } from './authorization.run.js'
import 'ng-redux'

import {
authConfig,
authInit
} from './authorization.config.js'

import {
configure,
Expand All @@ -27,7 +29,6 @@ import { NavigationController } from './navigation/navigation-controller.js'
import { NavigationFactory } from './navigation.service.js'
import { PollingFactory } from './polling.service.js'
import { RBACFactory } from './rbac.service.js'
import { ReduxFactory } from './redux.service.js'
import { RouterModule } from './router/router.module.js'
import { SaveModalDialogFactory } from './save-modal-dialog/save-modal-dialog.factory.js'
import { SessionFactory } from './session.service.js'
Expand All @@ -49,7 +50,6 @@ export const CoreModule = angular
'ngCookies',
'ngMessages',
'ngSanitize',
'ngRedux',
'ngStorage',
'ui.router',
'ui.router.state.events',
Expand Down Expand Up @@ -85,7 +85,6 @@ export const CoreModule = angular
.factory('Navigation', NavigationFactory)
.factory('Polling', PollingFactory)
.factory('RBAC', RBACFactory)
.factory('Redux', ReduxFactory)
.factory('SaveModalDialog', SaveModalDialogFactory)
.factory('Session', SessionFactory)
.factory('ShoppingCart', ShoppingCartFactory)
Expand Down
31 changes: 0 additions & 31 deletions client/app/core/redux.service.js

This file was deleted.

18 changes: 4 additions & 14 deletions client/app/core/session.service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import TokenActions from '../actions/token'
/* eslint-disable dot-notation */
/** @ngInject */

export function SessionFactory (lodash, $http, $q, $sessionStorage, $cookies, $ngRedux, RBAC, Redux, Polling) {
export function SessionFactory ($http, $sessionStorage, $cookies, RBAC, Polling) {
const model = {
token: null,
user: {}
Expand All @@ -21,20 +19,13 @@ export function SessionFactory (lodash, $http, $q, $sessionStorage, $cookies, $n
setPause: setPause,
updateUserSession: updateUserSession
}
const vm = this
const actions = TokenActions
vm.unsubscribe = $ngRedux.connect(mapStateToThis, actions)(vm)
function mapStateToThis (token) {
return { token: token.token }
}

destroy()

return service

function setAuthToken (token) {
model.token = token
vm.addToken(token)
$http.defaults.headers.common['X-Auth-Token'] = model.token
$sessionStorage.token = model.token
}
Expand Down Expand Up @@ -63,7 +54,6 @@ export function SessionFactory (lodash, $http, $q, $sessionStorage, $cookies, $n

function destroy () {
model.token = null
Redux.clear()
model.user = {}
destroyWsToken()
delete $http.defaults.headers.common['X-Miq-Group']
Expand Down Expand Up @@ -139,9 +129,9 @@ export function SessionFactory (lodash, $http, $q, $sessionStorage, $cookies, $n
}

// Helpers
function active () {
const token = vm.token.token || false

return token
function active () {
// may not be current, but if we have one, we'll rely on API 401ing if it's not
return angular.isString(model.token) ? model.token : false
}
}
6 changes: 0 additions & 6 deletions client/app/reducers/index.js

This file was deleted.

11 changes: 0 additions & 11 deletions client/app/reducers/token.js

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"merge": "1.2.0",
"moment-timezone": "0.5.13",
"ng-annotate-loader": "0.6.1",
"ng-redux": "3.5.2",
"ngprogress": "VictorBjelkholm/ngProgress#v1.1.3",
"ngstorage": "0.3.11",
"ngtemplate-loader": "2.0.1",
Expand All @@ -104,8 +103,6 @@
"patternfly-timeline": "patternfly/patternfly-timeline#master-dist",
"postcss-loader": "2.0.8",
"q": "1.5.1",
"redux": "3.7.2",
"redux-persist": "4.10.1",
"request": "2.83.0",
"rxjs": "5.5.0",
"sass-loader": "6.0.6",
Expand Down
Loading

0 comments on commit 2b9ba12

Please sign in to comment.