Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-rest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-rest
Commits
d8732805
Commit
d8732805
authored
Jun 30, 2011
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- REST Interface:
Added support for DELETE operations
parent
f38688b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
intranet-rest-procs.tcl
tcl/intranet-rest-procs.tcl
+96
-0
No files found.
tcl/intranet-rest-procs.tcl
View file @
d8732805
...
...
@@ -314,6 +314,30 @@ ad_proc -private im_rest_call {
}
}
}
DELETE
{
# Is the post operation performed on a particular object or on the object_type?
if
{
""
!=
$rest
_oid && 0 !=
$rest
_oid
}
{
if
{[
catch
{
# DELETE with object_id => delete operation
ns_log Notice
"im_rest_call: Found a DELETE operation on object_type=
$rest
_otype with object_id=
$rest
_oid"
im_rest_delete_object
\
-format
$format
\
-user_id
$user
_id
\
-rest_otype
$rest
_otype
\
-rest_oid
$rest
_oid
\
-query_hash_pairs
$query
_hash_pairs
}
err_msg
]}
{
ns_log Error
"im_rest_call: Error during DELETE operation:
$err
_msg"
}
}
else
{
# DELETE without object_id is not allowed - you can only destroy a known object
ns_log Error
"im_rest_call: You have to specify an object to DELETE."
}
}
default
{
return
[
im_rest_error -format
$format
-http_status 400 -message
"Unknown HTTP request '
$method
'. Valid requests include {GET|POST|PUT|DELETE}."
]
}
...
...
@@ -1477,6 +1501,78 @@ ad_proc -private im_rest_post_object_type {
return
}
ad_proc -private im_rest_delete_object
{
{
-format
"xml"
}
{
-user_id 0
}
{
-rest_otype
""
}
{
-rest_oid 0
}
{
-query_hash_pairs
{}
}
{
-debug 0
}
}
{
Handler for DELETE rest calls to an individual object:
Update the specific object using a generic update procedure
}
{
ns_log Notice
"im_rest_delete_object: rest_otype=
$rest
_otype, rest_oid=
$rest
_oid, user_id=
$user
_id, format='
$format
', query_hash=
$query
_hash_pairs"
# Get the content of the HTTP DELETE request
set content
[
im_rest_get_content
]
ns_log Notice
"im_rest_delete_object: content=
$content
"
# Only administrators have the right to DELETE
if
{
!
[
im_user_is_admin_p
$user
_id
]}
{
im_rest_error -format
$format
-http_status 401 -message
"User #
$user
_id is not a system administrator. You need admin rights to perform a DELETE."
}
# Deal with certain subtypes
switch
$rest
_otype
{
im_ticket
{
set nuke_otype
"im_project"
}
default
{
set nuke_otype
$rest
_otype
}
}
if
{[
catch
{
set nuke_tcl
[
list
"
${nuke_otype}
_nuke"
-user_id
$user
_id
$rest
_oid
]
eval
$nuke
_tcl
}
err_msg
]}
{
im_rest_error -format
$format
-http_status 404 -message
"DELETE for object #
$rest
_oid of type '
$rest
_otype' returned an error:
$err
_msg"
}
# The update was successful - return a suitable message.
switch
$format
{
html
{
set page_title
"object_type:
$rest
_otype"
doc_return 200
"text/html"
"
[
im_header
$page
_title
[
im_rest_header_extra_stuff
]][
im_navbar
]
<table>
<tr class=rowtitle><td class=rowtitle>Object ID</td></tr>
<tr<td>
$rest
_oid</td></tr>
</table>
[
im_footer
]
"
}
json
{
# Empty data: The empty array is necessary for Sencha in order to call callbacks
# without error. However, adding data here will create empty records in the store later,
# so the array needs to be empty.
set data_list
[
list
]
foreach key
[
array
names hash_array
]
{
set value
$hash
_array
(
$key
)
lappend data_list
"
\"
$key
\"
:
\"
[
im_quotejson
$value
]
\"
"
}
set data
"
\[
{
[
join
$data
_list
", "
]
}
\]
"
set result
"{
\"
success
\"
:
\"
true
\"
,
\"
message
\"
:
\"
Object updated
\"
,
\"
data
\"
:
$data
}"
doc_return 200
"text/html"
$result
}
xml
{
doc_return 200
"text/xml"
"<?xml version='1.0'?>
\n
<object_id id=
\"
$rest
_oid
\"
>
$rest
_oid</object_id>
\n
"
}
}
return
}
ad_proc -private im_rest_post_object
{
{
-format
"xml"
}
{
-user_id 0
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment