Skip to content

Commit

Permalink
Merge branch 'dev-v2' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
jefmoura committed May 28, 2018
2 parents 4c164ba + 7f51a7b commit d3326fe
Show file tree
Hide file tree
Showing 33 changed files with 912 additions and 1,071 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ pipeline:
secrets: [SECRET_PASS]
commands:
- pip install -r requirements/ci.txt
- flake8 */tests/ */forms.py tola/ --exclude=settings,migrations,models.py,tola/__init__.py
- python manage.py test
when:
event: [push, tag]
event: [pull_request, push, tag]

build-docker-image:
image: plugins/docker
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ install:
services:
- mongodb
- redis-server
script: python manage.py test
script:
- flake8 */tests/ */forms.py tola/ --exclude=settings,migrations,models.py,tola/__init__.py
- python manage.py test
after_success:
- coveralls
before_install:
Expand Down
2 changes: 2 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys

if __name__ == "__main__":
reload(sys)
sys.setdefaultencoding('utf-8')

if 'test' in sys.argv:
settings = 'tola.settings.test'
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ django-rest-swagger==2.1.1
djangorestframework==3.6.3
djangorestframework-jsonapi==2.1.1
google-api-python-client==1.5.1
psycopg2
psycopg2-binary
httplib2==0.9.2
mongoengine==0.10.6
oauth2client==2.2.0
Expand All @@ -23,6 +23,6 @@ requests-oauthlib==0.5.0
six==1.10.0
cryptography==2.1.3
fabric==1.14.0
celery==4.0.2
celery==4.1.1
django-celery-results==1.0.1
redis==2.10.5
1 change: 1 addition & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

coveralls==1.2.0
factory_boy==2.9.2
flake8==3.5.0
mock==2.0.0
10 changes: 7 additions & 3 deletions silo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ class SiloViewSet(viewsets.ReadOnlyModelViewSet):
# this permission sets seems to break the default permissions set by the restframework
# permission_classes = (IsOwnerOrReadOnly,)
permission_classes = (IsAuthenticated, Silo_IsOwnerOrCanRead,)
filter_fields = ('owner__username','shared__username','id','tags','public')
filter_fields = ('owner__username','shared__username',
'id','tags','public')
filter_backends = (filters.DjangoFilterBackend,)

def get_queryset(self):
Expand All @@ -294,13 +295,16 @@ def get_queryset(self):
else:
user = tola_user.user
return Silo.objects.filter(
Q(owner=user) | Q(public=True) | Q(shared=user))
Q(owner=user) | Q(public=True) | Q(shared=user)
| Q(owner__tola_user__organization=tola_user.organization))
else:
user = self.request.user
if user.is_superuser:
return Silo.objects.all()

return Silo.objects.filter(Q(owner=user) | Q(public=True))
return Silo.objects.filter(Q(owner=user) | Q(public=True) |
Q(owner__tola_user__organization=\
user.tola_user.organization))

@detail_route()
def data(self, request, id):
Expand Down
22 changes: 16 additions & 6 deletions silo/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.core.urlresolvers import reverse_lazy
from silo.models import Silo, Read
from django import forms
from django.contrib.auth.models import User
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit, Reset, Field, Hidden
from django.core.exceptions import ValidationError
from collections import OrderedDict

from silo.models import Silo, WorkflowLevel1
from silo.models import Read, Silo, WorkflowLevel1
from tola.activity_proxy import get_by_url, get_workflowteams


Expand All @@ -30,6 +31,7 @@ def __init__(self, user=None, *args, **kwargs):
super(SiloForm, self).__init__(*args, **kwargs)
# Filter programs based on the program teams from Activity
if user:
self.fields['shared'].queryset = User.objects.exclude(pk=user.pk)
params = {
'workflow_user__tola_user_uuid': user.tola_user.tola_user_uuid
}
Expand All @@ -54,8 +56,16 @@ def __init__(self, user=None, *args, **kwargs):

class Meta:
model = Silo
fields = ['id', 'name', 'description', 'tags', 'shared', 'owner',
'workflowlevel1']
fields = ['id', 'name', 'description', 'tags', 'shared',
'share_with_organization', 'owner', 'workflowlevel1']

def clean_shared(self):
data = self.cleaned_data['shared']
owner = self.data.get('owner')
if owner:
if data.filter(pk=owner).exists():
raise ValidationError('You can not share table with owner.')
return data


