This project is the API for the Learning Platform. It is a Django project using the Django REST Framework application. It integrates with the Github OAuth platform to create accounts and perform authorization for the companion Learning Platform React client.
- Install Postman
- Open Postman app
- Click File > Import from the navbar
- Drag the
LearnOps.postman_collection.json
file into the dialog - Requests will be imported and should appear on the left.
If you are a Windows user, you will need to install WSL and Ubuntu.
Do only steps 1-4 of these instructions if you have never installed WSL before.
Do not do step 5... only steps 1-4.
Ubuntu on WSL install instructions
Once you are done, you will be working in an Ubuntu terminal during all setup and developing on the API.
If you already have Postgres installed in Ubuntu, then you need to uninstall it and kill the existing cluster.
sudo apt remove postgresql
sudo pg_ctlcluster {version} main stop
sudo pg_dropcluster {version} main --stop
Make sure you have git
installed so you can clone and work on the project.
If you are setting this project up on a new WSL Linux installation, you need to create a new SSH key for that OS.
- Set up an SSH key pair for Linux/Mac
- Add the public SSH key to your Github account
- Make sure SSH agent is running
- Use
ssh-add
to add your new private key to the shell session
This application uses Github for authorization instead of user accounts in Django. You will need to set up your own OAuth application for use during local development.
- Go to your Github account settings
- Open Developer Settings
- Open OAuth Apps
- Click Register New Application button
- Application name should be Learning Platform
- Homepage URL should be
http://localhost:3000
- Enter a description if you like
- Authorization callback should be
http://localhost:8000/auth/github/callback
- Leave Enable Device Flow unchecked
- Click the Register Application button
- Click the Generate a new client secret button
- DO NOT CLOSE TAB. CLIENT AND SECRET NEEDED BELOW.
- Fork this repo to your own Github account. Set your fork as remote origin. Set this repository as remote upstream.
- Clone your fork to your directory of choice.
cd
into the project directory that gets created.
Several environment variables need to be set up by you to make the setup process faster and more secure.
- Open the project directory in your code editor.
- Make a copy of the
.env.template
file in the project directory and name it.env
. - Replace all "replace_me" values in the file and be sure to read the notes below.
- The
LEARN_OPS_CLIENT_ID
andLEARN_OPS_SECRET_KEY
values will be listed in the open tab you created previously for the Github OAuth app. - For the Django secret key, a quick way to get a good secret key is to visit Djecrety.
- The superuser variables will be your credentials for logging into the Django admin panel where you can view and update data in a web interface.
- The
LEARN_OPS_PASSWORD
variable is the password for a database user that will be created your local database. Make it something simple.
Once your environment variables are established, you will run a bash script to install all the software needed for the API to run, create the database tables needed, and seed the database with some data.
In your terminal, be in the project directory, and run the following command.
./setup.sh
Once this script is complete, you will have the Postgres database, and some starter data seeded in it.
The setup script installs Python 3.9.1, so your last step is to start the virtual environment for the project with the correct version.
pipenv --python 3.9.1 shell
Go back to VSCode and start a Django debugger (recommend creating a launcher profile for yourself). If the setup was successful, you will see the following output in the VSCode integrated terminal.
Performing system checks...
System check identified no issues (0 silenced).
September 09, 2023 - 19:46:38
Django version 4.2.2, using settings 'LearningPlatform.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
- Visit http://localhost:8000/admin
- Authenticate with the superuser credentials you specified in your environment variables and ensure that you gain access to the admin interface.
If you successfully authenticated, follow these steps to access the instructor interface of the Learning Platform. You must have already cloned and set up the client application before you perform these steps.
- Start the React client application.
- Authorize the client with Github.
- Visit the admin interface and authenticate with your superuser credentials.
- Click on Users in the left navigation.
- Find the account that was just created for your Github authorization by searching for your Github username.
- Click on your user account.
- Toggle Staff status to be on.
- In the Group sections, double click Instructor so that it moves to the Chosen groups list.
- Close the browser tab that is running the Learning Platform.
- Open a new tab and visit http://localhost:3000 again and authenticate.
- You should now see the instructor interface.