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
3f6cc654
Commit
3f6cc654
authored
7 years ago
by
Ambrus Simon
Browse files
Options
Downloads
Patches
Plain Diff
update containerutil to use analyses coll
parent
af38c54d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/dao/containerutil.py
+27
-30
27 additions, 30 deletions
api/dao/containerutil.py
with
27 additions
and
30 deletions
api/dao/containerutil.py
+
27
−
30
View file @
3f6cc654
...
...
@@ -6,7 +6,7 @@ from ..auth import INTEGER_ROLES
CONT_TYPES
=
[
'
acquisition
'
,
'
analysis
'
,
'
collection
'
,
'
group
'
,
'
project
'
,
'
session
'
]
def
get
P
erm
(
name
):
def
get
_p
erm
(
name
):
return
INTEGER_ROLES
[
name
]
def
add_id_to_subject
(
subject
,
pid
):
...
...
@@ -100,16 +100,15 @@ class ContainerReference(object):
def
__init__
(
self
,
type
,
id
):
if
type
not
in
CONT_TYPES
:
raise
Exception
(
'
Container type must be one of {}
'
.
format
(
CONT_TYPES
))
if
type
==
'
analysis
'
:
self
.
__class__
=
AnalysisReference
if
not
isinstance
(
type
,
basestring
):
raise
Exception
(
'
Container type must be of type str
'
)
if
not
isinstance
(
id
,
basestring
):
raise
Exception
(
'
Container id must be of type str
'
)
self
.
type
=
type
self
.
id
=
id
self
.
type
=
type
self
.
collection
=
singular_to_plural
[
type
]
self
.
id
=
id
@classmethod
def
from_dictionary
(
cls
,
d
):
...
...
@@ -126,7 +125,7 @@ class ContainerReference(object):
)
def
get
(
self
):
result
=
config
.
db
[
self
.
type
+
'
s
'
].
find_one
({
'
_id
'
:
bson
.
ObjectId
(
self
.
id
)})
result
=
config
.
db
[
self
.
collection
].
find_one
({
'
_id
'
:
bson
.
ObjectId
(
self
.
id
)})
if
result
is
None
:
raise
Exception
(
'
No such {} {} in database
'
.
format
(
self
.
type
,
self
.
id
))
return
result
...
...
@@ -139,32 +138,18 @@ class ContainerReference(object):
return
None
def
file_uri
(
self
,
filename
):
return
'
/
'
+
self
.
type
+
'
s/
'
+
self
.
id
+
'
/files/
'
+
filename
def
check_access
(
self
,
userID
,
perm_name
):
perm
=
getPerm
(
perm_name
)
if
self
.
type
==
'
analysis
'
:
analysis
=
self
.
get
()
par_coll
,
par_id
=
singular_to_plural
[
analysis
[
'
parent
'
][
'
type
'
]],
analysis
[
'
parent
'
][
'
id
'
]
return
'
/{}/{}/analyses/{}/files/{}
'
.
format
(
par_coll
,
par_id
,
self
.
id
,
filename
)
return
'
/{}/{}/files/{}
'
.
format
(
self
.
collection
,
self
.
id
,
filename
)
def
check_access
(
self
,
uid
,
perm_name
):
perm
=
get_perm
(
perm_name
)
for
p
in
self
.
get
()[
'
permissions
'
]:
if
p
[
'
_id
'
]
==
u
serID
and
get
P
erm
(
p
[
'
access
'
])
>
perm
:
if
p
[
'
_id
'
]
==
u
id
and
get
_p
erm
(
p
[
'
access
'
])
>
perm
:
return
raise
Exception
(
'
User {} does not have {} access to {} {}
'
.
format
(
userID
,
perm_name
,
self
.
type
,
self
.
id
))
class
AnalysisReference
(
ContainerReference
):
# pylint: disable=redefined-builtin
# TODO: refactor to resolve pylint warning
def
get
(
self
):
result
=
config
.
db
.
sessions
.
find_one
({
'
analyses._id
'
:
self
.
id
},
{
'
permissions
'
:
1
,
'
analyses
'
:
{
'
$elemMatch
'
:
{
'
_id
'
:
self
.
id
}}})
if
result
is
None
or
result
.
get
(
'
analyses
'
)
is
None
:
raise
Exception
(
'
No such analysis {} in database
'
.
format
(
self
.
id
))
analysis
=
result
[
'
analyses
'
][
0
]
analysis
[
'
permissions
'
]
=
result
[
'
permissions
'
]
analysis
[
'
session_id
'
]
=
result
[
'
_id
'
]
return
analysis
def
file_uri
(
self
,
filename
):
analysis
=
self
.
get
()
return
'
/sessions/
'
+
str
(
analysis
[
'
session_id
'
])
+
'
/analyses/
'
+
self
.
id
+
'
/files/
'
+
filename
raise
Exception
(
'
User {} does not have {} access to {} {}
'
.
format
(
uid
,
perm_name
,
self
.
type
,
self
.
id
))
class
FileReference
(
ContainerReference
):
...
...
@@ -192,3 +177,15 @@ def create_containerreference_from_dictionary(d):
def
create_containerreference_from_filereference
(
fr
):
return
ContainerReference
.
from_filereference
(
fr
)
singular_to_plural
=
{
'
group
'
:
'
groups
'
,
'
project
'
:
'
projects
'
,
'
session
'
:
'
sessions
'
,
'
acquisition
'
:
'
acquisitions
'
,
'
analysis
'
:
'
analyses
'
,
'
file
'
:
'
files
'
,
}
plural_to_singular
=
{
p
:
s
for
s
,
p
in
singular_to_plural
.
iteritems
()}
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