Permalink
Browse files

Added optional 'cat' argument to resource_page; when requesting a

page, the controller will now return a 404 when requested id is not
the specified cat.
  • Loading branch information...
1 parent 7654f05 commit 45bca641cab5c15a780dfbb5b7da0e53f5afcd1e @arjan arjan committed Mar 15, 2010
Showing with 8 additions and 1 deletion.
  1. +8 −1 modules/mod_base/resources/resource_page.erl
@@ -32,7 +32,14 @@ resource_exists(ReqData, Context) ->
Context1 = ?WM_REQ(ReqData, Context),
ContextQs = z_context:ensure_qs(Context1),
try
- ?WM_REPLY(m_rsc:exists(get_id(ContextQs), ContextQs), ContextQs)
+ Id = get_id(ContextQs),
+ true = m_rsc:exists(Id, ContextQs),
@kaos

kaos Nov 14, 2012

Owner

Is it really a good idea to blow up here if the resource doesn't exist?

I'd propose to include the exist check in the case:

case {m_rsc:exists(Id, ContextQs), z_context:get(cat, ContextQs)} of
  {Exists, undefined} -> ?WM_REPLY(Exists, ContextQs);
  {true, Cat} -> ?WM_REPLY(m_rsc:is_a(Id, Cat, ContextQs), ContextQs);
  _ -> ?WM_REPLY(false, ContextQs)
end
@kaos

kaos Nov 14, 2012

Owner

committed in ae823f4.

+ case z_context:get(cat, ContextQs) of
+ undefined ->
+ ?WM_REPLY(true, ContextQs);
+ Cat ->
+ ?WM_REPLY(m_rsc:is_a(Id, Cat, ContextQs), ContextQs)
+ end
catch
_:_ -> ?WM_REPLY(false, ContextQs)
end.

2 comments on commit 45bca64

Owner

arjan replied Nov 14, 2012

That looks nice, so if the rsc does not match the cat, it will give a 404?

Owner

kaos replied Nov 14, 2012

Yep, as you intended. I haven't looked at what it does when the resource doesn't exist, but it feels more "right"(tm) returning false rather than failing with a pattern missmatch.

Just wanted to make sure I wasn't missing something (like yesterday ;) before committing it... I'll go ahead with it, then.

Please sign in to comment.