EnviDat / ckanext-restricted

CKAN extension for restricting access to resources
GNU Affero General Public License v3.0
7 stars 26 forks source link

After setting up this extension, we have no access to all the datasets because of Internal server error #10

Closed 0wenwu closed 4 years ago

0wenwu commented 5 years ago

The extension is very useful to me. I intend to divide the user into two parts. One is who login the CKAN, and the other one is who don't login The former have the download access, and the latter just have only preview access.

So I did as the readme. There are some errors when I run the CKAN:

Traceback (most recent call last):
  File "c:\users\administrator\envs\ckan\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\users\administrator\envs\ckan\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "D:\CodeApp\workspace\ckan\ckan\views\dataset.py", line 478, in read
    u'is_activity_archive': bool(activity_id),
  File "D:\CodeApp\workspace\ckan\ckan\lib\base.py", line 148, in render
    return flask_render_template(template_name, **extra_vars)
  File "c:\users\administrator\envs\ckan\lib\site-packages\flask\templating.py", line 134, in render_template
    context, ctx.app)
  File "c:\users\administrator\envs\ckan\lib\site-packages\flask\templating.py", line 116, in _render
    rv = template.render(context)
  File "c:\users\administrator\envs\ckan\lib\site-packages\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "c:\users\administrator\envs\ckan\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "D:\CodeApp\workspace\ckan\ckan\templates\package\read.html", line 1, in top-level template code
    {% extends "package/read_base.html" %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\package\read_base.html", line 1, in top-level template code
    {% extends "package/base.html" %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\package\base.html", line 3, in top-level template code
    {% set pkg = pkg_dict %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "c:\users\administrator\envs\ckan\lib\site-packages\ckanext\restricted\templates\base.html", line 1, in top-level template code
    {% ckan_extends %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\base.html", line 106, in top-level template code
    {%- block page %}{% endblock -%}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 19, in block "page"
    {%- block content %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 22, in block "content"
    {% block main_content %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 74, in block "main_content"
    {% block primary %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 87, in block "primary"
    {% block primary_content %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\page.html", line 107, in block "primary_content"
    {% block primary_content_inner %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\package\read.html", line 44, in block "primary_content_inner"
    {% block package_resources %}
  File "D:\CodeApp\workspace\ckan\ckan\templates\package\read.html", line 45, in block "package_resources"
    {% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources, is_activity_archive=is_activity_archive %}
  File "D:\CodeApp\workspace\ckan\ckan\lib\jinja_extensions.py", line 269, in _call
    return base.render_snippet(*args, **kwargs)
  File "D:\CodeApp\workspace\ckan\ckan\lib\base.py", line 107, in render_snippet
    raise exc
TemplateNotFound: package\snippets\resource_item.html

Here is some relevant content in my development.ini:

ckan.plugins = stats text_view image_view recline_view scheming_datasets repeating composite restricted
ckanext.restricted.some_setting = restricted.json

restricted.json is also listed below:

{
  "scheming_version": 1,
  "dataset_type": "dataset",
  "about": "",
  "about_url": "http://github.com/ckan/ckanext-scheming",
  "dataset_fields": [...],
  [...]
  "resource_fields": [
    {
      "field_name": "restricted",
      "label": "Access Restriction",
      "preset": "composite",
      "subfields": [{
          "field_name": "level",
          "label": "Level",
          "preset": "select",
          "form_include_blank_choice": false,
          "required": true,
          "choices": [{
              "value": "public",
              "label": "Public"
            },
            {
              "value": "registered",
              "label": "Registered Users"
            },
            {
              "value": "any_organization",
              "label": "Any Organization Members (Trusted Users)"
            },
            {
              "value": "same_organization",
              "label": "Same Organization Members"
            },
            {
              "value": "only_allowed_users",
              "label": "Allowed Users Only"
            }
          ]
        },
        {
          "field_name": "allowed_users",
          "label": "Allowed Users",
          "preset": "tag_string_autocomplete",
          "data-module-source": "/api/2/util/user/autocomplete?q=?"
        }
      ]
    }
  ]
}
espona commented 5 years ago

Dear wuweihust, the installation looks ok, the error doesn't make much sense since the template 'resource_item.html' does exist. I have a different order on the plugins in the .ini configuration, just to test, could you put restricted as the first plugin in the ckan.plugins line? Good luck!

0wenwu commented 5 years ago

Thank you for your rapid response. I put restricted as the first plugin in the ckan.plugins line, but it still doesn't work. In fact, it is not that clear to me how to set up in development.ini and schema.json after all the relevant extension were installed. Firstly, the JSON file you showed in Readme should add to which file? Is that schema.json? Secondly, Readme says "ckanext.restricted.some_setting = some_default_value", what does this mean?

Dear wuweihust, the installation looks ok, the error doesn't make much sense since the template 'resource_item.html' does exist. I have a different order on the plugins in the .ini configuration, just to test, could you put restricted as the first plugin in the ckan.plugins line? Good luck!

espona commented 5 years ago

Hi, sorry that with ckanext.restricted.some_setting = some_default_value is part of the default README, I will remove it to avoid confusion.

On the ini file you just need to add restricted (and scheming, composite, repeating) to the plugin list as you did.

The JSON I show is the one that is used for scheming, please take a look at the documentation of that extension, it defines all the fields of your datasets. On the ini file you write: scheming.dataset_schemas = ckanext.envidat_theme:restricted.json and then the presets too: scheming.presets = ckanext.scheming:presets.json ckanext.repeating:presets.json ckanext.composite:presets.json

Here you have an example of such a file: https://github.com/EnviDat/ckanext-envidat_schema/blob/master/ckanext/envidat_schema/datacite_dataset.json Or more simple: https://github.com/ckan/ckanext-scheming/blob/master/ckanext/scheming/ckan_dataset.json

That is the JSON file you add the restricted fields to (at resource level). You need scheming working first to then use this extension.

0wenwu commented 5 years ago

Thanks, Lucia. Very helpful directions. I'd like to ask one more question, Where should I put the schema.json? I See all the project put it under the "ckanext" folder, is that necessary? and how to quote the scheming configuration file built by ourselves?

espona commented 5 years ago

No problem, feel free to ask :) Yes, the schema.json file should be inside a ckanext folder, that means inside an extension. In our case, we have a specific extension "envidat_theme" and we have the file in that extension. to use it, just add the following line to the ini file: scheming.dataset_schemas = ckanext.envidat_theme:schema.json If you want to use the default one in scheming extension, then you do: scheming.dataset_schemas = ckanext.scheming:ckan_dataset.json

I hope it helps!

0wenwu commented 5 years ago

Thx, it's very nice of you for the rapid reply.

Does it mean that I should build a extension first before I can make a self-defined schema json file?

Besides, I have installed ckanext-repeating from github pip install git+https://github.com/eawag-rdm/ckanext-repeating.git@master Should I install extension by downloading it and then running python setup.py develop. Maybe it will be more convenient for development?

Once I added restricted to ckan.plugins, the website of dataset will show "Internal server error". And then I removed, dataset can be visited normally.

No problem, feel free to ask :) Yes, the schema.json file should be inside a ckanext folder, that means inside an extension. In our case, we have a specific extension "envidat_theme" and we have the file in that extension. to use it, just add the following line to the ini file: scheming.dataset_schemas = ckanext.envidat_theme:schema.json If you want to use the default one in scheming extension, then you do: scheming.dataset_schemas = ckanext.scheming:ckan_dataset.json

I hope it helps!

espona commented 5 years ago

Sorry for the delay, and yes, it would be advisable to create your own extension if you wish to have a custom schema. I alternatively you can fork an existing one but we have chosen always to do our own extension.

Best, Lucia

On 28 May 2019, at 04:30, Owen Wu notifications@github.com wrote:

Thx, it's very nice of you for the rapid reply. I have installed ckanext-scheming by pip. So I can not modify the default json file directly. Does it mean that I should build a extension first before I can make a self-defined schema json file?

No problem, feel free to ask :) Yes, the schema.json file should be inside a ckanext folder, that means inside an extension. In our case, we have a specific extension "envidat_theme" and we have the file in that extension. to use it, just add the following line to the ini file: scheming.dataset_schemas = ckanext.envidat_theme:schema.json If you want to use the default one in scheming extension, then you do: scheming.dataset_schemas = ckanext.scheming:ckan_dataset.json

I hope it helps!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/EnviDat/ckanext-restricted/issues/10?email_source=notifications&email_token=ACYBP454GIAKZWMRGTAAUZTPXSKNNA5CNFSM4HP4IEIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWKZNUA#issuecomment-496342736, or mute the thread https://github.com/notifications/unsubscribe-auth/ACYBP45DIONTHZQJ6AKDCYLPXSKNNANCNFSM4HP4IEIA.

olivierdalang commented 4 years ago

Couldn't the .json be provided with the ckanext-restricted extension itself ? Seems a bit strange to require another extension to provide a default file for ckanext-restricted.

dyaw-Drexel commented 4 years ago

So I actually just figured out what was going on here – I just had my variables in the ini file set wrong! Easy fix!

From: olivierdalang notifications@github.com Sent: Monday, March 30, 2020 4:20 PM To: EnviDat/ckanext-restricted ckanext-restricted@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [EnviDat/ckanext-restricted] After setting up this extension, we have no access to all the datasets because of Internal server error (#10)

External.

Couldn't the .json be provided with the ckanext-restricted extension itself ? Seems a bit strange to require another extension to provide a default file for ckanext-restricted.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FEnviDat%2Fckanext-restricted%2Fissues%2F10%23issuecomment-606225827&data=02%7C01%7Cdjy38%40drexel.edu%7C70a553aaf7db411063b708d7d4e7c941%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C637211964287617303&sdata=67eu1Hd%2FJtOylUYjfpN0J3otVhyuHcy2CxWxnD4r7tA%3D&reserved=0, or unsubscribehttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMEE2DYW34B74U3GFJN4CX3RKD5IVANCNFSM4HP4IEIA&data=02%7C01%7Cdjy38%40drexel.edu%7C70a553aaf7db411063b708d7d4e7c941%7C3664e6fa47bd45a696708c4f080f8ca6%7C0%7C0%7C637211964287627297&sdata=NUNxzpu7HupoI1%2BnS1rldtCB4zJY1mk04WMFL%2FospVM%3D&reserved=0.

espona commented 4 years ago

The json is dependent on the instance, we use a custom one if you are interested https://github.com/EnviDat/ckanext-envidat_theme/blob/master/ckanext/envidat_theme/datacite_dataset.json.