Skip to content

Commit

Permalink
refactor: use getServerConfiguration instead of getVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsut committed Oct 27, 2020
1 parent 1d84921 commit 95b3129
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 93 deletions.
49 changes: 27 additions & 22 deletions webapp/app/containers/App/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
GET_EXTERNAL_AUTH_PROVIDERS_SUCESS,
TRY_EXTERNAL_AUTH,
EXTERNAL_AUTH_LOGOUT,
GET_VERSION,
GET_VERSION_SUCCESS,
GET_VERSION_FAIL,
GET_SERVER_CONFIGURATIONS,
GET_SERVER_CONFIGURATIONS_SUCCESS,
GET_SERVER_CONFIGURATIONS_FAIL,
LOGIN,
LOGGED,
LOGIN_ERROR,
Expand Down Expand Up @@ -63,9 +63,13 @@ import {
GET_USER_BY_TOKEN_FAIL
} from './constants'

import { IGetgetCaptchaParams, IResetPasswordParams } from '../FindPassword/types'
import {
IGetgetCaptchaParams,
IResetPasswordParams
} from '../FindPassword/types'

import { IReduxActionStruct } from 'utils/types'
import { IServerConfigurations } from './types'

export function getExternalAuthProviders() {
return {
Expand Down Expand Up @@ -107,28 +111,29 @@ export function login(username, password, resolve) {
}
}

export function getVersion(resolve?) {
export function getServerConfigurations() {
return {
type: GET_VERSION,
payload: {
resolve
}
type: GET_SERVER_CONFIGURATIONS
}
}

export function getVersionSuccess (version) {
export function serverConfigurationsGetted(
configurations: IServerConfigurations
) {
return {
type: GET_VERSION_SUCCESS,
type: GET_SERVER_CONFIGURATIONS_SUCCESS,
payload: {
version
configurations
}
}
}

export function getVersionFail(err) {
export function getServerConfigurationsFail(error) {
return {
type: GET_VERSION_FAIL,
payload: {err}
type: GET_SERVER_CONFIGURATIONS_FAIL,
payload: {
error
}
}
}

Expand Down Expand Up @@ -356,7 +361,7 @@ export function downloadFileFail(error) {
}
}

export function getCaptchaforResetPassword (
export function getCaptchaforResetPassword(
params: IGetgetCaptchaParams
): IReduxActionStruct<IGetgetCaptchaParams> {
return {
Expand All @@ -383,7 +388,7 @@ export function getCaptchaforResetPasswordError(error) {
}
}

export function resetPasswordUnlogged (
export function resetPasswordUnlogged(
params: IResetPasswordParams
): IReduxActionStruct<IResetPasswordParams> {
return {
Expand All @@ -392,7 +397,7 @@ export function resetPasswordUnlogged (
}
}

export function resetPasswordUnloggedSuccess (result) {
export function resetPasswordUnloggedSuccess(result) {
return {
type: RESET_PASSWORD_UNLOGGED_SUCCESS,
payload: {
Expand All @@ -401,7 +406,7 @@ export function resetPasswordUnloggedSuccess (result) {
}
}

export function resetPasswordUnloggedFail (error) {
export function resetPasswordUnloggedFail(error) {
return {
type: RESET_PASSWORD_UNLOGGED_ERROR,
payload: {
Expand All @@ -410,7 +415,7 @@ export function resetPasswordUnloggedFail (error) {
}
}

export function getUserByToken (token) {
export function getUserByToken(token) {
return {
type: GET_USER_BY_TOKEN,
payload: {
Expand All @@ -419,7 +424,7 @@ export function getUserByToken (token) {
}
}

export function getUserByTokenSuccess (user) {
export function getUserByTokenSuccess(user) {
return {
type: GET_USER_BY_TOKEN_SUCCESS,
payload: {
Expand All @@ -428,7 +433,7 @@ export function getUserByTokenSuccess (user) {
}
}

export function getUserByTokenFail (error) {
export function getUserByTokenFail(error) {
return {
type: GET_USER_BY_TOKEN_FAIL,
payload: {
Expand Down
6 changes: 3 additions & 3 deletions webapp/app/containers/App/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export const UPDATE_TEAM_PROJECT_PERMISSION = 'davinci/permission/UPDATE_TEAM_PR
export const UPDATE_TEAM = 'davinci/permission/UPDATE_TEAM'
export const DELETE_TEAM = 'davinci/permission/DELETE_TEAM'

export const GET_VERSION = 'davinci/GET_VERSION'
export const GET_VERSION_SUCCESS = 'davinci/GET_VERSION_SUCCESS'
export const GET_VERSION_FAIL = 'davinci/GET_VERSION_FAIL'
export const GET_SERVER_CONFIGURATIONS = 'davinci/GET_SERVER_CONFIGURATIONS'
export const GET_SERVER_CONFIGURATIONS_SUCCESS = 'davinci/GET_SERVER_CONFIGURATIONS_SUCCESS'
export const GET_SERVER_CONFIGURATIONS_FAIL = 'davinci/GET_SERVER_CONFIGURATIONS_FAIL'

export const GET_USER_BY_TOKEN = 'davinci/GET_USER_BY_TOKEN'
export const GET_USER_BY_TOKEN_SUCCESS = 'davinci/GET_USER_BY_TOKEN_SUCCESS'
Expand Down
24 changes: 9 additions & 15 deletions webapp/app/containers/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
* >>
*/

import React, { useCallback } from 'react'
import React from 'react'
import Helmet from 'react-helmet'
import { connect } from 'react-redux'
import { createStructuredSelector } from 'reselect'
import { Route, HashRouter as Router, Switch, Redirect, withRouter } from 'react-router-dom'
import { Route, HashRouter as Router, Switch, Redirect } from 'react-router-dom'
import { RouteComponentWithParams } from 'utils/types'

import { compose } from 'redux'
import { logged, logout, getUserByToken } from './actions'
import { logged, logout, getServerConfigurations, getUserByToken } from './actions'
import injectReducer from 'utils/injectReducer'
import reducer from './reducer'
import injectSaga from 'utils/injectSaga'
Expand All @@ -43,22 +43,15 @@ import { Background } from 'containers/Background/Loadable'
import { Main } from 'containers/Main/Loadable'
import { Activate } from 'containers/Register/Loadable'

interface IAppStateProps {
logged: boolean
}

interface IAppDispatchProps {
onLogged: (user) => void
onLogout: () => void
onGetLoginUser: (token: string) => any
}

type AppProps = IAppStateProps & IAppDispatchProps & RouteComponentWithParams
type MappedStates = ReturnType<typeof mapStateToProps>
type MappedDispatches = ReturnType<typeof mapDispatchToProps>
type AppProps = MappedStates & MappedDispatches & RouteComponentWithParams

export class App extends React.PureComponent<AppProps> {

constructor (props: AppProps) {
super(props)
props.onGetServerConfigurations()
this.checkTokenLink()
}

Expand Down Expand Up @@ -169,7 +162,8 @@ const mapStateToProps = createStructuredSelector({
const mapDispatchToProps = (dispatch) => ({
onLogged: (user) => dispatch(logged(user)),
onLogout: () => dispatch(logout()),
onGetLoginUser: (token) => dispatch(getUserByToken(token))
onGetLoginUser: (token: string) => dispatch(getUserByToken(token)),
onGetServerConfigurations: () => dispatch(getServerConfigurations())
})

const withConnect = connect(
Expand Down
23 changes: 16 additions & 7 deletions webapp/app/containers/App/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ import {
UPDATE_PROFILE_SUCCESS,
GET_EXTERNAL_AUTH_PROVIDERS_SUCESS,
DownloadStatus,
GET_VERSION_SUCCESS
GET_SERVER_CONFIGURATIONS_SUCCESS
} from './constants'


const initialState = {
externalAuthProviders: null,
logged: null,
Expand All @@ -52,7 +51,8 @@ const initialState = {
downloadListLoading: false,
downloadList: null,
downloadListInfo: null,
version: null
version: '',
oauth2Enabled: false
}

const appReducer = (state = initialState, action) =>
Expand All @@ -76,8 +76,10 @@ const appReducer = (state = initialState, action) =>
draft.logged = true
draft.loginUser = action.payload.user
break
case GET_VERSION_SUCCESS:
draft.version = action.payload.version
case GET_SERVER_CONFIGURATIONS_SUCCESS:
draft.version = action.payload.configurations.version
draft.oauth2Enabled =
action.payload.configurations.security.oauth2.enable
break
case LOGOUT:
draft.logged = false
Expand All @@ -88,7 +90,13 @@ const appReducer = (state = initialState, action) =>
break
case UPDATE_PROFILE_SUCCESS:
const { id, name, department, description } = action.payload.user
draft.loginUser = { ...draft.loginUser, id, name, department, description }
draft.loginUser = {
...draft.loginUser,
id,
name,
department,
description
}
break
case SHOW_NAVIGATOR:
draft.navigator = true
Expand All @@ -113,7 +121,8 @@ const appReducer = (state = initialState, action) =>
draft.downloadListLoading = false
break
case DOWNLOAD_FILE_SUCCESS:
draft.downloadList.find(({ id }) => action.payload.id === id).status = DownloadStatus.Downloaded
draft.downloadList.find(({ id }) => action.payload.id === id).status =
DownloadStatus.Downloaded
break
}
})
Expand Down
66 changes: 37 additions & 29 deletions webapp/app/containers/App/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
LOGOUT,
CHECK_NAME,
ACTIVE,
GET_VERSION,
GET_SERVER_CONFIGURATIONS,
UPDATE_PROFILE,
CHANGE_USER_PASSWORD,
JOIN_ORGANIZATION,
Expand All @@ -46,8 +46,6 @@ import {
GET_USER_BY_TOKEN
} from './constants'
import {
logged,
getVersion,
loginError,
activeSuccess,
activeError,
Expand All @@ -66,17 +64,26 @@ import {
getCaptchaforResetPasswordError,
resetPasswordUnloggedSuccess,
resetPasswordUnloggedFail,
getVersionSuccess,
getVersionFail,
serverConfigurationsGetted,
getServerConfigurationsFail,
getUserByTokenFail,
getUserByTokenSuccess
} from './actions'
import request, { removeToken, getToken } from 'utils/request'
import request, {
removeToken,
getToken,
setTokenExpired,
IDavinciResponse
} from 'utils/request'
import { errorHandler } from 'utils/util'
import api from 'utils/api'

import { IReduxActionStruct } from 'utils/types'
import { IResetPasswordParams, IGetgetCaptchaParams } from '../FindPassword/types'
import {
IResetPasswordParams,
IGetgetCaptchaParams
} from '../FindPassword/types'
import { IServerConfigurations } from './types'

export function* getExternalAuthProviders() {
try {
Expand All @@ -92,19 +99,20 @@ export function* getExternalAuthProviders() {
}
}

export function* getDavinciVersion(action) {
const {resolve} = action.payload
export function* getServerConfigurations(action) {
try {
const version = yield call(request, {
method: 'get',
url: api.version
})
yield put(getVersionSuccess(version))
if (resolve) {
resolve(version)
}
const result: IDavinciResponse<IServerConfigurations> = yield call(
request,
{
method: 'get',
url: api.configurations
}
)
const configurations = result.payload
setTokenExpired(configurations.jwtToken.timeout)
yield put(serverConfigurationsGetted(configurations))
} catch (err) {
yield put(getVersionFail(err))
yield put(getServerConfigurationsFail(err))
errorHandler(err)
}
}
Expand Down Expand Up @@ -403,24 +411,24 @@ export function* getUserByToken(action) {

export default function* rootGroupSaga() {
yield all([
throttle(1000, CHECK_NAME, checkNameUnique as any),
takeEvery(ACTIVE, activeUser as any),
takeLatest(GET_EXTERNAL_AUTH_PROVIDERS, getExternalAuthProviders as any),
takeEvery(TRY_EXTERNAL_AUTH, tryExternalAuth as any),
takeEvery(EXTERNAL_AUTH_LOGOUT, externalAuthlogout as any),
takeEvery(LOGIN, login as any),
throttle(1000, CHECK_NAME, checkNameUnique),
takeEvery(ACTIVE, activeUser),
takeLatest(GET_EXTERNAL_AUTH_PROVIDERS, getExternalAuthProviders),
takeEvery(TRY_EXTERNAL_AUTH, tryExternalAuth),
takeEvery(EXTERNAL_AUTH_LOGOUT, externalAuthlogout),
takeEvery(LOGIN, login),
takeEvery(LOGOUT, logout),
takeEvery(UPDATE_PROFILE, updateProfile as any),
takeEvery(UPDATE_PROFILE, updateProfile),
takeEvery(CHANGE_USER_PASSWORD, changeUserPassword as any),
takeEvery(
GET_CAPTCHA_FOR_RESET_PASSWORD,
getCaptchaForResetPassword as any
),
takeEvery(RESET_PASSWORD_UNLOGGED, resetPasswordUnlogged as any),
takeEvery(GET_USER_BY_TOKEN, getUserByToken as any),
takeEvery(JOIN_ORGANIZATION, joinOrganization as any),
takeEvery(RESET_PASSWORD_UNLOGGED, resetPasswordUnlogged as any),
takeEvery(GET_USER_BY_TOKEN, getUserByToken),
takeEvery(JOIN_ORGANIZATION, joinOrganization),
takeLatest(LOAD_DOWNLOAD_LIST, getDownloadList),
takeLatest(DOWNLOAD_FILE, downloadFile),
takeLatest(GET_VERSION, getDavinciVersion)
takeLatest(GET_SERVER_CONFIGURATIONS, getServerConfigurations)
])
}
12 changes: 11 additions & 1 deletion webapp/app/containers/App/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ export interface IDownloadRecord {
uuid?: string
}


export interface IServerConfigurations {
version: string
jwtToken: {
timeout: number
}
security: {
oauth2: {
enable: boolean
}
}
}
Loading

0 comments on commit 95b3129

Please sign in to comment.