Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #67

Merged
merged 56 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
012459f
Success msg changes in revokation
YathurshanT Apr 10, 2023
8c04a93
Merge branch 'develop' of https://github.com/xeptagondev/carbon-regis…
YathurshanT Apr 10, 2023
8e846f5
add local host address
dhanushkaxep Apr 10, 2023
0403191
Rebuild web
palindaa Apr 11, 2023
6c5f091
Changes in Forbidden resources default error messages
YathurshanT Apr 11, 2023
00e3aab
CHanges in error messages
YathurshanT Apr 11, 2023
d2dcb54
Merge pull request #68 from xeptagondev/carbon-133
dhanushkaxep Apr 11, 2023
3b0fbe8
Added import for DataResponseMessageDto
YathurshanT Apr 11, 2023
b38a4d9
Merge pull request #69 from xeptagondev/carbon-133
dhanushkaxep Apr 11, 2023
0c41002
backend permission refactored
dhanushkaxep Apr 11, 2023
69a80ff
Merge pull request #61 from xeptagondev/feature/carbon-100
palindaa Apr 11, 2023
f17a0d7
Merge pull request #70 from xeptagondev/feature/carbon-140
palindaa Apr 11, 2023
59986e3
Fix NAN show in programme view
palindaa Apr 11, 2023
dbd55f9
lint issue fix
palindaa Apr 11, 2023
23e63ee
Fix itmo issue company name
palindaa Apr 11, 2023
e4b0b46
Merge pull request #71 from xeptagondev/fix/itmo
palindaa Apr 11, 2023
121a0b6
revert prod url to dev system
palindaa Apr 11, 2023
2d7e268
Merge pull request #72 from xeptagondev/revert_prod_change
palindaa Apr 11, 2023
6c87dcd
Change dashboard time to 14 days
palindaa Apr 11, 2023
7c0e29b
Merge pull request #73 from xeptagondev/revert_prod_change
palindaa Apr 11, 2023
8b20cf3
Fix dashboard time range
palindaa Apr 12, 2023
89f4c40
Merge pull request #74 from xeptagondev/revert_prod_change
palindaa Apr 12, 2023
ce8f9ca
Add user insert manually
palindaa Apr 12, 2023
be72342
Merge pull request #75 from xeptagondev/revert_prod_change
palindaa Apr 12, 2023
47849ed
Fix user role issue
palindaa Apr 12, 2023
d0225a5
Merge pull request #76 from xeptagondev/revert_prod_change
palindaa Apr 12, 2023
f995631
add email sending limit
dhanushkaxep Apr 12, 2023
609c3af
merged develop
YathurshanT Apr 12, 2023
0749ac8
Fix serverless payload issue
palindaa Apr 12, 2023
b190c4c
Merge pull request #77 from xeptagondev/revert_prod_change
palindaa Apr 12, 2023
282e4da
Update sector mapping for itmo
palindaa Apr 12, 2023
8e61717
Update cron time
palindaa Apr 12, 2023
91d86cf
Merge pull request #78 from xeptagondev/feature/ITMObug
palindaa Apr 12, 2023
679172c
Add location coordinated migrater
palindaa Apr 12, 2023
18da3ea
Merge pull request #79 from xeptagondev/feature/ITMObug
palindaa Apr 12, 2023
e88c794
Merge branch 'develop' of https://github.com/xeptagondev/carbon-regis…
dhanushkaxep Apr 17, 2023
38b5368
Fixed the issue while rejecting already rejected programmes
YathurshanT Apr 17, 2023
550f2d4
changed serverUrl
YathurshanT Apr 17, 2023
9171fe7
Merge pull request #81 from xeptagondev/catbon-133-fixes
dhanushkaxep Apr 17, 2023
6eb9169
Added the missing bracket in rejectProgramme function
YathurshanT Apr 17, 2023
0c0c882
Merge pull request #82 from xeptagondev/catbon-133-fixes
dhanushkaxep Apr 17, 2023
32f0f8a
Merge pull request #80 from xeptagondev/feature/carbon-98
palindaa Apr 17, 2023
aaff877
Fixed the transfer req cancel error message issue
YathurshanT Apr 17, 2023
a2cd97d
Merge pull request #83 from xeptagondev/catbon-133-fixes
dhanushkaxep Apr 17, 2023
2bf3bd0
fix email issues
dhanushkaxep Apr 17, 2023
f30f386
Fix pgsql ledger issue
palindaa Apr 17, 2023
c9ef692
Merge pull request #84 from xeptagondev/feature/carbon-100
palindaa Apr 17, 2023
2a6dc23
Merge pull request #85 from xeptagondev/feature/128
palindaa Apr 17, 2023
acec735
Fix config change bug
palindaa Apr 18, 2023
5698a06
Update documentation on ITMO
palindaa Apr 18, 2023
8acc882
fix tranfer cancel email issue
dhanushkaxep Apr 18, 2023
b3b029c
Update readme
palindaa Apr 18, 2023
20eeeb2
Merge pull request #87 from xeptagondev/feature/carbon-100
palindaa Apr 18, 2023
11ae6a0
Merge pull request #86 from xeptagondev/doc
palindaa Apr 18, 2023
1eee9c0
Merge pull request #66 from xeptagondev/develop
palindaa Apr 18, 2023
59db9c7
Merge branch 'main' into develop
palindaa Apr 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/frontend-deployment-dev.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad this is reverted

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
deploy_front_end:
runs-on: ubuntu-latest
env:
REACT_APP_BACKEND: https://ck5kt5uaw1.execute-api.us-east-1.amazonaws.com/dev
COUNTRY_NAME: 'Antarctic Region Dev'
REACT_APP_BACKEND: https://api.carbreg.org
# https://ck5kt5uaw1.execute-api.us-east-1.amazonaws.com/dev
COUNTRY_NAME: 'Antarctic Region'
COUNTRY_FLAG_URL: 'https://carbon-common-dev.s3.amazonaws.com/flag.png'
COUNTRY_CODE: 'NG'
REACT_APP_MAPBOXGL_ACCESS_TOKEN: ${{ secrets.MAPBOXGL_ACCESS_TOKEN }}
Expand Down
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,112 @@ Carbon credit calculation implemented in a separate node module. [Please refer t
### Serial Number Generation
Serial Number generation implemented in a separate node module. [Please refer this](./libs/serial-number-gen/README.md) for more information.

<a name="external"></a>
## External Connectivity

### ITMO Platform
1. Carbon Registry make a daily to the retrieve ITMO platform programmes.
2. Programmes create in the Carbon Registry when programmes are authorized in the ITMO Platform
3. The Carbon Registry update when the programmes are Issued with credits in the ITMO Platform

#### <b>Lifecycle</b>
![alt text](./documention/imgs/ITMOxCARBON_LifeCycle.svg)

#### <b>Programme Creation and Authorisation</b>
- Authorisation of programmes in the ITMO Platform identified by the event name: "ITMO-Design Document (DD) & Validation Report / Upload on National Public Registry".
- If the Company Tax Id doesn’t exist in the Carbon Registry, that company created in the Carbon Registry.
- When creating the programme:
- The programme created with the state “Pending”
- The credit estimate set to 100 by default
- The company percentage set to 100%
- The serial number for the programme generated the same as any other programme in the Carbon Registry.
- Programmes retrieved from the ITMO Platform and created in the Carbon Registry can Authorised/Rejected by a Government user the same as any other programme in the Carbon Registry
- When a programme is authorised, the authorised credits will be the default credit estimate mentioned above. The programme can be issued with credits by a Government user the same as any other programme in the Carbon Registry.

#### <b>Credit Issuance</b>
- Credits can be issued for programmes retrieved from the ITMO Platform and created in the Carbon Registry in two ways;
- By a Government user the same as any other programme.
- Credit issuance in the ITMO Platform which should be reflected in the Carbon Registry.
- In the case of 2 above,
- Credit issuance identified by the event name: "Upload Final Monitoring Report" in the ITMO Platform.


#### <b>Field Mapping</b>

<b>Company</b>
| **Name in the Carbon Registry** | **Mandatory in the Carbon Registry** | **Name in the ITMO Platform** |
| --- | --- | --- |
| Tax ID (_taxId_) | Yes | company |
| Name (_name_) | Yes | company |
| Email (_email_) | Yes | Set default : nce.digital+[_organisation_]@undp.org |
| Phone Number (_phoneNo_) | Yes | Set default : 00 |
| Website | | |
| Address | | Set default : Country if the Registry |
| Logo | | |
| Country (_country_) | | Set default : Country of the Registry |
| Role (_companyRole_) | Yes | Set default : ProgrammeDeveloper |

<br><b>User</b>
| Name in the Carbon Registry | Mandatory in the Carbon Registry | Name in the ITMO Platform |
| --- | --- | --- |
| Email (_email_) | Yes | Set default : nce.digital+[_organisation_]@undp.org |
| Role (_role_) | Yes | Set default : Admin |
| Phone Number (_phoneNo_) | | Set default : 00 |

<br><b>Programme</b>
| **Name in the Carbon Registry** | **Mandatory in the Carbon Registry** | **Name in the ITMO Platform** |
| --- | --- | --- |
| Programme Name (title) | Yes | Name |
| External ID (externalId) | Yes | id |
| Credit Issuance Serial Number | | |
| Current Status | | Set default : Pending |
| Applicant Type | | Set default : Programme Developer |
| Sector (_sector_) | Yes | Sector |
| Sectoral Scope (_sectoralScope_) | Yes | Set default : 1 if ITMO term does not exist |
| Programme Start Date (_startTime_) | Yes | createdAt |
| Programme End Date (_endTime_) | Yes | createdAt + 10 years |
| Geographical Location (Regional) (_geographicalLocation_) | Yes | country _(Name not mentioned as ISO3 or actual name)_ |
| Buyer Country Eligibility | | |
| Programme Cost (USD) (_programmeCostUSD_) | Yes | Set default : Null |
| Financing Type | | |
| Grant Equivalent Amount | | |
| Carbon Price (Dollars per ton) | | |
| Company | | company |
| Company Tax ID (_proponentTaxVatId_) | Yes | company |
| Company Percentage (_proponentPercentage_) | Yes | Set default : 100% |
| Type of Mitigation Action/Activity (_typeOfMitigation_) | Yes | |
| GHGs Covered (_greenHouseGasses_) | Yes | Set default : CO2 |
| Credits Authorised | | Set default : 100 |
| Credits Issued | | Set default : 10 |
| Credits Transferred | | |
| Credits Frozen | | |
| Credits Retired | | |
| Credits authorised for international transfer and use (Total cumulative maximum amount of Mitigation Outcomes for which international transfer and use is authorized) | | |
| Crediting Period (years) | | |
| Programme Materials | | Files \* |
| Project Materials | | Files \* |
| **Credit Calculation Fields / Mitigation Type Calculation** | | |
| **Agriculture** | | |
| Land Area | | |
| Land Area Unit | | |
| **Solar** | | |
| energy generation | | |
| energy generation unit | | |
| consumer group | | |

#### <b>Assumptions</b>
- Programme estimated credit amount is 100.
- Programme issued credit amount is always 10.

#### <b>Docker Integration Setup</b>
1. Append `data-importer` to `docker-compose` file `replicator` service `RUN_MODULE` env variable with comma separated.
2. Update following env variables in the `docker-compose` file `replicator` service.
- ITMO_API_KEY
- ITMO_EMAIL
- ITMO_PASSWORD
- ITMO_ENDPOINT
3. Programmes will import on each docker restart.

<a name="user"></a>
## User Onboarding and Permissions Model

Expand Down
4 changes: 2 additions & 2 deletions backend/services/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ DB_USER=root
DB_NAME=carbondbdev
LOG_LEVEL=debug
carbon_dev_common=carbon-common-dev
SOURCE_EMAIL=info@xeptagon.com
SOURCE_EMAIL=nce.digital@undp.org
IS_EMAIL_DISABLED=false
LEDGER_TYPE=QLDB
FILE_SERVICE=S3
LOCATION_SERVICE=MAPBOX
ASYNC_OPERATIONS_TYPE=Queue
DISABLE_LOW_PRIORITY_EMAIL=true
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueuedev.fifo
DOMAIN_MAP=false
DOMAIN_MAP=true
2 changes: 1 addition & 1 deletion backend/services/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ LOCATION_SERVICE=MAPBOX
ASYNC_OPERATIONS_TYPE=Queue
DISABLE_LOW_PRIORITY_EMAIL=true
ASYNC_QUEUE_NAME=https://sqs.us-east-1.amazonaws.com/302213478610/AsyncQueueprod.fifo
DOMAIN_MAP=true
DOMAIN_MAP=false
6 changes: 5 additions & 1 deletion backend/services/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ functions:
timeout: 60
handler: src/data-importer/handler.handler
events:
- schedule: cron(0 5 * * ? *)
- schedule:
rate: cron(0 1 * * ? *)
enabled: true
input:
importTypes: ITMO_SYSTEM
ssmToEnvironment:
- DB_PASSWORD
- ITMO_API_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export class ITMOSystemImporter implements ImporterInterface {
SectoralScope.EnergyDistribution,
TypeOfMitigation.ENERGY_DISTRIBUTION,
];
case "agriculture":
return [
Sector.Agriculture,
SectoralScope.Agriculture,
TypeOfMitigation.AGRICULTURE
]
default:
return [
Sector.Other,
Expand All @@ -102,6 +108,9 @@ export class ITMOSystemImporter implements ImporterInterface {
if (!rootUser) {
throw new Error(`Root user does not exist in the system`);
}

rootUser['companyName'] = (await this.companyService.findGovByCountry(this.configService.get("systemCountry")))?.name;

if (!projects || !projects.data || !projects.data.data) {
this.logger.log(`No projects received ${projects}`);
throw new Error(`No projects received ${projects}`);
Expand Down
2 changes: 1 addition & 1 deletion backend/services/src/i18n/en/company.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"noSuspendedCompany": "No suspended company found",
"companyActivationSuccess": "Successfully activated company",
"companyActivationFailed": "Company activate failed. Please try again",
"companyTaxIdExist": "Company tax id already exist",
"companyTaxIdExist": "This Company Tax ID already exists",
"companyUpdateFailed": "Company update failed. Please try again",
"cantSuspendUrOwn": "Can not suspend your own company",
"cantActivateUrOwn": "Can not activate your own company"
Expand Down
3 changes: 1 addition & 2 deletions backend/services/src/i18n/en/programme.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"unExpectedProgOwnerPerc": "Unexpected programme owner percentages",
"notImplementedForMitigationType": "Not implemented for mitigation type {}",
"transferReqNotExist": "Transfer request does not exist",
"transferReqAlreadyCancelled": "This transfer request has already been cancelled",
"acceptOrRejAlreadyCancelled": "This transfer request has been cancelled",
"acceptOrRejCancelledReq": "This transfer request has been cancelled",
"invalidApproverForTransferReq": "Invalid approver for the transfer request",
"invalidApproverForRetirementReq": "Invalid approver for the retirement request",
"noPendReqFound": "This transfer request has been cancelled",
Expand Down
2 changes: 1 addition & 1 deletion backend/services/src/i18n/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"companyCreateNotPermittedForTheCompanyRole": "Company create does not permitted for your company role",
"companyUpdateFailed": "Company update failed. Please try again",
"propValueAlreadyExist": "{} already exist",
"taxIdExistAlready": "Company tax id already exist",
"taxIdExistAlready": "This Company Tax ID already exists",
"deleteUserSuccess": "The user has been deleted successfully",
"deleteOneAdminWhenOnlyOneAdmin": "The user cannot be deleted as the user is the only admin",
"userUnAUth": "This action is unauthorised",
Expand Down
28 changes: 28 additions & 0 deletions backend/services/src/setup/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { LedgerDBInterface } from "../shared/ledger-db/ledger.db.interface";
import { Handler } from 'aws-lambda';
import { LocationModule } from "../shared/location/location.module";
import { LocationInterface } from "../shared/location/location.interface";
import { ProgrammeModule } from "../shared/programme/programme.module";
import { ProgrammeService } from "../shared/programme/programme.service";
const fs = require('fs')

export const handler: Handler = async (event) => {
Expand All @@ -27,10 +29,36 @@ export const handler: Handler = async (event) => {
if (!event) {
event = process.env;
}

const userApp = await NestFactory.createApplicationContext(UserModule, {
logger: getLogger(UserModule),
});
const userService = userApp.get(UserService);

if (event.type === 'IMPORT_USERS' && event.body) {
const users = event.body.split('\n');
for (const user of users) {
const fields = user.split(',');
if (fields.length < 7) {
continue;
}
// (name: string, companyRole: CompanyRole, taxId: string, password: string, email: string, userRole: string
const cr = (fields[4] == 'Government' ? CompanyRole.GOVERNMENT : fields[4] == 'Certifier' ? CompanyRole.CERTIFIER : CompanyRole.PROGRAMME_DEVELOPER)
const ur = (fields[5] == 'admin' ? Role.Admin : fields[5] == 'Manager' ? Role.Manager : Role.ViewOnly)
await userService.createUserWithPassword(fields[0], cr, fields[3], fields[6], fields[1], ur, fields[2]);
}
return;
}

if (event.type === 'UPDATE_COORDINATES') {
const prApp = await NestFactory.createApplicationContext(ProgrammeModule, {
logger: getLogger(ProgrammeModule),
});
const programmeService = prApp.get(ProgrammeService);
await programmeService.regenerateRegionCoordinates()
return;
}

const u = await userService.findOne(event['rootEmail']);
if (u != undefined) {
console.log('Root user already created and setup is completed')
Expand Down
Loading