Better implementation of CMS_API.source_of_path_alias (a_alias).

That now returns the path, only if the alias exists, otherwise returns Void.
Improved path alias validation.
This commit is contained in:
2015-07-07 17:40:12 +02:00
parent cc94c59eed
commit 85cff0b139
3 changed files with 16 additions and 8 deletions

View File

@@ -122,8 +122,10 @@ feature -- Forms ...
else
-- TODO: implement full path alias validation
end
if attached a_response.api.location_alias (f_path_alias) as l_aliased_location then
fd.report_invalid_field ("path_alias", "Path is already aliazed to location %"" + l_aliased_location + "%" !")
if
attached a_response.api.source_of_path_alias (f_path_alias) as l_aliased_location
then
fd.report_invalid_field ("path_alias", "Path is already aliased to location %"" + a_response.link (Void, l_aliased_location, Void) + "%" !")
end
end
end(?, response)

View File

@@ -326,18 +326,17 @@ feature -- Path aliases
end
end
source_of_path_alias (a_alias: READABLE_STRING_8): READABLE_STRING_8
source_of_path_alias (a_alias: READABLE_STRING_8): detachable READABLE_STRING_8
-- Resolved path for alias `a_alias'.
--| the CMS supports aliases for path, and then this function simply returns
--| the effective target path/url for this `a_alias'.
--| For instance: articles/2015/may/this-is-an-article can be an alias to node/123
--| This function will return "node/123".
--| If the alias is bad (i.e does not alias real path), then this function
--| returns the alias itself.
--| returns Void.
do
Result := a_alias
if attached storage.source_of_path_alias (Result) as l_path then
Result := l_path
if attached storage.source_of_path_alias (a_alias) as l_source_path then
Result := l_source_path
end
end

View File

@@ -38,7 +38,11 @@ feature {WSF_ROUTER_MAPPING} -- Dispatch helper
if not l_path.is_empty and l_path [1] = '/' then
l_path.remove_head (1)
end
Result := api.source_of_path_alias (l_path)
if attached api.source_of_path_alias (l_path) as l_aliased_path then
Result := l_aliased_path
else
Result := l_path
end
if Result.is_empty then
Result := "/"
elseif Result [1] /= '/' then
@@ -49,4 +53,7 @@ feature {WSF_ROUTER_MAPPING} -- Dispatch helper
end
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end