Skip to content

Commit cac447b

Browse files
authored
Merge pull request #34 from Samagra-Development/gitpod
Merge gitpod into main
2 parents 776f9c0 + 58fb978 commit cac447b

File tree

656 files changed

+36700
-25856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

656 files changed

+36700
-25856
lines changed

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
POSTGRES_USER=postgres
2+
POSTGRES_PASSWORD=postgres
3+
DATABASE_USERNAME=fusionauth
4+
DATABASE_PASSWORD=hkaLBM3RVnyYeYeqE3WI1w2e4Avpy0Wd5O3s3
5+
ES_JAVA_OPTS="-Xms512m -Xmx512m"
6+
FUSIONAUTH_APP_MEMORY=512M
7+
8+
MINIO_USERNAME=workflow-dev
9+
MINIO_PASSWORD=workflow-dev
10+
MINIO_BUCKETNAME=affiliationbucket
11+
12+
# central envs
13+
CENTRAL_USER_EMAIL=chakshu@samagragovernance.in
14+
CENTRAL_USER_PASS=StrongPassword@1234

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.turbo
22
node_modules
3-
.idea
3+
.idea
4+
5+
pgdata

.gitpod.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
tasks:
2+
- name: Setup Development Env
3+
openMode: tab-after
4+
init: |
5+
type -p curl >/dev/null || sudo apt install curl -y
6+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
7+
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
8+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
9+
sudo apt update
10+
sudo apt install gh -y
11+
gp sync-done dev-setup
12+
- name: Install ODK Central
13+
openMode: tab-after
14+
init: |
15+
gp sync-done dev-setup
16+
bash install-central.sh
17+
- name: Setup Enketo Express
18+
openMode: tab-after
19+
init: |
20+
gp sync-done dev-setup
21+
bash install-node.sh
22+
nvm use 14
23+
cd packages/enketo-express && pnpm i && pnpm i -g grunt
24+
bash update-config.sh
25+
gp sync-done setup
26+
command: |
27+
grunt develop
28+
- name: Setup Form Manager
29+
openMode: tab-after
30+
init: |
31+
gp sync-await setup
32+
source .env
33+
docker run --name enketo-redis-main -p 6369:6379 -d redis
34+
cd packages/form-manager
35+
echo "MINIO_USERNAME=$MINIO_USERNAME" >> .env
36+
echo "MINIO_PASSWORD=$MINIO_PASSWORD" >> .env
37+
echo "MINIO_BUCKETNAME=$MINIO_BUCKETNAME" >> .env
38+
nvm use 16
39+
pnpm install
40+
command: |
41+
npm run start:dev
42+
- name: Setup React Wrapper
43+
openMode: tab-after
44+
init: |
45+
gp sync-await setup
46+
cd apps/wrapper
47+
nvm use 16
48+
pnpm install
49+
bash make-envs-for-react.sh
50+
command: |
51+
npm run start
52+
53+
ports:
54+
- port: 8065
55+
onOpen: ignore
56+
visibility: public
57+
description: Enketo Express
58+
59+
- port: 3006
60+
onOpen: ignore
61+
visibility: public
62+
description: Form Manager
63+
64+
- port: 3000
65+
onOpen: ignore
66+
visibility: public
67+
description: React Wrapper
68+
69+
- port: 8080
70+
onOpen: ignore
71+
visibility: public
72+
description: Hasura
73+
74+
- port: 9011
75+
onOpen: ignore
76+
visibility: public
77+
description: Fusion Auth
78+
79+
- port: 8090
80+
onOpen: ignore
81+
visibility: public
82+
description: ODK Central
83+
84+
- port: 9001
85+
onOpen: ignore
86+
visibility: public
87+
description: Minio UI
88+
89+
- port: 9000
90+
onOpen: ignore
91+
visibility: public
92+
description: Minio API

README.md

Lines changed: 55 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<p align="center">
2-
<h1>Enketo - ODK Backend</h1>
2+
<h1>Workflow Module</h1>
33
</p>
44

5+
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Samagra-Development/workflow/tree/gitpod)
6+
57
## About :open_book:
68

