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
ef77b3b8
Commit
ef77b3b8
authored
7 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add mock endpoints for suggest
parent
86da1841
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/dao/containerutil.py
+16
-0
16 additions, 0 deletions
api/dao/containerutil.py
api/handlers/containerhandler.py
+52
-0
52 additions, 0 deletions
api/handlers/containerhandler.py
api/jobs/handlers.py
+52
-5
52 additions, 5 deletions
api/jobs/handlers.py
with
120 additions
and
5 deletions
api/dao/containerutil.py
+
16
−
0
View file @
ef77b3b8
...
...
@@ -17,10 +17,26 @@ SINGULAR_TO_PLURAL = {
'
job
'
:
'
jobs
'
,
'
project
'
:
'
projects
'
,
'
session
'
:
'
sessions
'
,
'
subject
'
:
'
subjects
'
,
'
user
'
:
'
users
'
,
}
PLURAL_TO_SINGULAR
=
{
p
:
s
for
s
,
p
in
SINGULAR_TO_PLURAL
.
iteritems
()}
# NOTE: Following structures have subject as a hierarhcy level although
# it is not yet a formalized level of the hierarchy throughout API
CONTAINER_HIERARCHY
=
[
'
groups
'
,
'
projects
'
,
'
subjects
'
,
'
sessions
'
,
'
acquisitions
'
]
# Generate {child: parent} and {parent: child} maps from ordered hierarchy list
CHILD_FROM_PARENT
=
{
p
:
CONTAINER_HIERARCHY
[
ind
+
1
]
for
ind
,
p
in
enumerate
(
CONTAINER_HIERARCHY
[:
-
1
]
)}
PARENT_FROM_CHILD
=
{
c
:
CONTAINER_HIERARCHY
[
ind
]
for
ind
,
c
in
enumerate
(
CONTAINER_HIERARCHY
[
1
:]
)}
def
propagate_changes
(
cont_name
,
cont_ids
,
query
,
update
,
include_refs
=
False
):
"""
...
...
This diff is collapsed.
Click to expand it.
api/handlers/containerhandler.py
+
52
−
0
View file @
ef77b3b8
import
bson
import
datetime
import
dateutil
from
random
import
randint
from
..
import
config
from
..
import
util
...
...
@@ -570,6 +571,57 @@ class ContainerHandler(base.RequestHandler):
else
:
self
.
abort
(
404
,
'
Element not removed from container {} {}
'
.
format
(
self
.
storage
.
cont_name
,
_id
))
# def tree(self, cont_name, cid, **kwargs):
# """
# Given a container reference, return display information about parents, children and files.
# Container types acceptable for reference:
# - Groups
# - Projects
# - Subjects
# - Sessions
# - Acquisitions
# - Analyses
# NOTE: Access via this endpoint is not logged. Only information necessary for display should be returned.
# NOTE: Subject level is supported ahead of official separation in DB and API routes.
# """
# ## Mocked returns for development
# response = {
# 'cont_type': cont_name,
# '_id': cid,
# 'label': '{} {}'.format(containerutil.singularize(cont_name), cid),
# 'parents': []
# 'files': [{'name': 'file_'+i+'.zip'} for i in range(rantint(0,5))],
# 'children': {}
# }
# if containerutil.singularize(cont_name) in containerutil.CHILD_FROM_PARENT:
# child_cont = containerutil.CHILD_FROM_PARENT[cont_name]
# s_child_cont = containerutil.singularize(child_cont)
# response['children'][child_cont] = [{'cont_name': s_child_cont, '_id': ''+i, 'label': s_child_cont+' '+i} for i in range(rantint(0,5))]
# parent_cont = None
# if cont_type == 'analyses':
# parent_cont = 'sessions'
# else:
# response['children']['analyses'] = 'analyses': [{'cont_name': 'analysis', '_id': ''+i, 'label': 'analysis '+i} for i in range(rantint(0,5))]
# parent_cont = containerutil.PARENT_FROM_CHILD.get(cont_name)
# while parent_cont:
# response['parents'].append({'cont_type': parent_cont, '_id': 1, 'label': '{} {}'.format(containerutil.singularize(parent_name), 1)})
# parent_cont = containerutil.PARENT_FROM_CHILD.get(parent_cont)
# return response
def
get_groups_with_project
(
self
):
"""
method to return the list of groups for which there are projects accessible to the user
...
...
This diff is collapsed.
Click to expand it.
api/jobs/handlers.py
+
52
−
5
View file @
ef77b3b8
...
...
@@ -7,6 +7,7 @@ import os
import
StringIO
from
jsonschema
import
ValidationError
from
urlparse
import
urlparse
from
random
import
randint
from
.
import
batch
from
..
import
config
...
...
@@ -16,9 +17,9 @@ from ..auth import require_drone, require_login, require_admin, has_access
from
..auth.apikeys
import
JobApiKey
from
..dao
import
hierarchy
from
..dao.containerstorage
import
ProjectStorage
,
SessionStorage
,
AcquisitionStorage
from
..dao.containerutil
import
ContainerReference
,
pluralize
from
..util
import
humanize_validation_error
,
set_for_download
from
..validators
import
validate_data
,
verify_payload_exists
from
..dao.containerutil
import
ContainerReference
,
pluralize
,
singularize
,
CHILD_FROM_PARENT
,
PARENT_FROM_CHILD
from
..web
import
base
from
..web.encoder
import
pseudo_consistent_json_encode
from
..web.errors
import
APIPermissionException
,
APINotFoundException
,
InputValidationException
...
...
@@ -67,12 +68,58 @@ class GearHandler(base.RequestHandler):
@require_login
def
suggest
(
self
,
_id
,
cont_name
,
cid
):
cr
=
ContainerReference
(
cont_name
,
cid
)
if
not
self
.
superuser_request
:
cr
.
check_access
(
self
.
uid
,
'
ro
'
)
"""
Given a container reference, return display information about parents, children and files
as well as information about which best match each gear input
Container types acceptable for reference:
- Groups
- Projects
- Subjects
- Sessions
- Acquisitions
- Analyses
NOTE: Access via this endpoint is not logged. Only information necessary for display should be returned.
NOTE: Subject level is supported ahead of official separation in DB and API routes.
"""
## Mocked returns for development
response
=
{
'
cont_type
'
:
cont_name
,
'
_id
'
:
cid
,
'
label
'
:
'
{} {}
'
.
format
(
singularize
(
cont_name
),
cid
),
'
parents
'
:
[],
'
files
'
:
[{
'
name
'
:
'
file_{}.zip
'
.
format
(
i
)}
for
i
in
range
(
randint
(
0
,
5
))],
'
children
'
:
[]
}
if
cont_name
in
CHILD_FROM_PARENT
:
child_cont
=
CHILD_FROM_PARENT
[
cont_name
]
s_child_cont
=
singularize
(
child_cont
)
response
[
'
children
'
].
extend
([{
'
cont_type
'
:
child_cont
,
'
_id
'
:
''
+
str
(
i
),
'
label
'
:
s_child_cont
+
'
'
+
str
(
i
)}
for
i
in
range
(
randint
(
1
,
5
))])
parent_cont
=
None
if
cont_name
==
'
analyses
'
:
parent_cont
=
'
sessions
'
else
:
response
[
'
children
'
].
extend
([{
'
cont_type
'
:
'
analyses
'
,
'
_id
'
:
str
(
i
),
'
label
'
:
'
analysis
'
+
str
(
i
)}
for
i
in
range
(
randint
(
0
,
5
))])
parent_cont
=
PARENT_FROM_CHILD
.
get
(
cont_name
)
while
parent_cont
:
response
[
'
parents
'
].
append
({
'
cont_type
'
:
parent_cont
,
'
_id
'
:
1
,
'
label
'
:
'
{} {}
'
.
format
(
singularize
(
parent_cont
),
1
)})
parent_cont
=
PARENT_FROM_CHILD
.
get
(
parent_cont
)
gear
=
get_gear
(
_id
)
return
suggest_container
(
gear
,
cont_name
+
'
s
'
,
cid
)
for
f
in
response
[
'
files
'
]:
f
[
'
suggested
'
]
=
{}
for
i
in
gear
[
'
gear
'
].
get
(
'
inputs
'
,
{}).
iterkeys
():
f
[
'
suggested
'
][
i
]
=
bool
(
randint
(
0
,
1
))
return
response
@require_admin
def
upload
(
self
):
# pragma: no cover
...
...
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