feat: basic backend #158
Loading…
Reference in a new issue
No description provided.
Delete branch "11-backend"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Backend implementation as per the spec #11 (backend.md)
Testing Checklist
This testing can be fully automated using an LLM and cURL , this list is merely a checklist of the possibilities covered by the changes in this branch.
Setup
JWT_SECRETset (no SMTP → OTP codes appear in the server log).karriba-seed -email [email protected].http://localhost:8080. All responses are JSON; errors use{"error":{"code","message"}}.1. Health & Auth
GET /v1/health→200 {"status":"ok","version":...}(no auth)POST /v1/auth/otp/request(registered contact) →200,expires_in:900; code appears in logPOST /v1/auth/otp/request(unregistered contact) → identical200(no code generated)POST /v1/auth/otp/verifywith the logged code →200withaccess_token,refresh_token, correctuserpayloadPOST /v1/auth/otp/verifywrong code →400 INVALID_OTPPOST /v1/auth/refreshwith the returned token →200with a newrefresh_token; reusing the old one →401 REVOKED_TOKEN2. Access Control
401403 INSUFFICIENT_ROLE4033. Orgs (sys-admin token)
POST /v1/orgs→201;initial_manager.role:"manager"; a tenant DB file for the new org id is createdGET /v1/orgs/:id→200withuser_countPATCH /v1/orgs/:idrename →200; archive, then confirm members get403while sys-admin still reads it4. Users (manager token)
GET /v1/orgs/:id/users→200POST /v1/orgs/:id/usersinvite member →201"supervisor") →400 INVALID_ROLE400 ORG_REQUIRES_MANAGERDELETE .../users/:selfId→2045. Pagination
GET /v1/orgs/:id/users?limit=1→ 1 item + non-nullnext_cursor?limit=1&cursor=<value>→ next page; last page hasnext_cursor:null6. Entitlements
GET /v1/orgs/:id/entitlements(any member) →200PUT /v1/orgs/:id/entitlements(sys-admin)["pesticide","cloud_sync"]→200PUT["cloud_sync"]alone →400 ENHANCEMENT_REQUIRES_STANDALONE(withmodule/requires)PUTunknown module →400 INVALID_MODULEPUTas manager/member →4037. Rate Limiting (needs a proxy-free direct hit)
429 RATE_LIMITEDNotes
Be sure also to hook up the CI/CD to run go tests
WIP: feature: backendto feature: backend📦 Build Successful!
Commit:
bc36d27Size: 59M
Download APK
This should be ready for review 🫡This should be one of the last BIG changes 😅
Great! I plan to review this week, Thursday at the latest.
All the stuff mentioned in the MR description also has automated tests to run in CI?
@addison wrote in #158 (comment):
I think most of it should be covered. There may be some gap I'm unaware of.
@ -0,0 +4,4 @@COPY go.mod go.sum ./RUN go mod downloadCOPY . .RUN CGO_ENABLED=0 go build -o karriba-server ./cmd/karriba-serverWe need to enable cgo, right? Otherwise everything is going to fail inside this image.
b5c1f922e3adds test case to show bug in refresh handling3b7fb60has a test for concurrent OTP bug1d8a1c0has a fix for the test - members of archived organizations need read access to the orgs endpoint so they know that their organization is archived - see line 671 of spec 115f28d53has a test for bug with entitlements handlingI used codex to help me find a few concerns, and added test cases to show the different situations.
It would also be good to include a CI job to build the docker image to make sure it is fine in every PR.
Addressed the test concerns and added the build CI job 😄
feature: backendto feat: basic backendThis one might take a few review iterations since it is so big 😅
@ -0,0 +1,9 @@-- Tenant DB schema mirrors the Flutter app's Drift schema.-- This is a placeholder; the full schema should be kept in syncWhen do we replace the placeholder? In a separate PR or in the cloud sync spec?
We could make it in a separate PR to avoid making adding much more to this one since it is already this big😅
Yeah, I agree. Especially if we pivot to a separate sync project with an event-log approach.
A few more tests for a few more broken edge cases. Auth systems are tricky 😅
feat: basic backendto WIP: feat: basic backend📦 Build Successful!
Commit:
9931082Size: 62M
Download APK
WIP: feat: basic backendto feat: basic backendGreat foundation!