       (let [{:keys [cast! db]} (om/get-shared owner)
             doc-id (:document/id app)
             doc (doc-model/find-by-id @db doc-id)
-            no-private-docs? (not (contains? (get-in app [:cust :flags]) :flags/private-docs))
-            cant-edit-privacy? (when-not (:team app)
-                                 (not (auth/owner? @db doc (get-in app [:cust]))))]
+            team? (boolean (:team app))
+            private-docs-flag? (contains? (get-in app [:cust :flags]) :flags/private-docs)
+            can-edit-privacy? (if team?
+                                (auth/has-team-permission? app (:team/uuid (:team app)))
+                                (auth/owner? @db doc (get-in app [:cust])))]
         (html
          [:section.menu-view
           (case (:document/privacy doc)

                                  :name "privacy"
                                  :checked (keyword-identical? :document.privacy/public (:document/privacy doc))
                                  :disabled (keyword-identical? :document.privacy/public (:document/privacy doc))
                                  :onChange #(if cant-edit-privacy?
                                               (utils/stop-event %)
                                               (cast! :document-privacy-changed
                                                      {:doc-id doc-id
                                                       :setting :document.privacy/public}))}]
           [:label.privacy-label {:class (when cant-edit-privacy? "disabled")
                                  :title (when cant-edit-privacy? "You must be the owner of this doc to change its privacy.")
                                  :for "privacy-public"
                                  :role "button"}
            (common/icon :public)
            [:span "Public"]
            (when cant-edit-privacy?
              [:small "(privacy change requires owner)"])]
           [:input.privacy-radio {:type "radio"
                                  :hidden "true"
                                  :id "privacy-read-only"
                                  :name "privacy"
                                  :checked (keyword-identical? :document.privacy/read-only (:document/privacy doc))
                                  :disabled cant-edit-privacy?
                                  :onChange #(if cant-edit-privacy?
                                               (utils/stop-event %)
                                               (cast! :document-privacy-changed
                                                      {:doc-id doc-id
                                                       :setting :document.privacy/read-only}))}]
           [:label.privacy-label {:class (when cant-edit-privacy? "disabled")
                                  :title (when cant-edit-privacy? "You must be the owner of this doc to change its privacy.")
                                  :for "privacy-read-only"
                                  :role "button"}
            (common/icon :read-only)
            [:span "Read-only"]
            (when cant-edit-privacy?
              [:small "(privacy change requires owner)"])]
           (if no-private-docs?
             [:a.vein.external {:href "/pricing"}
              (common/icon :private)
              [:span "Private"]

                                     :id "privacy-private"
                                     :name "privacy"
                                     :checked (keyword-identical? :document.privacy/private (:document/privacy doc))
                                     :disabled (not can-edit-privacy?)
                                     :onChange #(if can-edit-privacy?
                                                  (cast! :document-privacy-changed
                                                         {:doc-id doc-id
                                                          :setting :document.privacy/private})
                                                  (utils/stop-event %))}]
              [:label.privacy-label {:class (when-not can-edit-privacy? "disabled")
                                     :title (when-not can-edit-privacy? "You must be the owner of this doc to change its privacy.")
                                     :for "privacy-private"
                                     :role "button"}
               (common/icon :private)
               [:span "Private"]
               (when-not can-edit-privacy?
                 [:small "(privacy change requires owner)"])]))]])))))

(defn export [app owner]
