girder / girder

A data management platform for the web, developed by Kitware

Home Page:http://girder.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AccessControlMixin doesn't work with models defined in plugins

Xarthisius opened this issue · comments

Description

AccessControlMixin uses ModelImporter.load to load a proper model class throughout its methods. The signature of the latter is:

def model(model, plugin='_core'):

However, almost all invocation of ModelImporter.load in AccessControlMixin simply pass a single argument self.resourceColl. The only place where the additional plugin kwarg is handled is here:

elif isinstance(loadType, list) and len(loadType) == 2:
ModelImporter.model(*loadType).load(loadId, level=level, user=user, exc=exc)

Expected results

Handle models defined in plugins, e.g.:

# server/models/form.py
class Form(AccessControlledModel):
    def initialize(self):
        self.name = "form"

# server/models/entry.py
class FormEntry(acl_mixin.AccessControlMixin, Model):
    def initialize(self):
        self.name = "entry"
        self.ensureIndices(["formId", "data.sampleId"])
        self.resourceColl = ("form", "jsonforms")
        self.resourceParent = "formId"

Actual results

Traceback (most recent call last):
  File "/girder/girder/api/rest.py", line 630, in endpointDecorator
    val = fun(self, path, params)
  File "/girder/girder/api/rest.py", line 1216, in GET
    return self.handleRoute('GET', path, params)
  File "/girder/girder/api/rest.py", line 970, in handleRoute
    val = handler(**kwargs)
  File "/girder/girder/api/describe.py", line 709, in wrapped
    return fun(*args, **kwargs)
  File "/girder/girder/api/rest.py", line 445, in wrapped
    val = fun(*args, **kwargs)
  File "/girder/plugins/jsonforms/server/rest/entry.py", line 38, in listFormEntry
    cursor = FormEntryModel().findWithPermissions(
  File "/girder/girder/utility/acl_mixin.py", line 303, in findWithPermissions
    if (not isinstance(self.model(self.resourceColl), AccessControlledModel) or
  File "/girder/girder/utility/model_importer.py", line 88, in model
    module = 'girder.models.%s' % model

One solution would be to add a special attribute to AccessControlMixin called model_name: str, and if present, would override the default behavior.

Or else it could be called acl_proxy_model and it could be set to a model class.