From d59ee0e0185cf845c8dc38e52a815c1156ee0691 Mon Sep 17 00:00:00 2001 From: Rahul K R Date: Mon, 5 Feb 2024 09:34:53 +0530 Subject: [PATCH 01/81] README 2.5.0 --- README.md | 245 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 198 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 587d766c..c2ef52cb 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,23 @@ CONTENTS OF THIS FILE --------------------- * Dependencies - * Ionic-Android build Setup - * Cli setup + * Command-line setup * Project setup - * Build apk - * Debug apk + * Build MentorED + * Debug MentorED + * Hashicorp Vault Setup + * Jenkins Pipeline + * Ansible Deployment Script + * Env Files, Server.js And Pm2 Config Files DEPENDENCIES ---------------------- +------------ + * Ionic: - Ionic CLI : 6.19.1 (/usr/local/lib/node_modules/@ionic/cli) - Ionic Framework : @ionic/angular 6.1.7 + Ionic CLI : 7.1.1 (/usr/local/lib/node_modules/@ionic/cli) + Ionic Framework : @ionic/angular 6.7.5 @angular-devkit/build-angular : 13.2.6 @angular-devkit/schematics : 13.2.6 @angular/cli : 13.2.6 @@ -22,10 +26,10 @@ DEPENDENCIES * Capacitor: - Capacitor CLI : 3.5.1 - @capacitor/android : 3.5.0 - @capacitor/core : 3.5.1 - @capacitor/ios : 3.5.0 + Capacitor CLI : 5.5.1 + @capacitor/android : 5.5.1 + @capacitor/core : 5.5.1 + @capacitor/ios : 5.5.1 * Cordova: @@ -36,61 +40,208 @@ DEPENDENCIES * Utility: cordova-res : 0.15.4 - native-run : 1.6.0 + native-run : 1.7.4 * System: - Android SDK Tools : 26.1.1 (/home/afnan/Android/Sdk) - NodeJS : v14.19.0 (/usr/local/bin/node) - npm : 6.14.16 + Android SDK Tools : 26.1.1 + NodeJS : v18.18.2 (you can download from https://nodejs.org/) + npm : 10.2.0 OS : Linux 5.13 -IONIC-ANDROID BUILD SETUP ---------------------- - -- [Install java] (https://www.oracle.com/java/technologies/downloads/#java8) -- [Install Gradle] (https://gradle.org/install/) -- [Install Android Studio] (https://developer.android.com/studio) - -- After Android studio installation, install SDK -- Open Android studio and goto settings/appearance and behavior/system settings/Android SDK -- Install appropriate Android sdk platform package. -- Add environment variables in ~/.bashrc or ~/.bash_profile as follows - export ANDROID_SDK_ROOT=path_to_sdk - export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin - export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools -- Reference: https://ionicframework.com/docs/installation/android - - CLI SETUP ---------------------- +--------- -- `npm install -g ionic` -- `npm install @capacitor/core` -- `npm install @capacitor/cli --save-dev` -- `npx cap init` +- npm install -g ionic +- npm install -g @ionic/cli +- npm install @capacitor/core +- npm install @capacitor/cli --save-dev PROJECT SETUP ---------------------- +------------- - git clone the repo (https://github.com/ELEVATE-Prjoect/mentoring-mobile-app.git) +- Checkout to latest branch.(currently release-2.5.0) - Add environment files inside src/environments - Go to project folder and run npm i -BUILD APK ---------------------- -- To check attached devices do adb devices -- Run ionic build (Make sure you have attached device) +BUILD MENTORED +-------------- + +- Run npx cap sync +- Run ionic build - Run ionic cap sync -- Run ionic capacitor run android --prod -- Apk location project_folder/platforms/android/app/build/outputs/apk/debug/apk_name.apk +- Run ionic serve to serve the project in local -DEBUG APK +DEBUG MENTORED +-------------- + +- Open the running app in browser +- Start inspecting using chrome dev tools or any alternatives + +HASHICORP VAULT SETUP --------------------- -- Open chrome and enter chrome://inspect -- Select app \ No newline at end of file + +JENKINS PIPELINE +---------------- + +For automating your app deployment, you can use Jenkins. You can create a Jenkins job and run that job each time you want a deployment. +For that you can create a Jenkins job and add a pipeline script for the job inside the job’s ‘Configure’ section. For example, see below. + + pipeline { agent any + options { + disableConcurrentBuilds() + } + stages { + stage("git"){ + steps{ + + git branch: '', url: '' + } + + } + stage("ansible run"){ + steps{ + + ansiblePlaybook becomeUser: 'jenkins', + credentialsId:’your-cred-id’, + extras: "-e vaultAddress= -e gitBranch=", + installation: 'ansible', + inventory: '', + playbook: '' + } + + } + } + } + +This pipeline will help to fetch the latest code from the given branch in repo and run the ansible script which we are about to create for building and deploying our application. + +ANSIBLE DEPLOYMENT SCRIPT +------------------------- + +Add an ansible script inside the ‘deployment’ folder in the root folder of your project. And add that path in your jenkins pipeline. When you run the job in jenkins, this script will get executed step by step till the end. Please update all the necessary details in the below example. + +Eg : + + - hosts: “” + vars: + project_path: + root_path: + //Add variables here if needed. (Remove this line in your code) + tasks: + - name: Get the token for Hashicorp vault + slurp: + src: "" + register: slurpfile + - name: Run vault credentials and get the environment related secrets stored in hashicorp vault + shell: "curl --location --request GET '{{ vaultAddress }}' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data' > '{{root_path}}/data2.json'" + register: vaultCurl + - name: Change directory + shell: cd {{project_path}} + - name: Fetch the latest code + git: + repo: git-url + dest: "{{project_path}}" + version: "{{gitBranch}}" + force: yes + - name: Update npm + shell: cd {{project_path}} && npm i --force + - name: Set permission + shell: chmod 744 {{ project_path }}/src/scripts/json2env.sh + - name: Generate .env and store it in environment folder + shell: cat {{root_path}}/data2.json | jq '.data' > {{ project_path }}/src/environments/environment.ts && sed -i '1s/^/export const environment = \n/' {{ project_path }}/src/environments/environment.ts + register: envConfig + - debug: msg=" cred {{ envConfig }} " + - name: Change directory + shell: chdir {{project_path}} + - name: Fetch pm2 config file from Hashicorp vault + shell: "curl --location --request GET '{{ vaultAddress }}' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data.data' > '{{ project_path }}/pm2.config.json'" + register: pm2 + - name: Change directory + shell: cd {{project_path}} + - name: Remove www folder + shell: rm -rf www + - name: Build pwa app to deploy + shell: cd {{project_path}} && ionic build --prod + - name: Start pm2 with pm2 config file and finish deployment + shell: cd {{project_path}} && pm2 start pm2.config.json + + +Please remove all the unwanted lines. + +You also have to add a script inside /src/scripts/json2env.sh + + + #!/bin/sh + + tr -d '\n' | + grep -o '"[A-Za-z\_][A-Za-z_0-9]\+"\s*:\s*\("[^"]\+"\|[0-9\.]\+\|true\|false\|null\)' | + sed 's/"\(._\)"\s_:\s\*"\?\([^"]\+\)"\?/\1= "\2"/' + +This script will convert the fetched data from hashicorp to env files. + + + +ENV FILES, SERVER.JS AND PM2 CONFIG FILES +----------------------------------------- + +For deploying your application, you need an Environment file, Server.js, and a pm2.config.json file. Adding structure of those below for reference. + + export const environment = { + production: true / false, + name: "", + staging: true / false, + dev: true / false, + baseUrl: "", + sqliteDBName: " (if you have)", + deepLinkUrl: "", + privacyPolicyUrl: "", + termsOfServiceUrl: "", + }; + +* pm2.config.json file structure : + + { + "apps": [ + { + "name": "", + "script": "server.js", + "args": [], + "instances": "1", + "exec_mode": "cluster", + "watch": false, + "merge_logs": true, + "env": { + "NODE_ENV": "production", + "PORT": + } + } + ] + } + + +* Server.js file structure: + + const express = require('express'); + const path = require('path'); + const app = express(); + const port = process.env.PORT || 7601; + + + app.use(express.static(path.join(__dirname, 'www'))); + + + app.get('*', (req, res) => { + res.sendFile(path.join(__dirname, 'www', 'index.html')); + }); + + + app.listen(port, () => { + console.log(`Server is running on port ${port}`); + }); From 57021db2ff4d8c2e289161acd51c25e209dc4658 Mon Sep 17 00:00:00 2001 From: Nanditha K <106753017+nanditha938@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:10:09 +0530 Subject: [PATCH 02/81] Edits to product names, dependencies, and project setup - Changed MentorED to Mentor. - Corrected capitalization in product names such as HashiCorp and Node.js. - Added title case for headings. - Tabulated the dependencies. - Corrections to URL and instructions in Project Setup. --- README.md | 86 ++++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index c2ef52cb..24062f48 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,32 @@ -CONTENTS OF THIS FILE +# Customizing the PWA + +Contents --------------------- * Dependencies * Command-line setup * Project setup - * Build MentorED - * Debug MentorED - * Hashicorp Vault Setup + * Build Mentor + * Debug Mentor + * HashiCorp Vault setup * Jenkins Pipeline * Ansible Deployment Script - * Env Files, Server.js And Pm2 Config Files + * Environment files, Server.js, and pm2.config.json -DEPENDENCIES +Dependencies ------------ -* Ionic: - - Ionic CLI : 7.1.1 (/usr/local/lib/node_modules/@ionic/cli) - Ionic Framework : @ionic/angular 6.7.5 - @angular-devkit/build-angular : 13.2.6 - @angular-devkit/schematics : 13.2.6 - @angular/cli : 13.2.6 - @ionic/angular-toolkit : 6.1.0 - -* Capacitor: - - Capacitor CLI : 5.5.1 - @capacitor/android : 5.5.1 - @capacitor/core : 5.5.1 - @capacitor/ios : 5.5.1 - -* Cordova: - - Cordova CLI : 11.0.0 - Cordova Platforms : none - Cordova Plugins : no whitelisted plugins (0 plugins total) - -* Utility: - - cordova-res : 0.15.4 - native-run : 1.7.4 - -* System: - - Android SDK Tools : 26.1.1 - NodeJS : v18.18.2 (you can download from https://nodejs.org/) - npm : 10.2.0 - OS : Linux 5.13 - +| Requirement | Description | +|--------------|-----------| +| Ionic CLI|Version 7.1.1 (/usr/local/lib/node_modules/@ionic/cli)| +| Ionic Framework |
  • @ionic/angular 6.7.5
  • @angular-devkit/build-angular : 13.2.6
  • @angular-devkit/schematics : 13.2.6
  • @angular/cli : 13.2.6
  • @ionic/angular-toolkit : 6.1.0
| +| Capacitor |
  • Capacitor CLI : 5.5.1
  • @capacitor/android : 5.5.1
  • @capacitor/core : 5.5.1
  • @capacitor/ios : 5.5.1
| +| Cordova |
  • Cordova CLI : 11.0.0
  • Cordova Platforms : none
  • Cordova Plugins : no whitelisted plugins (0 plugins total)
| +| Utility |
  • cordova-res : 0.15.4
  • native-run : 1.7.4
+| System |
  • Android SDK Tools : 26.1.1
  • Node.js®: v18.18.2
  • npm: 10.2.0
  • OS : Linux 5.13
| -CLI SETUP +CLI Setup --------- - npm install -g ionic @@ -59,16 +35,16 @@ CLI SETUP - npm install @capacitor/cli --save-dev -PROJECT SETUP +Project Setup ------------- -- git clone the repo (https://github.com/ELEVATE-Prjoect/mentoring-mobile-app.git) -- Checkout to latest branch.(currently release-2.5.0) -- Add environment files inside src/environments -- Go to project folder and run npm i +1. Clone the [repository](https://github.com/ELEVATE-Project/mentoring-mobile-app.git). +2. Change to the latest GitHub branch (**release-2.5.0**). +3. Add environment files into the src/environments folder. +4. Go to the project folder and run `npm i`. -BUILD MENTORED +Build Mentor -------------- - Run npx cap sync @@ -77,17 +53,17 @@ BUILD MENTORED - Run ionic serve to serve the project in local -DEBUG MENTORED +Debug Mentor -------------- -- Open the running app in browser -- Start inspecting using chrome dev tools or any alternatives +- Open the running app in the browser. +- Start inspecting using Chrome dev tools or any alternatives. -HASHICORP VAULT SETUP +HashiCorp Vault Setup --------------------- -JENKINS PIPELINE +Jenkins Pipeline ---------------- For automating your app deployment, you can use Jenkins. You can create a Jenkins job and run that job each time you want a deployment. @@ -122,7 +98,7 @@ For that you can create a Jenkins job and add a pipeline script for the job insi This pipeline will help to fetch the latest code from the given branch in repo and run the ansible script which we are about to create for building and deploying our application. -ANSIBLE DEPLOYMENT SCRIPT +Ansible Deployment Script ------------------------- Add an ansible script inside the ‘deployment’ folder in the root folder of your project. And add that path in your jenkins pipeline. When you run the job in jenkins, this script will get executed step by step till the end. Please update all the necessary details in the below example. @@ -188,8 +164,8 @@ This script will convert the fetched data from hashicorp to env files. -ENV FILES, SERVER.JS AND PM2 CONFIG FILES ------------------------------------------ +Structure of Environment file, Server.js, and pm2.config.json +------------------------------------------------------------- For deploying your application, you need an Environment file, Server.js, and a pm2.config.json file. Adding structure of those below for reference. From 4ca2c74bc9d4422d59cea5463650a4355f5db321 Mon Sep 17 00:00:00 2001 From: Nanditha K <106753017+nanditha938@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:11:50 +0530 Subject: [PATCH 03/81] Added instructions in CLI Setup and Build Mentor sections. Added code blocks to the file structures. --- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 24062f48..65f0c67e 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,29 @@ Dependencies CLI Setup --------- -- npm install -g ionic -- npm install -g @ionic/cli -- npm install @capacitor/core -- npm install @capacitor/cli --save-dev +1. Install the Ionic framework. + ``` + npm install -g ionic + ``` + +2. Install the Ionic client. + + ``` + npm install -g @ionic/cli + ``` + +3. Install the Capacitor Core. + + ``` + npm install @capacitor/core + ``` + +4. Install the Capacitor runtime Client. + + ``` + npm install @capacitor/cli --save-dev + ``` Project Setup ------------- @@ -47,17 +65,39 @@ Project Setup Build Mentor -------------- -- Run npx cap sync -- Run ionic build -- Run ionic cap sync -- Run ionic serve to serve the project in local +1. To add the Capacitor plugin, run the following command: + + ``` + npx cap sync + + ``` + +2. To run a development build, run the following command: + + ``` + ionic build + ``` + +3. To perform an Ionic build and update any Capacitor plugins or dependencies, run the capacitor sync command. + + ``` + ionic cap sync + + ``` + +4. Run the project on your local system using the following command: + + ``` + ionic serve + + ``` Debug Mentor -------------- -- Open the running app in the browser. -- Start inspecting using Chrome dev tools or any alternatives. +1. Open the running app in the browser. +2. Start inspecting using Chrome dev tools or any alternatives. HashiCorp Vault Setup --------------------- @@ -101,9 +141,7 @@ This pipeline will help to fetch the latest code from the given branch in repo a Ansible Deployment Script ------------------------- -Add an ansible script inside the ‘deployment’ folder in the root folder of your project. And add that path in your jenkins pipeline. When you run the job in jenkins, this script will get executed step by step till the end. Please update all the necessary details in the below example. - -Eg : +Add an ansible script inside the ‘deployment’ folder in the root folder of your project. And add that path in your jenkins pipeline. When you run the job in jenkins, this script will get executed step by step till the end. Please update all the necessary details in the following example: - hosts: “” vars: @@ -167,8 +205,11 @@ This script will convert the fetched data from hashicorp to env files. Structure of Environment file, Server.js, and pm2.config.json ------------------------------------------------------------- -For deploying your application, you need an Environment file, Server.js, and a pm2.config.json file. Adding structure of those below for reference. +For deploying your application, you need an Environment file, Server.js, and a pm2.config.json file. +### Structure of environment.ts File + + ```jsx export const environment = { production: true / false, name: "", @@ -180,9 +221,11 @@ For deploying your application, you need an Environment file, Server.js, and a p privacyPolicyUrl: "", termsOfServiceUrl: "", }; +``` -* pm2.config.json file structure : +### Structure of pm2.config.json File +```json { "apps": [ { @@ -200,10 +243,11 @@ For deploying your application, you need an Environment file, Server.js, and a p } ] } +``` +### Structure of Server.js File -* Server.js file structure: - +```jsx const express = require('express'); const path = require('path'); const app = express(); @@ -221,3 +265,4 @@ For deploying your application, you need an Environment file, Server.js, and a p app.listen(port, () => { console.log(`Server is running on port ${port}`); }); +``` From 6a14be00d47074d5444103cc165814f310dd4acb Mon Sep 17 00:00:00 2001 From: Nanditha K <106753017+nanditha938@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:27:39 +0530 Subject: [PATCH 04/81] Added the updated Ansible script received from the team. Editorial changes to HashiCorp setup, Jenkins, and Ansible script sections. --- README.md | 217 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 112 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index 65f0c67e..85db7a4a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Customizing the PWA +The Mentor PWA is developed using the Ionic framework. This document provides instructions on setting up the development environment. + Contents --------------------- @@ -26,8 +28,8 @@ Dependencies | Utility |
  • cordova-res : 0.15.4
  • native-run : 1.7.4
| System |
  • Android SDK Tools : 26.1.1
  • Node.js®: v18.18.2
  • npm: 10.2.0
  • OS : Linux 5.13
| -CLI Setup ---------- +Setting up the CLI +------------------ 1. Install the Ionic framework. @@ -53,8 +55,8 @@ CLI Setup npm install @capacitor/cli --save-dev ``` -Project Setup -------------- +Setting up the Project +---------------------- 1. Clone the [repository](https://github.com/ELEVATE-Project/mentoring-mobile-app.git). 2. Change to the latest GitHub branch (**release-2.5.0**). @@ -62,8 +64,8 @@ Project Setup 4. Go to the project folder and run `npm i`. -Build Mentor --------------- +Building the Mentor App +----------------------- 1. To add the Capacitor plugin, run the following command: @@ -93,114 +95,119 @@ Build Mentor ``` -Debug Mentor --------------- +Debugging the Mentor App +------------------------ 1. Open the running app in the browser. 2. Start inspecting using Chrome dev tools or any alternatives. -HashiCorp Vault Setup ---------------------- +Setting up the HashiCorp Vault +------------------------------ +After setting up the HashiCorp Vault, you must add the Vault address to the Jenkins® Pipeline script and Ansible® deployment script. -Jenkins Pipeline ----------------- - -For automating your app deployment, you can use Jenkins. You can create a Jenkins job and run that job each time you want a deployment. -For that you can create a Jenkins job and add a pipeline script for the job inside the job’s ‘Configure’ section. For example, see below. - - pipeline { agent any - options { - disableConcurrentBuilds() - } - stages { - stage("git"){ - steps{ - - git branch: '', url: '' - } - - } - stage("ansible run"){ - steps{ - - ansiblePlaybook becomeUser: 'jenkins', - credentialsId:’your-cred-id’, - extras: "-e vaultAddress= -e gitBranch=", - installation: 'ansible', - inventory: '', - playbook: '' - } - - } - } - } +Creating a Jenkins Job +---------------------- +To automate your app deployment using Jenkins, do as follows: + +1. Create a Jenkins job each time you want a deployment. + +2. Add the pipeline script for the job inside the job’s **Configure** section. This pipeline will fetch the latest code from the given branch in the repository and run the [Ansible script](#deploying-the-application-using-an-ansible-script). + + ``` + pipeline { agent any + options { + disableConcurrentBuilds() + } + stages { + stage("git"){ + steps{ + + git branch: '', url: '' + } + + } + stage("ansible run"){ + steps{ + + ansiblePlaybook becomeUser: 'jenkins', + credentialsId:’your-cred-id’, + extras: "-e vaultAddress= -e gitBranch=", + installation: 'ansible', + inventory: '', + playbook: '' + } + + } + } + } + ``` -This pipeline will help to fetch the latest code from the given branch in repo and run the ansible script which we are about to create for building and deploying our application. - -Ansible Deployment Script -------------------------- - -Add an ansible script inside the ‘deployment’ folder in the root folder of your project. And add that path in your jenkins pipeline. When you run the job in jenkins, this script will get executed step by step till the end. Please update all the necessary details in the following example: - - - hosts: “” - vars: - project_path: - root_path: - //Add variables here if needed. (Remove this line in your code) - tasks: - - name: Get the token for Hashicorp vault - slurp: - src: "" - register: slurpfile - - name: Run vault credentials and get the environment related secrets stored in hashicorp vault - shell: "curl --location --request GET '{{ vaultAddress }}' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data' > '{{root_path}}/data2.json'" - register: vaultCurl - - name: Change directory - shell: cd {{project_path}} - - name: Fetch the latest code - git: - repo: git-url - dest: "{{project_path}}" - version: "{{gitBranch}}" - force: yes - - name: Update npm - shell: cd {{project_path}} && npm i --force - - name: Set permission - shell: chmod 744 {{ project_path }}/src/scripts/json2env.sh - - name: Generate .env and store it in environment folder - shell: cat {{root_path}}/data2.json | jq '.data' > {{ project_path }}/src/environments/environment.ts && sed -i '1s/^/export const environment = \n/' {{ project_path }}/src/environments/environment.ts - register: envConfig - - debug: msg=" cred {{ envConfig }} " - - name: Change directory - shell: chdir {{project_path}} - - name: Fetch pm2 config file from Hashicorp vault - shell: "curl --location --request GET '{{ vaultAddress }}' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data.data' > '{{ project_path }}/pm2.config.json'" - register: pm2 - - name: Change directory - shell: cd {{project_path}} - - name: Remove www folder - shell: rm -rf www - - name: Build pwa app to deploy - shell: cd {{project_path}} && ionic build --prod - - name: Start pm2 with pm2 config file and finish deployment - shell: cd {{project_path}} && pm2 start pm2.config.json - - -Please remove all the unwanted lines. - -You also have to add a script inside /src/scripts/json2env.sh - - - #!/bin/sh - - tr -d '\n' | - grep -o '"[A-Za-z\_][A-Za-z_0-9]\+"\s*:\s*\("[^"]\+"\|[0-9\.]\+\|true\|false\|null\)' | - sed 's/"\(._\)"\s_:\s\*"\?\([^"]\+\)"\?/\1= "\2"/' - -This script will convert the fetched data from hashicorp to env files. +Deploying the Application Using an Ansible Script +------------------------------------------------- +To build and deploy the application using an Ansible script, do as follows: +1. Add an Ansible script to the **deployment** folder in the root folder of your project. + + >**Note**: Update the script with details (such as paths) that are specific to your project. + + ``` + - hosts: + vars: + project_path: + root_path: + //Add variables here if needed. (Remove this line in your code) + tasks: + - name: Slurp host file + slurp: + src: "" + register: slurpfile + - name: Run the HashiCorp Vault credentials + shell: "curl --location --request GET '{{ vaultAddress }}mentored-portal' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data' > '{{root_path}}/data2.json'" + register: vaultCurl + - name: Change directory + shell: cd {{project_path}} + - name: Fetch the latest code + git: + repo: https://github.com/ELEVATE-Project/mentoring-mobile-app + dest: "{{project_path}}" + version: "{{gitBranch}}" + force: yes + - name: Update npm + shell: cd {{project_path}} && npm i --force + - name: Set permission + shell: chmod 744 {{ project_path }}/src/scripts/json2env.sh + - name: Generate .env + shell: cat {{root_path}}/data2.json | jq '.data' > {{ project_path }}/src/environments/environment.ts && sed -i '1s/^/export const environment = \n/' {{ project_path }}/src/environments/environment.ts + register: envConfig + - debug: msg=" cred {{ envConfig }} " + - name: Change directory + shell: chdir {{project_path}} + - name: Fetch pm2 config file + shell: "curl --location --request GET '{{ vaultAddress }}portalPm2Config' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data.data' > '{{ project_path }}/pm2.config.json'" + register: pm2 + - name: Change directory + shell: cd {{project_path}} + - name: Remove www folder + shell: rm -rf www + - name: Build pwa app + shell: cd {{project_path}} && ionic build --prod + - name: Start pm2 + shell: cd {{project_path}} && pm2 start pm2.config.json + ``` + +3. Add the script's path to the [Jenkins Pipeline script](#creating-a-jenkins-job). When you run the Jenkins job, the script is executed. + +4. To convert the JSON file that was fetched from the HashiCorp Vault to an env format, add the following script to ```/src/scripts/json2env.sh.```: + + ``` + #!/bin/sh + + tr -d '\n' | + grep -o '"[A-Za-z\_][A-Za-z_0-9]\+"\s*:\s*\("[^"]\+"\|[0-9\.]\+\|true\|false\|null\)' | + sed 's/"\(._\)"\s_:\s\*"\?\([^"]\+\)"\?/\1= "\2"/' + ``` Structure of Environment file, Server.js, and pm2.config.json ------------------------------------------------------------- From 7d5050bdf6180a82ec23ea06a59715d2aaa4650f Mon Sep 17 00:00:00 2001 From: Nanditha K <106753017+nanditha938@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:18:17 +0530 Subject: [PATCH 05/81] Edits to 'Contents' Included links to the specific sections in Contents. --- README.md | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 85db7a4a..72d8b3a4 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,15 @@ The Mentor PWA is developed using the Ionic framework. This document provides in Contents --------------------- - * Dependencies - * Command-line setup - * Project setup - * Build Mentor - * Debug Mentor - * HashiCorp Vault setup - * Jenkins Pipeline - * Ansible Deployment Script - * Environment files, Server.js, and pm2.config.json - + * [Dependencies](#dependencies) + * [Setting up the CLI](#setting-up-the-cli) + * [Setting up the Project](#setting-up-the-project) + * [Building the Application](#building-the-application) + * [Debugging the Application](#debugging-the-application) + * [Setting up the HashiCorp® Vault](#setting-up-the-hashicorp-vault) + * [Creating a Jenkins® Job](#creating-a-jenkins-job) + * [Deploying the Application Using an Ansible® Script](#deploying-the-application-using-an-ansible-script) + * [Structure of Environment file, Server.js, and pm2.config.json](#structure-of-environment-file-serverjs-and-pm2configjson) Dependencies ------------ @@ -64,8 +63,8 @@ Setting up the Project 4. Go to the project folder and run `npm i`. -Building the Mentor App ------------------------ +Building the Application +------------------------ 1. To add the Capacitor plugin, run the following command: @@ -95,8 +94,8 @@ Building the Mentor App ``` -Debugging the Mentor App ------------------------- +Debugging the Application +------------------------- 1. Open the running app in the browser. 2. Start inspecting using Chrome dev tools or any alternatives. @@ -104,7 +103,7 @@ Debugging the Mentor App Setting up the HashiCorp Vault ------------------------------ -After setting up the HashiCorp Vault, you must add the Vault address to the Jenkins® Pipeline script and Ansible® deployment script. +After setting up the HashiCorp Vault, you must add the Vault address to the Jenkins Pipeline script and Ansible deployment script. Creating a Jenkins Job ---------------------- From 2659f2b3cd5235daa013c88005623133d18fec72 Mon Sep 17 00:00:00 2001 From: Cafnanc Date: Fri, 10 May 2024 12:47:35 +0530 Subject: [PATCH 06/81] readme changes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72d8b3a4..f9c2e941 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Setting up the Project ---------------------- 1. Clone the [repository](https://github.com/ELEVATE-Project/mentoring-mobile-app.git). -2. Change to the latest GitHub branch (**release-2.5.0**). +2. Change to the latest GitHub branch (**release-2.6.1**). 3. Add environment files into the src/environments folder. 4. Go to the project folder and run `npm i`. From 68bbf427792cd985791e401bf7d67e408e3524b7 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Thu, 30 May 2024 16:35:59 +0530 Subject: [PATCH 07/81] Addition of Dockerfile --- Dockerfile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5b6b0612 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM node:14 AS build + +WORKDIR /app + +RUN npm install -g @angular/cli@13.2.3 + +RUN npm install -g @ionic/cli@6.0.0 + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN ionic build --prod + +FROM node:14 AS final + +WORKDIR /usr/src/app + +COPY --from=build /app/www ./www + +RUN npm install -g serve + +EXPOSE 80 + +CMD ["serve", "-s", "www", "-p", "80"] From ae45cf243e0edd1be434106cd278a9434562fef2 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Thu, 30 May 2024 16:51:31 +0530 Subject: [PATCH 08/81] Added build script and Jenkinsfile --- Jenkinsfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 26 ++++++++------------------ 2 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..276f2938 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,47 @@ +node('build-slave') { + try { + String ANSI_GREEN = "\u001B[32m" + String ANSI_NORMAL = "\u001B[0m" + String ANSI_BOLD = "\u001B[1m" + String ANSI_RED = "\u001B[31m" + String ANSI_YELLOW = "\u001B[33m" + + ansiColor('xterm') { + stage('Checkout') { + if (!env.hub_org) { + println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL) + error 'Please resolve the errors and rerun..' + } else + println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL) + } + + cleanWs() + checkout scm + commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + build_tag = sh(script: "echo " + params.github_release_tag.split('/')[-1] + "_" + commit_hash + "_" + env.BUILD_NUMBER, returnStdout: true).trim() + echo "build_tag: " + build_tag + + + stage('Build') { + env.NODE_ENV = "build" + print "Environment will be : ${env.NODE_ENV}" + sh('chmod 777 build.sh') + sh("bash -x build.sh ${build_tag} ${env.NODE_NAME} ${docker_server}") + } + + + stage('ArchiveArtifacts') { + sh ("echo ${build_tag} > build_tag.txt") + archiveArtifacts "metadata.json" + archiveArtifacts "build_tag.txt" + currentBuild.description = "${build_tag}" + } + + } + } + catch (err) { + currentBuild.result = "FAILURE" + throw err + } + +} \ No newline at end of file diff --git a/build.sh b/build.sh index c0d209d4..9c889345 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,11 @@ -rm -rf node_modules -rm -rf www - -rm package-lock.json && npm install - - #!/bin/bash +# Build script +set -eo pipefail -rm android/app/build/outputs/apk/debug - -ionic capacitor build android --release --prod --stacktrace - -cd android - -./gradlew clean - -./gradlew bundle - -cd .. +build_tag=$1 +name='kb-portal' +node=$2 +org=$3 -jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore mentoring-key.keystore android/app/build/outputs/bundle/release/app-release.aab mentoring-key \ No newline at end of file +docker build -f Dockerfile --label commitHash=$(git rev-parse --short HEAD) -t ${org}/${name}:${build_tag} . +echo {\"image_name\" : \"${name}\", \"image_tag\" : \"${build_tag}\", \"node_name\" : \"$node\"} > metadata.json \ No newline at end of file From 3a584aae6a5b77f528cdf25c9427a212f92a912d Mon Sep 17 00:00:00 2001 From: rakeshSgr Date: Fri, 31 May 2024 17:48:16 +0530 Subject: [PATCH 09/81] jenkins and build file updated --- Jenkinsfile | 2 +- build.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 276f2938..4dd47b27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,4 +44,4 @@ node('build-slave') { throw err } -} \ No newline at end of file +} diff --git a/build.sh b/build.sh index 9c889345..47b726ba 100755 --- a/build.sh +++ b/build.sh @@ -3,9 +3,9 @@ set -eo pipefail build_tag=$1 -name='kb-portal' +name='mentoring-portal' node=$2 org=$3 docker build -f Dockerfile --label commitHash=$(git rev-parse --short HEAD) -t ${org}/${name}:${build_tag} . -echo {\"image_name\" : \"${name}\", \"image_tag\" : \"${build_tag}\", \"node_name\" : \"$node\"} > metadata.json \ No newline at end of file +echo {\"image_name\" : \"${name}\", \"image_tag\" : \"${build_tag}\", \"node_name\" : \"$node\"} > metadata.json From 5457943ecaf817fac07dc4e982d318de81e9b2f1 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Tue, 4 Jun 2024 13:45:48 +0530 Subject: [PATCH 10/81] env file added for post build addition --- src/app/app.component.ts | 3 +-- src/app/core/services/http/http.service.ts | 3 +-- src/app/core/services/user/user.service.ts | 3 +-- src/app/core/services/util/util.service.ts | 3 +-- src/app/pages/auth/login/login.page.ts | 9 ++++----- src/app/pages/auth/otp/otp.page.ts | 7 +++---- src/app/pages/auth/register/register.page.ts | 17 ++++++++--------- .../auth/reset-password/reset-password.page.ts | 17 ++++++++--------- .../change-password/change-password.page.ts | 17 ++++++++--------- src/assets/env/env.js | 18 ++++++++++++++++++ src/index.html | 2 ++ 11 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 src/assets/env/env.js diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0944e64a..d756725f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -10,7 +10,6 @@ import { ProfileService } from './core/services/profile/profile.service'; import { Location } from '@angular/common'; import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx'; import { App, URLOpenListenerEvent } from '@capacitor/app'; -import { environment } from 'src/environments/environment'; import { Capacitor } from '@capacitor/core'; import { SwUpdate } from '@angular/service-worker'; import { PermissionService } from './core/services/permission/permission.service'; @@ -164,7 +163,7 @@ export class AppComponent { }) App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => { this.zone.run(() => { - const domain = environment.deepLinkUrl + const domain = window['env']['deepLinkUrl']; const slug = event.url.split(domain).pop(); if (slug) { this.router.navigateByUrl(slug); diff --git a/src/app/core/services/http/http.service.ts b/src/app/core/services/http/http.service.ts index 4225b4a6..eebc7149 100644 --- a/src/app/core/services/http/http.service.ts +++ b/src/app/core/services/http/http.service.ts @@ -1,6 +1,5 @@ import { Injectable, Injector } from '@angular/core'; import { RequestParams } from '../../interface/request-param'; -import { environment } from 'src/environments/environment'; import * as _ from 'lodash-es'; import { UserService } from '../user/user.service'; import { NetworkService } from '../network.service'; @@ -34,7 +33,7 @@ export class HttpService { private translate: TranslateService, private alert: AlertController, ) { - this.baseUrl = environment.baseUrl; + this.baseUrl = window['env']['baseUrl']; } async setHeaders() { diff --git a/src/app/core/services/user/user.service.ts b/src/app/core/services/user/user.service.ts index 7488d74d..2857e1b7 100644 --- a/src/app/core/services/user/user.service.ts +++ b/src/app/core/services/user/user.service.ts @@ -4,7 +4,6 @@ import { LocalStorageService } from '../localstorage.service'; import * as _ from 'lodash-es'; import jwt_decode from "jwt-decode"; import * as moment from 'moment'; -import { environment } from 'src/environments/environment'; import { Subject } from 'rxjs'; @Injectable({ @@ -18,7 +17,7 @@ export class UserService { constructor( private localStorage: LocalStorageService, ) { - this.baseUrl = environment.baseUrl; + this.baseUrl = window['env']['baseUrl']; } async getUserValue() { diff --git a/src/app/core/services/util/util.service.ts b/src/app/core/services/util/util.service.ts index 206eb27e..751dc8b2 100644 --- a/src/app/core/services/util/util.service.ts +++ b/src/app/core/services/util/util.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'; import { Share } from '@capacitor/share'; import { AlertController, ModalController } from '@ionic/angular'; import { TranslateService } from '@ngx-translate/core'; -import { environment } from 'src/environments/environment'; import { ISocialSharing } from '../../interface/soical-sharing-interface'; import { ModelComponent } from 'src/app/shared/components/model/model.component'; import * as Bowser from "bowser" @@ -28,7 +27,7 @@ export class UtilService { } getDeepLink(url){ - return environment.deepLinkUrl+url; + return window['env']['deepLinkUrl']+url; } async shareLink(param:ISocialSharing) { diff --git a/src/app/pages/auth/login/login.page.ts b/src/app/pages/auth/login/login.page.ts index 9907ac07..f129338e 100644 --- a/src/app/pages/auth/login/login.page.ts +++ b/src/app/pages/auth/login/login.page.ts @@ -5,7 +5,6 @@ import { TranslateService } from '@ngx-translate/core'; import { AuthService, LocalStorageService, UserService, UtilService } from 'src/app/core/services'; import { DynamicFormComponent, JsonFormData } from 'src/app/shared/components/dynamic-form/dynamic-form.component'; import { CommonRoutes } from 'src/global.routes'; -import { environment } from 'src/environments/environment'; import { ProfileService } from 'src/app/core/services/profile/profile.service'; import { localKeys } from 'src/app/core/constants/localStorage.keys'; import { RecaptchaComponent } from 'ng-recaptcha'; @@ -52,7 +51,7 @@ export class LoginPage implements OnInit { }, ], }; - siteKey = (environment as any)?.recaptchaSiteKey ? (environment as any)?.recaptchaSiteKey :"" + siteKey = window['env']?.recaptchaSiteKey ? window['env']?.recaptchaSiteKey.recaptchaSiteKey :"" id: any; userDetails: any; recaptchaResolved: boolean = this.siteKey ? false : true; @@ -67,9 +66,9 @@ export class LoginPage implements OnInit { captchaToken:any=""; labels = ["LOGIN_TO_MENTOR_ED"]; mentorId: any; - supportEmail: any = environment.supportEmail; - privacyPolicyUrl =environment.privacyPolicyUrl; - termsOfServiceUrl = environment.termsOfServiceUrl; + supportEmail: any = window['env'].supportEmail; + privacyPolicyUrl = window['env'].privacyPolicyUrl; + termsOfServiceUrl = window['env'].termsOfServiceUrl; constructor(private authService: AuthService, private router: Router,private utilService: UtilService, private menuCtrl: MenuController, private activatedRoute: ActivatedRoute,private profileService: ProfileService, private translateService: TranslateService, private localStorage: LocalStorageService, private userService: UserService) { diff --git a/src/app/pages/auth/otp/otp.page.ts b/src/app/pages/auth/otp/otp.page.ts index 17a73417..e74ba5c4 100644 --- a/src/app/pages/auth/otp/otp.page.ts +++ b/src/app/pages/auth/otp/otp.page.ts @@ -5,7 +5,6 @@ import { TranslateService } from '@ngx-translate/core'; import { AuthService, LocalStorageService, ToastService } from 'src/app/core/services'; import { ProfileService } from 'src/app/core/services/profile/profile.service'; import { CommonRoutes } from 'src/global.routes'; -import { environment } from 'src/environments/environment'; import { Location } from '@angular/common'; import { RecaptchaComponent } from 'ng-recaptcha'; @@ -26,7 +25,7 @@ export class OtpPage implements OnInit { 'border-radius': '8px' } }; - siteKey = (environment as any)?.recaptchaSiteKey ? (environment as any)?.recaptchaSiteKey :"" + siteKey = window['env']?.recaptchaSiteKey ? window['env']?.recaptchaSiteKey.recaptchaSiteKey :"" resetPasswordData = { email: null, password: null, otp: null }; public headerConfig: any = { // menu: true, @@ -44,8 +43,8 @@ export class OtpPage implements OnInit { labels; signupData: any; checked: boolean = false; - privacyPolicyUrl =environment.privacyPolicyUrl; - termsOfServiceUrl = environment.termsOfServiceUrl; + privacyPolicyUrl = window['env'].privacyPolicyUrl; + termsOfServiceUrl = window['env'].termsOfServiceUrl; captchaToken:any=""; recaptchaResolved: boolean = this.siteKey ? false : true; showOtp:any = false; diff --git a/src/app/pages/auth/register/register.page.ts b/src/app/pages/auth/register/register.page.ts index b2ed3c28..ba6f9e53 100644 --- a/src/app/pages/auth/register/register.page.ts +++ b/src/app/pages/auth/register/register.page.ts @@ -9,7 +9,6 @@ import { ActivatedRoute, Router } from '@angular/router'; import { CommonRoutes } from 'src/global.routes'; import { TranslateService } from '@ngx-translate/core'; import { ProfileService } from 'src/app/core/services/profile/profile.service'; -import { environment } from 'src/environments/environment'; @Component({ selector: 'app-register', @@ -61,13 +60,13 @@ export class RegisterPage implements OnInit { position: 'floating', errorMessage:{ required: "Enter password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password?.minLength +" characters." : "Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password?.minLength +" characters." : "Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, validators: { required: true, - minLength:(environment as any)?.password?.minLength ? (environment as any)?.password?.minLength: 8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength:window['env']?.password?.minLength ? window['env']?.password?.minLength: 8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", }, }, { @@ -79,13 +78,13 @@ export class RegisterPage implements OnInit { position: 'floating', errorMessage:{ required: "Re-enter password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password.minLength+" characters.":"Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password.minLength+" characters.":"Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, validators: { required: true, - minLength: (environment as any)?.password?.minLength ? (environment as any)?.password.minLength:8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength: window['env']?.password?.minLength ? window['env']?.password.minLength:8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", } } ] diff --git a/src/app/pages/auth/reset-password/reset-password.page.ts b/src/app/pages/auth/reset-password/reset-password.page.ts index c90e4254..a4cc56b8 100644 --- a/src/app/pages/auth/reset-password/reset-password.page.ts +++ b/src/app/pages/auth/reset-password/reset-password.page.ts @@ -6,7 +6,6 @@ import { Router } from '@angular/router'; import { ProfileService } from 'src/app/core/services/profile/profile.service'; import { ToastService } from 'src/app/core/services'; import { TranslateService } from '@ngx-translate/core'; -import { environment } from 'src/environments/environment'; @Component({ selector: 'app-reset-password', @@ -41,14 +40,14 @@ export class ResetPasswordPage implements OnInit { type: 'password', errorMessage:{ required: "Enter new password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password?.minLength+" characters.":"Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password?.minLength+" characters.":"Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, position: 'floating', validators: { required: true, - minLength:(environment as any)?.password?.minLength? (environment as any)?.password?.minLength: 8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength:window['env']?.password?.minLength? window['env']?.password?.minLength: 8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", }, }, { @@ -59,14 +58,14 @@ export class ResetPasswordPage implements OnInit { type: 'password', errorMessage:{ required: "Re-enter new password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password?.minLength+" characters.":"Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password?.minLength+" characters.":"Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, position: 'floating', validators: { required: true, - minLength:(environment as any)?.password?.minLength? (environment as any)?.password?.minLength: 8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength:window['env']?.password?.minLength? window['env']?.password?.minLength: 8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", }, }, ], diff --git a/src/app/pages/change-password/change-password.page.ts b/src/app/pages/change-password/change-password.page.ts index 929f4c76..afed5970 100644 --- a/src/app/pages/change-password/change-password.page.ts +++ b/src/app/pages/change-password/change-password.page.ts @@ -3,7 +3,6 @@ import { TranslateService } from '@ngx-translate/core'; import * as _ from 'lodash'; import { AuthService, ToastService } from 'src/app/core/services'; import { DynamicFormComponent, JsonFormData } from 'src/app/shared/components'; -import { environment } from 'src/environments/environment'; @Component({ selector: 'app-change-password', @@ -44,14 +43,14 @@ public headerConfig: any = { type: 'password', errorMessage:{ required: "Enter new password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password?.minLength+" characters.":"Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password?.minLength+" characters.":"Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, position: 'floating', validators: { required: true, - minLength:(environment as any)?.password?.minLength? (environment as any)?.password?.minLength: 8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength:window['env']?.password?.minLength? window['env']?.password?.minLength: 8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", }, }, { @@ -62,14 +61,14 @@ public headerConfig: any = { type: 'password', errorMessage:{ required: "Re-enter new password", - minlength:(environment as any)?.password?.minLength ? "Please enter minimum " + (environment as any)?.password?.minLength+" characters.":"Please enter minimum 8 characters.", - pattern: (environment as any)?.password?.errorMessage ? (environment as any)?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", + minlength:window['env']?.password?.minLength ? "Please enter minimum " + window['env']?.password?.minLength+" characters.":"Please enter minimum 8 characters.", + pattern: window['env']?.password?.errorMessage ? window['env']?.password?.errorMessage :"Only letters, numbers,!@#%$&()-`.+,/\" are allowed", }, position: 'floating', validators: { required: true, - minLength:(environment as any)?.password?.minLength? (environment as any)?.password?.minLength: 8, - pattern: (environment as any)?.password?.regexPattern ? (environment as any)?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", + minLength:window['env']?.password?.minLength? window['env']?.password?.minLength: 8, + pattern: window['env']?.password?.regexPattern ? window['env']?.password?.regexPattern :"^[a-zA-Z0-9!@#%$&()\\-`.+,/\"]*$", }, }, ], diff --git a/src/assets/env/env.js b/src/assets/env/env.js new file mode 100644 index 00000000..0aeb8c7d --- /dev/null +++ b/src/assets/env/env.js @@ -0,0 +1,18 @@ +window["env"] = { + production: true, + name: 'debug environment', + staging: false, + dev: false, + baseUrl: 'base url', + sqliteDBName: 'db name', + deepLinkUrl: 'deep link', + privacyPolicyUrl:'privacy policy', + termsOfServiceUrl:'t&c', + supportEmail: "", + recaptchaSiteKey:"", + password:{ + minLength:10, + rejectPattern:"", + errorMessage:"" + }, +}; \ No newline at end of file diff --git a/src/index.html b/src/index.html index d2f7f7ea..2a67d5a7 100644 --- a/src/index.html +++ b/src/index.html @@ -22,6 +22,8 @@ + + From 6d37f040edc1787aef2e4beee6f189c3370bfb8a Mon Sep 17 00:00:00 2001 From: Haritest Date: Wed, 5 Jun 2024 15:20:32 +0530 Subject: [PATCH 11/81] Update and rename environment.sample.ts to environment.ts --- src/environments/{environment.sample.ts => environment.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/environments/{environment.sample.ts => environment.ts} (100%) diff --git a/src/environments/environment.sample.ts b/src/environments/environment.ts similarity index 100% rename from src/environments/environment.sample.ts rename to src/environments/environment.ts From 76432264722a9efba7b53650821450102f770199 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Tue, 11 Jun 2024 18:29:36 +0530 Subject: [PATCH 12/81] Port number update --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b6b0612..381b5b48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,6 @@ COPY --from=build /app/www ./www RUN npm install -g serve -EXPOSE 80 +EXPOSE 7601 -CMD ["serve", "-s", "www", "-p", "80"] +CMD ["serve", "-s", "www", "-p", "7601"] From 2834caefb038d87252722c9f0aeea866ac85c5f3 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Fri, 14 Jun 2024 12:21:18 +0530 Subject: [PATCH 13/81] baseHref and DeployUrl updated --- angular.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/angular.json b/angular.json index b364e760..fc95aa39 100644 --- a/angular.json +++ b/angular.json @@ -19,6 +19,8 @@ "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", + "baseHref": "/mentorship/", + "deployUrl": "/mentorship/", "assets": [ { "glob": "**/*", From aac2f66f83d7d2c38bf7789c57d01ed526948eb2 Mon Sep 17 00:00:00 2001 From: 5Amogh Date: Fri, 14 Jun 2024 13:46:01 +0530 Subject: [PATCH 14/81] path added to load env.js --- src/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.html b/src/index.html index 2a67d5a7..b7a992e9 100644 --- a/src/index.html +++ b/src/index.html @@ -22,7 +22,7 @@ - + From 81ded7d031e30273a12a8156aab1ce2ae4739a58 Mon Sep 17 00:00:00 2001 From: Cafnanc Date: Fri, 21 Jun 2024 14:38:51 +0530 Subject: [PATCH 15/81] theme changes --- .../components/manage-session/manage-session.component.scss | 2 +- src/app/pages/auth/register/register.page.scss | 4 ++-- src/app/pages/created-by-me/created-by-me.page.scss | 2 +- src/app/pages/mentor-details/mentor-details.page.scss | 2 +- src/app/pages/tabs/home/home.page.scss | 2 +- src/app/pages/tabs/profile/profile.page.scss | 2 +- .../components/generic-details/generic-details.component.scss | 4 ++-- .../components/generic-table/generic-table.component.scss | 2 +- .../components/search-popover/search-popover.component.scss | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/modules/admin/components/manage-session/manage-session.component.scss b/src/app/modules/admin/components/manage-session/manage-session.component.scss index 1f0d037c..918287aa 100644 --- a/src/app/modules/admin/components/manage-session/manage-session.component.scss +++ b/src/app/modules/admin/components/manage-session/manage-session.component.scss @@ -27,7 +27,7 @@ width: 20px; height: 20px; border-radius: 50%; - background-color: #832215; + background-color: var(--ion-color-primary); display: flex; align-items: center; justify-content: center; diff --git a/src/app/pages/auth/register/register.page.scss b/src/app/pages/auth/register/register.page.scss index 0fcc9229..249675b9 100644 --- a/src/app/pages/auth/register/register.page.scss +++ b/src/app/pages/auth/register/register.page.scss @@ -20,8 +20,8 @@ } .underline{ text-decoration: underline; - text-decoration-color: rgb(187, 3, 3); - color: rgb(187, 3, 3); + text-decoration-color: var(--ion-color-primary); + color: var(--ion-color-primary); margin-top: 2px; cursor: pointer; } diff --git a/src/app/pages/created-by-me/created-by-me.page.scss b/src/app/pages/created-by-me/created-by-me.page.scss index 4ea9d9d9..3bad38b4 100644 --- a/src/app/pages/created-by-me/created-by-me.page.scss +++ b/src/app/pages/created-by-me/created-by-me.page.scss @@ -11,7 +11,7 @@ padding: 5px 10px; } .no-details-message{ - color: red; + color: var(--ion-color-primary); font-size:larger; text-align: center; } diff --git a/src/app/pages/mentor-details/mentor-details.page.scss b/src/app/pages/mentor-details/mentor-details.page.scss index a9716e21..897a7588 100644 --- a/src/app/pages/mentor-details/mentor-details.page.scss +++ b/src/app/pages/mentor-details/mentor-details.page.scss @@ -27,7 +27,7 @@ ion-segment-button{ width: 50%; } .no-details-message{ - color: red; + color: var(--ion-color-primary); font-size:larger; text-align: center; margin: 20px; diff --git a/src/app/pages/tabs/home/home.page.scss b/src/app/pages/tabs/home/home.page.scss index 3fa25dbb..614c0754 100644 --- a/src/app/pages/tabs/home/home.page.scss +++ b/src/app/pages/tabs/home/home.page.scss @@ -94,7 +94,7 @@ h3{ width: 26px; height: 26px; border-radius: 50%; - background-color: #832215; + background-color: var(--ion-color-primary); --color: white; } .close-icon { diff --git a/src/app/pages/tabs/profile/profile.page.scss b/src/app/pages/tabs/profile/profile.page.scss index ef9c1dcf..72e64036 100644 --- a/src/app/pages/tabs/profile/profile.page.scss +++ b/src/app/pages/tabs/profile/profile.page.scss @@ -1,5 +1,5 @@ .no-details-message{ - color: red; + color: var(--ion-color-primary); font-size:larger; text-align: center; } diff --git a/src/app/shared/components/generic-details/generic-details.component.scss b/src/app/shared/components/generic-details/generic-details.component.scss index e06a4a5a..40c622a6 100644 --- a/src/app/shared/components/generic-details/generic-details.component.scss +++ b/src/app/shared/components/generic-details/generic-details.component.scss @@ -23,8 +23,8 @@ ion-chip{ } .view-mentee-list{ - color: #832915; - border: 1px solid #832915; + color: var(--ion-color-primary); + border: 1px solid var(--ion-color-primary); border-radius: 10px; } .mentee-count{ diff --git a/src/app/shared/components/generic-table/generic-table.component.scss b/src/app/shared/components/generic-table/generic-table.component.scss index 8a89cda2..5f0e9a41 100644 --- a/src/app/shared/components/generic-table/generic-table.component.scss +++ b/src/app/shared/components/generic-table/generic-table.component.scss @@ -55,7 +55,7 @@ margin: 0 10px; } .primary-color{ color: #ffffff; - --background: #832915; + --background: var(--ion-color-primary); height: 30px; min-width: 40px; padding: 0%; diff --git a/src/app/shared/components/search-popover/search-popover.component.scss b/src/app/shared/components/search-popover/search-popover.component.scss index c0ae7d89..d9ff309d 100644 --- a/src/app/shared/components/search-popover/search-popover.component.scss +++ b/src/app/shared/components/search-popover/search-popover.component.scss @@ -24,7 +24,7 @@ .primary-color{ color: #ffffff; - --background: #832915; + --background: var(--ion-color-primary); height: 30px; padding: 0%; } From b092a6eef6090b0d2b6b01f445c105720aaf7943 Mon Sep 17 00:00:00 2001 From: Cafnanc Date: Fri, 21 Jun 2024 16:08:36 +0530 Subject: [PATCH 16/81] KB theme updated --- src/global.scss | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/global.scss b/src/global.scss index 489a9348..79a20613 100644 --- a/src/global.scss +++ b/src/global.scss @@ -30,7 +30,7 @@ :root { --ion-default-font: "NotoSans-Regular"; --ion-font-family: "NotoSans-Regular"; - --ion-color-primary: #832215; + --ion-color-primary: #024BA3; --red: rgb(255, 0, 0); --white:#fff; --black:#000; @@ -376,4 +376,11 @@ ion-searchbar { --min-width: 100%; --min-height: 100%; } +} + +.user-role-modal{ + --max-height:350px; + --max-width: 300px; + --border-radius: 6px; + --box-shadow: 0 28px 48px rgba(0, 0, 0, 0.4); } \ No newline at end of file From 5f5210b052b37341f0d146def1486b903888657c Mon Sep 17 00:00:00 2001 From: Cafnanc Date: Fri, 21 Jun 2024 16:10:01 +0530 Subject: [PATCH 17/81] KB theme updated --- src/global.scss | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/global.scss b/src/global.scss index 79a20613..eb307dea 100644 --- a/src/global.scss +++ b/src/global.scss @@ -376,11 +376,4 @@ ion-searchbar { --min-width: 100%; --min-height: 100%; } -} - -.user-role-modal{ - --max-height:350px; - --max-width: 300px; - --border-radius: 6px; - --box-shadow: 0 28px 48px rgba(0, 0, 0, 0.4); } \ No newline at end of file From c39992c24520a44908ef72d2ef525bcd120c4919 Mon Sep 17 00:00:00 2001 From: Cafnanc Date: Tue, 25 Jun 2024 11:38:51 +0530 Subject: [PATCH 18/81] Page restrictions added, guards for restricting template and routes --- src/app/core/constants/page.ids.ts | 19 +++++++++ .../allowPageAccess.guard.spec.ts | 16 +++++++ .../allowPageAccess/allowPageAccess.guard.ts | 26 ++++++++++++ .../modules/private/private-routing.module.ts | 42 +++++++++++++++---- src/app/modules/private/private.page.html | 6 +-- src/app/modules/private/private.page.ts | 22 +++++----- src/app/pages/tabs/tabs-routing.module.ts | 7 +++- src/app/pages/tabs/tabs.page.html | 8 ++-- src/app/pages/tabs/tabs.page.ts | 2 + .../directive/allowTemplate.directive.ts | 21 ++++++++++ src/app/shared/shared.module.ts | 7 +++- 11 files changed, 148 insertions(+), 28 deletions(-) create mode 100644 src/app/core/constants/page.ids.ts create mode 100644 src/app/core/guards/allowPageAccess/allowPageAccess.guard.spec.ts create mode 100644 src/app/core/guards/allowPageAccess/allowPageAccess.guard.ts create mode 100644 src/app/shared/directive/allowTemplate.directive.ts diff --git a/src/app/core/constants/page.ids.ts b/src/app/core/constants/page.ids.ts new file mode 100644 index 00000000..3467b748 --- /dev/null +++ b/src/app/core/constants/page.ids.ts @@ -0,0 +1,19 @@ +export const PAGE_IDS = { + profile: 'PROFILE_PAGE', + loginActivity: 'LOGIN_ACTIVITY_PAGE', + changePassword: 'CHANGE_PASSWORD_PAGE', + mentorDirectory: 'MENTOR_DIRECTORY_PAGE', + dashboard: 'DASHBOARD_PAGE', + home: 'HOME_PAGE', + adminWorkspace: 'ADMIN_WORKSPACE_PAGE', + language: 'LANGUAGE_PAGE', + helpVideos: 'HELP_VIDEOS_PAGE', + help: 'HELP_PAGE', + faq: "FAQ_PAGE", + landing: "LANDING_PAGE", + login: "LOGIN_PAGE", + register: "REGISTER_PAGE", + resetPassword: "RESET_PASSWORD_PAGE", + otp: "OTP_PAGE", + editProfile: "EDIT_PROFILE" +}; diff --git a/src/app/core/guards/allowPageAccess/allowPageAccess.guard.spec.ts b/src/app/core/guards/allowPageAccess/allowPageAccess.guard.spec.ts new file mode 100644 index 00000000..7128a57d --- /dev/null +++ b/src/app/core/guards/allowPageAccess/allowPageAccess.guard.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AllowPageAccess } from './allowPageAccess.guard'; + +describe('AllowPageAccess', () => { + let guard: AllowPageAccess; + + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(AllowPageAccess); + }); + + it('should be created', () => { + expect(guard).toBeTruthy(); + }); +}); diff --git a/src/app/core/guards/allowPageAccess/allowPageAccess.guard.ts b/src/app/core/guards/allowPageAccess/allowPageAccess.guard.ts new file mode 100644 index 00000000..b49df14f --- /dev/null +++ b/src/app/core/guards/allowPageAccess/allowPageAccess.guard.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { CommonRoutes } from 'src/global.routes'; +import { UtilService } from '../../services'; +import { environment } from 'src/environments/environment'; +import { UserService } from '../../services'; + +@Injectable({ + providedIn: 'root' +}) +export class AllowPageAccess implements CanActivate { + constructor(private router: Router){} + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + + if(environment.restictedPages.includes(route.data.pageId)) { + this.router.navigate(["/"]); + return false + } + return true + } + +} diff --git a/src/app/modules/private/private-routing.module.ts b/src/app/modules/private/private-routing.module.ts index ef4487a7..f4f4f489 100644 --- a/src/app/modules/private/private-routing.module.ts +++ b/src/app/modules/private/private-routing.module.ts @@ -4,6 +4,8 @@ import { PrivatePage } from './private.page'; import { CommonRoutes } from 'src/global.routes'; import { PrivateGuard } from 'src/app/core/guards/private.guard'; import { CREATE_SESSION_FORM } from 'src/app/core/constants/formConstant'; +import { PAGE_IDS } from 'src/app/core/constants/page.ids'; +import { AllowPageAccess } from 'src/app/core/guards/allowPageAccess/allowPageAccess.guard'; const routes: Routes = [ { @@ -43,7 +45,10 @@ const routes: Routes = [ { path: CommonRoutes.EDIT_PROFILE, loadChildren: () => import('../../pages/edit-profile/edit-profile.module').then(m => m.EditProfilePageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.editProfile + } }, { path: CommonRoutes.HOME_SEARCH, @@ -63,22 +68,34 @@ const routes: Routes = [ { path: CommonRoutes.HELP, loadChildren: () => import('../../pages/help/help.module').then(m => m.HelpPageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.help + } }, { path: CommonRoutes.FAQ, loadChildren: () => import('../../pages/faq/faq.module').then(m => m.FaqPageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.faq + } }, { path: CommonRoutes.LANGUAGE, loadChildren: () => import('../../pages/language/language.module').then(m => m.LanguagePageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.language + } }, { path: CommonRoutes.HELP_VIDEOS, loadChildren: () => import('../../pages/help-video/help-video.module').then(m => m.HelpVideoPageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.helpVideos + } }, { path: CommonRoutes.MENTOR_QUESTIONNAIRE, @@ -88,17 +105,26 @@ const routes: Routes = [ { path: CommonRoutes.ADMIN, loadChildren: () => import('../../modules/admin/admin.module').then(m => m.AdminModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.adminWorkspace + } }, { path: CommonRoutes.CHANGE_PASSWORD, loadChildren: () => import('../../pages/change-password/change-password.module').then(m => m.ChangePasswordPageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.changePassword + } }, { path: CommonRoutes.LOGIN_ACTIVITY, loadChildren: () => import('../../pages/login-activity/login-activity.module').then(m => m.LoginActivityPageModule), - canActivate: [PrivateGuard] + canActivate: [PrivateGuard, AllowPageAccess], + data: { + pageId: PAGE_IDS.loginActivity + } }, { path: '', diff --git a/src/app/modules/private/private.page.html b/src/app/modules/private/private.page.html index 868a5085..a3ed9f05 100644 --- a/src/app/modules/private/private.page.html +++ b/src/app/modules/private/private.page.html @@ -18,7 +18,7 @@ {{"VIEW_ROLES" | translate}} - {{"PROFILE" | translate}} + {{"PROFILE" | translate}} @@ -27,13 +27,13 @@