Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created August 25, 2021 18:15
Show Gist options
  • Save camsaul/07ee8b34d34fda3cf08ba8c0a9e56aa2 to your computer and use it in GitHub Desktop.
Save camsaul/07ee8b34d34fda3cf08ba8c0a9e56aa2 to your computer and use it in GitHub Desktop.
Metabase data permissions graph spec
(ns metabase.models.permissions.graph.data
(:require [clojure.spec.alpha :as s]))
(s/def ::id
(s/and int? pos?))
(s/def :metabase.models.permissions.graph.data.table/read
#{:all :none})
(s/def :metabase.models.permissions.graph.data.table/query
#{:all :none :segmented})
(s/def ::table
(s/or
:key #{:none :all}
:map (s/keys :req-un [(or :metabase.models.permissions.graph.data.table/read
:metabase.models.permissions.graph.data.table/query)])))
(s/def ::schema
(s/or
:key #{:none :all}
;; TODO -- should the map be required to be non-empty?
:map (s/map-of ::id ::table)))
(s/def ::schemas
(s/or
:key #{:all :none :block}
;; TODO -- should the map be required to be non-empty?
:map (s/map-of string? ::schema)))
(s/def ::native
#{:write :none})
(s/def ::database
;; TODO -- should this be required to be non-empty?
;; TODO -- constrain allowed together.
(s/keys :opt-un [::schemas ::native]))
(s/def ::group
(s/map-of ::id ::database))
(s/def ::groups
(s/map-of ::id ::group))
(s/def ::revision int?)
(s/def ::graph
(s/keys :req-un [::groups ::revision]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment