Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
janno42 committed May 1, 2022
2 parents dac9376 + 13e63cb commit d0bf4aa
Show file tree
Hide file tree
Showing 160 changed files with 14,052 additions and 14,857 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/debug-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Debug Mode Test Run

on:
push:
branches:
- main

jobs:
tests:
runs-on: ubuntu-18.04

container:
image: python:3.7

services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: evap
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

name: Debug mode

steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Add localsettings
run: cp evap/settings_test.py evap/localsettings.py
- name: Run tests
run: python manage.py test --debug-mode
20 changes: 18 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
include:
- name: Coverage
command: coverage run manage.py test && codecov -X gcov
- name: Debug mode
command: python manage.py test --debug-mode
- name: Reverse order
command: python manage.py test --reverse

Expand All @@ -47,6 +45,24 @@ jobs:
run: ${{ matrix.command }}


mypy:
runs-on: ubuntu-18.04

container:
image: python:3.7

name: MyPy

steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Add localsettings
run: cp evap/settings_test.py evap/localsettings.py
- name: Run MyPy
run: mypy -p evap

linter:
runs-on: ubuntu-18.04

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
TAGS
.*
!.gitignore
!.github
*.kpf
*.komodoproject

Expand Down
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The software is licensed under the MIT license. The source code includes other
components in whole or in part; namely Bootstrap Datepicker, Font Awesome,
jQuery, jQuery Formset, Moment, Popper, Select2, Sisyphus, Sortable.
jQuery, jQuery Formset, Moment, Select2, Sisyphus, Sortable.
These components are used under the MIT resp. SIL OFL licenses.

The source repository may include logos, names or other trademarks of the
Expand All @@ -12,8 +12,8 @@ not touched by the software license.

