Updated Example (API) to use the new CMS_STORAGE interface.
This commit is contained in:
@@ -37,8 +37,12 @@ feature -- Basic operations
|
|||||||
if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal ("basic")) and then
|
if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal ("basic")) and then
|
||||||
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then
|
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then
|
||||||
if api_service.login_valid (l_auth_login, l_auth_password) then
|
if api_service.login_valid (l_auth_login, l_auth_password) then
|
||||||
req.set_execution_variable ("user", create {CMS_USER}.make (l_auth_login))
|
if attached api_service.user_by_name (l_auth_login) as l_user then
|
||||||
execute_next (req, res)
|
req.set_execution_variable ("user", l_user)
|
||||||
|
execute_next (req, res)
|
||||||
|
else
|
||||||
|
-- Internal server error
|
||||||
|
end
|
||||||
else
|
else
|
||||||
log.write_error (generator + ".execute login_valid failed for: " + l_auth_login )
|
log.write_error (generator + ".execute login_valid failed for: " + l_auth_login )
|
||||||
execute_next (req, res)
|
execute_next (req, res)
|
||||||
|
|||||||
@@ -133,12 +133,13 @@ feature -- HTTP Methods
|
|||||||
u_node: CMS_NODE
|
u_node: CMS_NODE
|
||||||
l_page: ROC_RESPONSE
|
l_page: ROC_RESPONSE
|
||||||
do
|
do
|
||||||
if attached current_user_name (req) then
|
to_implement ("Check if user has permissions")
|
||||||
|
if attached current_user (req) as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||||
u_node := extract_data_form (req)
|
u_node := extract_data_form (req)
|
||||||
u_node.set_id (l_id.integer_value)
|
u_node.set_id (l_id.integer_value)
|
||||||
api_service.update_node_content (u_node.id, u_node.content)
|
api_service.update_node_content (l_user.id, u_node.id, u_node.content)
|
||||||
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||||
else
|
else
|
||||||
do_error (req, res, l_id)
|
do_error (req, res, l_id)
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ feature -- HTTP Methods
|
|||||||
u_node: CMS_NODE
|
u_node: CMS_NODE
|
||||||
l_page: ROC_RESPONSE
|
l_page: ROC_RESPONSE
|
||||||
do
|
do
|
||||||
if attached current_user_name (req) then
|
to_implement ("Check user permissions!!!")
|
||||||
|
if attached current_user (req) as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||||
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||||
@@ -113,7 +114,9 @@ feature -- HTTP Methods
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- New node
|
-- New node
|
||||||
api_service.new_node (extract_data_form (req))
|
u_node := extract_data_form (req)
|
||||||
|
u_node.set_author (l_user)
|
||||||
|
api_service.new_node (u_node)
|
||||||
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -126,12 +129,13 @@ feature -- HTTP Methods
|
|||||||
local
|
local
|
||||||
u_node: CMS_NODE
|
u_node: CMS_NODE
|
||||||
do
|
do
|
||||||
if attached current_user_name (req) then
|
|
||||||
|
if attached current_user (req) as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||||
u_node := extract_data_form (req)
|
u_node := extract_data_form (req)
|
||||||
u_node.set_id (l_id.integer_value)
|
u_node.set_id (l_id.integer_value)
|
||||||
api_service.update_node (u_node)
|
api_service.update_node (l_user.id,u_node)
|
||||||
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||||
else
|
else
|
||||||
do_error (req, res, l_id)
|
do_error (req, res, l_id)
|
||||||
|
|||||||
@@ -132,12 +132,13 @@ feature -- HTTP Methods
|
|||||||
u_node: CMS_NODE
|
u_node: CMS_NODE
|
||||||
l_page: ROC_RESPONSE
|
l_page: ROC_RESPONSE
|
||||||
do
|
do
|
||||||
if attached current_user_name (req) then
|
to_implement ("Check if user has permissions!!!")
|
||||||
|
if attached current_user (req) as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||||
u_node := extract_data_form (req)
|
u_node := extract_data_form (req)
|
||||||
u_node.set_id (l_id.integer_value)
|
u_node.set_id (l_id.integer_value)
|
||||||
api_service.update_node_summary (u_node.id, u_node.summary)
|
api_service.update_node_summary (l_user.id,u_node.id, u_node.summary)
|
||||||
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||||
else
|
else
|
||||||
do_error (req, res, l_id)
|
do_error (req, res, l_id)
|
||||||
|
|||||||
@@ -133,12 +133,13 @@ feature -- HTTP Methods
|
|||||||
u_node: CMS_NODE
|
u_node: CMS_NODE
|
||||||
l_page: ROC_RESPONSE
|
l_page: ROC_RESPONSE
|
||||||
do
|
do
|
||||||
if attached current_user_name (req) then
|
to_implement ("Check if user has permissions")
|
||||||
|
if attached current_user (req) as l_user then
|
||||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||||
u_node := extract_data_form (req)
|
u_node := extract_data_form (req)
|
||||||
u_node.set_id (l_id.integer_value)
|
u_node.set_id (l_id.integer_value)
|
||||||
api_service.update_node_title (u_node.id, u_node.title)
|
api_service.update_node_title (l_user.id,u_node.id, u_node.title)
|
||||||
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
(create {ROC_RESPONSE}.make (req, "")).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||||
else
|
else
|
||||||
do_error (req, res, l_id)
|
do_error (req, res, l_id)
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ feature -- Access
|
|||||||
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
|
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: Node
|
||||||
|
|
||||||
nodes: LIST[CMS_NODE]
|
nodes: LIST[CMS_NODE]
|
||||||
-- List of nodes.
|
-- List of nodes.
|
||||||
do
|
do
|
||||||
@@ -56,7 +58,7 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Node
|
feature -- Change: Node
|
||||||
|
|
||||||
new_node (a_node: CMS_NODE)
|
new_node (a_node: CMS_NODE)
|
||||||
-- Add a new node
|
-- Add a new node
|
||||||
@@ -69,31 +71,37 @@ feature -- Node
|
|||||||
storage.delete_node (a_id)
|
storage.delete_node (a_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node (a_node: CMS_NODE)
|
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
|
||||||
do
|
do
|
||||||
storage.update_node (a_node)
|
storage.update_node (a_id,a_node)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
fixme ("Check preconditions")
|
fixme ("Check preconditions")
|
||||||
storage.update_node_title (a_id, a_title)
|
storage.update_node_title (a_id,a_node_id,a_title)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
fixme ("Check preconditions")
|
fixme ("Check preconditions")
|
||||||
storage.update_node_summary (a_id, a_summary)
|
storage.update_node_summary (a_id,a_node_id, a_summary)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
fixme ("Check preconditions")
|
fixme ("Check preconditions")
|
||||||
storage.update_node_content (a_id, a_content)
|
storage.update_node_content (a_id,a_node_id, a_content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- User
|
feature -- Access: User
|
||||||
|
|
||||||
|
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
|
||||||
|
do
|
||||||
|
Result := storage.user_by_name (a_username)
|
||||||
|
end
|
||||||
|
feature -- Change User
|
||||||
|
|
||||||
new_user (a_user: CMS_USER)
|
new_user (a_user: CMS_USER)
|
||||||
-- Add a new user `a_user'.
|
-- Add a new user `a_user'.
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ feature -- User Nodes
|
|||||||
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
|
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
|
||||||
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
|
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
|
||||||
do
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
|
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
|
||||||
-- Possible list of nodes where the user identified by `a_id', is the author.
|
-- Possible list of nodes where the user identified by `a_id', is the author.
|
||||||
do
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change: user
|
feature -- Change: user
|
||||||
@@ -67,6 +69,7 @@ feature -- Access: roles and permissions
|
|||||||
|
|
||||||
user_roles: LIST [CMS_USER_ROLE]
|
user_roles: LIST [CMS_USER_ROLE]
|
||||||
do
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ feature -- Access: node
|
|||||||
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
|
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
|
||||||
-- Possible list of node's collaborator.
|
-- Possible list of node's collaborator.
|
||||||
do
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Node
|
feature -- Node
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`users` (
|
|||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE INDEX `username` (`username` ASC))
|
UNIQUE INDEX `username` (`username` ASC))
|
||||||
ENGINE = InnoDB
|
ENGINE = InnoDB
|
||||||
|
AUTO_INCREMENT = 2
|
||||||
DEFAULT CHARACTER SET = latin1;
|
DEFAULT CHARACTER SET = latin1;
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`nodes` (
|
|||||||
`summary` TEXT NOT NULL,
|
`summary` TEXT NOT NULL,
|
||||||
`content` MEDIUMTEXT NOT NULL,
|
`content` MEDIUMTEXT NOT NULL,
|
||||||
`author_id` INT(10) UNSIGNED NULL DEFAULT NULL,
|
`author_id` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||||
`version` INT(10) ZEROFILL NULL,
|
`version` INT(10) UNSIGNED ZEROFILL NULL DEFAULT NULL,
|
||||||
`editor_id` INT(10) UNSIGNED NULL DEFAULT NULL,
|
`editor_id` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
INDEX `fk_nodes_users1_idx` (`author_id` ASC),
|
INDEX `fk_nodes_users1_idx` (`author_id` ASC),
|
||||||
@@ -56,6 +57,7 @@ CREATE TABLE IF NOT EXISTS `cms_dev`.`nodes` (
|
|||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION)
|
ON UPDATE NO ACTION)
|
||||||
ENGINE = InnoDB
|
ENGINE = InnoDB
|
||||||
|
AUTO_INCREMENT = 11
|
||||||
DEFAULT CHARACTER SET = latin1;
|
DEFAULT CHARACTER SET = latin1;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ feature -- Node
|
|||||||
|
|
||||||
delete_node (a_id: INTEGER_64)
|
delete_node (a_id: INTEGER_64)
|
||||||
do
|
do
|
||||||
|
node_provider.delete_from_user_nodes(a_id)
|
||||||
node_provider.delete_node (a_id)
|
node_provider.delete_node (a_id)
|
||||||
post_node_provider_execution
|
post_node_provider_execution
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -224,6 +224,18 @@ feature -- Basic operations
|
|||||||
post_execution
|
post_execution
|
||||||
end
|
end
|
||||||
|
|
||||||
|
delete_from_user_nodes (a_id: INTEGER_64)
|
||||||
|
local
|
||||||
|
l_parameters: STRING_TABLE [ANY]
|
||||||
|
do
|
||||||
|
log.write_information (generator + ".delete_from_user_nodes")
|
||||||
|
create l_parameters.make (1)
|
||||||
|
l_parameters.put (a_id, "id")
|
||||||
|
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_from_user_node, l_parameters))
|
||||||
|
db_handler.execute_change
|
||||||
|
post_execution
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Basic Operations: User_Nodes
|
feature -- Basic Operations: User_Nodes
|
||||||
|
|
||||||
add_author (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
|
add_author (a_user_id: INTEGER_64; a_node_id: INTEGER_64)
|
||||||
@@ -413,6 +425,8 @@ feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
|
|||||||
|
|
||||||
Select_exist_user_node: STRING= "Select Count(*) from Users_nodes where users_id=:user_id and nodes_id=:node_id;"
|
Select_exist_user_node: STRING= "Select Count(*) from Users_nodes where users_id=:user_id and nodes_id=:node_id;"
|
||||||
|
|
||||||
|
sql_delete_from_user_node: STRING = "delete from users_nodes where nodes_id=:id"
|
||||||
|
|
||||||
|
|
||||||
feature --
|
feature --
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user