Skip to content

quantum-brackets/holis

Repository files navigation

HOLIS

Holistic Online Learning Institute System

Database Setup

Production Database

https://supabase.com/dashboard/project/ntystxwkhldciewdnzqk

Development Database

Run the following SQL to set up the necessary tables.

-- Create the institutions table
CREATE TABLE institutions (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    slug TEXT UNIQUE NOT NULL,
    data JSONB NOT NULL
);

-- Create the institution_members table
CREATE TABLE institution_members (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    institution_id UUID NOT NULL REFERENCES institutions(id) ON DELETE CASCADE,
    user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
    data JSONB NOT NULL,
    UNIQUE(institution_id, user_id)
);

-- Enable Row Level Security (RLS) for the institutions table
ALTER TABLE institutions ENABLE ROW LEVEL SECURITY;

-- Allow read access to everyone for the institutions table
CREATE POLICY "Allow public read access to institutions"
ON institutions
FOR SELECT
USING (true);

-- Allow authenticated users to insert new institutions
CREATE POLICY "Allow authenticated users to create institutions"
ON institutions
AS PERMISSIVE
FOR INSERT
TO authenticated
WITH CHECK (true);

-- Create a policy that allows users with 'admin' role in institution_members to update institution records
CREATE POLICY "Admins can update their institution records"
ON institutions
FOR UPDATE
TO authenticated
USING (
    EXISTS (
        SELECT 1
        FROM institution_members im
        WHERE
            im.institution_id = institutions.id AND
            im.user_id = auth.uid() AND
            (im.data->'groups')::jsonb ? 'admin'
    )
);

-- Enable RLS for the institution_members table
ALTER TABLE institution_members ENABLE ROW LEVEL SECURITY;

-- Allow members to see their own membership record
CREATE POLICY "Allow members to view their own membership"
ON institution_members
FOR SELECT
USING (auth.uid() = user_id);

-- Allow authenticated users to insert new membership records
CREATE POLICY "Enable insert for authenticated users only"
ON institution_members
AS PERMISSIVE
FOR INSERT
TO authenticated
WITH CHECK (true);

-- Update RLS policy to allow users to update only their own institution_members records
CREATE POLICY "Users can update their own membership"
ON institution_members
AS PERMISSIVE
FOR UPDATE
TO authenticated
USING (user_id = auth.uid())
WITH CHECK (user_id = auth.uid());

HTTPS Setup

Production Domain

Add the subdomain used by the institution to the inst.education domain list

https://vercel.com/edusys/holis/settings/domains

Development Domain

The application supports both localhost and wildcard domains (*.holis.test). The certificate configuration is in certs/localhost.conf.

Generate SSL Certificate

openssl req -x509 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pem -days 365 -nodes -config certs/localhost.conf -extensions v3_req

Trust the Certificate MacOS

security add-trusted-cert -r trustRoot -k ~/Library/Keychains/login.keychain certs/cert.pem

Regenerate Certificate After Configuration Changes

If you've made changes to the certificate configuration or are experiencing SSL issues with subdomains:

  1. Remove the old certificate from your keychain:

    security delete-certificate -c "localhost"
    security delete-certificate -c "*.holis.test"
  2. Regenerate the certificate:

    See Generate SSL Certificate

  3. Trust the new certificate:

    See Trust the Certificate

  4. Restart your development server

Local DNS Setup

Option 1: Using /etc/hosts

Add the following entries to your /etc/hosts file:

127.0.0.1 holis.test
127.0.0.1 institution-name.holis.test

Replace institution-name with your specific subdomain names as needed.

Option 2: Using dnsmasq (recommended for wildcard domains)
  1. Install dnsmasq:

    brew install dnsmasq
  2. Configure dnsmasq to resolve *.holis.test to localhost by creating/editing /usr/local/etc/dnsmasq.conf:

    address=/.holis.test/127.0.0.1
    
  3. Start or restart dnsmasq:

    sudo brew services restart dnsmasq
  4. Configure macOS to use dnsmasq for .test domains by creating a resolver:

    sudo mkdir -p /etc/resolver
    echo 'nameserver 127.0.0.1' | sudo tee /etc/resolver/test

About

Holistic Online Learning Institute System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages