|
3 | 3 | (defvalidator validate-board
|
4 | 4 | (("id" :type id :required t)
|
5 | 5 | ("user_id" :type id :required t)
|
| 6 | + ("parent_id" :type id) |
6 | 7 | ("keys" :type sequence :required t :coerce simple-vector)
|
7 |
| - ("body" :type cl-async-util:bytes-or-string))) |
| 8 | + ("body" :type cl-async-util:bytes-or-string)) |
| 9 | + :old t) |
8 | 10 |
|
9 | 11 | (defafun populate-boards-data (future) (boards &key (get-privs t) get-notes get-personas)
|
10 | 12 | "Populate certain information given a list of boards."
|
|
32 | 34 | (finish future boards))))
|
33 | 35 | (finish future boards)))
|
34 | 36 |
|
35 |
| -(defafun get-affected-users-from-board-ids (future) (board-ids) |
| 37 | +(adefun get-all-boards (user-id persona-ids) |
| 38 | + "Given a user id and list of persona ids, get all boards this user has access |
| 39 | + to." |
| 40 | + (declare (ignore persona-ids)) |
| 41 | + ;; TODO: actually build this function out and make it useful. until then, we |
| 42 | + ;; rely on old (and slow) tricks |
| 43 | + (get-user-boards user-id :get-persona-boards t :get-personas t)) |
| 44 | + |
| 45 | +(adefun get-affected-users-from-board-ids (board-ids) |
36 | 46 | "For all given board-ids (list), find users that will be affected by changes
|
37 | 47 | to those boards or items in those boards. Returns a list of user-ids."
|
| 48 | + (unless board-ids |
| 49 | + (return-from get-affected-users-from-board-ids)) |
38 | 50 | (alet* ((sock (db-sock))
|
39 | 51 | (query (r:r
|
40 | 52 | (:attr
|
|
64 | 76 | (board-user-ids (r:to-array sock cursor))
|
65 | 77 | (nil (r:stop sock cursor)))
|
66 | 78 | (r:disconnect sock)
|
67 |
| - (finish future (concatenate 'vector shared-user-ids board-user-ids)))) |
| 79 | + (concatenate 'vector shared-user-ids board-user-ids))) |
68 | 80 |
|
69 |
| -(defafun get-user-boards (future) (user-id &key get-persona-boards get-notes get-personas) |
| 81 | +(adefun get-user-boards (user-id &key get-persona-boards get-notes get-personas) |
70 | 82 | "Get all boards for a user."
|
71 | 83 | (alet* ((sock (db-sock))
|
72 | 84 | (query (r:r (:get-all
|
|
84 | 96 | (boards-populated (populate-boards-data all-boards
|
85 | 97 | :get-notes get-notes
|
86 | 98 | :get-personas get-personas)))
|
87 |
| - (finish future boards-populated)))) |
| 99 | + boards-populated))) |
88 | 100 |
|
89 |
| -(defafun get-all-user-board-ids (future) (user-id &key shared) |
| 101 | +(defafun get-all-user-board-ids (future) (user-id &key shared persona-ids) |
90 | 102 | "Gets ALL a user's board IDs, with option to specify grabbing shared boards."
|
91 |
| - (alet* ((persona-ids (if shared |
92 |
| - (get-user-persona-ids user-id) |
93 |
| - #())) |
| 103 | + (alet* ((persona-ids (if persona-ids |
| 104 | + persona-ids |
| 105 | + (if shared |
| 106 | + (get-user-persona-ids user-id) |
| 107 | + #()))) |
94 | 108 | (sock (db-sock)))
|
95 | 109 | (flet ((get-user-board-ids (append)
|
96 | 110 | (alet* ((query (r:r (:attr
|
|
116 | 130 | (r:stop sock cursor)
|
117 | 131 | (get-user-board-ids board-ids))))))
|
118 | 132 |
|
| 133 | +(adefun get-user-board-perms (user-id &key min-perms) |
| 134 | + "Grab all a users boards, including shared, with permissions." |
| 135 | + (alet* ((persona-ids (get-user-persona-ids user-id)) |
| 136 | + (user-board-ids (get-all-user-board-ids user-id)) |
| 137 | + (sock (db-sock)) |
| 138 | + (qry (r:r (:pluck |
| 139 | + (:zip |
| 140 | + (:eq-join |
| 141 | + (:get-all |
| 142 | + (:table "boards_personas_link") |
| 143 | + (coerce persona-ids 'list) |
| 144 | + :index (db-index "boards_personas_link" "to")) |
| 145 | + "board_id" |
| 146 | + (:table "boards"))) |
| 147 | + (list "user_id" "board_id" "perms")))) |
| 148 | + (cursor (r:run sock qry)) |
| 149 | + (shared (r:to-array sock cursor)) |
| 150 | + (index (hash))) |
| 151 | + (r:stop/disconnect sock cursor) |
| 152 | + ;; set permissions for shared boards |
| 153 | + (loop for entry across shared |
| 154 | + for id = (gethash "board_id" entry) |
| 155 | + for perms = (gethash "perms" entry) do |
| 156 | + (when (or (not min-perms) |
| 157 | + (<= min-perms perms)) |
| 158 | + (setf (gethash id index) (hash ("id" id) |
| 159 | + ("owner" (gethash "user_id" entry)) |
| 160 | + ("perms" perms))))) |
| 161 | + ;; set user-owned to the "owned" permission (3) in the index |
| 162 | + (loop for id across user-board-ids |
| 163 | + for perms = 3 do |
| 164 | + (when (or (not min-perms) |
| 165 | + (<= min-perms perms)) |
| 166 | + (setf (gethash id index) (hash ("id" id) |
| 167 | + ("owner" user-id) |
| 168 | + ("perms" perms))))) |
| 169 | + index)) |
| 170 | + |
119 | 171 | (defafun get-persona-boards (future) (persona-id &key populate get-notes)
|
120 | 172 | "Get all boards for a persona."
|
121 | 173 | (alet* ((sock (db-sock))
|
|
177 | 229 | (defafun add-board (future) (user-id board-data)
|
178 | 230 | "Save a board with a user."
|
179 | 231 | (setf (gethash "user_id" board-data) user-id)
|
180 |
| - (add-id board-data) |
181 | 232 | (let ((cid (gethash "cid" board-data)))
|
182 | 233 | (validate-board (board-data future)
|
183 | 234 | (alet* ((sock (db-sock))
|
|
260 | 311 | (defafun get-user-board-permissions (future) (user/persona-id board-id)
|
261 | 312 | "Returns an integer used to determine a user/persona's permissions for the
|
262 | 313 | given board.
|
263 |
| - |
| 314 | +
|
264 | 315 | 0 == no permissions
|
265 | 316 | 1 == read permissions
|
266 | 317 | 2 == update permissions
|
|
388 | 439 | (finish future entry)))
|
389 | 440 |
|
390 | 441 | (defafun add-board-remote-invite (future) (user-id board-id from-persona-id invite-id permission-value to-email)
|
391 |
| - "Creates a remote (ie email) invite permission record on a board so the |
| 442 | + "Creates a remote (ie email) invite permission record on a board so the |
392 | 443 | recipient of an invite can join the board without knowing what their account
|
393 | 444 | will be in advance."
|
394 | 445 | (alet* ((email (obscure-email to-email)))
|
|
0 commit comments