Skip to content

Commit

Permalink
Merge branch 'develop' into config/set-up-CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
alvechdel authored Jan 6, 2022
2 parents b542ddc + 7b689b7 commit 26d1e59
Show file tree
Hide file tree
Showing 40 changed files with 23,399 additions and 288 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ coverage.xml

# Django stuff:
*.log
local_settings.py
decide/*/migrations

# Flask stuff:
Expand Down
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% prepara el repositorio para su despliegue.
release: sh -c 'cd decide && python manage.py migrate'
release: sh -c 'cd decide && python manage.py makemigrations && python manage.py migrate'
% especifica el comando para lanzar Decide
web: sh -c 'cd decide && gunicorn decide.wsgi --log-file -'
web: sh -c 'cd decide && gunicorn decide.wsgi --log-file -'
2 changes: 1 addition & 1 deletion decide/base/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class Migration(migrations.Migration):
('x', base.models.BigBigField(blank=True, null=True)),
],
),
]
]
34 changes: 34 additions & 0 deletions decide/booth/static/booth/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,37 @@
margin-top: 20px;
margin-left: 40px;
}
#bots-footer {
position: fixed;
width: 100%;
bottom : 0px;
margin-top: 10px;
height : 60px;
text-align: center;
vertical-align: middle;
padding-top: 0.5 rem;
background-color: rgba(var(--bs-secondary-rgb),var(--bs-bg-opacity));
color: #fff;
}

#start_tlg {
border: #79aec8;
border-radius: 12px;
font-size: 14px;
color: #fff;
text-transform: uppercase;
background-color: #79aec8;
letter-spacing: 0.5px;
padding: 8px;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
-ms-border-radius: 12px;
-o-border-radius: 12px;
}

#start_tlg:hover{
background-color: #417690;
}
.chartjs-render-monitor{
margin: 77px 10px;
}
2 changes: 1 addition & 1 deletion decide/booth/templates/booth/booth.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h2>[[ voting.question.desc ]]</h2>
}
this.postData("{% url "gateway" "store" "/" %}", data)
.then(data => {
this.showAlert("success", '{% trans "Conglatulations. Your vote has been sent" %}');
this.showAlert("success", '{% trans "Congratulations. Your vote has been sent" %}');
})
.catch(error => {
this.showAlert("danger", '{% trans "Error: " %}' + error);
Expand Down
2 changes: 1 addition & 1 deletion decide/booth/templates/booth/boothM.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ <h2>[[ voting.question.desc ]]</h2>
}
this.postData("{% url "gateway" "store" "/" %}", data)
.then(data => {
this.showAlert("success", '{% trans "Conglatulations. Your vote has been sent" %}');
this.showAlert("success", '{% trans "Congratulations. Your vote has been sent" %}');
})
.catch(error => {
this.showAlert("danger", '{% trans "Error: " %}' + error);
Expand Down
2 changes: 1 addition & 1 deletion decide/census/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.5 on 2021-12-11 16:57
# Generated by Django 2.2.5 on 2022-01-06 16:55

from django.db import migrations, models

Expand Down
18 changes: 18 additions & 0 deletions decide/census/migrations/0002_census_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.5 on 2022-01-06 17:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('census', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='census',
name='type',
field=models.CharField(choices=[('V', 'Voting'), ('BV', 'BinaryVoting'), ('MV', 'MultipleVoting'), ('SV', 'ScoreVoting')], default='V', max_length=2),
),
]
18 changes: 9 additions & 9 deletions decide/census/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ class CensusTestCase(BaseTestCase):

def setUp(self):
super().setUp()
self.census = Census(voting_id=1, voter_id=1)
self.census = Census(voting_id=1, voter_id=1, type='V')
self.census.save()

def tearDown(self):
super().tearDown()
self.census = None

def test_check_vote_permissions(self):
response = self.client.get('/census/{}/?voter_id={}'.format(1, 2), format='json')
response = self.client.get('/census/{}/?voter_id={}&type=V'.format(1, 2), format='json')
self.assertEqual(response.status_code, 401)
self.assertEqual(response.json(), 'Invalid voter')

response = self.client.get('/census/{}/?voter_id={}'.format(1, 1), format='json')
response = self.client.get('/census/{}/?voter_id={}&type=V'.format(1, 1), format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), 'Valid voter')

def test_list_voting(self):
response = self.client.get('/census/?voting_id={}'.format(1), format='json')
response = self.client.get('/census/?voting_id={}&type=V'.format(1), format='json')
self.assertEqual(response.status_code, 401)

self.login(user='noadmin')
response = self.client.get('/census/?voting_id={}'.format(1), format='json')
response = self.client.get('/census/?voting_id={}&type=V'.format(1), format='json')
self.assertEqual(response.status_code, 403)

self.login()
response = self.client.get('/census/?voting_id={}'.format(1), format='json')
response = self.client.get('/census/?voting_id={}&type=V'.format(1), format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'voters': [1]})

def test_add_new_voters_conflict(self):
data = {'voting_id': 1, 'voters': [1]}
data = {'voting_id': 1, 'voters': [1], 'type': 'V'}
response = self.client.post('/census/', data, format='json')
self.assertEqual(response.status_code, 401)

Expand All @@ -55,7 +55,7 @@ def test_add_new_voters_conflict(self):
self.assertEqual(response.status_code, 409)

def test_add_new_voters(self):
data = {'voting_id': 2, 'voters': [1,2,3,4]}
data = {'voting_id': 2, 'voters': [1,2,3,4], 'type': 'V'}
response = self.client.post('/census/', data, format='json')
self.assertEqual(response.status_code, 401)

Expand All @@ -69,7 +69,7 @@ def test_add_new_voters(self):
self.assertEqual(len(data.get('voters')), Census.objects.count() - 1)

def test_destroy_voter(self):
data = {'voters': [1]}
data = {'voters': [1], 'type':'V'}
response = self.client.delete('/census/{}/'.format(1), data, format='json')
self.assertEqual(response.status_code, 204)
self.assertEqual(0, Census.objects.count())
9 changes: 6 additions & 3 deletions decide/census/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
class CensusCreate(generics.ListCreateAPIView):
permission_classes = (UserIsStaff,)

def create(self, request,type, *args, **kwargs):
def create(self, request, *args, **kwargs):
voting_id = request.data.get('voting_id')
voters = request.data.get('voters')
type = request.data.get('type')
try:
for voter in voters:
census = Census(voting_id=voting_id, voter_id=voter, type=type)
Expand All @@ -31,8 +32,9 @@ def create(self, request,type, *args, **kwargs):
return Response('Error try to create census', status=ST_409)
return Response('Census created', status=ST_201)

def list(self, request, type, *args, **kwargs):
def list(self, request, *args, **kwargs):
voting_id = request.GET.get('voting_id')
type = request.GET.get('type')
voters = Census.objects.filter(
voting_id=voting_id, type=type).values_list('voter_id', flat=True)
return Response({'voters': voters})
Expand All @@ -42,8 +44,9 @@ class CensusDetail(generics.RetrieveDestroyAPIView):

def destroy(self, request, voting_id, *args, **kwargs):
voters = request.data.get('voters')
type = request.data.get('type')
census = Census.objects.filter(
voting_id=voting_id, voter_id__in=voters)
voting_id=voting_id, voter_id__in=voters, type=type)
census.delete()
return Response('Voters deleted from census', status=ST_204)

Expand Down
46 changes: 28 additions & 18 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '^##ydkswfu0+=ofw0l#$kv^8n)0$i(qd&d&ol#p9!b$8*5%j1+'

#will change on production
TELEGRAM_TOKEN = '2111051748:AAH1R736I0_HsZEW6_22Tf0r-OqihtF5x88'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand Down Expand Up @@ -82,12 +79,19 @@
'visualizer',
'voting','''

BASEURL = 'http://decide-full-tortuga-2.herokuapp.com/visualizer/'

APIS = {}

import django_heroku
django_heroku.settings(locals())
BASEURL = 'http://decide-full-tortuga-2.herokuapp.com'

APIS = {
'authentication': BASEURL,
'base': BASEURL,
'booth': BASEURL,
'census': BASEURL,
'mixnet': BASEURL,
'postproc': BASEURL,
'store': BASEURL,
'visualizer': BASEURL,
'voting': BASEURL,
}

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
Expand Down Expand Up @@ -127,14 +131,16 @@
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'prueba',
'CLIENT': {
'host': '127.0.0.1',
}
"CLIENT": {
"name": 'decide',
"host": 'mongodb+srv://decide:@decide.3vypb.mongodb.net/decide?retryWrites=true&w=majority',
"username": 'decide',
"password": 'decide',
"authMechanism": "SCRAM-SHA-1",
},
}
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -175,9 +181,6 @@

STATIC_URL = '/static/'

#temporary link to visualizer page for bots
VISUALIZER_VIEW="https://decide-full-tortuga-2.herokuapp.com/visualizer/"

# number of bits for the key, all auths should use the same number of bits
KEYBITS = 256

Expand All @@ -199,4 +202,11 @@
vars()[k] = v


INSTALLED_APPS = INSTALLED_APPS + MODULES
INSTALLED_APPS = INSTALLED_APPS + MODULES

NOSE_ARGS = [
'--with-xunit'
]

import django_heroku
django_heroku.settings(locals(), test_runner=False)
Loading

0 comments on commit 26d1e59

Please sign in to comment.