Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GitHub Actions runs the functional and browser suites on pushes and pull request
| Requirement 121 startup test can time out | A slow API startup can fail the reminder test before it reaches the notification assertions. |
| Checkout supports Stripe sandbox only | Card payments use test transactions in EGP. Checkout needs an `sk_test_` key and accepts one settlement method per request. |
| SMTP and Google Calendar need separate configuration | Email password reset, probation emails and Calendar sync need provider credentials. Automated tests use local mail and controlled provider responses. Live provider availability needs a separate check. |
| Optional advisor and administrator seeds require prepared fixtures | The advisor preview seed expects a published Scientific Methods offering and a future term. The administrator preview seed looks up student IDs that differ from those created by Quick demo sign-in. The installation steps use the base and timetable seeds. |
| Optional advisor and administrator seeds require prepared fixtures | The advisor preview seed expects a published Scientific Methods offering and a future term. The administrator preview seed looks up student IDs that differ from those used by the standard sign-in fixtures. The installation steps use the base and timetable seeds. |
| Assessment deployment needs its own accounts and data | Local seed fixtures are for development. The hosted portal needs provisioned university accounts and a smoke test of each role. See [production readiness](docs/production-readiness.md). |

## Code style
Expand Down Expand Up @@ -190,23 +190,23 @@ Install **Git, Node.js 22.12 or later with npm, MongoDB Community 8.x, and Mongo

~~~powershell
mongosh --host 127.0.0.1 --eval "rs.initiate({_id:'rs0',members:[{_id:0,host:'127.0.0.1:27017'}]})"
$env:BOBOS_PORTAL_DEMO='standard'
npm run dev
~~~

