Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Fay Arnold
djangoldp
Commits
dcab4da1
Commit
dcab4da1
authored
4 years ago
by
Calum Mackervoy
Browse files
Options
Downloads
Patches
Plain Diff
bugfix: resolve_id raises error if given a base container
parent
ee354b9c
No related branches found
Branches containing commit
Tags
v0.6.25
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangoldp/models.py
+14
-1
14 additions, 1 deletion
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
16 additions
and
16 deletions
djangoldp/models.py
+
14
−
1
View file @
dcab4da1
...
...
@@ -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,15 @@ class Model(models.Model):
@classonlymethod
def
resolve_id
(
cls
,
id
):
'''
Resolves the id of a given path (e.g. /container/1/)
Raises ValidationError if the path has no id, a Resolver404 if the path cannot be found
and an ObjectDoesNotExist exception if the resource does not exist
'''
id
=
cls
.
__clean_path
(
id
)
view
,
args
,
kwargs
=
get_resolver
().
resolve
(
id
)
if
len
(
kwargs
.
keys
())
==
0
:
raise
ValidationError
(
'
no id in given path
'
)
return
view
.
initkwargs
[
'
model
'
].
objects
.
get
(
**
kwargs
)
@classonlymethod
...
...
@@ -128,12 +135,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 @
dcab4da1
...
...
@@ -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 @
dcab4da1
...
...
@@ -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