79
Enketo has been used all around the world for a wide range of uses from needs assessments in humanitarian aid, to raising historical awareness, to clinical research, to election monitoring.
@@ -33,129 +35,88 @@ node -v
3335
npm -v
3436
```
3537

36-
## Installation Steps :walking:
38+
# How to get up and running?
3739

38-
### 1. Fork it :fork_and_knife:
40+
- Fork this repo 🍴
41+
- Click on the Gitpod button above ☝️
42+
- It opens a complete development setup directly 😄
43+
- No need to clone and struggle with installing packages, managing node versions, banging head on the keyboard, etc (Cool right?)
3944

40-
You can get your own fork/copy of [enketo](https://github.com/Samagra-Development/enketo) by using the <kbd><b>Fork</b></kbd> button.
45+
### This is how it looks 👀
46+
![Gitpod Image](https://user-images.githubusercontent.com/46066481/227315278-7e4f4ee7-ffa5-4ffb-b614-54126d72f467.png)
4147

42-
### 2. Clone it :busts_in_silhouette:
48+
# How to interact?
49+
- If you go to ports on terminal and open the `React Wrapper app` running on port 3000 you can see a demo UI like this 👇
4350

44-
You need to clone (download) it to a local machine using
51+
![Workfow Demo UI](https://user-images.githubusercontent.com/46066481/227316968-487e52db-0236-4282-b57a-73d71788d4ea.gif)
52+
- Currently offering 4 demo flows namely
53+
- Jumping Forms (Opening of next form once once is submitted)
54+
- Hasura Submissions (Basically saving the form data to any database, hasura extending postgres in this case)
55+
- Offline capabilites (How the form behaves when working offline)
56+
- File Upload (How to handle uploading files to any desired CDN, Minio in this case)
4557

46-
```sh
47-
git clone https://github.com/Your_Username/enketo.git
48-
```
58+
# Flows Explained 📝
59+
## Jumping Forms
60+
- This flow basically covers how you can configure your forms using form spec file (covered in a little while) to handle how the submission works. Like opening another form or redirecting to some page within the app or opening this link [here](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
4961

50-
> This makes a local copy of the repository in your machine.
62+
![Jumping Form Workflow](https://user-images.githubusercontent.com/46066481/227321550-55aee2c8-8c2e-4443-a922-9c23134e6e23.gif)
5163

52-
Once you have cloned the `enketo` repository in GitHub, move to that folder first using the change directory command.
64+
## Hasura Submissions
65+
- Covering how to handle form data submission to your database be it a sql or NoSql based db. In our setup we have used Hasura which creates an instant GraphQL data provider to use with Postgres based db
5366

54-
```sh
55-
# This will change directory to a folder enketo
56-
cd enketo
57-
```
5867

59-
Move to this folder for all other commands.
68+
![Hasura Submissions](https://user-images.githubusercontent.com/46066481/227329443-0c832935-ac4c-42ea-80e6-ee00282aa6e6.gif)
6069

61-
### 3. Set it up :arrow_up:
70+
## Offline Capabilites
71+
- Just touching on to the offline capabilites offered right now. Here we have configured the form such that rather than failing form submissions entirely, it throws a warning/info message to the user indicating that the user is offline and is advised to resubmit the form once they're back online.
6272

63-
Run the following commands to see that _your local copy_ has a reference to _your forked remote repository_ in GitHub :octocat:
73+
![Offline Capabilites](https://user-images.githubusercontent.com/46066481/227333111-fba64444-de4b-4075-8c71-8cb1f783a1b7.gif)
6474

65-
```sh
66-
git remote -v
67-
origin https://github.com/Your_Username/enketo.git (fetch)
68-
origin https://github.com/Your_Username/enketo.git (push)
69-
```
70-
71-
### 4. Run it :checkered_flag:
72-
73-
```sh
74-
cd enketo-express
75-
docker run --name enketo-redis-main -p 6379:6379 -d redis
76-
docker run --name enketo-redis-cache -p 6380:6379 -d redis
77-
npm install
78-
npm i -g grunt
79-
grunt develop
80-
```
81-
82-
```sh
83-
cd ../enketo-core
84-
npm install
85-
npm start
86-
```
8775

88-
```sh
89-
cd ../enketo-transformer
90-
npm install
91-
npm start
92-
```
76+
## File Upload
77+
- One of the most important thing in any kind of form input is how to handle file uploads. Workflow module allows you to configure your cdn easily and point file uploads directly to the CDN effortleslly 💃 In our configuration we have used Minio to store all the uploaded files.
9378

94-
```sh
95-
cd ../forms
96-
python3 -m http.server
97-
```
79+
![File Upload](https://user-images.githubusercontent.com/46066481/227331536-c28224a7-4b60-41ce-93a3-59fe20033201.gif)
9880

99-
You can preview your form on http://localhost:8005/preview?xform=http://localhost:8080/getForm/SOE
10081

101-
### 5. For integrating your backend
82+
# How to integrate custom backend?
10283

103-
Customize the [submission url](https://github.com/Samagra-Development/enketo/blob/main/enketo-express/public/js/src/module/connection.js#L150) with your hosted backend.
84+
In order to achiever this, the submission url in the form spec (covered later below) with your hosted backend.
85+
![Submission Url](https://user-images.githubusercontent.com/46066481/227327334-30bd083e-cee3-488c-81b5-e8d68a72c91f.png)
10486

105-
## Future Enhancements :rocket:
87+
# Future Enhancements :rocket:
10688

10789
- [Encrypting query parameters on rendering the enketo form. ](https://github.com/Samagra-Development/enketo/issues/1)
10890
- Writing a API for changing an XML form directly from it.
10991
- add npm scripts for install
11092

11193
We are trying to an inversion of control here.
11294

95+
# API Docs 🤓
96+
11397
### For Get API
11498

11599
`curl --location --request GET 'http://localhost:3002/form/form2'`
116100

117-
### Form Prefill API
101+
### Form PrefillXML API
118102

119103
```sh
120-
curl --location --request POST 'http://localhost:3002/prefill' \
121-
--header 'Content-Type: application/json' \
122-
--data-raw '{
123-
"prefillSpec": {
124-
"pf_name": "`${onFormSuccessData.name}`",
125-
"pf_iti": "`${onFormSuccessData.itiByIti.name}`",
126-
"pf_trade": "`${onFormSuccessData.tradeName}`",
127-
"pf_batch": "`${onFormSuccessData.batch}`",
128-
"pf_industry": "`${onFormSuccessData.industryByIndustry.name}`",
129-
"ojt_month": "`${onFormSuccessData.industryByIndustry.schedules[0].is_industry === true ? 1 : 0}`"
130-
},
131-
"onFormSuccessData": {
132-
"name": "DEVA",
133-
"batch": "2021-2023",
134-
"id": 8,
135-
"DOB": "2005-03-04",
136-
"affiliationType": "NCVT",
137-
"registrationNumber": "ICA211021569832",
138-
"tradeName": "Electrician",
139-
"iti": 7,
140-
"industry": 1,
141-
"itiByIti": {
142-
"id": 7,
143-
"name": "GITI Nagina"
144-
},
145-
"industryByIndustry": {
146-
"id": 1,
147-
"name": "Kaushal Bhawan",
148-
"latitude": 30.695753,
149-
"longitude": 76.872025,
150-
"schedules": [
151-
{
152-
"is_industry": true
153-
}
154-
]
155-
}
156-
},
157-
"form": "form2"
158-
}'
104+
curl 'https://3006-samagradevelop-workflow-mxpsr1yqse0.ws-us92.gitpod.io/prefillXML?form=jumping_form_1&onFormSuccessData=formFunction' \
105+
-H 'authority: 3006-samagradevelop-workflow-mxpsr1yqse0.ws-us92.gitpod.io' \
106+
-H 'accept: */*' \
107+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
108+
-H 'content-type: text/plain;charset=UTF-8' \
109+
-H 'origin: https://3000-samagradevelop-workflow-mxpsr1yqse0.ws-us92.gitpod.io' \
110+
-H 'referer: https://3000-samagradevelop-workflow-mxpsr1yqse0.ws-us92.gitpod.io/' \
111+
-H 'sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"' \
112+
-H 'sec-ch-ua-mobile: ?0' \
113+
-H 'sec-ch-ua-platform: "macOS"' \
114+
-H 'sec-fetch-dest: empty' \
115+
-H 'sec-fetch-mode: cors' \
116+
-H 'sec-fetch-site: same-site' \
117+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' \
118+
--data-raw '{}' \
119+
--compressed
159120
```
160121

161122
## Architecture
@@ -259,4 +220,4 @@ TODO: Add details on the specifications
259220

260221
## Possible Attack Vectors
261222
1. XSS (High Priority) - Simple form
262-
2. SQL Injection (High Priority) - needs to be fixed.
223+
2. SQL Injection (High Priority) - needs to be fixed.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "REACT_APP_GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL}" > .env

0 commit comments

Comments
 (0)