class NewColumnForm(forms.Form):
Expand Down Expand Up @@ -149,7 +159,7 @@ def __init__(self, *args, **kwargs):
if (item != "_id" and item != "silo_id" and item != "edit_date"
and item != "create_date" and item != "read_id"):
self.fields[item] = forms.CharField(
label=item, initial=item, required=False,widget="")
label=item, initial=item, required=False, widget="")
self.fields[item + "_delete"] = forms.BooleanField(
label="delete " + item, initial=False, required=False,
widget="")
Expand All @@ -164,8 +174,8 @@ class MongoEditForm(forms.Form):
silo_id = forms.IntegerField(required=False, widget=forms.HiddenInput())

def __init__(self, *args, **kwargs):
kwargs.pop('silo_pk')
extra = kwargs.pop("extra")
silo_pk = kwargs.pop('silo_pk')
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-sm-5'
Expand Down
6 changes: 3 additions & 3 deletions silo/google_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def export_gsheet(request, id):
file_id = request.GET.get('resource_id', None)
if read_url == None or file_id == None:
messages.error(request, "A Google Spreadsheet is not selected to import data to it.")
return HttpResponseRedirect(reverse('listSilos'))
return HttpResponseRedirect(reverse('list_silos'))

storage = Storage(GoogleCredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
Expand Down Expand Up @@ -174,7 +174,7 @@ def export_gsheet(request, id):
messages.success(request, link)
else:
messages.error(request, 'Something went wrong.')
return HttpResponseRedirect(reverse('listSilos'))
return HttpResponseRedirect(reverse('list_silos'))

@login_required
def export_new_gsheet(request, id):
Expand Down Expand Up @@ -217,7 +217,7 @@ def export_new_gsheet(request, id):
messages.success(request, link)
else:
messages.error(request, 'Something went wrong; try again.')
return HttpResponseRedirect(reverse('listSilos'))
return HttpResponseRedirect(reverse('list_silos'))


def import_from_google_spreadsheet(credential_json, silo, spreadsheet_key):
Expand Down
4 changes: 2 additions & 2 deletions silo/gviews_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def export_to_gsheet_helper(user, spreadsheet_id, silo_id, query, headers):
logger.error("Silo with id=%s does not exist" % silo_id)
msgs.append({"level": messages.ERROR,
"msg": "Silo with id=%s does not exist" % silo_id,
"redirect": reverse('listSilos')})
"redirect": reverse('list_silos')})
return msgs

try:
Expand Down Expand Up @@ -635,7 +635,7 @@ def export_to_gsheet(request, id):
return HttpResponseRedirect(msg.get("redirect"))
messages.add_message(request, msg.get("level"), msg.get("msg"))

return HttpResponseRedirect(reverse('listSilos'))
return HttpResponseRedirect(reverse('list_silos'))


@login_required
Expand Down
47 changes: 47 additions & 0 deletions silo/migrations/0043_auto_20180509_0153.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-05-09 08:53
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
('silo', '0042_auto_20180323_0857'),
]

operations = [
migrations.AddField(
model_name='silo',
name='share_with_organization',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='organization',
name='organization_uuid',
field=models.CharField(default=uuid.uuid4, max_length=255, unique=True, verbose_name=b'Organization UUID'),
),
migrations.AlterField(
model_name='silo',
name='workflowlevel1',
field=models.ManyToManyField(blank=True, to='silo.WorkflowLevel1'),
),
migrations.AlterField(
model_name='tolauser',
name='tola_user_uuid',
field=models.CharField(default=uuid.uuid4, max_length=255, unique=True, verbose_name=b'TolaUser UUID'),
),
migrations.AlterField(
model_name='tolauser',
name='workflowlevel1',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='silo.WorkflowLevel1'),
),
migrations.AlterField(
model_name='workflowlevel2',
name='workflowlevel1',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='silo.WorkflowLevel1'),
),
]
1 change: 1 addition & 0 deletions silo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class Silo(models.Model):
reads = models.ManyToManyField(Read, related_name='silos')
tags = models.ManyToManyField(Tag, related_name='silos', blank=True)
shared = models.ManyToManyField(User, related_name='silos', blank=True)
share_with_organization = models.BooleanField(default=False)
description = models.CharField(max_length=255, blank=True, null=True)
organization = models.ForeignKey(Organization, blank=True, null=True)
country = models.ForeignKey(Country, blank=True, null=True)
Expand Down
7 changes: 6 additions & 1 deletion silo/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def has_object_permission(self, request, view, obj):
permitted = [obj.owner == request.user]
permitted.append(request.user.is_superuser)
permitted.append(obj.public)
permitted.append(request.user.id in obj.shared.values_list('id', flat=True))
permitted.append(request.user.id in obj.shared.values_list('id',
flat=True))
if hasattr(obj.owner ,'tola_user'):
permitted.append(
obj.owner.tola_user.organization ==\
request.user.tola_user.organization)

return any(permitted)

Expand Down
Loading

0 comments on commit d3326fe

Please sign in to comment.