Skip to content

Commit

Permalink
ui:preparation for documents authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Baus committed Feb 2, 2021
1 parent 49b0ede commit 2569412
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion frontend/src/pages/Confirmation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ schemes
base64: Joi.string()
.required()
.allow(""),
fileName: Joi.string().allow("")
fileName: Joi.string().allow(""),
orgAccess: Joi.array().items(Joi.string()).optional()
}),
status: Joi.string().valid("open"),
dueDate: Joi.date().allow(null),
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/pages/Documents/DocumentUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@ export default class DocumentUpload extends Component {
constructor() {
super();
this.state = {
name: ""
name: "",
orgAccess: []
};
}

checkOrgAccess = (org, checked) => {
this.setState((state) => {
const {orgAccess} = state;
// adding organisation
if (checked) {
if (!orgAccess.includes(org)) {
orgAccess.push(org);
}
} else {
if (orgAccess.includes(org)) {
orgAccess.splice(orgAccess.indexOf(org), 1);
}
}
return {orgAccess};
});
}

render = () => {
const { storeWorkflowDocument, workflowDocuments } = this.props;
return (
Expand All @@ -47,6 +65,17 @@ export default class DocumentUpload extends Component {
id="documentnameinput"
onChange={event => this.setState({ name: event.target.value })}
/>
{/* {
['Org1', 'Org2'].map((org) => {
return (
<div key={`org-access-${org}`}>
{org}
<Checkbox value={org} onChange={event => this.checkOrgAccess(event.target.value, event.target.checked)} />
</div>
);
})
} */}
<Button
style={styles.uploadButton}
disabled={
Expand All @@ -67,7 +96,7 @@ export default class DocumentUpload extends Component {
reader.onloadend = e => {
if (e.target.result !== undefined) {
const dataUrl = e.target.result.split(";base64,")[1];
storeWorkflowDocument(this.state.name, dataUrl, file.name);
storeWorkflowDocument(this.state.name, dataUrl, file.name, this.state.orgAccess);
}
this.setState({ name: "" });
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Workflows/WorkflowDialogContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const mapDispatchToProps = dispatch => {
hideWorkflowDialog: () => dispatch(hideWorkflowDialog()),
setCurrentStep: step => dispatch(setCurrentStep(step)),
storeSnackbarMessage: message => dispatch(storeSnackbarMessage(message)),
storeWorkflowDocument: (payload, name, fileName) => dispatch(storeWorkflowDocument(payload, name, fileName)),
storeWorkflowDocument: (payload, name, fileName, orgAccess) => dispatch(storeWorkflowDocument(payload, name, fileName, orgAccess)),
defaultWorkflowExchangeRate: exchangeRate => dispatch(defaultWorkflowExchangeRate(exchangeRate)),
storeWorkflowAssignee: assignee => dispatch(storeWorkflowAssignee(assignee)),
assignWorkflowItem: (
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/Workflows/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,13 @@ export function storeWorkflowType(workflowType) {
};
}

export function storeWorkflowDocument(id, base64, fileName) {
export function storeWorkflowDocument(id, base64, fileName, orgAccess) {
return {
type: WORKFLOW_DOCUMENT,
id: id,
base64: base64,
fileName: fileName
fileName: fileName,
orgAccess
};
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Workflows/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default function detailviewReducer(state = defaultState, action) {
return state.updateIn(["workflowToAdd", "documents"], documents =>
Immutable.List([
...documents,
Immutable.Map({ id: action.id, base64: action.base64, fileName: action.fileName })
Immutable.Map({ id: action.id, base64: action.base64, fileName: action.fileName, orgAccess: action.orgAccess })
])
);
case WORKFLOWITEM_TYPE:
Expand Down

0 comments on commit 2569412

Please sign in to comment.