Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AccessControlMixin doesn't work with models defined in plugins #3535

Open
Xarthisius opened this issue Apr 19, 2024 · 1 comment
Open

AccessControlMixin doesn't work with models defined in plugins #3535

Xarthisius opened this issue Apr 19, 2024 · 1 comment

Comments

@Xarthisius
Copy link
Contributor

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
@zachmullen
Copy link
Member

zachmullen commented Apr 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants