Fakultas Ilmu Komputer UI

Commit 26782da6 authored by Ryan Karyadiputera's avatar Ryan Karyadiputera
Browse files

test3

parent d82d6ddb
Pipeline #76868 failed with stages
in 6 minutes and 25 seconds
[
{
"jenis_praktikum": "",
"status_kelola": false,
"user": {
"username": "ferenica.dwi",
"email": "ferenica.dwi@ui.ac.id",
"full_name": "Ferenica Dwi"
},
"org_code": "",
"npm": "1801801802",
"periode": {
"id": 1,
"nama": "2019/2020 - Genap"
},
"faculty": "",
"major": "",
"program": "",
"supervisor_sekolah": null,
"supervisor_lembaga": null
},
{
"jenis_praktikum": "",
"status_kelola": false,
"user": {
"username": "nabila.fathia",
"email": "nabila.fathia@ui.ac.id",
"full_name": "Nabila Fathia"
},
"org_code": "",
"npm": "1801801803",
"periode": {
"id": 1,
"nama": "2019/2020 - Genap"
},
"faculty": "",
"major": "",
"program": "",
"supervisor_sekolah": null,
"supervisor_lembaga": null
},
{
"jenis_praktikum": "",
"status_kelola": false,
"user": {
"username": "nunun.hidayah",
"email": "nunun.hidayah@ui.ac.id",
"full_name": "Nunun Hidayah"
},
"org_code": "",
"npm": "1801801804",
"periode": {
"id": 1,
"nama": "2019/2020 - Genap"
},
"faculty": "",
"major": "",
"program": "",
"supervisor_sekolah": null,
"supervisor_lembaga": null
},
{
"jenis_praktikum": "",
"status_kelola": false,
"user": {
"username": "ryan.karyadiputera",
"email": "ryan.karyadiputera@ui.ac.id",
"full_name": "Ryan Karyadiputera"
},
"org_code": "",
"npm": "1801801805",
"periode": {
"id": 1,
"nama": "2019/2020 - Genap"
},
"faculty": "",
"major": "",
"program": "",
"supervisor_sekolah": null,
"supervisor_lembaga": null
},
{
"jenis_praktikum": "",
"status_kelola": false,
"user": {
"username": "salsabila.adnan",
"email": "salsabila.adnan@ui.ac.id",
"full_name": "Salsabila Adnan"
},
"org_code": "",
"npm": "1801801801",
"periode": {
"id": 1,
"nama": "2019/2020 - Genap"
},
"faculty": "",
"major": "",
"program": "",
"supervisor_sekolah": null,
"supervisor_lembaga": null
}
]
\ No newline at end of file
venv
env
__pycache__/
*.pyc
.example.env.dev
.example.env.production
.example.env.staging
sip/settings/dev.py
sip/settings/production.py
\ No newline at end of file
# Created by https://www.toptal.com/developers/gitignore/api/python,django,vscode,sonarqube,sonar
# Edit at https://www.toptal.com/developers/gitignore?templates=python,django,vscode,sonarqube,sonar
### Quick Push Script
push.py
push.cmd
### Quick Coverage Check Script
coverage.cmd
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
sip/db.sqlite3
db.sqlite3-journal
media
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/
### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log
# Translations
*.mo
# Django stuff:
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
doc/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# profiling data
.prof
### Python ###
# Byte-compiled / optimized / DLL files
# C extensions
# Distribution / packaging
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
# Installer logs
# Unit test / coverage reports
# Translations
# Django stuff:
# Flask stuff:
# Scrapy stuff:
# Sphinx documentation
# PyBuilder
# Jupyter Notebook
# IPython
# pyenv
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
# Celery stuff
# SageMath parsed files
# Environments
# Spyder project settings
# Rope project settings
# mkdocs documentation
# mypy
# Pyre type checker
# pytype static type analyzer
# profiling data
### Sonar ###
#Sonar generated dir
/.sonar/
### SonarQube ###
# SonarQube ignore files.
#
# https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
# Sonar Scanner working directories
.sonar/
.scannerwork/
# http://www.sonarlint.org/commandline/
# SonarLint working directories, configuration files (including credentials)
.sonarlint/
### vscode ###
.vscode/*
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# End of https://www.toptal.com/developers/gitignore/api/python,django,vscode,sonarqube,sonar
# Data seed
data_seed/lembaga*
data_seed_v2
# Script bash
migrate.local
check-code.sh
serve.sh
credentials
**/media/
# Backend database
db_backend/
stages:
- flake8
- build
- deploy
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
image: python:latest
cache:
key: test
paths:
- .cache/pip
- venv/
before_script:
- python3 -V
- pip3 install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip3 install -r requirements.txt
- echo "DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY" > sip/settings/.env
- echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> sip/settings/.env
- echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env
- echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env
heroku-deploy:
image: ruby:2.4
stage: deploy
cache: {}
before_script:
- gem install dpl
- wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
script:
- dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
- export HEROKU_API_KEY=$HEROKU_APIKEY
only:
- staging
- /^.*URGENT-.*$/
# pull official base image
FROM python:3.9.1-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# copy project
COPY . .
CMD [ "gunicorn", "sip.wsgi:application", "--bind", "0.0.0.0:8000" ]
\ No newline at end of file
web: DJANGO_SETTINGS_MODULE=sip.settings.staging gunicorn sip.wsgi --log-file -
# MKPPL-SI Penilaian dan Evaluasi Praktikum
## __Getting Started__
Pastikan **python3** dan **git** sudah terinstall pada laptop/komputer Anda.
```bash
git clone https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2020/mkppl-si-penilaian-dan-evaluasi-praktikum.git
cd mkppl-si-penilaian-dan-evaluasi-praktikum
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
## __Setup Local__
### Settings Directory Tree
```
...
+-- sip
| +-- settings
| | +-- static (generated)
| | +-- dev.py (for local)
| | +-- production.py (for production)
| | +-- staging.py (for staging)
|
...
```
### __Environment Variables__
Contoh bentuk file `.env.dev`, ini akan di-*load* pada `settings/dev.py`
***Catatan: file ini dapat berubah menyesuaikan flow, ini hanya contoh.***
```
SECRET_KEY="sm1l3_sw33t_s1st3r_sUrpr1s3_s3rvc1c3"
DB_NAME=db_name
DB_USER=admin
DB_PASS=db_password
DB_HOST=db
DB_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres_password
POSTGRES_DB=postgres_db_name
```
### __How To Run on Local Development__
1. Buat .env di folder sip/settings/ dengan secret key-nya. Tambahin line ini di file-nya:
```bash
DJANGO_SECRET_KEY="s3cr3t_k3y_c4nn0t_h4ck3d_by_l33t_1337"
```
2. Lakukan makemigrations dan migrate
```bash
python manage.py makemigrations --settings=sip.settings.dev
python manage.py migrate --settings=sip.settings.dev
```
3. Jalankan aplikasi menggunakan `manage.py runserver` pada port 8000, spesifikasi settings yang digunakan adalah `dev` atau local.
```bash
python manage.py runserver 8000 --settings=<path>.sip.settings.dev
```
### __Pipelines and Coverage__
[![pipeline status](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/badges/staging/pipeline.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/commits/staging/)
[![coverage report](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/badges/staging/coverage.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/commits/staging/)
from .models import (
Mahasiswa,
SupervisorSekolah,
SupervisorLembaga,
KoordinatorKuliah,
Administrator,
User,
Periode,
Config
)
from django.contrib import admin
"""Profile model admin class."""
@admin.register(Mahasiswa)
class MahasiswaAdmin(admin.ModelAdmin):
pass
"""Profile model admin class."""
@admin.register(SupervisorSekolah)
class SupervisorSekolahAdmin(admin.ModelAdmin):
pass
"""Profile model admin class."""
@admin.register(KoordinatorKuliah)
class KoordinatorKuliahAdmin(admin.ModelAdmin):
pass
"""Profile model admin class."""
@admin.register(SupervisorLembaga)
class SupervisorLembagaAdmin(admin.ModelAdmin):
pass
"""Profile model admin class."""
@admin.register(Administrator)
class AdministratorAdmin(admin.ModelAdmin):
pass
@admin.register(Periode)
class PeriodeAdmin(admin.ModelAdmin):
pass
@admin.register(Config)
class ConfigAdmin(admin.ModelAdmin):
pass
from django.apps import AppConfig
class AuthenticationConfig(AppConfig):
name = 'authentication'
verbose_name = "Authentication"
from django_cas_ng import views as cas_views
from django_cas_ng.models import ProxyGrantingTicket, SessionTicket
from django_cas_ng.utils import get_protocol, get_redirect_url, get_cas_client
from django_cas_ng.signals import cas_user_logout
from django.http import JsonResponse, HttpRequest, HttpResponse, HttpResponseRedirect
from django.conf import settings
from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
from urllib import parse as urllib_parse
from rest_framework.response import Response
from rest_framework_jwt.settings import api_settings
from django.contrib.auth.models import update_last_login
from .models import User
JWT_PAYLOAD_HANDLER = api_settings.JWT_PAYLOAD_HANDLER
JWT_ENCODE_HANDLER = api_settings.JWT_ENCODE_HANDLER
class APILoginView(cas_views.LoginView):
def successful_login(self, request: HttpRequest, next_page: str) -> HttpResponse:
"""
This method is called on successful login. Override this method for
custom post-auth actions (i.e, to add a cookie with a token).
:param request:
:param next_page:
:return:
"""
try:
user = User.objects.get(email=f'{request.user.email}@ui.ac.id')
except User.DoesNotExist:
user = request.user
new_next_page = next_page
if user.email == "":
new_next_page = settings.SUCCESS_SSO_AUTH_REDIRECT + 'not-login/'
user.delete()
elif not user.is_active:
new_next_page = settings.SUCCESS_SSO_AUTH_REDIRECT + 'not-login/'
else:
payload = JWT_PAYLOAD_HANDLER(user)
jwt_token = JWT_ENCODE_HANDLER(payload)
update_last_login(None, user)
new_next_page = settings.SUCCESS_SSO_AUTH_REDIRECT + 'login-sivitas/' + jwt_token
return HttpResponseRedirect(new_next_page)
class APILogoutView(cas_views.LogoutView):
def get(self, request: HttpRequest) -> HttpResponse:
"""
Redirects to CAS logout page
:param request:
:return:
"""
next_page = settings.SUCCESS_SSO_AUTH_REDIRECT