Open [the portal](http://localhost:5173/) and check [API health](http://localhost:3000/api/health). The health response should include `"database":"connected"`. The frontend proxies `/api` requests locally. Quick demo sign-in is available only on localhost; hosted deployments use university credentials. On macOS or Linux use `export BOBOS_PORTAL_DEMO=standard` before starting.
Open [the portal](http://localhost:5173/) and check [API health](http://localhost:3000/api/health). The health response should include `"database":"connected"`. The frontend proxies `/api` requests locally. Sign in with your university email and password.

4. On a **fresh local demo database**, open a third terminal in Bobos to load sample academic data and create the demo accounts. Keep `ALLOW_DEMO_SEED=true` in your local `.env` for this step.

~~~powershell
$env:BOBOS_PORTAL_DEMO='standard'
npm run seed --workspace @bobos/api
Invoke-RestMethod -Method Post http://localhost:3000/api/identity/seed-demo | Out-Null
npm run seed:group4 --workspace @bobos/api
~~~

The base seed clears user, student, course, term, and offering collections in the configured database. `seed:group4` replaces the active timetable of the two demo student accounts. Use the sample accounts and database for this recipe. See the [B1 fixture guide](docs/b1-seed.md) for more request-history scenarios and the [configuration template](.env.example) for SMTP, Stripe sandbox, and Google Calendar settings.

If you use Bash, run `curl -X POST http://localhost:3000/api/identity/seed-demo` in place of `Invoke-RestMethod`.
If you use Bash, set `export BOBOS_PORTAL_DEMO=standard` before the base seed and run `curl -X POST http://localhost:3000/api/identity/seed-demo` in place of `Invoke-RestMethod`.

### Optional integrations

Expand All @@ -216,7 +216,7 @@ Install **Git, Node.js 22.12 or later with npm, MongoDB Community 8.x, and Mongo
| Stripe | Set `STRIPE_SECRET_KEY` to a sandbox key and `WEB_ORIGIN` to the portal origin. Use a Stripe test card through **Pay by card**. |
| Google Calendar | Set `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, and `GOOGLE_REDIRECT_URI`. Register `http://localhost:3000/api/calendar/oauth/callback` in Google Cloud for the default ports. Generate a separate 32-byte hex value for `CALENDAR_TOKEN_ENCRYPTION_KEY`. Sign in as a student and open **Calendar sync**. |

For more advising data, run `npm run seed:evaluation --workspace @bobos/api` on a separate local demo database. If you need the dedicated extra-hours payment scenarios, set `EXTRA_HOURS_DEMO_URI` to `mongodb://127.0.0.1:27017/extra_hours_manual?replicaSet=rs0` and run `node scripts/seed-extra-hours-demo.mjs`. To view these accounts, point the local API's `MONGODB_URI` at that database and restart with `BOBOS_PORTAL_DEMO=extra-hours`.
For more advising data, run `npm run seed:evaluation --workspace @bobos/api` on a separate local demo database. If you need the dedicated extra-hours payment scenarios, set `EXTRA_HOURS_DEMO_URI` to `mongodb://127.0.0.1:27017/extra_hours_manual?replicaSet=rs0` and run `node scripts/seed-extra-hours-demo.mjs`. To view these accounts, point the local API's `MONGODB_URI` at that database and restart the API, then enter the fixture credentials on the sign-in screen.

For a static frontend build, run `npm run build`. If frontend and API run on different hosts, set `VITE_API_BASE_URL` at build time to the API origin and `WEB_ORIGIN` on the server to the frontend origin. The API start command is `npm run start --workspace @bobos/api`.

Expand Down Expand Up @@ -263,7 +263,7 @@ npm run test:regression

## How to use

On the local sign-in screen, open **Quick demo sign-in** and select a role after seeding. You can also sign in with these fixture accounts. They share the local-only password `Password123!`.
Enter one of these seeded accounts on the local sign-in screen. They share the local-only password `Password123!`.

| Role | Local demo email | Start here |
| --- | --- | --- |
Expand Down
61 changes: 4 additions & 57 deletions apps/web/public/portal-studio/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ let liveProfile;
let liveInbox;
let coordinatorSchedules;
let liveAdvisor;
const localDemoSignInAvailable = ['localhost','127.0.0.1'].includes(location.hostname);
const signedIn = () => Boolean(localStorage.getItem(workspaceSessionKey));
const pageKey = key => Object.hasOwn(pages,key) ? key : 'overview';
const returnPage = key => {
Expand Down Expand Up @@ -951,7 +950,7 @@ function mountLiveCalendar(panel) {
const state = panel.querySelector('.calendar-connection-state');
const controls = panel.querySelector('.calendar-sync-actions');
const syncLabel = 'Sync with Google Calendar';
let token = localStorage.getItem(workspaceSessionKey);
const token = localStorage.getItem(workspaceSessionKey);
let working = false;
let refreshing = false;
let renderedConnection;
Expand Down Expand Up @@ -980,19 +979,11 @@ function mountLiveCalendar(panel) {
returnAfterSignIn = 'calendar-sync';
navigate('login');
}
const localStudentDemo = ['localhost','127.0.0.1'].includes(location.hostname) && ['normalStudent','advisingStudent'].includes(role);
const connectPath = 'connect?' + new URLSearchParams({ portalOrigin: location.origin });
async function request(path, method = 'GET', retry = true) {
async function request(path, method = 'GET') {
const response = await fetch('../api/calendar/' + path, { method, headers: { Authorization: 'Bearer ' + token } });
const data = await response.json();
if (!response.ok) {
if (response.status === 401 && retry && localStudentDemo) {
localStorage.removeItem(workspaceSessionKey);
if (await signInDemoWorkspace(role)) {
token = localStorage.getItem(workspaceSessionKey);
return request(path, method, false);
}
}
if ([401, 403].includes(response.status)) {
if (response.status === 401) localStorage.removeItem(workspaceSessionKey);
controls.replaceChildren();
Expand Down Expand Up @@ -1042,15 +1033,7 @@ function mountLiveCalendar(panel) {
if (!token) {
controls.replaceChildren();
state.textContent = 'Not connected';
if (localStudentDemo) {
control(syncLabel, async () => {
if (!await signInDemoWorkspace(role)) { signIn(); return; }
token = localStorage.getItem(workspaceSessionKey);
const data = await request('connection');
if (data.connected) await refresh();
else location.assign((await request(connectPath)).authorizationUrl);
}, { primary: true, pending: 'Opening Google…' });
} else control(syncLabel, signIn, { primary: true });
control(syncLabel, signIn, { primary: true });
return;
}
async function checkConnection(background = false) {
Expand Down Expand Up @@ -1138,11 +1121,6 @@ function auth(){
${page==='reset'?link('forgot','Request another code','auth-recovery'):''}
${link('login','Back to sign in','auth-recovery')}`}
</form>
${page==='login' && localDemoSignInAvailable ? `<fieldset class="preview-role-picker">
<legend>Quick demo sign-in</legend>
<div class="preview-role-options">${Object.entries(roleNames).map(([id,label])=>
button(label,'preview-sign-in','preview-role-button',`data-preview-role="${id}"`)).join('')}</div>
</fieldset>` : ''}
</section>
</div>
<figure class="signin-print"><div class="desk-lamp-scene"><img src="images/borrowed-light.svg" alt="Desk lamp lighting a sheet of paper" fetchpriority="high"></div></figure>
Expand Down Expand Up @@ -1558,7 +1536,7 @@ function startPreview(destination){
returnAfterSignIn = 'overview';
navigate(destination, url, history.state || {});
}
async function signInWorkspace(credentials, expectedRole){
async function signInWorkspace(credentials){
const response = await fetch('../api/identity/login', {
method:'POST',
headers:{'Content-Type':'application/json'},
Expand All @@ -1568,40 +1546,12 @@ async function signInWorkspace(credentials, expectedRole){
if (!response.ok || !data.token || !Object.hasOwn(roleNames,data.user?.role)) {
throw new Error(data.message || 'Could not sign in to the workspace.');
}
if (expectedRole && data.user.role !== expectedRole) throw new Error('The demo account has a different role.');
localStorage.setItem(workspaceSessionKey,data.token);
localStorage.setItem('portal-account-role', data.user.role);
sessionStorage.setItem(workspaceAccountNameKey, data.user.fullName || roleNames[data.user.role]);
return data.user.role;
}

async function signInDemoWorkspace(demoRole){
const response = await fetch(`../__bobos_local_demo?role=${encodeURIComponent(demoRole)}`);
if (!response.ok || !response.headers.get('content-type')?.includes('application/json')) {
const accounts = { normalStudent:'karim.normal@student.guc.edu.eg', advisingStudent:'layla.advising@student.guc.edu.eg', coordinator:'nadia.coordinator@guc.edu.eg', advisor:'sherif.advisor@guc.edu.eg', administrator:'admin@guc.edu.eg' };
if (!['localhost','127.0.0.1'].includes(location.hostname) || !accounts[demoRole]) return false;
await signInWorkspace({email:accounts[demoRole], password:'Password123!'},demoRole);
return true;
}
await signInWorkspace(await response.json(),demoRole);
return true;
}

async function choosePreviewRole(el){
if (page !== 'login' || !Object.hasOwn(roleNames,el.dataset.previewRole)) return;
const selected = el.dataset.previewRole;
const picker = el.closest('.preview-role-picker');
picker.disabled = true;
try {
if (!(await signInDemoWorkspace(selected))) throw new Error('Sign in with your university account.');
role = selected;
startPreview(returnAfterSignIn);
} catch (error) {
toast(error.message, "error");
} finally {
picker.disabled = false;
}
}
function toast(text, tone = 'success', options) {
document.querySelector('portal-action-feedback').show(tone, text, options);
}
Expand Down Expand Up @@ -1629,9 +1579,6 @@ function action(name,el){
return;
}
switch(name){
case 'preview-sign-in':
void choosePreviewRole(el);
break;
case 'sign-out':
document.querySelector('portal-action-feedback').clear();
{
Expand Down
2 changes: 1 addition & 1 deletion apps/web/public/portal-studio/desk-lamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ window.mountPortalControlInk = function (shadow, { coordinator = false } = {}) {
const bounds = dialog?.getBoundingClientRect();
const left = bounds ? bounds.left + dialog.clientLeft - dialog.scrollLeft : 0;
const top = bounds ? bounds.top + dialog.clientTop - dialog.scrollTop : 0;
const padding = target.matches('.preview-role-button') ? 1 : 3;
const padding = 3;
layer.style.left = `${rect.left - left - padding}px`;
layer.style.top = `${rect.top - top - padding}px`;
layer.style.width = `${rect.width + padding * 2}px`;
Expand Down
23 changes: 0 additions & 23 deletions apps/web/public/portal-studio/login-art.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,6 @@
.signin-actions .auth-recovery {justify-self:center;padding-inline:4px;font-size:13px;color:var(--muted)}
.auth-feedback {margin:0;color:var(--muted);font-size:13px;line-height:1.5}
.auth-feedback.error {color:var(--danger, #b14b3c)}
.preview-role-picker {
min-inline-size: 0;
margin: 22px 0 0;
padding: 10px 0 0;
border: 0;
border-top: 1px solid var(--line);
}
.preview-role-picker legend { padding: 0 10px 0 0; color: var(--muted); font-size: 13px; }
.preview-role-options { display: flex; flex-wrap: wrap; gap: 8px; }
.preview-role-button {
min-height: 40px;
padding: 7px 11px;
border: 1px solid var(--control);
border-radius: 7px;
background: var(--raised);
color: var(--ink);
font: inherit;
font-size: 13px;
cursor: pointer;
}
.preview-role-button:hover { background: var(--ink); color: var(--canvas); }
.preview-role-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media(max-width:760px){.auth:has(> .signin-print) .signin-print img{width:min(100%,38vh,400px)}}

.portal-studio .auth:has(> .signin-print) .signin-copy {
Expand Down Expand Up @@ -226,7 +204,6 @@ body > .portal-focus-ring[data-service-ink] {z-index:4}

@media (forced-colors:none) {
[data-portal-focus]:focus-visible {outline:none!important}
.preview-role-button[data-portal-focus]:focus-visible {border-color:transparent}
}
@media (prefers-reduced-motion:no-preference) {
.portal-focus-ring path {
Expand Down
66 changes: 1 addition & 65 deletions apps/web/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,6 @@ import { join, posix, relative, resolve } from "node:path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

const standardDemo = {
administrator: "admin@guc.edu.eg",
coordinator: "nadia.coordinator@guc.edu.eg",
advisor: "sherif.advisor@guc.edu.eg",
advisingStudent: "layla.advising@student.guc.edu.eg",
normalStudent: "karim.normal@student.guc.edu.eg",
};
const extraHoursDemo = {
coordinator: "extra.coordinator@guc.edu.eg",
advisor: "extra.advisor@guc.edu.eg",
advisingStudent: "extra.create@student.guc.edu.eg",
wallet: "extra.wallet@student.guc.edu.eg",
gateway: "extra.gateway@student.guc.edu.eg",
defer: "extra.defer@student.guc.edu.eg",
reject: "extra.reject@student.guc.edu.eg",
withdraw: "extra.withdraw@student.guc.edu.eg",
blank: "extra.blank@student.guc.edu.eg",
probation: "extra.probation@student.guc.edu.eg",
graduate: "extra.graduate@student.guc.edu.eg",
activation: "extra.activation@student.guc.edu.eg",
retry: "extra.retry@student.guc.edu.eg",
retryManual: "extra.retrymanual@student.guc.edu.eg",
refund: "extra.refund@student.guc.edu.eg",
};
const demoLabels = {
administrator: "Administrator", coordinator: "Coordinator", advisor: "Advisor",
normalStudent: "Normal student", advisingStudent: "Advising student", wallet: "Wallet student",
gateway: "Gateway student", defer: "Deferral student", reject: "Rejection student",
withdraw: "Withdrawal student", blank: "Blank-note student", probation: "Probation student",
graduate: "Graduation-limit student",
activation: "Course activation student",
retry: "Gateway retry student",
retryManual: "Gateway retry student (manual test)",
refund: "Refund history student",
};

function localPortalDemo() {
return {
name: "local-portal-demo",
configureServer(server) {
const preset = process.env.BOBOS_PORTAL_DEMO;
if (preset !== "standard" && preset !== "extra-hours") return;
server.middlewares.use("/__bobos_local_demo", (req, res) => {
if (req.method !== "GET" || !["127.0.0.1", "::1", "::ffff:127.0.0.1"].includes(req.socket.remoteAddress)) {
res.writeHead(404).end();
return;
}
const accounts = preset === "extra-hours" ? extraHoursDemo : standardDemo;
const role = new URL(req.url, "http://localhost").searchParams.get("role");
if (role !== null && !Object.hasOwn(accounts, role)) {
res.writeHead(404).end();
return;
}
const password = preset === "extra-hours" ? "ExtraHoursDemo123!" : "Password123!";
const data = role === null
? { accounts: Object.entries(accounts).map(([key, email]) => ({ label: demoLabels[key], email, password })) }
: { email: accounts[role], password };
res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" })
.end(JSON.stringify(data));
});
},
};
}

// Keep compatibility entry files and one actual Portal document in the build.
const portalPage = "portal-studio/index.html";
const htmlEntries = ["index.html", "workspace.html", "academic-services.html", portalPage];
Expand Down Expand Up @@ -118,7 +54,7 @@ function portalSite() {
}

export default defineConfig(({ command, isPreview }) => ({
plugins: [react(), localPortalDemo(), portalSite()],
plugins: [react(), portalSite()],
// Concurrent dev servers must keep their optimized dependencies separate.
...(command === "serve" && !isPreview && { cacheDir: `node_modules/.vite/dev-${process.pid}` }),
build: { rollupOptions: {
Expand Down
2 changes: 1 addition & 1 deletion docs/group-a-sprint2-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Probation emails are tested through a local SMTP test server, not a real GUC mai

### Manual extra-hours fixtures

Run `node scripts/seed-extra-hours-demo.mjs` from the repository root with `EXTRA_HOURS_DEMO_URI` set to the URI of a local MongoDB replica set database named `extra_hours_manual`. Run the API against that same database, and set `BOBOS_PORTAL_DEMO=extra-hours` when starting Vite to use its demo advisor and coordinator. The seed adds missing fixtures and preserves existing request and payment history. Use a new temporary replica set when you need a fresh run.
Run `node scripts/seed-extra-hours-demo.mjs` from the repository root with `EXTRA_HOURS_DEMO_URI` set to the URI of a local MongoDB replica set database named `extra_hours_manual`. Run the API against that same database, then sign in with the seeded advisor or coordinator credentials. The seed adds missing fixtures and preserves existing request and payment history. Use a new temporary replica set when you need a fresh run.

The demo uses term **EHTEST**, courses **EHT101**, **EHT202**, **EHT301**, and **EHT404**, and the password `ExtraHoursDemo123!`. The coordinator and advisor sign in with `extra.coordinator@guc.edu.eg` and `extra.advisor@guc.edu.eg`. The student accounts use `extra.<scenario>@student.guc.edu.eg`. The local demo picker includes accounts for wallet, gateway, deferral, retries, course activation, and refund history. The seed creates the starting requests. Complete the local settlement workflow to populate the history for each scenario.

Expand Down
Loading
Loading