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
5e530900
Commit
5e530900
authored
7 years ago
by
Ambrus Simon
Browse files
Options
Downloads
Patches
Plain Diff
analysis GET, DELETE and /notes working
parent
c60ebc49
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/api.py
+2
-2
2 additions, 2 deletions
api/api.py
api/dao/containerstorage.py
+11
-9
11 additions, 9 deletions
api/dao/containerstorage.py
api/handlers/refererhandler.py
+18
-47
18 additions, 47 deletions
api/handlers/refererhandler.py
bin/database.py
+2
-0
2 additions, 0 deletions
bin/database.py
with
33 additions
and
58 deletions
api/api.py
+
2
−
2
View file @
5e530900
...
...
@@ -248,7 +248,7 @@ endpoints = [
route
(
'
/<list_name:files>/<name:{fname}>
'
,
FileListHandler
,
m
=
[
'
GET
'
,
'
DELETE
'
]),
route
(
'
/<list_name:files>/<name:{fname}>/info
'
,
FileListHandler
,
h
=
'
get_info
'
,
m
=
[
'
GET
'
]),
route
(
'
/analyses
'
,
AnalysesHandler
,
m
=
[
'
POST
'
]),
route
(
'
/analyses
'
,
AnalysesHandler
,
m
=
[
'
POST
'
]),
prefix
(
'
/analyses
'
,
[
route
(
'
/<_id:{cid}>
'
,
AnalysesHandler
,
m
=
[
'
GET
'
,
'
DELETE
'
]),
route
(
'
/<_id:{cid}>/files
'
,
AnalysesHandler
,
h
=
'
download
'
,
m
=
[
'
GET
'
]),
...
...
@@ -263,7 +263,7 @@ endpoints = [
# Analysis notes
prefix
(
'
/{cname}
/
{cid}/<cont_name:analyses>/<cid:{cid}>
'
,
[
prefix
(
'
/
<:
{cname}
>/<:
{cid}
>
/<cont_name:analyses>/<cid:{cid}>
'
,
[
route
(
'
/<list_name:notes>
'
,
NotesListHandler
,
m
=
[
'
POST
'
]),
route
(
'
/<list_name:notes>/<_id:{nid}>
'
,
NotesListHandler
,
name
=
'
notes
'
,
m
=
[
'
GET
'
,
'
PUT
'
,
'
DELETE
'
]),
]),
...
...
This diff is collapsed.
Click to expand it.
api/dao/containerstorage.py
+
11
−
9
View file @
5e530900
...
...
@@ -460,20 +460,22 @@ class AnalysisStorage(ContainerStorage):
return
files
@staticmethod
def
fill_values
(
analysis
,
cont_name
,
cid
,
origin
):
def
fill_values
(
self
,
analysis
,
cont_name
,
cid
,
origin
):
parent
=
self
.
get_parent
(
cont_name
,
cid
)
defaults
=
{
'
parent
'
:
{
'
parent
'
:
{
'
type
'
:
containerutil
.
singularize
(
cont_name
),
'
id
'
:
bson
.
objectid
.
ObjectId
(
cid
)
'
id
'
:
bson
.
objectid
.
ObjectId
(
cid
)
},
'
_id
'
:
bson
.
objectid
.
ObjectId
(),
'
created
'
:
datetime
.
datetime
.
utcnow
(),
'
_id
'
:
bson
.
objectid
.
ObjectId
(),
'
created
'
:
datetime
.
datetime
.
utcnow
(),
'
modified
'
:
datetime
.
datetime
.
utcnow
(),
'
user
'
:
origin
.
get
(
'
id
'
),
'
user
'
:
origin
.
get
(
'
id
'
),
'
permissions
'
:
parent
[
'
permissions
'
],
'
public
'
:
parent
.
get
(
'
public
'
,
False
),
}
defaults
.
update
(
analysis
)
return
defaults
for
key
in
defaults
:
analysis
.
setdefault
(
key
,
defaults
[
key
])
def
create_job_and_analysis
(
self
,
cont_name
,
cid
,
analysis
,
job
,
origin
):
...
...
This diff is collapsed.
Click to expand it.
api/handlers/refererhandler.py
+
18
−
47
View file @
5e530900
...
...
@@ -16,7 +16,7 @@ from .. import upload
from
..
import
util
from
..
import
validators
from
..auth
import
containerauth
,
always_ok
from
..dao
import
containerstorage
,
noop
from
..dao
import
APIStorageException
,
containerstorage
,
noop
from
..web
import
base
from
..web.request
import
log_access
,
AccessType
...
...
@@ -59,6 +59,7 @@ class AnalysesHandler(RefererHandler):
storage_schema_file
=
'
analysis.json
'
payload_schema_file
=
'
analysis.json
'
def
post
(
self
,
cont_name
,
cid
):
"""
Default behavior:
...
...
@@ -88,7 +89,6 @@ class AnalysesHandler(RefererHandler):
analysis
=
upload
.
process_upload
(
self
.
request
,
upload
.
Strategy
.
analysis
,
origin
=
self
.
origin
)
self
.
storage
.
fill_values
(
analysis
,
cont_name
,
cid
,
self
.
origin
)
self
.
input_validator
(
analysis
,
'
POST
'
)
result
=
self
.
storage
.
create_el
(
analysis
)
if
result
.
acknowledged
:
...
...
@@ -97,57 +97,28 @@ class AnalysesHandler(RefererHandler):
self
.
abort
(
500
,
'
Analysis not added for container {} {}
'
.
format
(
cont_name
,
cid
))
def
get
(
self
,
cont_name
,
cid
,
_id
):
parent
=
self
.
storage
.
get_parent
(
cont_name
,
cid
)
permchecker
=
self
.
get_permchecker
(
parent
)
permchecker
(
noop
)(
'
GET
'
)
return
self
.
_get_container
(
_id
)
@log_access
(
AccessType
.
delete_analysis
)
def
delete
(
self
,
**
kwargs
):
# Overriding base class delete to audit action before completion
_id
=
kwargs
.
pop
(
'
cid
'
)
permchecker
,
storage
,
_
,
_
,
keycheck
=
self
.
_initialize_request
(
cont_name
,
list_name
,
_id
,
query_params
=
kwargs
)
def
delete
(
self
,
cont_name
,
cid
,
_id
):
parent
=
self
.
storage
.
get_parent
(
cont_name
,
cid
)
permchecker
=
self
.
get_permchecker
(
parent
)
permchecker
(
noop
)(
'
DELETE
'
)
self
.
log_user_access
(
AccessType
.
delete_file
,
cont_name
=
cont_name
,
cont_id
=
cid
)
permchecker
(
noop
)(
'
DELETE
'
,
_id
=
_id
,
query_params
=
kwargs
)
self
.
log_user_access
(
AccessType
.
delete_file
,
cont_name
=
cont_name
,
cont_id
=
_id
)
try
:
result
=
keycheck
(
storage
.
exec_op
)(
'
DELETE
'
,
_id
,
query_params
=
kwargs
)
result
=
self
.
storage
.
delete_el
(
_id
)
except
APIStorageException
as
e
:
self
.
abort
(
400
,
e
.
message
)
if
result
.
modified_count
==
1
:
return
{
'
modified
'
:
result
.
modified_count
}
else
:
self
.
abort
(
404
,
'
Element not removed from list {} in container {} {}
'
.
format
(
storage
.
list_name
,
storage
.
cont_name
,
_id
))
def
add_note
(
self
,
cont_name
,
cid
,
child_name
,
_id
):
_id
=
kwargs
.
pop
(
'
cid
'
)
analysis_id
=
kwargs
.
get
(
'
_id
'
)
permchecker
,
storage
,
_
,
_
,
_
=
self
.
_initialize_request
(
cont_name
,
list_name
,
_id
)
payload
=
self
.
request
.
json_body
notes_schema_file
=
list_handler_configurations
[
cont_name
][
'
notes
'
][
'
storage_schema_file
'
]
input_schema_uri
=
validators
.
schema_uri
(
'
input
'
,
notes_schema_file
)
input_validator
=
validators
.
from_schema_path
(
input_schema_uri
)
input_validator
(
payload
,
'
POST
'
)
payload
[
'
_id
'
]
=
str
(
bson
.
objectid
.
ObjectId
())
payload
[
'
user
'
]
=
payload
.
get
(
'
user
'
,
self
.
uid
)
payload
[
'
created
'
]
=
datetime
.
datetime
.
utcnow
()
permchecker
(
noop
)(
'
POST
'
,
_id
=
_id
)
result
=
storage
.
add_note
(
_id
=
_id
,
analysis_id
=
analysis_id
,
payload
=
payload
)
if
result
.
modified_count
==
1
:
return
{
'
modified
'
:
result
.
modified_count
}
else
:
self
.
abort
(
404
,
'
Element not added in list {} of container {} {}
'
.
format
(
storage
.
list_name
,
storage
.
cont_name
,
_id
))
def
delete_note
(
self
,
cont_name
,
list_name
,
**
kwargs
):
_id
=
kwargs
.
pop
(
'
cid
'
)
analysis_id
=
kwargs
.
pop
(
'
_id
'
)
permchecker
,
storage
,
_
,
_
,
_
=
self
.
_initialize_request
(
cont_name
,
list_name
,
_id
)
note_id
=
kwargs
.
get
(
'
note_id
'
)
permchecker
(
noop
)(
'
DELETE
'
,
_id
=
_id
)
result
=
storage
.
delete_note
(
_id
=
_id
,
analysis_id
=
analysis_id
,
note_id
=
note_id
)
if
result
.
modified_count
==
1
:
return
{
'
modified
'
:
result
.
modified_count
}
if
result
.
deleted_count
==
1
:
return
{
'
deleted
'
:
result
.
deleted_count
}
else
:
self
.
abort
(
404
,
'
Note
not removed from
analysis {}
'
.
format
(
analysis_
id
))
self
.
abort
(
404
,
'
Analysis {}
not removed from
container {} {}
'
.
format
(
_id
,
cont_name
,
c
id
))
def
download
(
self
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
bin/database.py
+
2
−
0
View file @
5e530900
...
...
@@ -1121,6 +1121,8 @@ def upgrade_to_32_closure(cont, cont_name):
for
analysis
in
cont
[
'
analyses
'
]:
analysis
[
'
_id
'
]
=
bson
.
ObjectId
(
analysis
[
'
_id
'
])
analysis
[
'
parent
'
]
=
{
'
type
'
:
cont_type
,
'
id
'
:
cont
[
'
_id
'
]}
analysis
[
'
permissions
'
]
=
cont
[
'
permissions
'
]
analysis
[
'
public
'
]
=
cont
.
get
(
'
public
'
,
False
)
config
.
db
[
'
analyses
'
].
insert_many
(
cont
[
'
analyses
'
])
config
.
db
[
cont_name
].
update_one
(
{
'
_id
'
:
cont
[
'
_id
'
]},
...
...
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