Skip to content

Commit

Permalink
Disable uploads, project creation and moving when read only (#3744)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikehrn authored Dec 23, 2024
1 parent 218de0e commit baea53e
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<FormFileUploadZone
ref="uploadZone"
v-slot="{ isDraggingFiles }"
:disabled="isUploading"
:disabled="isUploading || disabled"
:size-limit="maxSizeInBytes"
:accept="accept"
class="flex items-center h-full"
Expand Down Expand Up @@ -64,6 +64,7 @@ import {
const props = defineProps<{
projectId: string
modelName?: string
disabled?: boolean
}>()
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template>
<div class="text-foreground-2 text-sm flex flex-col items-center space-y-1">
<div
class="text-foreground-2 text-body-xs flex flex-col items-center justify-center space-y-1"
>
<template
v-if="
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ref="importArea"
:project-id="project.id"
:model-name="project.model.name"
:disabled="project.workspace?.readOnly"
class="h-full w-full"
/>
</div>
Expand Down Expand Up @@ -140,6 +141,10 @@ graphql(`
}
...ProjectModelPageVersionsPagination
...ProjectsModelPageEmbed_Project
workspace {
id
readOnly
}
}
`)
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend-2/components/project/page/models/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
:project-id="projectId"
:model-name="model.name"
class="w-full h-full"
:disabled="project?.workspace?.readOnly"
/>
</div>
</div>
Expand Down Expand Up @@ -140,6 +141,10 @@ graphql(`
role
visibility
...ProjectPageModelsActions_Project
workspace {
id
readOnly
}
}
`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
@clear-search="() => $emit('clear-search')"
/>
<div v-else>
<ProjectCardImportFileArea :project-id="projectId" class="h-36 col-span-4" />
<ProjectCardImportFileArea
:disabled="project?.workspace?.readOnly"
:project-id="projectId"
class="h-36 col-span-4"
/>
</div>
</template>
<InfiniteLoading
Expand Down
8 changes: 8 additions & 0 deletions packages/frontend-2/components/project/page/models/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</FormButton>
<FormButton
v-if="canContribute"
v-tippy="project?.workspace?.readOnly ? 'Workspace is read-only' : ''"
class="grow inline-flex sm:grow-0 lg:hidden"
:disabled="project?.workspace?.readOnly"
@click="showNewDialog = true"
>
New model
Expand Down Expand Up @@ -75,7 +77,9 @@
</FormButton>
<FormButton
v-if="canContribute"
v-tippy="project?.workspace?.readOnly ? 'Workspace is read-only' : ''"
class="hidden lg:inline-flex shrink-0"
:disabled="project?.workspace?.readOnly"
@click="showNewDialog = true"
>
New model
Expand Down Expand Up @@ -122,6 +126,10 @@ graphql(`
...FormUsersSelectItem
}
}
workspace {
id
readOnly
}
}
`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
@clear-search="$emit('clear-search')"
/>
<div v-else>
<ProjectCardImportFileArea :project-id="projectId" class="h-36 col-span-4" />
<ProjectCardImportFileArea
:project-id="projectId"
:disabled="project?.workspace?.readOnly"
class="h-36 col-span-4"
/>
</div>
</template>
<InfiniteLoading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ref="importArea"
:project-id="project.id"
:model-name="item.fullName"
:disabled="project?.workspace?.readOnly"
class="hidden"
/>
<div
Expand All @@ -70,6 +71,7 @@
v-else
:project-id="project.id"
:model-name="item.fullName"
:disabled="project?.workspace?.readOnly"
class="h-full w-full"
/>
</div>
Expand Down Expand Up @@ -247,6 +249,10 @@ enum StructureItemType {
graphql(`
fragment ProjectPageModelsStructureItem_Project on Project {
id
workspace {
id
readOnly
}
...ProjectPageModelsActions_Project
}
`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<ProjectCardImportFileArea
v-if="hasNoModels"
:project-id="project.id"
:disabled="project?.workspace?.readOnly"
class="h-28 col-span-4"
/>
</div>
Expand Down
13 changes: 10 additions & 3 deletions packages/frontend-2/components/projects/WorkspaceSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
clearable
:disabled-item-predicate="disabledItemPredicate"
:help="help"
:disabled-item-tooltip="disabledItemTooltip"
>
<template #nothing-selected>
{{ items && items.length > 0 ? 'Select workspace' : 'No workspaces' }}
Expand All @@ -31,7 +30,7 @@
</div>
</template>
<template #option="{ item }">
<div class="flex items-center gap-x-2">
<div v-tippy="tooltipText(item)" class="flex items-center gap-x-2">
<WorkspaceAvatar :logo="item.logo" :name="item.name" size="2xs" />
<span class="truncate text-foreground">{{ item.name }}</span>
</div>
Expand All @@ -51,6 +50,8 @@ graphql(`
role
name
logo
readOnly
slug
}
`)
Expand Down Expand Up @@ -94,6 +95,12 @@ const { selectedValue } =
const disabledItemPredicate = (item: ProjectsWorkspaceSelect_WorkspaceFragment) =>
props.disabledRoles
? props.disabledRoles.includes(item.role as WorkspaceRoles)
? props.disabledRoles.includes(item.role as WorkspaceRoles) || item.readOnly
: false
const tooltipText = (item: ProjectsWorkspaceSelect_WorkspaceFragment) =>
item.readOnly
? 'Workspace is read-only'
: props.disabledRoles?.includes(item.role as WorkspaceRoles)
? props.disabledItemTooltip
: ''
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
v-on="on"
/>
</div>
<FormButton @click="openNewProject = true">Create</FormButton>
<FormButton :disabled="disableCreate" @click="openNewProject = true">
Create
</FormButton>
</div>

<LayoutTable
Expand Down Expand Up @@ -144,6 +146,7 @@ graphql(`
defineProps<{
projects?: SettingsSharedProjects_ProjectFragment[]
workspaceId?: string
disableCreate?: boolean
}>()
const emit = defineEmits<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
v-model:search="search"
:projects="projects"
:workspace-id="workspaceId"
:disable-create="result?.workspace.readOnly"
@close="$emit('close')"
/>
<InfiniteLoading
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend-2/components/workspace/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@
</span>
<WorkspaceHeaderAddProjectMenu
v-if="!isWorkspaceGuest"
:is-workspace-admin="isWorkspaceAdmin"
button-copy="Add your first project"
:is-workspace-admin="isWorkspaceAdmin"
:disabled="workspace?.readOnly"
@new-project="openNewProject = true"
@move-project="showMoveProjectsDialog = true"
/>
Expand Down Expand Up @@ -128,6 +129,7 @@ graphql(`
completed
state
}
readOnly
}
`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<FormButton
color="outline"
:class="hideTextOnMobile ? 'hidden md:block' : ''"
:disabled="disabled"
@click="showMenu = !showMenu"
>
<div class="flex items-center gap-1">
Expand Down Expand Up @@ -48,6 +49,7 @@ const props = defineProps<{
hideTextOnMobile?: boolean
isWorkspaceAdmin: boolean
buttonCopy?: string
disabled?: boolean
}>()
const menuId = useId()
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend-2/components/workspace/header/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
v-if="!isWorkspaceGuest"
:is-workspace-admin="isWorkspaceAdmin"
hide-text-on-mobile
:disabled="workspaceInfo.readOnly"
@new-project="$emit('show-new-project-dialog')"
@move-project="$emit('show-move-projects-dialog')"
/>
Expand Down Expand Up @@ -95,6 +96,7 @@ graphql(`
...WorkspaceBase_Workspace
...WorkspaceTeam_Workspace
...BillingAlert_Workspace
readOnly
}
`)
Expand Down
Loading

0 comments on commit baea53e

Please sign in to comment.