Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
e6316086
Commit
e6316086
authored
4 years ago
by
Jean-Baptiste Pasquier
Browse files
Options
Downloads
Plain Diff
Merge branch '245-resolve-id-fixes' into 'master'
Resolve "DjangoLDP resolve_id error on container path" Closes
#245
See merge request
!130
parents
ee354b9c
b6ac3c93
No related branches found
No related tags found
1 merge request
!130
Resolve "DjangoLDP resolve_id error on container path"
Pipeline
#5946
passed
4 years ago
Stage: release
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangoldp/models.py
+18
-2
18 additions, 2 deletions
djangoldp/models.py
djangoldp/tests/models.py
+2
-1
2 additions, 1 deletion
djangoldp/tests/models.py
djangoldp/tests/tests_guardian.py
+0
-14
0 additions, 14 deletions
djangoldp/tests/tests_guardian.py
with
20 additions
and
17 deletions
djangoldp/models.py
+
18
−
2
View file @
e6316086
...
...
@@ -2,7 +2,7 @@ import json
import
uuid
from
urllib.parse
import
urlparse
from
django.conf
import
settings
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
,
ValidationError
from
django.contrib.auth
import
get_user_model
from
django.db
import
models
from
django.db.models
import
BinaryField
,
DateField
...
...
@@ -116,8 +116,18 @@ class Model(models.Model):
@classonlymethod
def
resolve_id
(
cls
,
id
):
'''
Resolves the id of a given path (e.g. /container/1/)
Raises Resolver404 if the path cannot be found, ValidationError if the path is for a model base
and an ObjectDoesNotExist exception if the resource does not exist
'''
id
=
cls
.
__clean_path
(
id
)
view
,
args
,
kwargs
=
get_resolver
().
resolve
(
id
)
match
=
get_resolver
().
resolve
(
id
)
kwargs
=
match
.
kwargs
view
=
match
.
func
if
match
.
url_name
.
endswith
(
'
-list
'
)
or
len
(
match
.
kwargs
.
keys
())
==
0
:
raise
ValidationError
(
'
resolve_id received a path for a container or nested container
'
)
return
view
.
initkwargs
[
'
model
'
].
objects
.
get
(
**
kwargs
)
@classonlymethod
...
...
@@ -128,12 +138,18 @@ class Model(models.Model):
@classonlymethod
def
resolve_container
(
cls
,
path
):
'''
retruns the model container of passed URL path
'''
path
=
cls
.
__clean_path
(
path
)
view
,
args
,
kwargs
=
get_resolver
().
resolve
(
path
)
return
view
.
initkwargs
[
'
model
'
]
@classonlymethod
def
resolve
(
cls
,
path
):
'''
resolves the containing model and associated id in the path. If there is no id in the path returns None
:param path: a URL path to check
:return: the container model and resolved id in a tuple
'''
if
settings
.
BASE_URL
in
path
:
path
=
path
[
len
(
settings
.
BASE_URL
):]
container
=
cls
.
resolve_container
(
path
)
...
...
This diff is collapsed.
Click to expand it.
djangoldp/tests/models.py
+
2
−
1
View file @
e6316086
...
...
@@ -188,7 +188,8 @@ class Post(Model):
class
Circle
(
Model
):
description
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
blank
=
False
)
name
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
description
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
team
=
models
.
ManyToManyField
(
settings
.
AUTH_USER_MODEL
,
through
=
"
CircleMember
"
,
blank
=
True
)
owner
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
,
related_name
=
"
owned_circles
"
,
on_delete
=
models
.
DO_NOTHING
,
null
=
True
,
blank
=
True
)
...
...
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_guardian.py
+
0
−
14
View file @
e6316086
...
...
@@ -38,13 +38,6 @@ class TestsGuardian(APITestCase):
response
=
self
.
client
.
get
(
'
/permissionless-dummys/
'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
# tests that dummy with permissions set enforces these permissions
def
test_list_dummy_permission_granted
(
self
):
self
.
setUpLoggedInUser
()
self
.
setUpGuardianDummyWithPerms
([
'
view
'
])
response
=
self
.
client
.
get
(
'
/permissionless-dummys/
'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_get_dummy_permission_granted
(
self
):
self
.
setUpLoggedInUser
()
self
.
setUpGuardianDummyWithPerms
([
'
view
'
])
...
...
@@ -58,13 +51,6 @@ class TestsGuardian(APITestCase):
response
=
self
.
client
.
get
(
'
/permissionless-dummys/{}/
'
.
format
(
dummy_without
.
slug
))
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_post_dummy_permission_granted
(
self
):
self
.
setUpLoggedInUser
()
self
.
setUpGuardianDummyWithPerms
([
'
add
'
])
post
=
{
'
some
'
:
"
some_new
"
,
"
slug
"
:
'
slug1
'
}
response
=
self
.
client
.
post
(
'
/permissionless-dummys/
'
,
data
=
json
.
dumps
(
post
),
content_type
=
'
application/ld+json
'
)
self
.
assertEqual
(
response
.
status_code
,
201
)
def
test_patch_dummy_permission_granted
(
self
):
self
.
setUpLoggedInUser
()
self
.
setUpGuardianDummyWithPerms
([
'
change
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment