Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Anders Harrisson
csentry
Commits
bd48fd07
Commit
bd48fd07
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add API to view/create comments on item
parent
5e8b9d5c
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
app/api/inventory.py
+17
-0
17 additions, 0 deletions
app/api/inventory.py
app/api/utils.py
+2
-1
2 additions, 1 deletion
app/api/utils.py
app/models.py
+12
-0
12 additions, 0 deletions
app/models.py
tests/functional/test_api.py
+1
-1
1 addition, 1 deletion
tests/functional/test_api.py
with
32 additions
and
2 deletions
app/api/inventory.py
+
17
−
0
View file @
bd48fd07
...
...
@@ -113,6 +113,23 @@ def patch_item(id_):
return
jsonify
(
item
.
to_dict
())
@bp.route
(
'
/items/<id_>/comments
'
)
@jwt_required
def
get_item_comments
(
id_
):
item
=
get_item_by_id_or_ics_id
(
id_
)
return
jsonify
([
comment
.
to_dict
()
for
comment
in
item
.
comments
])
@bp.route
(
'
/items/<id_>/comments
'
,
methods
=
[
'
POST
'
])
@jwt_required
@jwt_groups_accepted
(
'
admin
'
,
'
create
'
)
def
create_item_comment
(
id_
):
item
=
get_item_by_id_or_ics_id
(
id_
)
return
create_generic_model
(
models
.
ItemComment
,
mandatory_fields
=
(
'
text
'
,),
item_id
=
item
.
id
)
@bp.route
(
'
/actions
'
)
@jwt_required
def
get_actions
():
...
...
This diff is collapsed.
Click to expand it.
app/api/utils.py
+
2
−
1
View file @
bd48fd07
...
...
@@ -39,11 +39,12 @@ def get_generic_model(model, args, order_by=None):
return
jsonify
(
data
)
def
create_generic_model
(
model
,
mandatory_fields
=
(
'
name
'
,)):
def
create_generic_model
(
model
,
mandatory_fields
=
(
'
name
'
,)
,
**
kwargs
):
data
=
request
.
get_json
()
if
data
is
None
:
raise
utils
.
CSEntryError
(
'
Body should be a JSON object
'
)
current_app
.
logger
.
debug
(
f
'
Received:
{
data
}
'
)
data
.
update
(
kwargs
)
for
mandatory_field
in
mandatory_fields
:
if
mandatory_field
not
in
data
:
raise
utils
.
CSEntryError
(
f
"
Missing mandatory field
'
{
mandatory_field
}
'"
,
status_code
=
422
)
...
...
This diff is collapsed.
Click to expand it.
app/models.py
+
12
−
0
View file @
bd48fd07
...
...
@@ -333,6 +333,7 @@ class Item(CreatedMixin, db.Model):
'
children
'
:
[
str
(
child
)
for
child
in
self
.
children
],
'
macs
'
:
[
str
(
mac
)
for
mac
in
self
.
macs
],
'
history
'
:
self
.
history
(),
'
comments
'
:
[
str
(
comment
)
for
comment
in
self
.
comments
],
})
return
d
...
...
@@ -360,6 +361,17 @@ class ItemComment(CreatedMixin, db.Model):
text
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
item_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
item.id
'
),
nullable
=
False
)
def
__str__
(
self
):
return
self
.
text
def
to_dict
(
self
):
d
=
super
().
to_dict
()
d
.
update
({
'
text
'
:
self
.
text
,
'
item
'
:
str
(
self
.
item
),
})
return
d
class
Network
(
CreatedMixin
,
db
.
Model
):
vlan_name
=
db
.
Column
(
CIText
,
nullable
=
False
,
unique
=
True
)
...
...
This diff is collapsed.
Click to expand it.
tests/functional/test_api.py
+
1
−
1
View file @
bd48fd07
...
...
@@ -207,7 +207,7 @@ def test_create_item(client, user_token):
assert
response
.
status_code
==
201
assert
{
'
id
'
,
'
ics_id
'
,
'
serial_number
'
,
'
manufacturer
'
,
'
model
'
,
'
location
'
,
'
status
'
,
'
parent
'
,
'
children
'
,
'
macs
'
,
'
history
'
,
'
updated_at
'
,
'
created_at
'
,
'
user
'
}
==
set
(
response
.
json
.
keys
())
'
updated_at
'
,
'
created_at
'
,
'
user
'
,
'
comments
'
}
==
set
(
response
.
json
.
keys
())
assert
response
.
json
[
'
serial_number
'
]
==
'
123456
'
# Check that serial_number doesn't have to be unique
...
...
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