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

Readme updates #3202

Open
wants to merge 109 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
bc882b0
Add testing and frontend instructions
cesarvarela Nov 6, 2024
1b9b14f
Update README to clarify GraphQL API access and endpoints
cesarvarela Nov 6, 2024
97ec722
Add database migration instructions to README files
cesarvarela Nov 6, 2024
1251405
Move additional configuration section
cesarvarela Nov 6, 2024
14b1848
Move style guid
cesarvarela Nov 6, 2024
84459b1
Move prismic instructions
cesarvarela Nov 6, 2024
ed151be
Delete outdated basic setup instructions
cesarvarela Nov 6, 2024
8827c11
Delete outdated netlify instructions
cesarvarela Nov 6, 2024
6b63ad8
Delete error loging from main readme
cesarvarela Nov 6, 2024
457fcdc
Delete old social networks instructions
cesarvarela Nov 6, 2024
12dc477
Cleanup sample env file
cesarvarela Nov 6, 2024
8db169c
Move github workflow instructions
cesarvarela Nov 6, 2024
8f7be31
Add mailersend and cloudflare instructions
cesarvarela Nov 6, 2024
9537f20
Reorganize env vars
cesarvarela Nov 6, 2024
5646c2d
Update graphql endpoint instructions
cesarvarela Nov 6, 2024
7470add
Move netlify instructions
cesarvarela Nov 6, 2024
8040bd6
Fix prismic section headings
cesarvarela Nov 6, 2024
7330ac3
Set-up next auth server side
cesarvarela Nov 14, 2024
6a9d6ef
Update components
cesarvarela Nov 14, 2024
1b27150
Convert user context to typescript and remove Atlas calls
cesarvarela Nov 14, 2024
b6c5921
Add custom pages
cesarvarela Nov 15, 2024
1e5856c
Update typescript (jest)
cesarvarela Nov 15, 2024
ea18305
Update tests
cesarvarela Nov 15, 2024
06932eb
Allow mocking user sessions
cesarvarela Nov 15, 2024
fa727db
update command
cesarvarela Nov 15, 2024
fb90749
Update test files
cesarvarela Nov 15, 2024
6acf23d
Merge staging
cesarvarela Nov 19, 2024
0e8df00
update package lock
cesarvarela Nov 19, 2024
351f6a9
Remove unused function
cesarvarela Nov 19, 2024
2ada3ec
Fix wrong seesion fetch function
cesarvarela Nov 20, 2024
16e29c5
Update tests
cesarvarela Nov 20, 2024
0f89fdf
tmp add new variables
cesarvarela Nov 20, 2024
0e7f5c7
Add missing configs
cesarvarela Nov 20, 2024
430f7d9
Add missing variables
cesarvarela Nov 20, 2024
41b5531
Add missing env var
cesarvarela Nov 20, 2024
401e791
only debug on localhost
cesarvarela Nov 20, 2024
1e03b54
Update tests
cesarvarela Nov 20, 2024
2ec4780
Update tests
cesarvarela Nov 20, 2024
7b95d22
Update session with custom data
cesarvarela Nov 20, 2024
656e1b7
Update tests
cesarvarela Nov 20, 2024
10eb9cb
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Nov 20, 2024
66dff1a
Update tests
cesarvarela Nov 20, 2024
49970fc
Updates
cesarvarela Nov 20, 2024
c8e99a8
Fix test
cesarvarela Nov 20, 2024
82767cc
Update tests
cesarvarela Nov 20, 2024
4006f42
update test
cesarvarela Nov 21, 2024
cecf1f7
Update test
cesarvarela Nov 21, 2024
ba863bb
Update incidents table
cesarvarela Nov 21, 2024
90c0980
Update components
cesarvarela Nov 21, 2024
14dcb27
Update components
cesarvarela Nov 21, 2024
6b5ea6b
Delete unused pages
cesarvarela Nov 23, 2024
ede00f5
Add command to create magic links
cesarvarela Nov 25, 2024
820f74b
Update lockfile
cesarvarela Nov 25, 2024
56d6e85
Use email template for magic links
cesarvarela Nov 25, 2024
135476a
Update signup and login pages
cesarvarela Nov 26, 2024
1f7653d
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Nov 27, 2024
8a66771
Reduce timeouts
cesarvarela Nov 27, 2024
360a09d
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Nov 27, 2024
49fe877
Update tests
cesarvarela Nov 27, 2024
01bc41b
Update tests
cesarvarela Nov 27, 2024
f943244
Update test and add algolia mock
cesarvarela Nov 28, 2024
b4b6133
Update tests
cesarvarela Nov 28, 2024
b4fa1d0
update subscriptions tests
cesarvarela Nov 29, 2024
4c5ce1e
Update seeds
cesarvarela Nov 29, 2024
2cefdc3
Update tests
cesarvarela Nov 29, 2024
d617048
Update tests
cesarvarela Nov 29, 2024
94bb599
set default status invalid
cesarvarela Nov 29, 2024
d7c49db
Update test
cesarvarela Dec 2, 2024
a535b20
Update login
cesarvarela Dec 2, 2024
5d46951
Update workflows
cesarvarela Dec 2, 2024
5056d26
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 2, 2024
4f71a7a
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 3, 2024
99bf234
Add netlify redirect
cesarvarela Dec 3, 2024
f3a4b90
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 3, 2024
4c01ad7
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 3, 2024
7801e15
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 3, 2024
ca46f0c
Add missing wildcard
cesarvarela Dec 3, 2024
25417e9
Remove hardcoded values
cesarvarela Dec 4, 2024
7057e58
debug
cesarvarela Dec 4, 2024
a43a48c
Remove hardcoded url
cesarvarela Dec 4, 2024
45305db
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 5, 2024
5cee07b
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 11, 2024
c4f9a43
Merge remote-tracking branch 'upstream/staging' into feature-magic-links
cesarvarela Dec 12, 2024
1a9618a
Do not allow users to login without signing up first
cesarvarela Dec 12, 2024
18b9f24
Use different templates for sign ups and sign ins
cesarvarela Dec 12, 2024
19ef9df
Use local copy of package to fix issues with Jest not supporting ESM …
cesarvarela Dec 13, 2024
740aa01
Move functions to utils file
cesarvarela Dec 13, 2024
65dc408
Remove unused function
cesarvarela Dec 13, 2024
2e1bb7b
Add tests to signin auth methods
cesarvarela Dec 13, 2024
b7bd66d
Fix small issues
cesarvarela Dec 13, 2024
f1da9ce
Remove unused packages
cesarvarela Dec 13, 2024
476bf88
Add next auth sign up tests
cesarvarela Dec 16, 2024
cb909b9
Use encoded value
cesarvarela Dec 16, 2024
4b4f518
Add migration to fetch users from atlas and insert them in the new au…
cesarvarela Dec 16, 2024
5e16d93
Add tests to user creation.
cesarvarela Dec 17, 2024
3060987
Update test to handle new param
cesarvarela Dec 17, 2024
27f8369
Update tests
cesarvarela Dec 17, 2024
a76fe7f
Undo readme changes
cesarvarela Dec 19, 2024
7434a7e
Make sure dev env works without replica set
cesarvarela Dec 19, 2024
962ab3f
Streamline readme and update main architecture description
cesarvarela Dec 20, 2024
66f63db
Split readme into multiple files
cesarvarela Dec 20, 2024
a4d979e
Add documentation index
cesarvarela Dec 23, 2024
4c2a976
Remove duplicate section
cesarvarela Dec 23, 2024
b4cb679
Fix broken links
cesarvarela Dec 23, 2024
b5ae261
Expand on production data usage
cesarvarela Dec 27, 2024
52e428b
Add missing files to main doc
cesarvarela Dec 27, 2024
0eb1f38
Fix grammar and errors
cesarvarela Dec 27, 2024
58c9950
Update deployment docs
cesarvarela Dec 28, 2024
27db7cb
Remove unnecessary misc file and improve overall structure
cesarvarela Dec 28, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/test-playwright-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ jobs:
REALM_API_PRIVATE_KEY: ${{ secrets.REALM_API_PRIVATE_KEY }}
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: ${{ secrets.GATSBY_ROLLBAR_TOKEN }}
API_MONGODB_CONNECTION_STRING: mongodb://127.0.0.1:4110/
SITE_URL: http://localhost:8000
NEXTAUTH_URL: http://localhost:8000
NEXTAUTH_SECRET: 678x1irXYWeiOqTwCv1awvkAUbO9eHa5xzQEYhxhMms

