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

fix: misc scripting, crashes and unexpected behaviour #45

Merged
merged 75 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6a3119b
fix: text content, update img
SebassNoob Mar 25, 2024
09a9646
feat: import script
SebassNoob Mar 25, 2024
72be893
fix: config changes
SebassNoob Mar 25, 2024
9cec4a1
fix: config change again
SebassNoob Mar 26, 2024
8856158
fix: incorrect mapping of asset urls
SebassNoob Mar 26, 2024
d6b97df
fix: readability
SebassNoob Mar 26, 2024
8e8a54a
chore: untrack data files
SebassNoob Mar 27, 2024
47bc13e
fix: incorrect formatting for service session date
SebassNoob Mar 27, 2024
cc54f8e
fix: crash on 0 permissions
SebassNoob Mar 27, 2024
3970bf1
fix: failed request on 0 announcements navigation
SebassNoob Mar 27, 2024
4de0aa3
fix: infinite loading on dne announcement
SebassNoob Mar 27, 2024
c1395a8
fix: ghost keys and handle non-existent session in AttendanceMenuEntry
SebassNoob Mar 27, 2024
9e2a22f
fix: undefined build error
SebassNoob Mar 27, 2024
e2b31f0
fix: add alt props to img
SebassNoob Mar 27, 2024
3616cc2
fix: many ics allowed for service
SebassNoob Mar 29, 2024
06a8973
fix: sort services
SebassNoob Mar 29, 2024
52297c2
fix: imported names too short
SebassNoob Mar 29, 2024
ac85480
fix: nextattendance is wrong
SebassNoob Apr 1, 2024
b25936d
fix: fix tests
SebassNoob Apr 2, 2024
af9503f
fix: admin searching gives undefined pages
SebassNoob Apr 2, 2024
7c4f547
fix: allow search in service sessions
SebassNoob Apr 2, 2024
cee01c4
fix: timezone differences
SebassNoob Apr 3, 2024
1b74f5f
chore: raise rate limit
SebassNoob Apr 3, 2024
36d687d
fix: make service session search clearable
SebassNoob Apr 3, 2024
09cc876
chore: optimise + allow longer time to have qr available
SebassNoob Apr 4, 2024
92fe0a1
feat: import hours script
SebassNoob Apr 4, 2024
30b9adf
fix: minor change of plans for import hours
SebassNoob Apr 4, 2024
ea80bf2
chore: update readme
SebassNoob Apr 4, 2024
15010be
fix: modify update script path
SebassNoob Apr 4, 2024
f70cd78
fix: lower permissions mark absence failure
SebassNoob Apr 4, 2024
ed0c173
feat: manual password reset script
SebassNoob Apr 6, 2024
3fccbf2
feat: allow redirects on login
SebassNoob Apr 6, 2024
57967be
fix: dont report issues to sentry on dev server
SebassNoob Apr 6, 2024
853f140
fix: prerender error on useSearchParams
SebassNoob Apr 6, 2024
46e1013
chore: create sessions manually script
SebassNoob Apr 7, 2024
8f24003
fix: incorrect default value on searchable select
SebassNoob Apr 8, 2024
ca1458c
fix: incorrect usage of pw reset
SebassNoob Apr 10, 2024
82c286a
chore: bump next to 14.2
SebassNoob Apr 12, 2024
05e8ef9
refactor: Makefile build commands for different scenarios
SebassNoob Apr 12, 2024
6d9ea19
fix: CORS origin issue in API routes
SebassNoob Apr 12, 2024
81f7cf4
chore: Update docker-compose files to remove version field
SebassNoob Apr 13, 2024
5c1f160
chore: rename data-source to snake case
SebassNoob Apr 13, 2024
3979bf4
chore: simplify imports
SebassNoob Apr 13, 2024
d121f4b
chore: Update imports in unit tests to use @models/.
SebassNoob Apr 13, 2024
1cf288c
chore: bump bun to 1.1.3
SebassNoob Apr 13, 2024
5a017eb
chore: Update docker-compose files to include VERSION environment var…
SebassNoob Apr 13, 2024
19e224d
chore: add footer version
SebassNoob Apr 13, 2024
1d970d1
chore: add release for sentry observability
SebassNoob Apr 13, 2024
85943fb
fix: naming conflict in version
SebassNoob Apr 14, 2024
2d76a36
fix: reorganise files
SebassNoob Apr 14, 2024
2d50372
fix: naming conflict
SebassNoob Apr 15, 2024
a1c840c
refactor: reuse code for describe()
SebassNoob Apr 15, 2024
5135cf2
chore: add node-xlsx package for Excel file handling
SebassNoob Apr 15, 2024
ae98fef
feat: implement logic for GM exports
SebassNoob Apr 15, 2024
68cc7b2
chore: remove newlines
SebassNoob Apr 16, 2024
9abafd2
feat: refactor validation middleware
SebassNoob Apr 16, 2024
3b38c1e
refactor: redo exports
SebassNoob Apr 16, 2024
935250c
fix: show full output on build failure
SebassNoob Apr 16, 2024
cf47dfb
fix: prevent memory leak by cleaning dumpfiles >7 days old
SebassNoob Apr 17, 2024
d807b2a
chore: prettier
SebassNoob Apr 17, 2024
347fd55
refactor: use early return clause
SebassNoob Apr 17, 2024
9f76ce9
feat: allow for exports date filtering
SebassNoob Apr 18, 2024
27fab73
fix: restrict endpoint
SebassNoob Apr 18, 2024
719c560
feat: add frontend
SebassNoob Apr 19, 2024
9cd4995
refactor: efficiently compare edit action changes
SebassNoob Apr 17, 2024
a466ec8
fix: incorrect pathing for renamed data_source
SebassNoob Apr 17, 2024
685be3f
chore: revert #c116271
SebassNoob Apr 17, 2024
0c54073
feat: add diffing algorithm
SebassNoob Apr 17, 2024
c2448d6
feat: add bulk service hour changes
SebassNoob Apr 17, 2024
b26412b
fix: dockerfile failure due to incorrect shell syntax
SebassNoob Apr 17, 2024
ed6ef1a
feat: add endpoint linkage and clean up
SebassNoob Apr 19, 2024
8e90721
fix: consise regex number syntax
SebassNoob Apr 19, 2024
70d2acc
fix: build error
SebassNoob Apr 19, 2024
b1abdd1
fix: update service hours in bulk overwriting value
SebassNoob Apr 19, 2024
b0e32b0
chore: bump version
SebassNoob Apr 19, 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
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.0.32
bun-version: 1.1.3

