This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
managing access: review and update for Invenio v3.2 and ES 7
- Loading branch information
Showing
7 changed files
with
110 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
12-managing-access/solution/my-site/my_site/authors/mappings/v6/authors/author-v1.0.0.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
12-managing-access/solution/my-site/my_site/authors/mappings/v7/authors/author-v1.0.0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
12-managing-access/solution/my-site/my_site/records/mappings/v6/records/record-v1.0.0.json
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
12-managing-access/solution/my-site/my_site/records/mappings/v7/records/record-v1.0.0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |