Skip to content

Commit

Permalink
Merge pull request #122 from csse-uoft/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
LesterLyu authored Jul 2, 2024
2 parents d92b8f8 + 2f47b7f commit 2b4f3a1
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 122 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy Alpha

on:
push:
branches: [ alpha ]

jobs:
build-frontend:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Write SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.ALPHA_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
echo "${{ vars.ALPHA_SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
- name: Use Node.js 16
uses: actions/setup-node@v2
with:
node-version: 16
cache-dependency-path: |
frontend/yarn.lock
backend/yarn.lock
cache: 'yarn'

- name: Install Frontend Dependencies
working-directory: frontend
run: yarn install --frozen-lockfile

- name: Build Frontend
working-directory: frontend
run: CI=false yarn build; cp build/index.html build/404.html

- name: Install Docs Dependencies
working-directory: doc
run: yarn install

- name: Build Docs
working-directory: doc
run: yarn build; mv ./dist ../frontend/build/docs

- name: Make sure remote folder exists
run: ssh ${{vars.ALPHA_SSH_USER}}@${{vars.ALPHA_SSH_HOST}} -p ${{vars.ALPHA_SSH_PORT}} "mkdir -p SNM-I"

- name: Rsync built frontend
run: rsync -rvz -e "ssh -p ${{vars.ALPHA_SSH_PORT}}" --progress --delete ./frontend/build/* ${{vars.ALPHA_SSH_USER}}@${{vars.ALPHA_SSH_HOST}}:/home/ubuntu/SNM-I/frontend-build

- name: Rsync backend
run: rsync -rvz -e "ssh -p ${{vars.ALPHA_SSH_PORT}}" --progress --delete ./backend ${{vars.ALPHA_SSH_USER}}@${{vars.ALPHA_SSH_HOST}}:/home/ubuntu/SNM-I/

- name: Rsync scripts
run: rsync -rvz -e "ssh -p ${{vars.ALPHA_SSH_PORT}}" --progress --delete ./scripts ${{vars.ALPHA_SSH_USER}}@${{vars.ALPHA_SSH_HOST}}:/home/ubuntu/SNM-I/

- name: Update & Restart Backend
run: ssh ${{vars.ALPHA_SSH_USER}}@${{vars.ALPHA_SSH_HOST}} -p ${{vars.ALPHA_SSH_PORT}} "cd SNM-I && ./scripts/redeploy.sh"
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
#### `master` Branch
- URL: https://beta.socialneedsmarketplace.ca

[//]: # (- Docs: https://beta.socialneedsmarketplace.ca/docs/)
- Docs: https://beta.socialneedsmarketplace.ca/docs/

#### `release` Branch
- URL: https://socialneedsmarketplace.ca

[//]: # (- Docs: https://www.socialneedsmarketplace.ca/docs/)
- Docs: https://www.socialneedsmarketplace.ca/docs/

#### `alpha` Branch
- URL: https://alpha.socialneedsmarketplace.ca

- Docs: https://alpha.socialneedsmarketplace.ca/docs/
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MAIL_PASSWORD="password"
GRAPHDB_ADDRESS="http://127.0.0.1:7200"
GRAPHDB_USERNAME="username"
GRAPHDB_PASSWORD="password"
GRAPHDB_REPO="snmi"

# Custom MongoDB connection string
MONGODB_ADDRESS="mongodb://127.0.0.1:27017/snmi"
Expand Down
2 changes: 2 additions & 0 deletions backend/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if (isProduction)
const config = {
graphdb: {
addr: isProduction ? 'http://localhost:7200' : `http://${isDocker ? 'host.docker.internal' : 'localhost'}:7200`,
repositoryName: process.env.GRAPHDB_REPO || (process.env.test ? "snmiTest" : "snmi")
},
mongodb: {
addr: isProduction ? 'mongodb://localhost:27017/snmi' : `mongodb://localhost:27017/${process.env.test ? "snmiTest" : "snmi"}`
Expand All @@ -18,6 +19,7 @@ const config = {
'http://localhost:3002',
'https://www.socialneedsmarketplace.ca',
'https://beta.socialneedsmarketplace.ca',
'https://alpha.socialneedsmarketplace.ca',
'https://www.snmi.ca'],

frontend: {
Expand Down
5 changes: 3 additions & 2 deletions backend/loaders/graphDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ INSERT DATA {

let url;
for (let query of query_list){
url = `${graphdb.addr}/repositories/snmi/statements?update=${encodeURIComponent(query)}`;
url = `${graphdb.addr}/repositories/${graphdb.repositoryName}/statements?update=${encodeURIComponent(query)}`;

const response = await fetch(url, {
method: 'POST',
Expand Down Expand Up @@ -464,7 +464,8 @@ async function load() {
password: graphdb.password,
namespaces,
// The repository name, a new repository will be created if it does not exist.
repositoryName: process.env.test ? "snmiTest" : "snmi",
repositoryName: graphdb.repositoryName,
// Set to true if you want to see SPARQL queries
debug: false
});

Expand Down
3 changes: 2 additions & 1 deletion backend/routes/serviceProviders.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const express = require('express');
const {createSingleServiceProvider, fetchMultipleServiceProviders, fetchSingleServiceProvider,
deleteSingleServiceProvider, updateServiceProvider, searchMultipleServiceProviders
deleteSingleServiceProvider, updateServiceProvider, fetchHomeServiceProvider, searchMultipleServiceProviders
} = require("../services/genericData/serviceProvider");
const router = express.Router();

router.post('/providers', createSingleServiceProvider);
router.get('/providers', fetchMultipleServiceProviders);
router.get('/providers/home', fetchHomeServiceProvider);
router.get('/providers/search', searchMultipleServiceProviders);
router.get('/providers/:id', fetchSingleServiceProvider);
router.delete('/providers/:id', deleteSingleServiceProvider);
Expand Down
18 changes: 16 additions & 2 deletions backend/services/genericData/serviceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,21 @@ const deleteSingleServiceProvider = async (req, res, next) => {

};

const fetchHomeServiceProvider = async (req, res, next) => {
try {
const homeOrganization = await GDBOrganizationModel.findOne({status: 'Home'}, {populates: []});
if (!homeOrganization) {
return res.status(400).json({message: 'This deployment has no home organization'})
}
const provider = await GDBServiceProviderModel.findOne({organization: homeOrganization});
provider.organization = homeOrganization;
return res.status(200).json({provider, success: true});
} catch (e) {
next(e);
}
};

module.exports = {
createSingleServiceProvider, fetchMultipleServiceProviders, fetchSingleServiceProvider, deleteSingleServiceProvider,
updateServiceProvider, searchMultipleServiceProviders, getProviderById
createSingleServiceProvider, fetchMultipleServiceProviders, fetchSingleServiceProvider, deleteSingleServiceProvider,
updateServiceProvider, getProviderById, fetchHomeServiceProvider, searchMultipleServiceProviders
};
33 changes: 18 additions & 15 deletions backend/services/partnerNetwork/appointments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {GDBClientModel} = require("../../models");
const {GDBClientModel, GDBServiceProviderModel} = require("../../models");
const {GDBOrganizationModel} = require("../../models/organization");
const {GDBAppointmentModel} = require("../../models/appointment");
const {createSingleGenericHelper, fetchSingleGenericHelper, updateSingleGenericHelper} = require("../genericData");
Expand Down Expand Up @@ -166,10 +166,13 @@ async function receiveAppointmentHelper(req, partnerData) {
}

// Use the "Referer" header to identify the partner organization who sent the data
const partner = await GDBOrganizationModel.findOne({
endpointUrl: {$regex: regexBuilder(`(https?://)?${req.header.referer}`)}
});
if (!partner) {
const partner = await GDBServiceProviderModel.findOne({
organization: {
endpointUrl: {$regex: regexBuilder(`(https?://)?${req.headers.referer}`)}
}
}, {populates: ['organization']});
const partnerOrganization = partner.organization;
if (!partnerOrganization) {
throw new Error("Could not find partner organization with the same endpoint URL as the sender");
}

Expand Down Expand Up @@ -226,10 +229,10 @@ async function receiveAppointmentHelper(req, partnerData) {
if (partnerData.partnerIsReceiver) {
if (!(partnerData.referral?.id)) {
throw new Error('No referral ID provided');
}
if ('referral' in partnerData)
} else {
appointment.fields[PredefinedInternalTypes['referralForAppointment']._uri.split('#')[1]]
= partnerData.referral ? 'http://snmi#referral_' + partnerData.referral?.id : null;
= 'http://snmi#referral_' + partnerData.referral?.id;
}
}

return {appointment, originalAppointment, originalAppointmentJson, partner};
Expand All @@ -243,8 +246,7 @@ async function receiveNewAppointment(req, res, next) {
// Note, partnerData.partnerIsReceiver is true iff we are the appointment's referral's receiver
const partnerData = req.body;

const {appointment, originalAppointment, originalAppointmentJson, partner}
= await receiveAppointmentHelper(req, partnerData);
const {appointment, partner} = await receiveAppointmentHelper(req, partnerData);

if (!partnerData.partnerIsReceiver) {
return res.status(400).json({success: false, message: 'For a POST request, partnerIsReceiver must be true'});
Expand All @@ -262,8 +264,9 @@ async function receiveNewAppointment(req, res, next) {
// Notify the user of the new appointment
createNotificationHelper({
name: 'An appointment was received',
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.name)}</a>, one of your `
+ `partner organizations, just sent you <a href="/appointments/${newAppointment._id}">a new appointment</a>.`
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.organization.name)}</a>, one `
+ `of your partner organizations, just sent you <a href="/appointments/${newAppointment._id}">a new `
+ `appointment</a>.`
});

return res.status(201).json({ success: true, newId: newAppointment._id });
Expand Down Expand Up @@ -302,9 +305,9 @@ async function receiveUpdatedAppointment(req, res, next) {
// Notify the user of the updated appointment
createNotificationHelper({
name: 'An appointment was updated',
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.name)}</a>, one of your `
+ `partner organizations, just updated <a href="/appointments/${originalAppointment._id}">this appointment`
+ `</a>.`
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.organization.name)}</a>, one `
+ `of your partner organizations, just updated <a href="/appointments/${originalAppointment._id}">this `
+ `appointment</a>.`
});

return res.status(200).json({ success: true });
Expand Down
4 changes: 3 additions & 1 deletion backend/services/partnerNetwork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ async function fetchOrganizationHelper(req, genericId) {
method: 'GET',
headers: {
'X-RECEIVER-API-KEY': organization.apiKey,
...(!!senderApiKey && {'X-SENDER-API-KEY': senderApiKey})
...(!!senderApiKey && {'X-SENDER-API-KEY': senderApiKey}),
// Frontend hostname without http(s)://. i.e. `127.0.0.1`, `localhost`, `example.com`
'Referer': new URL(req.headers.origin).hostname,
},
});
clearTimeout(timeout);
Expand Down
18 changes: 9 additions & 9 deletions backend/services/partnerNetwork/referrals.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ async function receiveReferralHelper(req, partnerData) {
}

// Use the "Referer" header to identify the partner organization who sent the data
const partnerServiceProvider = await GDBServiceProviderModel.findOne({
const partner = await GDBServiceProviderModel.findOne({
organization: {
endpointUrl: {$regex: regexBuilder(`(https?://)?${req.header.referer}`)}
endpointUrl: {$regex: regexBuilder(`(https?://)?${req.headers.referer}`)}
}
});
const partner = partnerServiceProvider.organization;
if (!partner) {
}, {populates: ['organization']});
const partnerOrganization = partner.organization;
if (!partnerOrganization) {
throw new Error('Could not find partner organization with the same endpoint URL as the sender');
}

Expand All @@ -288,8 +288,8 @@ async function receiveReferralHelper(req, partnerData) {
}

// Determine which of the partner and home organizations is the receiver and which is the referrer
let receivingServiceProvider = partnerData.partnerIsReceiver ? homeServiceProvider : partnerServiceProvider;
let referringServiceProvider = partnerData.partnerIsReceiver ? partnerServiceProvider : homeServiceProvider;
let receivingServiceProvider = partnerData.partnerIsReceiver ? homeServiceProvider : partner;
let referringServiceProvider = partnerData.partnerIsReceiver ? partner : homeServiceProvider;

const originalReferral = await GDBReferralModel.findOne({idInPartnerDeployment: partnerData.id},
{populates: ['characteristicOccurrences.occurrenceOf.implementation', 'questionOccurrences',
Expand Down Expand Up @@ -357,7 +357,7 @@ async function receiveNewReferral(req, res, next) {
// Notify the user of the new referral
createNotificationHelper({
name: 'A referral was received',
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.name)}</a>, one of your `
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.organization.name)}</a>, one of your `
+ `partner organizations, just sent you <a href="/referrals/${newReferral._id}">a new referral</a>.`
});

Expand Down Expand Up @@ -402,7 +402,7 @@ async function receiveUpdatedReferral(req, res, next) {
// Notify the user of the updated referral
createNotificationHelper({
name: 'A referral was updated',
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.name)}</a>, one of your `
description: `<a href="/providers/organization/${partner._id}">${sanitize(partner.organization.name)}</a>, one of your `
+ `partner organizations, just updated <a href="/referrals/${originalReferral._id}">this referral</a>.`
});

Expand Down
Loading

0 comments on commit 2b4f3a1

Please sign in to comment.