Skip to content

webkom/admissions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

admissions

Recruitment for Abakus.

Table of contents

 

Environments

Production

opptak.abakus.no
OAuth through abakus.no

Staging

opptak-staging.abakus.no
OAuth through abakus.no

 

Local development

Prerequisites

To run this project, you need

  1. python 3.9
  2. Docker OR a postgresql database
  3. poetry (installation guide)
  4. Node and yarn

Running the project

When working in development you want to have LEGO running (both frontend and backend). This allows you to create an OAuth2 application from the settings menu in the webapp.

To do this, you need a total of 4 terminals (or shells if you like).

Terminal 1

Run LEGO by following the README here.

Terminal 2

Run LEGO-WEBAPP by following the README here.

Terminal 3

Install the projects dependencies with

$ poetry install

This command will also create a virtual environment in which the dependencies are installed, if one has not already been created and activated.

Then, run the following command

$ make dev_settings

The docker-compose.yml file provides a postgresql database. This uses a different port than LEGO, so you can run it in parallel as follows.

$ docker-compose up -d

Secrets

The .env file with secret keys is not included, but an example.env file has been provided in ./admissions/settings, so that you can simply rename the file and fill in the values.

example.env is setup to connect to an Oauth2 application already configured in LEGO, so if you don't need anything special you are good to go with that one.

If you want to configure another one, go to the OAuth2 tab in the user settings menu in the running dev version of lego-webapp. Open or create an application, and enter the values you find into your .env file. If you are creating a new OAuth2 application, enter http://127.0.0.1:5000/complete/lego/ as the redirect url.

# Create a copy of the example env file (run from the root of the project)
$ cp admissions/settings/example.env admissions/settings/.env

# Edit the file and change the KEY and SECRET
AUTH_LEGO_KEY="Client ID from OAuth2"
AUTH_LEGO_SECRET="Client Secret from OAuth2"
AUTH_LEGO_API_URL="http://localhost:8000/"

After creating and configuring your ./admissions/settings/.env file you are ready to migrate the database and run the server.

# Migrate the database migrations
$ poetry run python manage.py migrate

# Run the Django server
$ poetry run python manage.py runserver

If coding over long periods of time, or you want to flush the database, run poetry run python manage.py flush to flush it, and run the server again with poetry run python manage.py runserver.

Terminal 4

In the last terminal you are ready to start the frontend. The frontend requires Node. You simply need to install the requirements and run the dev-server as follows.

# Install dependencies
$ yarn

# Start the dev-server
$ yarn dev

Finally, you can go to 127.0.0.1:5000 and view the admissions page.

NB: The project has to be accessed through 127.0.0.1, and NOT localhost. This is because accessing both LEGO and admissions from the same hostname creates a conflict some session storage, so the login will not work.

To create an admission, first, open 127.0.0.1:5000 and click the "Logg inn" button at the bottom of the page to authorize as a user with permission to create admissions. Then, click "Administrer opptak" and create an admission. Phew, now you are ready to start developing!

 

Creating admissions

GUI

The simplest way to create an admission is through the GUI.

  1. Navigate to 127.0.0.1:5000
  2. Log in as a user with permission to create admissions.
  3. Click "Administrer opptak" at the bottom of the screen
  4. Success

Shell

Currently when running

# Create a custom admission for development
$ poetry run python manage.py create_admission

you create an admission connected to all groups, if they exist (they are generated the first time you log in). To connect it to a group, you can either do it through the GUI, or create it in the shell.
Note that when creating groups in the shell, you must import the Group model manually, as otherwise it will use the Django Group model instead of our own.

$ poetry run python manage.py shell_plus
> from admissions.admissions.models import Group
> new_group = Group.objects.create(name="GroupA")
> admission = Admission.objects.get(slug="opptak")
> admission.groups.add(new_group)

 

Permissions

The project gives permissions based on group memberships imported from LEGO.

Model Action Requirement
Admission CREATE Either (1) any member of Webkom, (2) leader of Abakus OR (3) leader of RevyStyret.
(1,2,3) user.is_staff
Admission EDIT Either (1) member of Webkom OR (2) creator of admission.
(1) user.is_member_of_webkom, (2) admission.created_by.
All applications VIEW & DELETE Member of a group in admission.admin_groups
Applications to a group VIEW & DELETE Member of a group in admission.groups WITH role LEADER or RERUITING
Group EDIT Member of a group in admission.groups WITH role LEADER or RERUITING

 

Run tests

Run django tests using tox. Note that we point at the admissions database running at :5433 if we are running lego and admissions in parallel

$ DATABASE_PORT=5433 poetry run tox -e tests

 

Code style

This codebase uses the PEP 8 code style. We enforce this with isort, black & flake8. In addition to the standards outlined in PEP 8, we have a few guidelines (see setup.cfg for more info):

Format the code with black & isort

$ make fixme

To check if it is formatted properly, run:

$ DATABASE_PORT=5433 poetry run tox -e isort -e flake8 -e black