Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/parklab/refinery-platform
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
jkmarx committed Jun 30, 2015
2 parents 3c92c98 + 7f7b2e7 commit 57eb38c
Show file tree
Hide file tree
Showing 73 changed files with 2,981 additions and 976 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network "private_network", ip: "192.168.50.50"

config.vm.provider "virtualbox" do |v|
v.memory = 1280
v.memory = 1024
v.cpus = 1
end

Expand Down
7 changes: 4 additions & 3 deletions refinery/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from sets import Set
from django.conf.urls.defaults import url
from django.contrib.auth.models import User, Group
from guardian.shortcuts import get_objects_for_user, get_objects_for_group
from guardian.shortcuts import get_objects_for_user, get_objects_for_group, \
get_perms
from tastypie import fields
from tastypie.authentication import SessionAuthentication, Authentication
from tastypie.authorization import Authorization
Expand Down Expand Up @@ -241,8 +242,8 @@ def res_sharing(self, request, **kwargs):
if request.method == 'GET':
kwargs['sharing'] = True
return self.process_get(request, res, **kwargs)
elif request.method == 'PATCH':
data = json.loads(request.raw_post_data)
elif request.method == 'PUT':
data = json.loads(request.body)
new_share_list = data['share_list']

groups_shared_with = map(
Expand Down
37 changes: 28 additions & 9 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ def share(self, group, readonly=True):
if not readonly:
assign_perm('change_%s' % self._meta.verbose_name, group, self)

resource_shared.send(sender=self)

def unshare(self, group):
remove_perm('read_%s' % self._meta.verbose_name, group, self)
remove_perm('change_%s' % self._meta.verbose_name, group, self)
Expand Down Expand Up @@ -286,6 +284,16 @@ def get_groups(self, changeonly=False, readonly=False):

return groups

def get_group_ids(self, changeonly=False, readonly=False):
groups = get_groups_with_perms(self)

ids = []

for group in groups:
ids.append(group.id)

return ids

# TODO: clean this up
def is_public(self):
permissions = get_groups_with_perms(self, attach_perms=True)
Expand All @@ -305,13 +313,6 @@ class Meta:
abstract = True


def print_shared(sender, **kwargs):
logger.info("Sharable Resouce has been shared with sender: %s" % sender)

resource_shared = Signal()
resource_shared.connect(print_shared)


class TemporaryResource:
'''Mix-in class for temporary resources like NodeSet instances.
Expand Down Expand Up @@ -487,6 +488,24 @@ def get_file_size(self):

return file_size

def share(self, group, readonly=True):
super(DataSet, self).share(group, readonly)
# This might be a hack but I couldn't find an easier solution to about
# the import loop. I found this solution here
# http://stackoverflow.com/a/7199514/981933
from core.search_indexes import DataSetIndex
logger.info("Re-index / update data set: %s", self)
DataSetIndex().update_object(self, using='core')

def unshare(self, group):
super(DataSet, self).unshare(group)
# This might be a hack but I couldn't find an easier solution to about
# the import loop. I found this solution here
# http://stackoverflow.com/a/7199514/981933
from core.search_indexes import DataSetIndex
logger.info("Re-index / update data set: %s", self)
DataSetIndex().update_object(self, using='core')


class InvestigationLink(models.Model):
data_set = models.ForeignKey(DataSet)
Expand Down
41 changes: 20 additions & 21 deletions refinery/core/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

class DataSetIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
# id of the user who owns this project
owner_id = indexes.CharField()
# ids of the groups who have read permission for this data set
group_ids = indexes.MultiValueField(null=True)
name = indexes.CharField(model_attr='name', null=True)
title = indexes.CharField(null=True)
uuid = indexes.CharField(model_attr='uuid')
Expand All @@ -34,6 +30,10 @@ class DataSetIndex(indexes.SearchIndex, indexes.Indexable):
measurement = indexes.MultiValueField(null=True, faceted=True)
technology = indexes.MultiValueField(null=True, faceted=True)

# We only need one multi value field to story every id that has access since
# Solr only handles read permissions.
access = indexes.MultiValueField(null=True)

# We add this for autocomplete.
content_auto = indexes.EdgeNgramField(null=True)

Expand All @@ -53,14 +53,13 @@ def prepare_title(self, object):
def prepare_content_auto(self, object):
return object.get_investigation().get_title()

def prepare_owner_id(self, object):
if object.get_owner() is None:
return None

return object.get_owner().id

def prepare_group_ids(self, object):
return [g["id"] for g in object.get_groups()]
def prepare_access(self, object):
access_list = []
if object.get_owner() is not None:
access_list.append('u_{}'.format(object.get_owner().id))
for group_id in object.get_group_ids():
access_list.append('g_{}'.format(group_id))
return access_list

def prepare_submitter(self, object):
investigation = object.get_investigation()
Expand Down Expand Up @@ -174,10 +173,7 @@ def prepare(self, data_set):

class ProjectIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
# id of the user who owns this project
owner_id = indexes.CharField()
# ids of the groups who have read permission for this data set
group_ids = indexes.MultiValueField(null=True)
access = indexes.MultiValueField(null=True)
name = indexes.CharField(model_attr='name', null=True)
uuid = indexes.CharField(model_attr='uuid')
summary = indexes.CharField(model_attr='summary')
Expand All @@ -192,11 +188,14 @@ class ProjectIndex(indexes.SearchIndex, indexes.Indexable):
def get_model(self):
return Project

def prepare_owner_id(self, object):
return object.get_owner().id

def prepare_group_ids(self, object):
return [g["id"] for g in object.get_groups()]
def prepare_access(self, object):
access_list = []
if object.get_owner() is not None:
access_list.append('u_{}'.format(object.get_owner().id))
for group in object.get_groups():
if id in group:
access_list.append('g_{}'.format(group.id))
return access_list

def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
Expand Down
28 changes: 17 additions & 11 deletions refinery/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from django.conf.urls.defaults import patterns, url


urlpatterns = patterns('core.views',
url(r'^$', 'home', name="home" ),
url(r'^about/$', 'about', name="about" ),
url(r'^contact/$', 'contact', name="contact" ),
url(r'^statistics/$', 'statistics', name="statistics" ),
urlpatterns = patterns(
'core.views',
url(r'^$', 'home', name="home"),
url(r'^about/$', 'about', name="about"),
url(r'^contact/$', 'contact', name="contact"),
url(r'^statistics/$', 'statistics', name="statistics"),
url(r'^users/(?P<query>[\@\.\-\+a-z0-9]+)/$', 'user'),
# "name" is required for use with the url tag in templates
# "name" is required for use with the url tag in templates
url(r'^users/(?P<query>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', 'user', name="user"),
url(r'^users/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/edit/$', 'user_edit', name="user_edit"),
url(r'^groups/(?P<query>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', 'group', name="group"),
Expand All @@ -30,14 +31,19 @@
url(r'^data_sets/(?P<slug>[a-zA-Z0-9\_]+)/$', 'data_set_slug', name="data_set_slug"),
url(r'^workflows/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', 'workflow', name="workflow"),
url(r'^workflows/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/edit/$', 'workflow_edit', name="workflow_edit"),
url(r'^workflows/(?P<slug>[a-zA-Z0-9\_]+)/$', 'workflow_slug', name="workflow_slug"),
url(r'^workflows/(?P<slug>[a-zA-Z0-9\_]+)/$', 'workflow_slug', name="workflow_slug"),
url(r'^workflow_engines/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', 'workflow_engine', name="workflow_engine"),

url(r'^data_sets/(?P<ds_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/samples/(?P<study_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(?P<assay_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', 'samples', name="samples"),

url(r'^solr/igv/$', 'solr_igv' ),

url(r'^solr/igv/$', 'solr_igv'),
url(
r'^solr/core/select/$',
'solr_core_search',
name="solr_core_search"
),
url(r'^solr/(?P<core>.+)/select/$', 'solr_select', name="solr_select"),

# test solr/search view
url(r'^data_sets/(?P<ds_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/samples/(?P<study_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/(?P<assay_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/solr$', 'samples_solr', name="samples"),
)
Expand All @@ -54,6 +60,6 @@ def get_queryset(self):
context_object_name='datasets',
paginate_by=15,
template_name='core/data_sets.html'
))
))
)
"""
9 changes: 9 additions & 0 deletions refinery/core/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging
from core.search_indexes import DataSetIndex

logger = logging.getLogger(__name__)


def index_data_set(data_set):
logger.debug('Index new data set (uuid: %s)', data_set.uuid)
DataSetIndex().update_object(data_set, using='core')

0 comments on commit 57eb38c

Please sign in to comment.