- name: Install playwright browsers
run: npx playwright install --with-deps
Expand Down
774 changes: 38 additions & 736 deletions README.md

Large diffs are not rendered by default.

177 changes: 177 additions & 0 deletions site/docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# API

## Overview

The AIID API is built to facilitate interactions with the AI Incident Database.

1. **Access the Apollo Explorer**

Navigate to `http://localhost:8000/graphql` in your web browser. The Apollo Explorer instance should be displayed, allowing you to introspect and run queries against the API.

### Performing Queries

Here is an example query you can run in the Apollo Explorer to retrieve incidents:

```graphql
query {
incident {
incident_id
title
}
}
```

### Expected Response

The query should return a response similar to this:

```json
{
"data": {
"incident": {
"incident_id": 1,
"title": "Incident 1"
}
}
}
```

## Structure

### Folders

The API is contained within the `server` directory. The following folders are present in the project:

- **fields/**: Contains the field definitions for the GraphQL root fields.
- **generated/**: Holds the generated GraphQL types derived from the schema using the GraphQL code generator CLI.
- **tests/**: Contains the test cases written using Jest.
- **types/**: Contains the base GraphQL types.

#### Important Files

- **`schema.ts`**: Exposes the graphql schema.
- **`netlify/functions/graphql.ts`**: Sets up the **GraphQL server** and exposes it as a **Netlify function**, loading the schema from `schema.ts`.

## Running Code Generation

To run the GraphQL code generation CLI to generate TypeScript typings from the schema, allowing statically typed Apollo client mutations and queries, and statically typed server code:

```sh
npm run codegen
```

## Email notifications

### Subscription types

- **All**: This subscription type is not defined yet.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "all",
}
```
- **Incident**: Users with this subscription type will be notified when the incident associated is updated. This subscription type needs an incident_id value associated.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "incident",
"incident_id": 10,
}
```
- **New Incident**: Users with this subscription type will be notified when a new Incident is created. The notification will be sent after finish the next site build when the Incident page is actually created.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "new-incidents",
}
```
- **Entities**: Users can subscribe to a specific Entity. The user with this subscription type will be notified when a new Incident associated with an specific Entity is created or when an existing Incident is updated to be associated with that Entity.
```
{
"userId": "63320ce63ec803072c9f529c",
"type": "entity"
"entityId": "openai",
}
```
- **Submission Promoted**: Users that submit a new Incident Report are automatically subscribed to its promotion. Once the submission has been approved by an editor, the user will receive an email informing that the submission is now an incident/issue/report.
```
{
"userId": "63320ce63ec803072c9f529c",
"type": "submission-promoted"
}
```

These subscription types are also documented in [subscriptions.js](site/gatsby-site/src/utils/subscriptions.js) file.

### Sending Email Notifications

[MailerSend](https://www.mailersend.com/) is used to send email notifications.

Email notifications to New Incidents (subscription type **New Incident**), Incident updates (subscription type **Incident**) and Submission Promoted (subscription type **Submission Promoted**) are sent when the next build finishes. This is because we have to wait until the new Incident page is generated and accessible.
When a new Incident is created or updates, a pending notification item is saved into the `notifications` DB collection with `processed=false` field.
And finally, as part of the site build process, we processed all pending notifications (`processed=false`), send the emails to all recipients, and update the items with `processed=true` and `sentDate=[now]`.

#### Notifications collection definition

- **Incident Updated**
```
{
"type": "incident-updated",
"incident_id": 374,
"processed": false
}
```
- **New Incident Report**
```
{
"type": "new-report-incident",
"incident_id": 374,
"report_number": 2172,
"processed": false
}
```
- **New Incident**
```
{
"type": "new-incidents",
"incident_id": 374,
"processed": false
}
```
- **Entities**
```
{
"type": "entity",
"incident_id": 374,
"entity_id": "openai",
"isUpdate": true,
"processed": false
}
```
- **Submission Promoted**

```
{
"type": "submission-promoted",
"incident_id": 374,
"processed": false
}
```

## User Roles

All site users have one or more roles assigned to them. The role determines what actions the user can take on the site.

As soon as a user is signed in, the system assigns a `subscriber` role by default. Role assignment is handled manually by the site administrators.

**The roles are:**

| User Role | Permissions |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `subscriber` | This is the default role assigned to all users. It allows the user to subscribe to new incidents, specific incidents, entities, and anything else that is subscribeable. |
| `submitter` | This role allows the user to submit new incidents under their user account. |
| `incident_editor` | This role allows the user to:<br>- Edit and clone incidents<br>- See the live incident data. The live data is the data that is currently stored in the database. Keep in mind that incident pages are generated on each build, so if a user edits an incident, the change will be only visible if the live data options is activated until the next build finishes.<br>- Add, edit, approve and delete incident variants<br>- View and submit incident candidates<br>- Restore previous versions of incidents and reports.<br>- Approve and reject new submissions. Which involves converting a submission into an incident or report (create incident or report and linked notifications), or deleting the submission |
| `taxonomy_editor` | This role allows the user to edit all taxonomies. |
| `taxonomy_editor_{taxonomy_name}` | This role allows the user to edit a specific taxonomy. ie: `taxonomy_editor_csetv1` role allows the user to edit the `CSETv1` taxonomy. |
| `admin` | This role has full access to the site, including the ability to edit users' roles. |
File renamed without changes.
Loading
Loading