Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
fa1b58a3
Commit
fa1b58a3
authored
7 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add more detailed permission errors
parent
ed098407
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/auth/containerauth.py
+4
-1
4 additions, 1 deletion
api/auth/containerauth.py
api/dao/containerutil.py
+5
-4
5 additions, 4 deletions
api/dao/containerutil.py
api/handlers/containerhandler.py
+13
-4
13 additions, 4 deletions
api/handlers/containerhandler.py
api/web/base.py
+1
-0
1 addition, 0 deletions
api/web/base.py
with
23 additions
and
9 deletions
api/auth/containerauth.py
+
4
−
1
View file @
fa1b58a3
...
@@ -3,6 +3,8 @@ Purpose of this module is to define all the permissions checker decorators for t
...
@@ -3,6 +3,8 @@ Purpose of this module is to define all the permissions checker decorators for t
"""
"""
from
.
import
_get_access
,
INTEGER_PERMISSIONS
from
.
import
_get_access
,
INTEGER_PERMISSIONS
from
..web.errors
import
APIPermissionException
from
..
import
config
def
default_container
(
handler
,
container
=
None
,
target_parent_container
=
None
):
def
default_container
(
handler
,
container
=
None
,
target_parent_container
=
None
):
...
@@ -35,8 +37,9 @@ def default_container(handler, container=None, target_parent_container=None):
...
@@ -35,8 +37,9 @@ def default_container(handler, container=None, target_parent_container=None):
user_perms
=
_get_access
(
handler
.
uid
,
container
)
user_perms
=
_get_access
(
handler
.
uid
,
container
)
has_access
=
user_perms
>=
INTEGER_PERMISSIONS
[
required_perm
]
has_access
=
user_perms
>=
INTEGER_PERMISSIONS
[
required_perm
]
if
not
has_access
and
has_original_data
and
user_perms
==
INTEGER_PERMISSIONS
[
'
rw
'
]:
if
not
has_access
and
container
.
get
(
'
has_original_data
'
,
False
)
and
user_perms
==
INTEGER_PERMISSIONS
[
'
rw
'
]:
# The user was not granted access because the container had original data
# The user was not granted access because the container had original data
errors
=
{
'
reason
'
:
'
original_data_present
'
}
errors
=
{
'
reason
'
:
'
original_data_present
'
}
else
:
else
:
errors
=
{
'
reason
'
:
'
permission_denied
'
}
errors
=
{
'
reason
'
:
'
permission_denied
'
}
...
...
This diff is collapsed.
Click to expand it.
api/dao/containerutil.py
+
5
−
4
View file @
fa1b58a3
...
@@ -171,15 +171,16 @@ def container_has_original_data(container, child_cont_name=None):
...
@@ -171,15 +171,16 @@ def container_has_original_data(container, child_cont_name=None):
If the set only includes user and job uploaded files, the container
If the set only includes user and job uploaded files, the container
is not considered to have
"
original data
"
.
is not considered to have
"
original data
"
.
"""
"""
origin_types
=
set
()
for
f
in
container
.
get
(
'
files
'
,
[]):
for
f
in
container
.
get
(
'
files
'
,
[]):
origin_types
.
add
(
f
[
'
origin
'
][
'
type
'
])
if
f
[
'
origin
'
][
'
type
'
]
not
in
[
str
(
Origin
.
user
),
str
(
Origin
.
job
)]:
return
True
if
child_cont_name
:
if
child_cont_name
:
for
c
in
container
.
get
(
child_cont_name
,
[]):
for
c
in
container
.
get
(
child_cont_name
,
[]):
for
f
in
c
.
get
(
'
files
'
,
[]):
for
f
in
c
.
get
(
'
files
'
,
[]):
origin_types
.
add
(
f
[
'
origin
'
][
'
type
'
])
if
f
[
'
origin
'
][
'
type
'
]
not
in
[
str
(
Origin
.
user
),
str
(
Origin
.
job
)]:
return
origin_types
.
issubset
(
set
(
str
(
Origin
.
user
,
Origin
.
job
)))
return
True
return
False
class
ContainerReference
(
object
):
class
ContainerReference
(
object
):
...
...
This diff is collapsed.
Click to expand it.
api/handlers/containerhandler.py
+
13
−
4
View file @
fa1b58a3
...
@@ -13,7 +13,7 @@ from ..jobs.jobs import Job
...
@@ -13,7 +13,7 @@ from ..jobs.jobs import Job
from
..jobs.queue
import
Queue
from
..jobs.queue
import
Queue
from
..types
import
Origin
from
..types
import
Origin
from
..web
import
base
from
..web
import
base
from
..web.errors
import
APIStorageException
from
..web.errors
import
APIStorageException
,
APIPermissionException
from
..web.request
import
log_access
,
AccessType
from
..web.request
import
log_access
,
AccessType
log
=
config
.
log
log
=
config
.
log
...
@@ -531,20 +531,29 @@ class ContainerHandler(base.RequestHandler):
...
@@ -531,20 +531,29 @@ class ContainerHandler(base.RequestHandler):
_id
=
kwargs
.
pop
(
'
cid
'
)
_id
=
kwargs
.
pop
(
'
cid
'
)
self
.
config
=
self
.
container_handler_configurations
[
cont_name
]
self
.
config
=
self
.
container_handler_configurations
[
cont_name
]
self
.
storage
=
self
.
config
[
'
storage
'
]
self
.
storage
=
self
.
config
[
'
storage
'
]
container
=
self
.
_get_container
(
_id
,
get_children
=
True
)
if
cont_name
!=
'
acquisitions
'
:
get_children
=
True
else
:
get_children
=
False
container
=
self
.
_get_container
(
_id
,
get_children
=
get_children
)
container
[
'
cont_name
'
]
=
containerutil
.
singularize
(
cont_name
)
container
[
'
cont_name
'
]
=
containerutil
.
singularize
(
cont_name
)
if
cont_name
in
[
'
sessions
'
,
'
acquisitions
'
]:
if
cont_name
in
[
'
sessions
'
,
'
acquisitions
'
]:
container
[
'
has_original_data
'
]
=
containerutil
.
container_origin
_types
(
container
,
child_cont_name
=
self
.
config
.
get
(
'
children_cont
'
))
container
[
'
has_original_data
'
]
=
containerutil
.
container_
has_
origin
al_data
(
container
,
child_cont_name
=
self
.
config
.
get
(
'
children_cont
'
))
if
cont_name
==
'
acquisitions
'
:
if
cont_name
==
'
acquisitions
'
:
analyses
=
containerutil
.
get_referring_analyses
(
cont_name
,
_id
)
analyses
=
containerutil
.
get_referring_analyses
(
cont_name
,
_id
)
if
analyses
:
if
analyses
:
analysis_ids
=
[
str
(
a
[
'
_id
'
])
for
a
in
analyses
]
analysis_ids
=
[
str
(
a
[
'
_id
'
])
for
a
in
analyses
]
self
.
abort
(
400
,
'
Cannot delete acquisition {} referenced by analyses {}
'
.
format
(
_id
,
analysis_ids
))
errors
=
{
'
reason
'
:
'
analysis_conflict
'
}
raise
APIPermissionException
(
'
Cannot delete acquisition {} referenced by analyses {}
'
.
format
(
_id
,
analysis_ids
),
errors
=
errors
)
target_parent_container
,
_
=
self
.
_get_parent_container
(
container
)
target_parent_container
,
_
=
self
.
_get_parent_container
(
container
)
permchecker
=
self
.
_get_permchecker
(
container
,
target_parent_container
)
permchecker
=
self
.
_get_permchecker
(
container
,
target_parent_container
)
permchecker
(
noop
)(
'
DELETE
'
,
_id
)
permchecker
(
noop
)(
'
DELETE
'
,
_id
)
if
self
.
is_true
(
'
check
'
):
# User only wanted to check permissions, respond with 200
return
try
:
try
:
# This line exec the actual delete checking permissions using the decorator permchecker
# This line exec the actual delete checking permissions using the decorator permchecker
...
...
This diff is collapsed.
Click to expand it.
api/web/base.py
+
1
−
0
View file @
fa1b58a3
...
@@ -345,6 +345,7 @@ class RequestHandler(webapp2.RequestHandler):
...
@@ -345,6 +345,7 @@ class RequestHandler(webapp2.RequestHandler):
elif
isinstance
(
exception
,
errors
.
APIConsistencyException
):
elif
isinstance
(
exception
,
errors
.
APIConsistencyException
):
code
=
400
code
=
400
elif
isinstance
(
exception
,
errors
.
APIPermissionException
):
elif
isinstance
(
exception
,
errors
.
APIPermissionException
):
custom_errors
=
exception
.
errors
code
=
403
code
=
403
elif
isinstance
(
exception
,
errors
.
APINotFoundException
):
elif
isinstance
(
exception
,
errors
.
APINotFoundException
):
code
=
404
code
=
404
...
...
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