Skip to content

Commit

Permalink
fix: misc scripting, crashes and unexpected behaviour (#45)
Browse files Browse the repository at this point in the history
* fix: text content, update img

* feat: import script

* fix: config changes

* fix: config change again

* fix: incorrect mapping of asset urls

* fix: readability

* chore: untrack data files

* fix: incorrect formatting for service session date

* fix: crash on 0 permissions

* fix: failed request on 0 announcements navigation

* fix: infinite loading on dne announcement

* fix: ghost keys and handle non-existent session in AttendanceMenuEntry

* fix: undefined build error

* fix: add alt props to img

* fix: many ics allowed for service

* fix: sort services

* fix: imported names too short

* fix: nextattendance is wrong

* fix: fix tests

* fix: admin searching gives undefined pages

* fix: allow search in service sessions

* fix: timezone differences

* chore: raise rate limit

* fix: make service session search clearable

* chore: optimise + allow longer time to have qr available

* feat: import hours script

* fix: minor change of plans for import hours

* chore: update readme

* fix: modify update script path

* fix: lower permissions mark absence failure

* feat: manual password reset script

* feat: allow redirects on login

* fix: dont report issues to sentry on dev server

* fix: prerender error on useSearchParams

* chore: create sessions manually script

* fix: incorrect default value on searchable select

* fix: incorrect usage of pw reset

* chore: bump next to 14.2

* refactor: Makefile build commands for different scenarios

* fix: CORS origin issue in API routes

* chore: Update docker-compose files to remove version field

* chore: rename data-source to snake case

* chore: simplify imports

* chore: Update imports in unit tests to use @models/.

* chore: bump bun to 1.1.3

* chore: Update docker-compose files to include VERSION environment variable

* chore: add footer version

* chore: add release for sentry observability

* fix: naming conflict in version

* fix: reorganise files

* fix: naming conflict

* refactor: reuse code for describe()

* chore: add node-xlsx package for Excel file handling

* feat: implement logic for GM exports

* chore: remove newlines

* feat: refactor validation middleware

* refactor: redo exports

* fix: show full output on build failure

* fix: prevent memory leak by cleaning dumpfiles >7 days old

* chore: prettier

* refactor: use early return  clause

* feat: allow for exports date filtering

* fix: restrict endpoint

* feat: add frontend

* refactor: efficiently compare edit action changes

* fix: incorrect pathing for renamed data_source

* chore: revert #c116271

* feat: add diffing algorithm

* feat: add bulk service hour changes

* fix: dockerfile failure due to incorrect shell syntax

* feat: add endpoint linkage and clean up

* fix: consise regex number syntax

* fix: build error

* fix: update service hours in bulk overwriting value

* chore: bump version
  • Loading branch information
SebassNoob authored Apr 19, 2024
1 parent 12aca7e commit aa857c6
Show file tree
Hide file tree
Showing 106 changed files with 1,819 additions and 636 deletions.
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

0 comments on commit aa857c6

Please sign in to comment.