Commits

Anonymous committed 90fb189

apply the read mask in results returned from jaywalker

Comments (0)

Files changed (2)

src/jaywalker_resource.erl

             {execute_segment(JiakClient, StartBKs,SafeQuery++[LastSafe]),
              UnsafeQuery}
      end,
-    [SegResults|execute_query(JiakClient,SegResults,Leftover)].
+    [[jiak_resource:apply_read_mask(R) || R <- SegResults]
+     |execute_query(JiakClient,SegResults,Leftover)].
 
 execute_segment(JiakClient, Start, Steps) ->
     MR = [{link, Bucket, Key, false} || {Bucket, Key, _} <- Steps]

src/jiak_resource.erl

 	 last_modified/2,
 	 generate_etag/2,
 	 expires/2,
-         apply_read_mask/2,
+         apply_read_mask/1,
          pretty_print/2]).
 
 -define(JIAK_REQUIRED_PROPS, [allowed_fields, required_fields, read_mask,
 get_jiak_module(ReqData) ->
     case bucket_from_uri(ReqData) of
         {ok, Bucket} when is_atom(Bucket) ->
-            case code:which(Bucket) of
-                non_existing ->
-                    case default_jiak_module(Bucket) of
-                        undefined -> undefined;
-                        Mod when is_tuple(Mod) -> Mod
-                    end;
-                ModPath when is_list(ModPath) -> Bucket
-            end;
+            jiak_module_for_bucket(Bucket);
         {error, no_such_bucket} -> 
             undefined
     end.
 
+jiak_module_for_bucket(Bucket) when is_atom(Bucket) ->
+    case code:which(Bucket) of
+        non_existing ->
+            case default_jiak_module(Bucket) of
+                undefined -> undefined;
+                Mod when is_tuple(Mod) -> Mod
+            end;
+        ModPath when is_list(ModPath) -> Bucket
+    end.
+
 service_available(ReqData, Context=#ctx{key=container}) ->
     {ServiceAvailable, NewCtx} = 
         case wrq:method(ReqData) of
 				   incoming=NewObj}}
     end.
 
+%% @spec apply_read_mask(jiak_object()) -> jiak_object()
+%% @doc Remove fields from the jiak object that are not in the
+%%      bucket's read mask.  Determines the module to use, then
+%%      calls apply_read_mask/2.
+apply_read_mask(JiakObject={struct,_}) ->
+    Bucket = jiak_object:bucket(JiakObject),
+    apply_read_mask(jiak_module_for_bucket(Bucket), JiakObject).
+
 %% @spec apply_read_mask(jiak_module(), jiak_object()) -> jiak_object()
 %% @doc Remove fields from the jiak object that are not in the
-%%      bucket's read maks.
+%%      bucket's read mask.
 apply_read_mask(Module, JiakObject={struct,_}) ->
     {struct, OldData} = jiak_object:object(JiakObject),
     NewData = apply_read_mask1(OldData, Module:read_mask(), []),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.