Added basic webapi system to ROC CMS system.

Added sql_delete routine to replace sql_modify with "DELETE FROM .." sql statement.
Fixed filter setup when a module has more than one filter.
Fixed filter setup for site,admin and webapi modes.
Added CMS_AUTH_FILTER, and check if user is already authenticated, then skip following auth filters.
Added specific webapi handler classes for root, user, access token, ...
Added user profile system to the core module.
Moved /user/{uid} from auth module to core module.
Added possibility to add html before and after a cms form. (useful to add a form before or after, as nested form are forbidden).
Now theme can be installed using roc install command.
This commit is contained in:
Jocelyn Fiat
2017-09-05 15:54:40 +02:00
parent 34f0aa5844
commit ac9d29b971
88 changed files with 3552 additions and 553 deletions

View File

@@ -0,0 +1,90 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_MODULE_WEBAPI [G -> CMS_MODULE]
inherit
CMS_MODULE
rename
is_initialized as module_is_initialized,
is_enabled as module_is_enabled
redefine
module_api
end
feature {NONE} -- Initialization
make (a_module: G)
-- Initialize `Current'.
do
module := a_module
version := a_module.version
description := a_module.description
package := a_module.package
module_is_initialized := a_module.is_initialized
module_is_enabled := a_module.is_enabled
end
feature -- Access
module: G
name: STRING
do
Result := module.name
end
feature {CMS_API, CMS_MODULE_ADMINISTRATION, CMS_MODULE_WEBAPI} -- Access: API
module_api: detachable CMS_MODULE_API
-- Eventual module api.
do
Result := module.module_api
end
feature -- Status
is_initialized: BOOLEAN
-- Is Current module initialized?
do
Result := module.is_initialized
end
is_enabled: BOOLEAN
-- Is Current module enabled?
do
Result := module.is_enabled
end
feature -- Router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- <Precursor>
do
if a_router.base_url /= Void then
setup_webapi_router (a_router, a_api)
end
end
feature {NONE} -- Router/administration
setup_webapi_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- Setup url dispatching for Current module web API.
-- (note: `a_router` is already based with webapi path prefix).
require
is_initialized: is_initialized
router_has_base_url: a_router.base_url /= Void
deferred
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,15 @@
note
description: "Summary description for {CMS_WEBAPI_AUTH_FILTER}."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_WEBAPI_AUTH_FILTER
inherit
CMS_AUTH_FILTER
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,100 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_WEBAPI_HANDLER
inherit
WSF_HANDLER
CMS_API_ACCESS
CMS_ENCODERS
REFACTORING_HELPER
feature {NONE} -- Initialization
make (a_api: CMS_API)
-- Initialize Current handler with `a_api'.
do
api := a_api
end
feature -- API Service
api: CMS_API
feature -- Factory
new_webapi_response (req: WSF_REQUEST; res: WSF_RESPONSE): HM_WEBAPI_RESPONSE
do
-- create {MD_WEBAPI_RESPONSE} Result.make (req, res, api)
create {JSON_WEBAPI_RESPONSE} Result.make (req, res, api)
end
new_wepapi_error_response (msg: detachable READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE): HM_WEBAPI_RESPONSE
do
Result := new_webapi_response (req, res)
if msg /= Void then
Result.add_string_field ("error", msg)
else
Result.add_string_field ("error", "True")
end
end
send_not_found (m: detachable READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE)
local
rep: HM_WEBAPI_RESPONSE
do
if m /= Void then
rep := new_wepapi_error_response (m, req, res)
else
rep := new_wepapi_error_response ("Not found", req, res)
end
rep.set_status_code ({HTTP_STATUS_CODE}.not_found)
rep.execute
end
send_access_denied (m: detachable READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE)
local
rep: HM_WEBAPI_RESPONSE
do
if m /= Void then
rep := new_wepapi_error_response (m, req, res)
else
rep := new_wepapi_error_response ("Access denied", req, res)
end
rep.set_status_code ({HTTP_STATUS_CODE}.user_access_denied)
rep.execute
end
send_bad_request (m: detachable READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE)
local
rep: HM_WEBAPI_RESPONSE
do
if m /= Void then
rep := new_wepapi_error_response (m, req, res)
else
rep := new_wepapi_error_response ("Bad request", req, res)
end
rep.set_status_code ({HTTP_STATUS_CODE}.bad_request)
rep.execute
end
feature {NONE} -- Builder
add_user_links_to (u: CMS_USER; rep: HM_WEBAPI_RESPONSE)
do
rep.add_link ("account", "user/" + u.id.out, rep.api.webapi_path ("/user/" + u.id.out))
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,36 @@
note
description: "Interface providing webapi module."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_WITH_WEBAPI
feature -- Administration
module_webapi: like webapi
-- Associated web api module.
do
Result := internal_module_webapi
if Result = Void then
Result := webapi
internal_module_webapi := Result
end
end
feature {NONE} -- Implementation
internal_module_webapi: detachable like module_webapi
-- Cached version of `module_webapi`.
feature {NONE} -- Web API
webapi: CMS_MODULE_WEBAPI [CMS_MODULE]
-- Web API module.
deferred
end
note
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end