```
EvaP – Evaluation Platform
Copyright (C) 2011-2021 by Michael Grünewald, Stefan Richter, Johannes Linke,
and Johannes Wolf
Copyright (C) 2011-2022 by Johannes Wolf, Johannes Linke, Michael Grünewald,
Stefan Richter, and Richard Ebeling
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ vagrant ssh
That's it!
### Docker
We provide experimental support to run the development setup in a docker container using
```bash
vagrant up --provider docker
vagrant provision
vagrant ssh
```
## Contributing
We'd love to see contributions, feel free to fork! You should probably branch off ``main``, the branch ``release`` is used for stable revisions.
Expand Down
8 changes: 8 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Security Policy

Please do not open GitHub issues for anything you think might have a security implication.

Security issues and bugs should be reported privately by emailing any of the [organization members](https://github.com/orgs/e-valuation/people).

We will try to acknowledge your messages within 48 hours.
If for some reason you do not receive an acknowledgement, please follow up to ensure we received your original message.
34 changes: 22 additions & 12 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,38 @@
Vagrant.require_version ">= 1.8.1"

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.box_version = "= 20210928.0.0 "
config.vm.provider :virtualbox do |v, override|
override.vm.box = "ubuntu/bionic64"
override.vm.box_version = "= 20210928.0.0 "
override.vm.provision "shell", path: "deployment/provision_vagrant_vm.sh"

# port forwarding
config.vm.network :forwarded_port, guest: 8000, host: 8000 # django server
config.vm.network :forwarded_port, guest: 80, host: 8001 # apache
config.vm.network :forwarded_port, guest: 6379, host: 6379 # redis. helpful when developing on windows, for which redis is not available

config.vm.provider :virtualbox do |v, _override|
# disable logfile
if Vagrant::Util::Platform.windows?
v.customize [ "modifyvm", :id, "--uartmode1", "file", "nul" ]
else
v.customize [ "modifyvm", :id, "--uartmode1", "file", "/dev/null" ]
end
end

# show virtualbox gui, uncomment this to debug startup problems
#v.gui = true
config.vm.provider :docker do |d, override|
d.image = "ubuntu:bionic"
# Docker container really are supposed to be used differently. Hacky way to make it into a "VM".
d.cmd = ["tail", "-f", "/dev/null"]

# Workaround for no SSH server as long as https://github.com/hashicorp/vagrant/issues/8145 is still open
override.trigger.before :provision do |trigger|
trigger.ruby do |env, machine| system("vagrant docker-exec -it -- /evap/deployment/provision_vagrant_vm.sh") end
end
override.trigger.before :ssh do |trigger|
trigger.ruby do |env, machine| system("vagrant docker-exec -it -- sudo -H -u evap bash") end
end
end

# port forwarding
config.vm.network :forwarded_port, guest: 8000, host: 8000 # django server
config.vm.network :forwarded_port, guest: 80, host: 8001 # apache
config.vm.network :forwarded_port, guest: 6379, host: 6379 # redis. helpful when developing on windows, for which redis is not available

# override username to be evap instead of vagrant, just as it is on production.
# This is necessary so management script can assume evap is the correct user to
# execute stuff as.
Expand All @@ -34,6 +46,4 @@ Vagrant.configure("2") do |config|
if ARGV[0] == "ssh" or ARGV[0] == "ssh-config"
config.ssh.username = 'evap'
end

config.vm.provision "shell", path: "deployment/provision_vagrant_vm.sh"
end
2 changes: 1 addition & 1 deletion deployment/manage_autocompletion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# generated using
# ./manage.py | grep -v -E "^\[|^$" | tail -n +3 | sort | xargs
COMMANDS="admin_generator anonymize changepassword check clean_pyc clear_cache clearsessions collectstatic compile_pyc compilemessages create_command create_jobs create_template_tags createcachetable createsuperuser dbshell delete_squashed_migrations describe_form diffsettings drop_test_database dump_testdata dumpdata dumpscript export_emails find_template findstatic flush format generate_password generate_secret_key graph_models inspectdb lint list_model_info list_signals loaddata mail_debug makemessages makemigrations merge_model_instances migrate notes pipchecker precommit print_settings print_user_for_session refresh_results_cache reload_testdata remove_stale_contenttypes reset_db reset_schema run runjob runjobs runprofileserver runscript runserver runserver_plus scss send_reminders sendtestemail set_default_site set_fake_emails set_fake_passwords shell shell_plus show_template_tags show_urls showmigrations sqlcreate sqldiff sqldsn sqlflush sqlmigrate sqlsequencereset squashmigrations startapp startproject sync_s3 syncdata test testserver tools ts unreferenced_files update_evaluation_states update_permissions validate_templates"
COMMANDS="admin_generator anonymize changepassword check clean_pyc clear_cache clearsessions collectstatic compile_pyc compilemessages create_command create_jobs create_template_tags createcachetable createsuperuser dbshell delete_squashed_migrations describe_form diffsettings drop_test_database dump_testdata dumpdata dumpscript export_emails find_template findstatic flush format generate_password generate_secret_key graph_models inspectdb lint list_model_info list_signals loaddata mail_debug makemessages makemigrations merge_model_instances migrate notes pipchecker precommit print_settings print_user_for_session refresh_results_cache reload_testdata remove_stale_contenttypes reset_db reset_schema run runjob runjobs runprofileserver runscript runserver runserver_plus scss send_reminders sendtestemail set_default_site set_fake_emails set_fake_passwords shell shell_plus show_template_tags show_urls showmigrations sqlcreate sqldiff sqldsn sqlflush sqlmigrate sqlsequencereset squashmigrations startapp startproject sync_s3 syncdata test testserver tools translate ts typecheck unreferenced_files update_evaluation_states update_permissions validate_templates"
TS_COMMANDS="compile test render_pages"

_managepy_complete()
Expand Down
30 changes: 23 additions & 7 deletions deployment/provision_vagrant_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

set -x # print executed commands

MOUNTPOINT="/evap"
USER="evap"
REPO_FOLDER="/opt/evap"
ENV_FOLDER="/home/$USER/venv"

# force apt to not ask, just do defaults.
export DEBIAN_FRONTEND=noninteractive

# install python stuff
apt-get -q update

# system utilities that docker containers don't have
apt-get -q install -y sudo wget git bash-completion
# docker weirdly needs this -- see https://stackoverflow.com/questions/46247032/how-to-solve-invoke-rc-d-policy-rc-d-denied-execution-of-start-when-building
printf '#!/bin/sh\nexit 0' > /usr/sbin/policy-rc.d

# install python stuff
apt-get -q install -y python3.7 python3.7-dev python3-venv python3.7-venv gettext

# setup postgres
Expand All @@ -21,20 +28,26 @@ sudo -u postgres createdb -O evap evap

# setup redis
apt-get -q install -y redis-server
sed -i "s/^bind .*/bind 127.0.0.1/g" /etc/redis/redis.conf
service redis-server restart

# install apache
apt-get -q install -y apache2 apache2-dev

# With docker for mac, root will own the mount point (uid=0). chmod does not touch the host file system in these cases.
OWNER=$(stat -c %U "$MOUNTPOINT/evap")
if [ "$OWNER" == "root" ]; then chown -R 1042 "$MOUNTPOINT"; fi

# make user, create home folder, set uid to the same set in the Vagrantfile (required for becoming the synced folder owner), set default shell to bash
useradd -m -u 1042 -s /bin/bash evap
useradd -m -u $(stat -c "%u" "$MOUNTPOINT/evap") -s /bin/bash evap
# allow ssh login
cp -r /home/vagrant/.ssh /home/$USER/.ssh
chown -R $USER:$USER /home/$USER/.ssh
# allow sudo without password
echo "$USER ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/evap

# link the mounted evap folder from the home directory
ln -s /evap $REPO_FOLDER
ln -s "$MOUNTPOINT" "$REPO_FOLDER"

sudo -H -u $USER python3.7 -m venv $ENV_FOLDER
# venv will use ensurepip to install a new version of pip. We need to update that version.
Expand All @@ -58,13 +71,16 @@ a2dissite 000-default.conf
# see https://github.com/e-valuation/EvaP/issues/626
# and https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror
sed -i s,\#.\ /etc/default/locale,.\ /etc/default/locale,g /etc/apache2/envvars
systemctl reload apache2
service apache2 reload

cp /etc/skel/.bashrc /home/$USER/
# auto cd into /$USER on login and activate venv
echo "cd $REPO_FOLDER" >> /home/$USER/.bashrc
echo "source $ENV_FOLDER/bin/activate" >> /home/$USER/.bashrc

# required for docker (no-op if already started)
echo "sudo service postgresql start && sudo service redis-server start" >> /home/$USER/.bashrc

# install requirements
sudo -H -u $USER $ENV_FOLDER/bin/pip install -r $REPO_FOLDER/requirements-dev.txt

Expand All @@ -82,12 +98,12 @@ apt-get -q install -y libasound2 libgconf-2-4 libgbm1 libgtk-3-0 libnss3 libx11-
wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh --no-verbose --output-document - | sudo -H -u $USER bash

# setup evap
cd /$USER
git submodule update --init
cd "$MOUNTPOINT"
sudo -H -u $USER git submodule update --init
sudo -H -u $USER bash -c "source /home/$USER/.nvm/nvm.sh; nvm install --no-progress node; npm ci"
echo "nvm use node" >> /home/$USER/.bashrc
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py migrate --noinput
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py collectstatic --noinput
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py compilemessages --locale de_DE --locale en_US
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py compilemessages --locale de
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py loaddata test_data.json
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py refresh_results_cache
11 changes: 10 additions & 1 deletion evap/contributor/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.forms.widgets import CheckboxSelectMultiple
from django.utils.translation import gettext_lazy as _

from evap.evaluation.forms import UserModelChoiceField
from evap.evaluation.forms import UserModelChoiceField, UserModelMultipleChoiceField
from evap.evaluation.models import Course, Evaluation, Questionnaire, UserProfile
from evap.evaluation.tools import vote_end_datetime
from evap.staff.forms import ContributionForm
Expand All @@ -26,9 +26,13 @@ class Meta:
"name_en_field",
"vote_start_datetime",
"vote_end_date",
"participants",
"general_questionnaires",
"course",
)
field_classes = {
"participants": UserModelMultipleChoiceField,
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -45,6 +49,11 @@ def __init__(self, *args, **kwargs):
self.fields["vote_start_datetime"].localize = True
self.fields["vote_end_date"].localize = True

queryset = UserProfile.objects.exclude(is_active=False)
if self.instance.pk is not None:
queryset = (queryset | self.instance.participants.all()).distinct()
self.fields["participants"].queryset = queryset

if self.instance.general_contribution:
self.fields["general_questionnaires"].initial = [
q.pk for q in self.instance.general_contribution.questionnaires.all()
Expand Down
36 changes: 9 additions & 27 deletions evap/contributor/templates/contributor_evaluation_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ <h5 class="card-title">{% trans 'Course data' %}</h5>
<div class="card-body">
<div class="d-flex">
<h5 class="card-title me-auto">{% trans 'Evaluation data' %}</h5>
{% if not evaluation.allow_editors_to_edit %}
{% if evaluation.allow_editors_to_edit %}
<div>
<button type="button" class="btn btn-sm btn-light" onclick="changeEvaluationRequestModalShow();" id="changeEvaluationRequestModalButton">
<button type="button" class="btn btn-sm btn-light mb-3" onclick="createAccountRequestModalShow();" id="createAccountRequestModalButtonInEvaluationForm">
{% trans 'Request creation of new account' %}
</button>
</div>
{% else %}
<div>
<button type="button" class="btn btn-sm btn-light" onclick="changeEvaluationRequestModalShow();" id="changeEvaluationDataRequestModalButton">
{% trans 'Request changes' %}
</button>
</div>
Expand All @@ -80,26 +86,6 @@ <h5 class="card-title me-auto">{% trans 'Evaluation data' %}</h5>
</div>
</div>

<div class="card mb-3">
<div class="card-body">
<fieldset>
<div class="d-flex">
<h5 class="card-title me-auto">{% trans 'Participants' %}</h5>
<div>
<button type="button" class="btn btn-sm btn-light" onclick="changeParticipantRequestModalShow();" id="changeParticipantRequestModalButton">
{% trans 'Request changes' %}
</button>
</div>
</div>
<p>{% trans 'These people will be invited for the evaluation. Please let us know if this data is not correct.' %}</p>
<ul>
{% for p in evaluation.participants.all|dictsort:'last_name' %}
<li>{{ p.full_name }}</li>
{% endfor %}
</ul>
</fieldset>
</div>
</div>
<div class="card card-submit-area card-submit-area-3 text-center mb-3">
<div class="card-body">
{% if editable %}
Expand Down Expand Up @@ -147,11 +133,7 @@ <h5 class="modal-title" id="previewModalLabel">{% trans 'Preview' %}</h5>
};
</script>

{% blocktrans asvar title with evaluation_name=evaluation.full_name|safe %}Request participant changes for {{ evaluation_name }}{% endblocktrans %}
{% trans 'Please tell us what changes to the participants list we should make.' as teaser %}
{% include 'contact_modal.html' with modal_id='changeParticipantRequestModal' user=request.user title=title teaser=teaser %}

{% trans 'Request account creation' as title %}
{% blocktrans asvar title with evaluation_name=evaluation.full_name|safe %}Request account creation for {{ evaluation_name }}{% endblocktrans %}
{% trans 'Please tell us which new account we should create. We need the name and email for all new accounts.' as teaser %}
{% include 'contact_modal.html' with modal_id='createAccountRequestModal' user=request.user title=title teaser=teaser %}

Expand Down
Loading

0 comments on commit d0bf4aa

Please sign in to comment.