Skip to content
Snippets Groups Projects
Unverified Commit e976752d authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #7734 from metabase/collections-project-curate-permissions-ui

Collections project curate permissions UI
parents db4b02f6 a79f88fe
No related branches found
No related tags found
No related merge requests found
......@@ -161,7 +161,7 @@ class DefaultLanding extends React.Component {
<Box w={2 / 3}>
<Box>
<CollectionItemsLoader reload collectionId={collectionId || "root"}>
{({ allItems, pulses, cards, dashboards, empty }) => {
{({ collection, allItems, pulses, cards, dashboards, empty }) => {
let items = allItems;
if (!items.length) {
......@@ -224,16 +224,18 @@ class DefaultLanding extends React.Component {
/>
<Flex align="center">
<h3>{item.name}</h3>
<Box
ml="auto"
className="hover-child"
onClick={ev => {
ev.preventDefault();
this._unPinItem(item);
}}
>
<Icon name="pin" />
</Box>
{collection.can_write && (
<Box
ml="auto"
className="hover-child"
onClick={ev => {
ev.preventDefault();
this._unPinItem(item);
}}
>
<Icon name="pin" />
</Box>
)}
</Flex>
</Card>
</Link>
......@@ -262,7 +264,11 @@ class DefaultLanding extends React.Component {
name={item.name}
iconName={iconName}
iconColor={iconColor}
onPin={this._pinItem.bind(this)}
onPin={
collection.can_write
? this._pinItem.bind(this)
: null
}
/>
</Link>
</Box>
......@@ -308,60 +314,64 @@ class CollectionLanding extends React.Component {
</Subhead>
<Flex ml="auto">
<Box mx={1}>
<EntityMenu
items={[
{
title: t`New dashboard`,
icon: "dashboard",
link: `/questions/archive/`,
},
{
title: t`New pulse`,
icon: "pulse",
link: `/dashboards/archive`,
},
{
title: t`New collection`,
icon: "all",
link: `/dashboards/archive`,
},
]}
triggerIcon="add"
/>
</Box>
<Box mx={1}>
<EntityMenu
items={[
...(collectionId
? [
{
title: t`Edit this collection`,
icon: "editdocument",
link: `/collections/${currentCollection.id}`,
},
]
: []),
{
title: t`Edit permissions`,
icon: "lock",
link: `/collections/permissions?collectionId=${
currentCollection.id
}`,
},
...(collectionId
? [
{
title: t`Archive this collection`,
icon: "viewArchive",
link: `/collection/${collectionId}/archive`,
},
]
: []),
]}
triggerIcon="pencil"
/>
</Box>
{currentCollection.can_write && (
<Box mx={1}>
<EntityMenu
items={[
{
title: t`New dashboard`,
icon: "dashboard",
link: `/questions/archive/`,
},
{
title: t`New pulse`,
icon: "pulse",
link: `/dashboards/archive`,
},
{
title: t`New collection`,
icon: "all",
link: `/dashboards/archive`,
},
]}
triggerIcon="add"
/>
</Box>
)}
{currentCollection.can_write && (
<Box mx={1}>
<EntityMenu
items={[
...(collectionId
? [
{
title: t`Edit this collection`,
icon: "editdocument",
link: `/collections/${currentCollection.id}`,
},
]
: []),
{
title: t`Edit permissions`,
icon: "lock",
link: `/collections/permissions?collectionId=${
currentCollection.id
}`,
},
...(collectionId
? [
{
title: t`Archive this collection`,
icon: "viewArchive",
link: `/collection/${collectionId}/archive`,
},
]
: []),
]}
triggerIcon="pencil"
/>
</Box>
)}
<EntityMenu
items={[
{
......
......@@ -15,6 +15,7 @@ const CollectionItemsLoader = ({ collectionId, children, ...props }: Props) => (
children={({ object }) =>
object &&
children({
collection: object,
dashboards: object.dashboards,
cards: object.cards,
pulses: object.pulses,
......
......@@ -83,11 +83,10 @@
unspecified, it will return objects of all types."
[id model]
{model (s/maybe (s/enum "cards" "dashboards" "pulses"))}
(merge
(as-> (api/read-check Collection id, :archived false) <>
(hydrate <> :effective_location :effective_children :effective_ancestors)
(assoc <> :can_write (mi/can-write? <>)))
(collection-children model model->collection-children-fn id)))
(-> (api/read-check Collection id, :archived false)
(hydrate :effective_location :effective_children :effective_ancestors :can_write)
(merge (collection-children model model->collection-children-fn id))))
(api/defendpoint GET "/root"
"Fetch objects in the 'root' Collection. (The 'root' Collection doesn't actually exist at this point, so this just
......@@ -97,6 +96,7 @@
(merge
{:name (tru "Root Collection")
:id "root"
:can_write api/*is-superuser?* ; temporary until Root Collection perms are merged !
:effective_location "/"
:effective_children (collection/effective-children collection/root-collection)
:effective_ancestors []}
......
......@@ -102,7 +102,7 @@
(defn- remove-ids-from-collection-detail [results & {:keys [keep-collection-id?]
:or {keep-collection-id? false}}]
(into {} (for [[k items] (select-keys results (cond->> [:name :cards :dashboards :pulses]
(into {} (for [[k items] (select-keys results (cond->> [:name :cards :dashboards :pulses :can_write]
keep-collection-id? (cons :id)))]
[k (if-not (sequential? items)
items
......@@ -125,7 +125,8 @@
{:name "Debt Collection"
:cards [{:name "Birthday Card", :collection_position nil}]
:dashboards [{:name "Dine & Dashboard", :collection_position nil}]
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]}
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]
:can_write false}
(tt/with-temp Collection [collection {:name "Debt Collection"}]
(perms/grant-collection-read-permissions! (group/all-users) collection)
(with-some-children-of-collection collection
......@@ -135,7 +136,8 @@
;; ...and that you can also filter so that you only see the children you want to see
(expect
{:name "Art Collection"
:dashboards [{:name "Dine & Dashboard", :collection_position nil}]}
:dashboards [{:name "Dine & Dashboard", :collection_position nil}]
:can_write false}
(tt/with-temp Collection [collection {:name "Art Collection"}]
(perms/grant-collection-read-permissions! (group/all-users) collection)
(with-some-children-of-collection collection
......@@ -245,7 +247,8 @@
:id "root"
:cards [{:name "Birthday Card", :collection_position nil}]
:dashboards [{:name "Dine & Dashboard", :collection_position nil}]
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]}
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]
:can_write true}
(with-some-children-of-collection nil
(-> ((user->client :crowberto) :get 200 "collection/root")
(remove-ids-from-collection-detail :keep-collection-id? true))))
......@@ -256,7 +259,8 @@
:id "root"
:cards []
:dashboards [{:name "Dine & Dashboard", :collection_position nil}]
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]}
:pulses [{:name "Electro-Magnetic Pulse", :collection_position nil}]
:can_write false}
;; create a fake DB and don't give all users perms to it
(tt/with-temp* [Database [db]
Table [table {:db_id (u/get-id db)}]]
......@@ -272,9 +276,10 @@
;; Make sure this endpoint can also filter things
(expect
{:name "Root Collection"
:id "root"
:cards [{:name "Birthday Card", :collection_position nil}]}
{:name "Root Collection"
:id "root"
:cards [{:name "Birthday Card", :collection_position nil}]
:can_write true}
(with-some-children-of-collection nil
(-> ((user->client :crowberto) :get 200 "collection/root?model=cards")
(remove-ids-from-collection-detail :keep-collection-id? true))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment