Browse Source

Add action struct

master
Christian Fischer 9 months ago
parent
commit
8935f79ff8
2 changed files with 72 additions and 18 deletions
  1. +15
    -1
      server/privileges.rkt
  2. +57
    -17
      server/resource.rkt

+ 15
- 1
server/privileges.rkt View File

@@ -1,12 +1,26 @@
#lang racket

(provide minimum-access-mask
(provide (struct-out action)
minimum-access-mask
maximum-access-mask
mask-join
apply-mask
is-action-set?
is-mask-for?)

(struct
action
(id
fun
params)
#:transparent)


;; (define (run-action action resource)
;; TODO add check that action matches resource type
;; (let ((data (resource-data resource)))
;; (action-fun

;; An action set is the hash-of-lists-of-functions that define the
;; actions available on a resource type
(define (is-action-set? actions)


+ 57
- 17
server/resource.rkt View File

@@ -98,23 +98,63 @@

(struct file-data (path metadata-key))

(define (no-access-action)
'nothing)

(define (view-file path)
(file->string path
#:mode 'text))

(define (edit-file path contents)
(write-to-file contents
path
#:exists 'replace))

(define (view-metadata dbc key)
(redis-bytes-get dbc key))

(define (edit-metadata dbc key value)
(redis-bytes-set! dbc key value))
;; (define (no-access-action)
;; 'nothing)

(define no-access-action
(action "no-access"
(lambda ()
'no-access)
'()))

;; (define (view-file data)
;; (file->string (hash-ref data 'path)
;; #:mode 'text))

;; (define (edit-file path contents)
;; (write-to-file contents
;; path
;; #:exists 'replace))

(define view-file
(action "view"
(lambda (data)
(file->string (hash-ref data 'path) #:mode 'text))
'()))

(define edit-file
(action "edit"
(lambda (data contents)
(write-to-file contents
(hash-ref data 'path)
#:exists 'replace))))



;; TODO the dbc should be passed as a Racket parameter rather than an action param


;; params should be provided as keyword arguments
(define view-metadata
(action "view"
(lambda (data dbc)
(redis-bytes-get dbc
(hash-ref data 'key)))
'(dbc)))

(define edit-metadata
(action "edit"
(lambda (data dbc value)
(redis-bytes-set! dbc
(hash-ref data 'key)
value))
'(dbc value)))

;; (define (view-metadata dbc key)
;; (redis-bytes-get dbc key))

;; (define (edit-metadata dbc key value)
;; (redis-bytes-set! dbc key value))

(define dataset-file-data
(list (cons "no-access" no-access-action)


Loading…
Cancel
Save