@@ -33,13 +33,33 @@ | |||
group-masks) | |||
#:transparent) | |||
;; The Racket JSON library can only transform hashes that have | |||
;; symbol keys -- but Redis only deals with strings and bytestrings. | |||
;; These functions transform the keys of a hash between the two. | |||
(define (hash-symbol->string h) | |||
(for/hash ([(k v) (in-hash h)]) | |||
(values (~> k | |||
(symbol->string) | |||
(string->bytes/utf-8)) | |||
v))) | |||
(define (hash-string->symbol h) | |||
(for/hash ([(k v) (in-hash h)]) | |||
(values (~> k | |||
(bytes->string/utf-8) | |||
(string->symbol)) | |||
v))) | |||
;; Serializes a resource into a JSON bytestring for storage in Redis. | |||
(define (serialize-resource res) | |||
(jsexpr->bytes (hash 'name (resource-name res) | |||
'owner_id (resource-owner res) | |||
'data (resource-data res) | |||
'type (symbol->string (resource-type res)) | |||
'default_mask (resource-default-mask res) | |||
'default_mask (hash-symbol->string | |||
(resource-default-mask res)) | |||
'group_masks (resource-group-masks res)))) | |||
(define (deserialize-resource res) | |||
@@ -50,7 +70,8 @@ | |||
(parse 'owner_id) | |||
(parse 'data) | |||
(string->symbol (parse 'type)) | |||
(parse 'default_mask) | |||
(hash-string->symbol | |||
(parse 'default_mask)) | |||
(parse 'group_masks)))) | |||
(define (get-resource id) | |||
@@ -12,7 +12,6 @@ | |||
web-server/web-server | |||
(prefix-in filter: web-server/dispatchers/dispatch-filter) | |||
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer) | |||
"db.rkt" | |||
"groups.rkt" | |||
"privileges.rkt" | |||
@@ -37,8 +36,9 @@ | |||
(let* ((res (get-resource res-id)) | |||
(mask (get-mask-for-user | |||
res | |||
(string->number | |||
(bytes->string/utf-8 user-id))))) | |||
(~> user-id | |||
(bytes->string/utf-8) | |||
(string->number))))) | |||
(~> (apply-mask (dict-ref resource-types | |||
(resource-type res)) | |||
mask) | |||
@@ -73,13 +73,16 @@ | |||
(binding:form _ user-id) | |||
(binding:form _ branch) | |||
(binding:form _ action)) | |||
(let* ((res (get-resource res-id))) | |||
(let* ((res (get-resource res-id)) | |||
(branch (~> branch | |||
(bytes->string/utf-8) | |||
(string->symbol))) | |||
(action (bytes->string/utf-8 action))) | |||
(let ((action (access-action res | |||
(string->number | |||
(bytes->string/utf-8 user-id)) | |||
(cons (string->symbol | |||
(bytes->string/utf-8 branch)) | |||
(bytes->string/utf-8 action))))) | |||
(~> user-id | |||
(bytes->string/utf-8) | |||
(string->number)) | |||
(cons branch action)))) | |||
(if action | |||
(run-action action | |||
(resource-data res) | |||
@@ -92,11 +95,6 @@ | |||
(define (run-action-dispatcher conn req) | |||
(output-response conn (run-action-endpoint req))) | |||
;; Attempt to run an action on a resource as a given user | |||
;; TODO | |||
;; Run the server (will be moved to another module later) | |||
(define stop | |||
(serve | |||