Skip to content

Commit

Permalink
rename member -> membership
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Jan 12, 2024
1 parent 2aa6cea commit 3e9a001
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 206 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -48,6 +48,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-refresh": "^0.14.0",
"spark-md5": "^3.0.2",
"tailwind-merge": "^1.12.0",
"tailwindcss": "^3.3.1",
"tailwindcss-animate": "^1.0.5",
Expand Down
23 changes: 12 additions & 11 deletions src/sb/app/account/data.cljc
Expand Up @@ -36,26 +36,27 @@
:prepare az/with-account-id!}
[{:keys [account-id]}]
(into []
(comp (map :member/entity)
(comp (map :membership/entity)
(filter (comp #{:org} :entity/kind))
(map (q/pull entity.data/entity-keys)))
(db/where [[:member/account account-id]])))
(db/where [[:membership/account account-id]])))

(q/defquery all
{:endpoint {:query true}
:prepare az/with-account-id!}
[{:keys [account-id]}]
(u/timed `all
(->> (q/pull '[{:member/_account [:member/roles
{:member/entity [:entity/id
:entity/kind
:entity/title
:entity/created-at
{:image/avatar [:entity/id]}
{:image/background [:entity/id]}]}]}]
(->> (q/pull '[{:membership/_account
[:membership/roles
{:membership/entity [:entity/id
:entity/kind
:entity/title
:entity/created-at
{:image/avatar [:entity/id]}
{:image/background [:entity/id]}]}]}]
account-id)
:member/_account
(map #(u/lift-key % :member/entity)))))
:membership/_account
(map #(u/lift-key % :membership/entity)))))

#?(:clj
(defn login!
Expand Down
44 changes: 22 additions & 22 deletions src/sb/app/board/data.cljc
Expand Up @@ -103,7 +103,7 @@

(q/defquery show
{:prepare [(az/with-roles :board-id)]}
[{:keys [board-id member/roles]}]
[{:keys [board-id membership/roles]}]
(u/timed `show
(if-let [board (db/pull `[~@entity.data/entity-keys
:entity/member-tags
Expand All @@ -112,46 +112,46 @@
:board/registration-open?
{:entity/parent [~@entity.data/entity-keys :org/show-org-tab?]}]
board-id)]
(merge board {:member/roles roles})
(merge board {:membership/roles roles})
(throw (ex-info "Board not found!" {:status 400})))))

(def project-fields `[~@entity.data/entity-keys])
(def member-fields [{:member/account [:entity/id
:entity/kind
{:image/avatar [:entity/id]}
:account/display-name]}
(def member-fields [{:membership/account [:entity/id
:entity/kind
{:image/avatar [:entity/id]}
:account/display-name]}
{:entity/tags [:entity/id
:tag/label
:tag/color]}
:entity/field-entries
{:member/entity [:entity/id]}
{:membership/entity [:entity/id]}
{:entity/custom-tags [:tag/label]}
:member/roles])
:membership/roles])

(q/defquery members
{:prepare [(az/with-roles :board-id)]}
[{:keys [board-id member/roles]}]
[{:keys [board-id membership/roles]}]
(u/timed `members
(->> (db/where [[:member/entity board-id]])
(remove :entity/archived?)
(->> (db/where [[:membership/entity board-id]])
(remove (some-fn :entity/deleted-at :entity/archived?))
(mapv (db/pull `[~@entity.data/entity-keys
~@member-fields])))))

(q/defquery projects
{:prepare [(az/with-roles :board-id)]}
[{:keys [board-id member/roles]}]
[{:keys [board-id membership/roles]}]
(u/timed `projects
(->> (db/where [[:entity/parent board-id]])
(remove (some-fn :entity/draft? :entity/archived?))
(remove (some-fn :entity/draft? :entity/deleted-at :entity/archived?))
(mapv (db/pull project-fields)))))

(q/defquery drafts
{:prepare az/with-account-id}
[{:keys [account-id]}]
(into []
(comp (filter (comp (every-pred :entity/draft? #(= :project (:entity/kind %))) :member/entity))
(map #(db/pull project-fields (:member/entity %))))
(db/where [[:member/account (dl/resolve-id account-id)]])))
(comp (filter (comp (every-pred :entity/draft? #(= :project (:entity/kind %))) :membership/entity))
(map #(db/pull project-fields (:membership/entity %))))
(db/where [[:membership/account (dl/resolve-id account-id)]])))

(defn authorize-edit! [board account-id]
(when-not (or (validate/can-edit? account-id board)
Expand All @@ -168,10 +168,10 @@
(let [board (-> (dl/new-entity board :board :by account-id)
(validate/conform :board/as-map))
_ (authorize-create! board account-id)
member (-> {:member/entity board
:member/account account-id
:member/roles #{:role/admin}}
(dl/new-entity :member))]
member (-> {:membership/entity board
:membership/account account-id
:membership/roles #{:role/admin}}
(dl/new-entity :membership))]
(db/transact! [member])
board))

Expand All @@ -181,14 +181,14 @@
(fn [_ {:as params :keys [board-id account-id]}]
(validate/assert-can-edit! account-id (dl/entity board-id))
params)]}
[{:keys [board-id member/roles]}]
[{:keys [board-id membership/roles]}]
(u/timed `settings
(some->
(q/pull `[~@entity.data/entity-keys
:entity/member-tags
{:entity/member-fields ~field.data/field-keys}
{:entity/project-fields ~field.data/field-keys}] board-id)
(merge {:member/roles roles}))))
(merge {:membership/roles roles}))))
(comment
[:ul ;; i18n stuff
[:li "suggested locales:" (str (:entity/locale-suggestions board))]
Expand Down
7 changes: 4 additions & 3 deletions src/sb/app/board/ui.cljc
Expand Up @@ -68,12 +68,13 @@
(ui/defview register
{:route "/b/:board-id/register"}
[{:as params :keys [route]}]
(ui/with-form [!member {:member/name ?name :member/password ?pass}]
(ui/with-form [!membership {:membership/name ?name
:membership/password ?pass}]
[:div
[:h3 (t :tr/register)]
[field.ui/text-field ?name nil]
[field.ui/text-field ?pass nil]
[:button {:on-click #(p/let [res (routing/POST route @!member)]
[:button {:on-click #(p/let [res (routing/POST route @!membership)]
;; TODO - how to determine POST success?
#_(when (http-ok? res)
(routing/nav! [:board/read params])
Expand All @@ -99,7 +100,7 @@
(ui/defview show
{:route "/b/:board-id"}
[{:as params :keys [board-id]}]
(let [{:as board :keys [member/roles]} (data/show {:board-id board-id})
(let [{:as board :keys [membership/roles]} (data/show {:board-id board-id})
!current-tab (h/use-state (t :tr/members #_:tr/projects))
?filter (h/use-memo #(io/field))]
[:<>
Expand Down
8 changes: 4 additions & 4 deletions src/sb/app/entity/data.cljc
Expand Up @@ -33,7 +33,7 @@
:org
:board
:collection
:member
:membership
:project
:field
:discussion
Expand Down Expand Up @@ -123,16 +123,16 @@

(def rules
{:entity/tags (fn validate-changed-tags [roles k entity m]
(when-not (= :member (:entity/kind entity))
(when-not (= :membership (:entity/kind entity))
(validate/validation-failed! "Only members may have tags"))
(let [tags-before (into #{} (map :tag/id) (k entity))
tags-after (into #{} (map :tag/id) (k m))
tags-changed (concat
(set/difference tags-before tags-after) ;; removed
(set/difference tags-after tags-before)) ;; added
admin? (:role/board-admin roles)]
admin? (:role/board-admin roles)]
(when (seq tags-changed)
(let [tag-defs (-> entity :member/entity :entity/member-tags (u/index-by :tag/id))]
(let [tag-defs (-> entity :membership/entity :entity/member-tags (u/index-by :tag/id))]
(doseq [tag-id tags-changed ;; added
:let [tag (get tag-defs tag-id)]
:when (:tag/restricted? tag)]
Expand Down
2 changes: 1 addition & 1 deletion src/sb/app/entity/ui.cljc
Expand Up @@ -94,7 +94,7 @@
(ui/defview row
{:key :entity/id}
[{:as entity
:keys [entity/title member/roles]}]
:keys [entity/title membership/roles]}]
[:div.flex.hover:bg-gray-100.rounded-lg
[:a.flex.relative.gap-3.items-center.p-2.cursor-default.flex-auto
{:href (routing/entity-path entity 'ui/show)}
Expand Down
8 changes: 4 additions & 4 deletions src/sb/app/field/ui.cljc
Expand Up @@ -412,7 +412,7 @@
(io/field :many {:badge/label ?label
:badge/color (?color :default "#dddddd")}
:init init))}
[?badges {:as props :keys [member/roles]}]
[?badges {:as props :keys [membership/roles]}]
(when (or (seq ?badges)
(:role/board-admin roles))
(plural-editor (merge props
Expand All @@ -437,7 +437,7 @@
[:div.relative.w-10.h-10.overflow-hidden.rounded.outline.outline-black.outline-1 [color-field ?color {:field/can-edit? true}]]
[:button.flex.items-center {:type "submit"} [icons/checkmark "w-5 h-5 icon-gray"]]])
:show-?item (fn [{:as ?badge
:syms [?label ?color]} {:keys [member/roles]}]
:syms [?label ?color]} {:keys [membership/roles]}]
(let [bg (or (u/some-str @?color) "#ffffff")
color (color/contrasting-text-color bg)]
(v/x [:div.rounded.bg-badge.text-badge-txt.py-1.px-2.text-sm.inline-flex
Expand Down Expand Up @@ -689,10 +689,10 @@
{:make-?field (fn [init _props]
(io/field :many {:tag/id ?id}
:init init))}
[?tags {:as props :keys [field/can-edit? member/roles]}]
[?tags {:as props :keys [field/can-edit? membership/roles]}]
(let [all-tags (-> (io/closest ?tags :db/id)
db/entity
:member/entity
:membership/entity
:entity/member-tags)
by-id (reduce #(assoc %1 (:tag/id %2) %2) {} all-tags)
selected (into #{} (map :tag/id) @?tags)
Expand Down

0 comments on commit 3e9a001

Please sign in to comment.