Skip to content

Commit

Permalink
Remove indirection (#586)
Browse files Browse the repository at this point in the history
Remove indirection
  • Loading branch information
mjgiarlo committed May 30, 2019
2 parents 31cd3fe + bd4c0d5 commit f984650
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions __tests__/components/editor/Editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Header from '../../../src/components/editor/Header'

let props = {
location: { state: {resourceTemplateId: 'resourceTemplate:bf:Note'}},
authenticationState: {}
currentSession: null
}

describe('<Editor />', () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('<Editor />', () => {
})

describe('authenticated user', () => {
props.authenticationState = { currentSession: 'should be CognitoUserSession instance, but just checked for presence at present' }
props.currentSession = { dummy: 'should be CognitoUserSession instance, but just checked for presence at present' }
const wrapper = shallow(<Editor.WrappedComponent {...props} handleGenerateLD={handleGenerateLDFn} />)

it('does not displays a login warning message', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/editor/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Stanford University see LICENSE for license
// Copyright 2019 Stanford University see LICENSE for license

import React, {Component} from 'react'
import { connect } from 'react-redux'
Expand Down Expand Up @@ -52,7 +52,7 @@ class Editor extends Component {
Alert! No data can be saved unless you are logged in with group permissions.
</div>;

if (this.props.authenticationState.currentSession) {
if (this.props.currentSession) {
authenticationMessage = <span/>
}

Expand Down Expand Up @@ -82,12 +82,12 @@ Editor.propTypes = {
location: PropTypes.object,
resourceTemplateId: PropTypes.string,
history: PropTypes.object,
authenticationState: PropTypes.object
currentSession: PropTypes.object
}

const mapStateToProps = (state) => {
return {
authenticationState: Object.assign({}, state.authenticate.authenticationState)
currentSession: Object.assign({}, state.authenticate.authenticationState.currentSession)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/editor/ImportResourceTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ImportResourceTemplate extends Component {

createResource = async (content, group) => {
try {
const response = await createResourceTemplate(content, group, this.props.authenticationState)
const response = await createResourceTemplate(content, group, this.props.currentUser)
return response.response
} catch(error) {
this.setState({
Expand All @@ -56,7 +56,7 @@ class ImportResourceTemplate extends Component {

updateResource = async (content, group) => {
try {
const response = await updateResourceTemplate(content, group, this.props.authenticationState)
const response = await updateResourceTemplate(content, group, this.props.currentUser)
return response.response
} catch(error) {
return error.response
Expand Down Expand Up @@ -159,12 +159,12 @@ class ImportResourceTemplate extends Component {
ImportResourceTemplate.propTypes = {
children: PropTypes.array,
triggerHandleOffsetMenu: PropTypes.func,
authenticationState: PropTypes.object
currentUser: PropTypes.object
}

const mapStateToProps = (state) => {
return {
authenticationState: Object.assign({}, state.authenticate.authenticationState)
currentUser: Object.assign({}, state.authenticate.authenticationState.currentUser)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/sinopiaServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const getEntityTagFromGroupContainer = async group => {
return result.response.header.etag
}

const authenticate = async authenticationState => {
const authenticate = async currentUser => {
// first, make sure the client instance has a valid JWT id token set
await CognitoUtils.getIdTokenString(authenticationState.currentUser)
await CognitoUtils.getIdTokenString(currentUser)
.then(idToken => instance.apiClient.authentications['CognitoUser'].accessToken = idToken)
// TODO: add auth-related error handling similar to the catch on the createResourceWithHttpInfo try below, e.g.
// * display a warning that the operation failed due to error with current session
Expand All @@ -62,14 +62,14 @@ const authenticate = async authenticationState => {
// This will be done as part of https://github.com/LD4P/sinopia_editor/issues/528
}

export const createResourceTemplate = async (templateObject, group, authenticationState) => {
export const createResourceTemplate = async (templateObject, group, currentUser) => {
// If the authentication function throws, let the caller of this function catch it
await authenticate(authenticationState)
await authenticate(currentUser)
return await instance.createResourceWithHttpInfo(group, templateObject, { slug: templateObject.id, contentType: 'application/json' })
}

export const updateResourceTemplate = async (templateObject, group, authenticationState) => {
export const updateResourceTemplate = async (templateObject, group, currentUser) => {
// If the authentication function throws, let the caller of this function catch it
await authenticate(authenticationState)
await authenticate(currentUser)
return await instance.updateResourceWithHttpInfo(group, templateObject.id, templateObject, { contentType: 'application/json' })
}

0 comments on commit f984650

Please sign in to comment.