Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
managing access: review and update for Invenio v3.2 and ES 7
Browse files Browse the repository at this point in the history
  • Loading branch information
topless authored and Pablo Panero committed May 14, 2020
1 parent a0c31f2 commit 85bbac0
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 117 deletions.
9 changes: 5 additions & 4 deletions 12-managing-access/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
- [Step 1 - Allow for access only from the owner](#step-1---allow-for-access-only-from-the-owner)
- [Step 2 - search filter](#step-2---search-filter)
- [Step 3 - Create permissions](#step-3---create-permissions)
- [Extras - Additional excersises](#extras)
- [Extras - Additional exercises](#extras)

The goal of this tutorial is to implement record access permissions in simple and complicated cases.

Prerequisites:
1. previous steps with owner field

1. previous steps with owner field
2. at least two different users

```commandline
Expand All @@ -19,7 +19,7 @@ my-site users create [email protected] -a --password=123456 # create admin user ID
my-site users create [email protected] -a --password=123456 # create visitor user ID 3
```

2. at least two records
3. at least two records

```commandline
curl -k --header "Content-Type: application/json" --request POST --data '{"title":"My test record", "contributors": [{"name": "Doe, John"}], "owner": 1}' https://localhost:5000/api/records/?prettyprint=1
Expand All @@ -31,6 +31,7 @@ curl -k --header "Content-Type: application/json" --request POST --data '{"title
## Step 1 - Allow for access only from the owner

### Use case:

Restrict the access to read, edit and delete action for the record only to its owner.

1. We implement the permission factory. The permission requires a need to be fulfilled by a user for a record. In this case we remember that:
Expand Down Expand Up @@ -222,7 +223,7 @@ RECORDS_REST_ENDPOINTS = {

### Use case: restrict creation of records to authenticated users

1. Implement the permission factory in `my_site/records/permissions.py`
1. Implement the permission factory in `my_site/records/permissions.py`

```python
from invenio_access import Permission, authenticated_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
in Elasticsearch. You need to provide one mapping per major version of
Elasticsearch you want to support.
"""

from __future__ import absolute_import, print_function

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
# My site is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""Mappings for Elasticsearch 5.x."""

from __future__ import absolute_import, print_function
"""Mappings for Elasticsearch 7.x."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"mappings": {
"date_detection": false,
"numeric_detection": false,
"properties": {
"$schema": {
"type": "text",
"index": false
},
"id": {
"type": "keyword"
},
"name": {
"type": "text"
},
"organization": {
"type": "text"
},
"_created": {
"type": "date"
},
"_updated": {
"type": "date"
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"mappings": {
"date_detection": false,
"numeric_detection": false,
"properties": {
"$schema": {
"type": "text",
"index": false
},
"title": {
"type": "text",
"copy_to": "suggest_title"
},
"suggest_title": {
"type": "completion"
},
"author": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "text"
}
}
},
"id": {
"type": "keyword"
},
"owner": {
"type": "integer"
},
"publication_date": {
"type": "date",
"format": "date"
},
"contributors_count": {
"type": "short"
},
"contributors": {
"type": "object",
"properties": {
"ids": {
"type": "object",
"properties": {
"source": {
"type": "text"
},
"value": {
"type": "keyword"
}
}
},
"affiliations": {
"type": "text"
},
"role": {
"type": "keyword"
},
"email": {
"type": "text"
},
"name": {
"type": "text"
}
}
},
"_created": {
"type": "date"
},
"_updated": {
"type": "date"
}
}
}
}

0 comments on commit 85bbac0

Please sign in to comment.