- name: Install dependencies
run: cd interapp-backend && bun install
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ dist

pgdata/
minio_data/
dump/
dump/

*.csv
*.sql
117 changes: 10 additions & 107 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,10 @@
# Contributing guidelines

Thanks for coming onboard to contribute to this project. This document outlines a few common code guidelines when contributing to the project. Lead maintainers can choose to modify these guidelines if they feel it is too strict/lax. Last updated: 12 Dec 2023.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
RFC 2119.

## Table of Contents
- [Coding Guidelines](#coding-guidelines)
1. [General Guidelines](#general-guidelines)
2. [Backend Guidelines](#backend-guidelines)
3. [Frontend Guidelines](#frontend-guidelines)
- [Product Demo Guidelines](#product-demo-guidelines)

## Coding Guidelines
### General guidelines

- All features SHOULD NOT be commited directly to the ``main`` branch, unless you have a very specific reason to do so (eg. CI/CD testing). Otherwise, checkout a new branch and open a PR.

- You SHOULD follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) when making commits to the ``main``/``dev`` branches, and it is RECOMMENDED to do the same on all other branches.

- You MAY use the test suite in Github Actions to ensure that your current build of the project is stable to push to production.


### Backend Guidelines

- Before merging a PR with backend changes, you SHOULD check that tests pass and that you have tested your own changes.

- ``snake_case`` SHALL be used for all response/request body parameters.

```js
// this is fine
POST HTTP/1.1 /test 200
{
a_variable: "jewdfjskd",
a_very_long_name: "dsfkjsda"
}

GET HTTP/1.1 /test?variable_name=lol 200

// this is not ok
POST HTTP/1.1 /test 200
{
camelCase: "no"
}
```

- You SHOULD throw informative errors when an error occurs in response/query.

```js
// this is good
GET HTTP/1.1 /test 400
{
"error": "missing fields 'asdf', 'err'"
}

// this is not good
GET HTTP/1.1 /test 400
{
"error": "an error occurred. try again later"
}
```

### Frontend guidelines
- Pages (``page.tsx``) SHOULD be written with ``export default function``.
```ts
// good
export default function HomePage {...}

// bad
export const HomePage = () => {}
Homepage.displayName = 'HomePage'; // needed for NextJS
export default HomePage;
```
- Non-interactive components SHOULD be made a server component. This SHOULD include all pages (``pages.tsx``).

- Pages SHOULD be broken down into simple, reusable components if possible.

## Product Demo Guidelines

Thanks for coming in to test this project. This section details what to do when testing out demos/test builds.

- Look out for potential complex functionality that is not properly explained. Such behaviour may make it difficult for future users to understand how to use the website.

- Test forms/input fields with a variety of values, and attempt to cause errors if possible. This is really helpful in case an exploit is present in the inputs. Examples of invalid input values that one can test out:

- Username: ``a; DROP TABLE users;--`` (SQL injection, for technical users)
- UserID: ``2147483648`` (32 bit signed int overflow)
- Username: ``jjjj...jjjjjj`` (a very long string that may exceed memory limits)
- Email: ``a.dsfsajf`` (an input that is clearly not an email)
- Birthday: ``30/2/2023`` (a date that does not exist)
- Age: ``-1`` (an age that cannot exist)
- Start time: ``09:00``, End time: ``08:00`` (End time < Start time)
- Day of the week: ``Yesterday`` (Not a day of the week)
- Month: ``Decembuary`` (Not a month)

- Check for discrepancies in responsive display sizes. Ie. Does the size of screen affect readability of certain text/functionality? To test this on a PC, use the in-browser viewport resizing tool (CTRL + Shift + I on Chrome). Refer to your browser's support page for more information.

- Look out for behaviour that may be too complex for a normal user, or is not supported on touchscreen devices.






# Contributing guidelines

Thanks for coming onboard to contribute to this project. This document outlines a few common code guidelines when contributing to the project. Lead maintainers can choose to modify these guidelines if they feel it is too strict/lax. Last updated: 12 Dec 2023.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
RFC 2119.

WIP DO NOT CHANGE THIS FILE UNTIL POST 1.0
82 changes: 56 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@

.PHONY:
.ONESHELL:

SHELL := bash

# version := dev
ifeq ($(version), )
DC_CMD := docker compose -f docker-compose.dev.yml
else
DC_CMD := docker compose -f docker-compose.$(version).yml
tag := --$(version)
endif


build:
$(DC_CMD) -v down
$(DC_CMD) build
watch:
$(DC_CMD) watch
run:
$(DC_CMD) up -d
down:
$(DC_CMD) -v down



.PHONY:
.ONESHELL:

SHELL := bash

# version := dev
ifeq ($(version), )
DC_CMD := docker compose -f docker-compose.dev.yml
else
DC_CMD := docker compose -f docker-compose.$(version).yml
tag := --$(version)
endif

APP_VERSION := $(shell git describe --tag --abbrev=0 2>/dev/null)-$(shell git rev-parse --short HEAD 2>/dev/null)
# if the git describe command fails, we will set the APP_VERSION to an empty string
ifeq ($(APP_VERSION),-)
APP_VERSION :=
endif
export APP_VERSION

# scenario 1: version=prod, real=true
# we need to down the container, prune the system, and rebuild the container

# scenario 2: version=prod, real=false
# we need to down the container, change the .env file, rebuild the container, and revert the .env file
# replace the IP address with localhost so that the container can connect to the local database

# scenario 3: version=* (dev, staging), real=*
# we need to down the container and rebuild the container
ifeq ($(version), prod)
ifeq ($(real), true)
BUILD_COMMANDS = $(DC_CMD) -v down ;\
docker system prune -f ;\
$(DC_CMD) build --no-cache
else
BUILD_COMMANDS = trap "find . -iname .env.*.bak -exec sh -c 'mv $$0 $${0%.bak}' {} \;" SIGINT ;\
$(DC_CMD) -v down ;\
find . -iname .env.* -exec cp {} {}.bak \; ;\
find . -iname .env.* ! -iname "*.bak" -exec sed -i -e 's/13.229.79.214/localhost/g' {} \; ;\
$(DC_CMD) build --no-cache ;\
find . -iname .env.*.bak -exec sh -c 'mv $$0 $${0%.bak}' {} \;
endif
else
BUILD_COMMANDS = $(DC_CMD) -v down ;\
$(DC_CMD) build
endif

build:
$(BUILD_COMMANDS)
watch:
$(DC_CMD) watch
run:
$(DC_CMD) up -d
down:
$(DC_CMD) -v down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# interapp
# OneInteract

<img src='./interapp-frontend/public/oneinteract.png' width='100'/>

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=raffles-interact_interapp&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=raffles-interact_interapp)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=raffles-interact_interapp&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=raffles-interact_interapp)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=raffles-interact_interapp&metric=bugs)](https://sonarcloud.io/summary/new_code?id=raffles-interact_interapp)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=raffles-interact_interapp&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=raffles-interact_interapp)
[![CI](https://github.com/raffles-interact/interapp/actions/workflows/pipeline.yml/badge.svg)](https://github.com/raffles-interact/interapp/actions/workflows/pipeline.yml)

A monorepo for Raffles Interact's administrative application. Built with Next.js and Express along with the Bun runtime.
A monorepo for Raffles Interact's administrative application.

Built with:

![Tech Stack](https://skillicons.dev/icons?i=nextjs,express,postgres,redis,aws,bun,typescript,nginx,docker) (+ Minio, TypeOrm, and more...)
## Setting up (development)

### Prerequisites
Expand All @@ -16,28 +21,32 @@ Ensure that you have the docker daemon running, along with ``bun``, ``make`` and

Clone with ``git clone https://github.com/raffles-interact/interapp.git``

Obtain both files (containing secret keys and the like) ``interapp-backend/.env.local`` and ``interapp-frontend/.env.local`` from the current set of maintainers.

### First time setup

1. Run ``touch ./interapp-backend/.env.local`` and paste the contents of the file that the maintainers gave you.
1. Put in both secret files ``.env.local`` in both the ``interapp-backend`` and ``interapp-frontend`` directories. Note that they are different files.

2. Navigate to ``./interapp-backend/`` and ``./interapp-frontend/`` and run ``bun i`` in both directories.
2. Install packages in both the ``interapp-backend`` and ``interapp-frontend`` directories (do not install in the root directory). Note that these 2 directories act as different project folders and are only unified during the build process with docker.

3. Run ``make build`` and ``make run``.
3. Set up the dev server with ``make build && make run``. Go onto the website and create an account with any username and id you want. Note down this username.
4. Run ``docker exec -it interapp-postgres sh`` (you should see ‘/ #’ pop up) to enter into a interactive shell after the containers are up. Run
``username=your_username_that_you_signed_up_with PGPASSWORD=postgres psql -U postgres -d interapp -c "INSERT INTO \"user_permission\" (\'username\', \'permission_id\', \'userUsername\') VALUES (\'$username\', 6, \'$username\')"`` to give yourself admin permissions. Exit the interactive shell.

4. (Optional) To give yourself all the permissions on the website, ssh into the ``interapp-postgres`` container and run an SQL query that gives your account permissions from 0 - 6. This should look like:
```sql
INSERT INTO user_permission (username, permission_id, "userUsername") VALUES (‘<username>’, 1, ‘<username>’), (‘<username>’, 2, ‘<username>’), (‘<username>’, 3, ‘<username>’), (‘<username>’, 4, ‘<username>’), (‘<username>’, 5, ‘<username>’), (‘<username>’, 6, ‘<username>’);
```

### Running

Run ``make build`` and ``make run`` for the development server. If needed, add ``version=(test|prod)`` for test and production servers respectively.
Run ``make build`` and ``make run`` for the development server.

If you'd like HMR on the backend/scheduler, use ``make watch`` instead of ``make run`` to use docker compose watch functionality, but this may take additional resources. If you are working on the frontend, ``make run`` is just fine.

If needed, add ``version=(test|prod)`` for test and production servers respectively, eg. ``make build version=test``

Go to ``localhost:3000`` for frontend and ``localhost:3000/api`` for api routes

## Setting up (testing/non-technical)

Please get ``.env.local`` from the current maintainers of the project, which is sensitive information that should not be shared. They will guide you on where to put the data.
Put in both secret files ``.env.local`` in both the ``interapp-backend`` and ``interapp-frontend`` directories. Note that they are different files, which contain sensitive information that should not be shared. Ask the maintainers how to do this if unsure.

1. If you're just testing the UI/frontend, just have ``docker`` installed in your terminal and have Docker desktop running. You can install docker [here](https://docs.docker.com/engine/install/).

Expand All @@ -53,7 +62,7 @@ Please get ``.env.local`` from the current maintainers of the project, which is

7. Go to ``localhost:3000`` on your browser, and verify that you can see the site.

8. For contributing, see [CONTRIBUTING.md](CONTRIBUTING.md#product-demo-guidelines)
8. For contributing, see [CONTRIBUTING.md](CONTRIBUTING.md)


## thanks
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
postgres:
container_name: interapp-postgres
Expand Down Expand Up @@ -110,6 +108,8 @@ services:
target: /app/db
env_file:
- ./interapp-backend/.env.development
environment:
- APP_VERSION=${APP_VERSION}
ports:
- 8000:8000
networks:
Expand All @@ -131,6 +131,8 @@ services:
- ./interapp-frontend/src:/app/src
env_file:
- ./interapp-frontend/.env.development
environment:
- NEXT_PUBLIC_APP_VERSION=${APP_VERSION}
ports:
- 3000:3000
networks:
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
postgres:
container_name: interapp-postgres
Expand Down Expand Up @@ -88,6 +86,8 @@ services:
dockerfile: prod.Dockerfile
env_file:
- ./interapp-backend/.env.production
environment:
- APP_VERSION=${APP_VERSION}
ports:
- 8000:8000
networks:
Expand All @@ -107,6 +107,8 @@ services:
- 3000:3000
env_file:
- ./interapp-frontend/.env.production
environment:
- NEXT_PUBLIC_APP_VERSION=${APP_VERSION}
networks:
- interapp-network
depends_on:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
postgres:
container_name: interapp-postgres-test
Expand Down Expand Up @@ -84,6 +82,8 @@ services:
dockerfile: tests/config/test.Dockerfile
env_file:
- ./interapp-backend/tests/config/.env.docker
environment:
- APP_VERSION=${APP_VERSION}
ports:
- 1234:1234
networks:
Expand Down
Loading
Loading