dservercore 0.20.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ """Auth utility functions."""
2
+
3
+ from dservercore.sql_models import (
4
+ User,
5
+ BaseURI,
6
+ )
7
+
8
+
9
+ def _get_user_obj(username):
10
+ return User.query.filter_by(username=username).first()
11
+
12
+
13
+ def _get_base_uri_obj(base_uri):
14
+ return BaseURI.query.filter_by(base_uri=base_uri).first()
15
+
16
+
17
+ def user_exists(username):
18
+ """Return True if the user exists."""
19
+ user = _get_user_obj(username)
20
+ if user is None:
21
+ return False
22
+ return True
23
+
24
+
25
+ def has_admin_rights(username):
26
+ """Return True if user has admin rights."""
27
+ user = _get_user_obj(username)
28
+ if user is None:
29
+ return False
30
+ return user.is_admin
31
+
32
+
33
+ def may_search(username, base_uri):
34
+ """Return True if user has privileges to search the base URI."""
35
+ user = _get_user_obj(username)
36
+ if user is None:
37
+ return False
38
+ base_uri = _get_base_uri_obj(base_uri)
39
+ if base_uri is None:
40
+ return False
41
+ return base_uri in user.search_base_uris
42
+
43
+
44
+ def may_access(username, uri):
45
+ """Return True if user has privileges to access the dataset URI."""
46
+ base_uri = uri.rsplit("/", 1)[0]
47
+ return may_search(username, base_uri)
48
+
49
+
50
+ def may_register(username, base_uri):
51
+ """Return True if user has privileges to register on the base URI."""
52
+ user = _get_user_obj(username)
53
+ if user is None:
54
+ return False
55
+ base_uri = _get_base_uri_obj(base_uri)
56
+ if base_uri is None:
57
+ return False
58
+ return base_uri in user.register_base_uris
59
+
60
+
61
+ def list_search_base_uris(username):
62
+ """Return list of base URIs the user may search."""
63
+ user = _get_user_obj(username)
64
+ if user is None:
65
+ return []
66
+ return [bu.base_uri for bu in user.search_base_uris]
67
+
68
+
69
+ def list_register_base_uris(username):
70
+ """Return list of base URIs the user may regiester datasets to."""
71
+ user = _get_user_obj(username)
72
+ if user is None:
73
+ return []
74
+ return [bu.base_uri for bu in user.register_base_uris]
@@ -0,0 +1,44 @@
1
+ """Routes for querying dataset entries by their UUIDs"""
2
+ from flask import (
3
+ abort,
4
+ jsonify
5
+ )
6
+ from flask_jwt_extended import (
7
+ jwt_required,
8
+ get_jwt_identity,
9
+ )
10
+
11
+ from flask_smorest.pagination import PaginationParameters
12
+
13
+ from dservercore.blueprint import Blueprint
14
+ from dservercore.sort import SortParameters
15
+ from dservercore.sql_models import DatasetSchema
16
+ import dservercore.utils_auth
17
+ from dservercore.utils import (
18
+ lookup_datasets_by_user_and_uuid,
19
+ DATASET_SORT_FIELDS
20
+ )
21
+
22
+
23
+ bp = Blueprint("uuids", __name__, url_prefix="/uuids")
24
+
25
+
26
+ @bp.route("/<uuid>", methods=["GET"])
27
+ @bp.sort(sort=["+uri"], allowed_sort_fields=DATASET_SORT_FIELDS)
28
+ @bp.paginate()
29
+ @bp.response(200, DatasetSchema(many=True))
30
+ @bp.alt_response(401, description="Not registered")
31
+ @jwt_required()
32
+ def uuid_get(pagination_parameters: PaginationParameters,
33
+ sort_parameters: SortParameters, uuid):
34
+ """List all instances of a dataset in any base_uris the user has access to."""
35
+ username = get_jwt_identity()
36
+ if not dservercore.utils_auth.user_exists(username):
37
+ # Unregistered users should see 401.
38
+ abort(401)
39
+
40
+ datasets = lookup_datasets_by_user_and_uuid(username, uuid,
41
+ pagination_parameters=pagination_parameters,
42
+ sort_parameters=sort_parameters)
43
+
44
+ return datasets
dservercore/version.py ADDED
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '0.20.0'
16
+ __version_tuple__ = version_tuple = (0, 20, 0)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 jic-dtool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.