Comparar commits

...

2 Commits

Autor SHA1 Mensagem Data
Phil Cherner dcce4c9a8f Add isSecure to projectForm state 2019-08-23 16:06:56 -07:00
Phil Cherner 7a708ed69e Add checkbox and move it to project form component from securitypicker 2019-08-23 09:04:39 -07:00
11 arquivos alterados com 65 adições e 41 exclusões
+2 -1
Ver Arquivo
@@ -292,6 +292,7 @@ export default class MockFactory {
predictTag: false,
},
autoSave: true,
isSecure: true,
};
}
@@ -1191,7 +1192,7 @@ export default class MockFactory {
/**
* Gets StorageType for asset providers
* @param providerType Asset Providet type
* @param providerType Asset Provider type
*/
private static getStorageType(providerType: string): StorageType {
switch (providerType) {
+1
Ver Arquivo
@@ -116,6 +116,7 @@ export interface IProject {
videoSettings: IProjectVideoSettings;
activeLearningSettings: IActiveLearningSettings;
autoSave: boolean;
isSecure: boolean;
assets?: { [index: string]: IAsset };
lastVisitedAssetId?: string;
}
@@ -10,6 +10,7 @@ describe("Security Token Picker", () => {
value: "",
securityTokens: [],
onChange: onChangeHandler,
isSecure: true,
};
function createComponent(props: ISecurityTokenPickerProps): ReactWrapper<ISecurityTokenPickerProps> {
@@ -1,5 +1,6 @@
import React, { SyntheticEvent } from "react";
import { ISecurityToken } from "../../../../models/applicationState";
import { connect } from "react-redux";
/**
* Security Token Picker Properties
@@ -13,6 +14,7 @@ export interface ISecurityTokenPickerProps {
value: string;
securityTokens: ISecurityToken[];
onChange: (value: string) => void;
isSecure: boolean;
}
/**
@@ -31,7 +33,8 @@ export class SecurityTokenPicker extends React.Component<ISecurityTokenPickerPro
<select id={this.props.id}
className="form-control"
value={this.props.value}
onChange={this.onChange}>
onChange={this.onChange}
disabled={!this.props.isSecure}>
<option value="">Generate New Security Token</option>
{this.props.securityTokens.map((item) => <option key={item.key} value={item.name}>{item.name}</option>)}
</select>
@@ -6,6 +6,11 @@
"type": "string",
"pattern": "^[^\\\\\\\\/:*?\\\\\\\"<>|]*$"
},
"isSecure": {
"title": "Secure Project?",
"type": "boolean",
"description": "Secure project with security token?"
},
"securityToken": {
"title": "${strings.projectSettings.securityToken.title}",
"description": "${strings.projectSettings.securityToken.description}",
@@ -11,6 +11,9 @@ import { ISecurityTokenPickerProps, SecurityTokenPicker } from "../../common/sec
import "vott-react/dist/css/tagsInput.css";
import { IConnectionProviderPickerProps } from "../../common/connectionProviderPicker/connectionProviderPicker";
import LocalFolderPicker from "../../common/localFolderPicker/localFolderPicker";
import Checkbox from "rc-checkbox";
import "rc-checkbox/assets/index.css";
import { CustomWidget } from "../../common/customField/customField";
// tslint:disable-next-line:no-var-requires
const formSchema = addLocValues(require("./projectForm.json"));
@@ -54,6 +57,16 @@ export interface IProjectFormState {
export default class ProjectForm extends React.Component<IProjectFormProps, IProjectFormState> {
private widgets = {
localFolderPicker: (LocalFolderPicker as any) as Widget,
checkbox: CustomWidget(Checkbox, (props) => ({
checked: props.value,
onChange: (value) => {
props.onChange(value.target.checked);
const tempForm = {...this.props.project};
tempForm["isSecure"] = value.target.checked
this.setState({formData: tempForm});
},
disabled: props.disabled,
})),
};
private tagsInput: React.RefObject<TagsInput>;
@@ -133,6 +146,7 @@ export default class ProjectForm extends React.Component<IProjectFormProps, IPro
value: props.formData,
securityTokens: this.props.appSettings.securityTokens,
onChange: props.onChange,
isSecure: (this.state.formData) ? this.state.formData.isSecure : true,
})),
sourceConnection: CustomField<IConnectionProviderPickerProps>(ConnectionPickerWithRouter, (props) => {
return {
@@ -1,4 +1,7 @@
{
"isSecure": {
"ui:widget": "checkbox"
},
"securityToken": {
"ui:field": "securityToken"
},
@@ -100,7 +100,7 @@ export default class ProjectSettingsPage extends React.Component<IProjectSetting
appSettings={this.props.appSettings}
onChange={this.onFormChange}
onSubmit={this.onFormSubmit}
onCancel={this.onFormCancel} />
onCancel={this.onFormCancel}/>
</div>
</div>
{this.props.project &&
+3 -4
Ver Arquivo
@@ -72,11 +72,10 @@ export function saveProject(project: IProject)
throw new AppError(ErrorCode.ProjectDuplicateName, `Project with name '${project.name}
already exists with the same target connection '${project.targetConnection.name}'`);
}
const projectToken = (project.isSecure) ? appState.appSettings.securityTokens
.find((securityToken) => securityToken.name === project.securityToken) : undefined;
const projectToken = appState.appSettings.securityTokens
.find((securityToken) => securityToken.name === project.securityToken);
if (!projectToken) {
if (!projectToken && project.isSecure) {
throw new AppError(ErrorCode.SecurityTokenNotFound, "Security Token Not Found");
}
+1
Ver Arquivo
@@ -68,6 +68,7 @@ export default class ImportService implements IImportService {
},
activeLearningSettings: null,
autoSave: true,
isSecure: true,
};
}
+30 -34
Ver Arquivo
@@ -53,27 +53,17 @@ export default class ProjectService implements IProjectService {
Guard.null(project);
try {
const loadedProject = decryptProject(project, securityToken);
let loadedProject = (securityToken) ? decryptProject(project, securityToken) : project;
// Ensure tags is always initialized to an array
if (!loadedProject.tags) {
loadedProject.tags = [];
}
// Initialize active learning settings if they don't exist
if (!loadedProject.activeLearningSettings) {
loadedProject.activeLearningSettings = defaultActiveLearningSettings;
}
// Initialize export settings if they don't exist
if (!loadedProject.exportFormat) {
loadedProject.exportFormat = defaultExportOptions;
}
loadedProject = this.checkProject(loadedProject);
this.ensureBackwardsCompatibility(loadedProject);
return Promise.resolve({ ...loadedProject });
} catch (e) {
if(!securityToken){
return Promise.resolve(project)
}
const error = new AppError(ErrorCode.ProjectInvalidSecurityToken, "Error decrypting project settings");
return Promise.reject(error);
}
@@ -87,30 +77,13 @@ export default class ProjectService implements IProjectService {
public async save(project: IProject, securityToken: ISecurityToken): Promise<IProject> {
Guard.null(project);
if (!project.id) {
project.id = shortid.generate();
}
// Ensure tags is always initialized to an array
if (!project.tags) {
project.tags = [];
}
// Initialize active learning settings if they don't exist
if (!project.activeLearningSettings) {
project.activeLearningSettings = defaultActiveLearningSettings;
}
// Initialize export settings if they don't exist
if (!project.exportFormat) {
project.exportFormat = defaultExportOptions;
}
project = this.checkProject(project);
project.version = packageJson.version;
const storageProvider = StorageProviderFactory.createFromConnection(project.targetConnection);
await this.saveExportSettings(project);
project = encryptProject(project, securityToken);
project = (securityToken) ? encryptProject(project, securityToken) : project;
await storageProvider.writeText(
`${project.name}${constants.projectFileExtension}`,
@@ -180,4 +153,27 @@ export default class ProjectService implements IProjectService {
}
}
}
private checkProject(project: IProject) {
if (!project.id) {
project.id = shortid.generate();
}
// Ensure tags is always initialized to an array
if (!project.tags) {
project.tags = [];
}
// Initialize active learning settings if they don't exist
if (!project.activeLearningSettings) {
project.activeLearningSettings = defaultActiveLearningSettings;
}
// Initialize export settings if they don't exist
if (!project.exportFormat) {
project.exportFormat = defaultExportOptions;
}
return project;
}
}