Workflow-App/Workflow/scripts/_add_field.py
sjcoetzeesj-coder 11d0178ab1 feat: commit Workflow app source; move CIPC credentials to env
Adds the full Next.js app (app/, components/, lib/, scripts/, assets/,
docs/, Dockerfile, compose, configs) to version control.

Security:
- CIPC BizPortal customer-code logins (Login 1 + Login 3) now read
  CIPC_LOGIN1_CODE / CIPC_LOGIN1_PASSWORD / CIPC_LOGIN3_CODE /
  CIPC_LOGIN3_PASSWORD from .env.local instead of source.
- BizPortal personal login in apply-bizportal route reads
  BIZPORTAL_ID_NO / BIZPORTAL_PASSWORD.
- Added .env.example as the committed template.

.gitignore excludes .env*, node_modules, .next, logs, sqlite, Playwright
storage_state.json (live CIPC cookies), scratch dirs, client PDFs and
debug screenshots.
2026-10-18 15:21:45 +02:00

47 lines
1.8 KiB
Python

"""Add the `last_updated` date field to the EMP201 PB collection
schema. Currently PB silently drops it because the field isn't in
the collection schema, even though the push script sends it."""
import os, requests, pathlib, json
for line in pathlib.Path(r'C:\Users\SJ\.minimax-agent\projects\Workflow\.env.local').read_text().splitlines():
if line.strip() and '=' in line and not line.startswith('#'):
k, v = line.split('=', 1)
os.environ.setdefault(k.strip(), v.strip())
token = os.environ['PB_TOKEN']
coll_id = 'pbc_2178038841'
h = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
# Get current schema
r = requests.get(f'https://pb.agent.apphub.co.za/api/collections/{coll_id}', headers=h, timeout=15)
fields = r.json().get('fields', [])
# Add last_updated if missing
if not any(f.get('name') == 'last_updated' for f in fields):
fields.append({
'name': 'last_updated',
'type': 'date',
'required': False,
'options': {},
})
r = requests.patch(
f'https://pb.agent.apphub.co.za/api/collections/{coll_id}',
headers=h, json={'fields': fields}, timeout=15,
)
print(f'Added last_updated: status={r.status_code}')
if r.status_code >= 400:
print(r.text[:500])
else:
print('last_updated already in schema')
# Now try writing the date
import sys
from datetime import datetime
dt_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S.000Z')
r = requests.patch(
'https://pb.agent.apphub.co.za/api/collections/ysterbaard_SARS_EMP201_PAYE/records/zrduajho6xfpb3q',
headers=h, json={'last_updated': dt_str}, timeout=15,
)
print(f'Write last_updated={dt_str!r}: status={r.status_code}')
if r.status_code < 400:
print(f' stored: {r.json().get("last_updated")!r}')
else:
print(r.text[:500])