opnform-host-nginx/client/pages/settings/workspace.vue

160 lines
4.0 KiB
Vue
Raw Normal View History

2023-12-09 15:47:03 +01:00
<template>
<div>
<div class="flex flex-wrap items-center gap-y-4">
2023-12-09 15:47:03 +01:00
<div class="flex-grow">
<div class="flex items-center gap-2">
<h3 class="font-semibold text-2xl text-gray-900">
Workspace settings
</h3>
<UTooltip text="Edit workspace">
<UButton
v-if="!workspace.is_readonly"
size="xs"
color="white"
icon="i-heroicons-pencil-square"
@click="editCurrentWorkspace"
/>
</UTooltip>
</div>
<small class="text-gray-500">You're currently editing the settings for the workspace "{{ workspace.name }}".
You can switch to another workspace in top left corner of the page.</small>
</div>
<div class="w-full flex flex-wrap gap-2">
Readonly User (#637) * Readonly User * Refactor FormPolicy and TemplatePolicy to centralize write operation logic - Introduced a private method `canPerformWriteOperation` in both FormPolicy and TemplatePolicy to encapsulate the logic for determining if a user can perform write operations on the respective models. - Updated the `update`, `delete`, `restore`, and `forceDelete` methods in FormPolicy to use the new method for improved readability and maintainability. - Simplified the `update` and `delete` methods in TemplatePolicy to leverage the centralized write operation logic. This refactoring enhances code clarity and reduces duplication across policy classes. * Refactor user and workspace permissions handling - Updated FormController to authorize form creation based on workspace context. - Removed the `is_readonly` attribute from UserResource and integrated it into WorkspaceResource for better encapsulation. - Refactored User model to eliminate the `getIsReadonlyAttribute` method, shifting readonly logic to the Workspace model. - Adjusted FormPolicy and TemplatePolicy to utilize workspace readonly checks for user permissions. - Updated various frontend components to reference workspace readonly status instead of user readonly status, enhancing clarity and consistency in permission handling. These changes improve the management of user permissions in relation to workspaces, ensuring a more robust and maintainable authorization system. * Fix isReadonlyUser * fix pint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-30 14:35:23 +01:00
<template v-if="!workspace.is_readonly">
<WorkSpaceCustomDomains v-if="useFeatureFlag('custom_domains') && !loading" />
<WorkSpaceEmailSettings v-if="!loading" />
</template>
<UButton
label="New Workspace"
icon="i-heroicons-plus"
:loading="loading"
@click="workspaceModal = true"
/>
2023-12-09 15:47:03 +01:00
</div>
</div>
<div
v-if="loading"
class="w-full text-blue-500 text-center"
>
2023-12-11 11:56:21 +01:00
<Loader class="h-10 w-10 p-5" />
2023-12-09 15:47:03 +01:00
</div>
<div
v-else-if="workspace"
class="my-4"
>
<WorkSpaceUser />
2023-12-09 15:47:03 +01:00
</div>
<!-- Workspace modal -->
<modal
:show="workspaceModal"
max-width="lg"
:compact-header="true"
@close="workspaceModal = false"
>
2023-12-09 15:47:03 +01:00
<template #icon>
<Icon
:name="isEditing ? 'heroicons:pencil-square' : 'heroicons:plus-circle'"
class="w-8 h-8"
/>
2023-12-09 15:47:03 +01:00
</template>
<template #title>
{{ isEditing ? 'Edit' : 'Create' }} Workspace
2023-12-09 15:47:03 +01:00
</template>
<div class="px-4">
<form
@submit.prevent="isEditing ? updateWorkspace() : createWorkspace()"
@keydown="form.onKeydown($event)"
>
2023-12-09 15:47:03 +01:00
<div>
<text-input
name="name"
class="mt-4"
:form="form"
:required="true"
label="Workspace Name"
2023-12-09 15:47:03 +01:00
/>
<text-input
name="emoji"
class="mt-4"
:form="form"
:required="false"
label="Emoji"
2023-12-09 15:47:03 +01:00
/>
</div>
<div class="w-full mt-6">
<v-button
:loading="form.busy"
class="w-full my-3"
>
2023-12-09 15:47:03 +01:00
Save
</v-button>
</div>
</form>
</div>
</modal>
</div>
</template>
<script setup>
import {fetchAllWorkspaces} from "~/stores/workspaces.js"
2023-12-09 15:47:03 +01:00
const workspacesStore = useWorkspacesStore()
Readonly User (#637) * Readonly User * Refactor FormPolicy and TemplatePolicy to centralize write operation logic - Introduced a private method `canPerformWriteOperation` in both FormPolicy and TemplatePolicy to encapsulate the logic for determining if a user can perform write operations on the respective models. - Updated the `update`, `delete`, `restore`, and `forceDelete` methods in FormPolicy to use the new method for improved readability and maintainability. - Simplified the `update` and `delete` methods in TemplatePolicy to leverage the centralized write operation logic. This refactoring enhances code clarity and reduces duplication across policy classes. * Refactor user and workspace permissions handling - Updated FormController to authorize form creation based on workspace context. - Removed the `is_readonly` attribute from UserResource and integrated it into WorkspaceResource for better encapsulation. - Refactored User model to eliminate the `getIsReadonlyAttribute` method, shifting readonly logic to the Workspace model. - Adjusted FormPolicy and TemplatePolicy to utilize workspace readonly checks for user permissions. - Updated various frontend components to reference workspace readonly status instead of user readonly status, enhancing clarity and consistency in permission handling. These changes improve the management of user permissions in relation to workspaces, ensuring a more robust and maintainable authorization system. * Fix isReadonlyUser * fix pint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-12-30 14:35:23 +01:00
const workspace = computed(() => workspacesStore.getCurrent)
const loading = computed(() => workspacesStore.loading)
useOpnSeoMeta({
title: "Workspaces",
})
definePageMeta({
middleware: "auth",
})
const form = useForm({
name: "",
emoji: "",
})
const workspaceModal = ref(false)
const isEditing = ref(false)
2023-12-09 15:47:03 +01:00
onMounted(() => {
fetchAllWorkspaces()
})
2023-12-09 15:47:03 +01:00
const editCurrentWorkspace = () => {
isEditing.value = true
form.name = workspace.value.name
form.emoji = workspace.value.icon || ''
workspaceModal.value = true
}
const updateWorkspace = () => {
form.put(`/open/workspaces/${workspace.value.id}/`).then((data) => {
workspacesStore.save(data.workspace)
workspaceModal.value = false
isEditing.value = false
useAlert().success('Workspace successfully updated!')
})
}
const createWorkspace = () => {
form.post("/open/workspaces/create").then((data) => {
2024-01-22 14:40:17 +01:00
workspacesStore.save(data.workspace)
workspacesStore.currentId = data.workspace.id
workspaceModal.value = false
useAlert().success(
"Workspace successfully created! You are now editing settings for your new workspace.",
)
})
2023-12-09 15:47:03 +01:00
}
watch(workspaceModal, (newValue) => {
if (!newValue) {
isEditing.value = false
form.reset()
}
})
2023-12-09 15:47:03 +01:00
</script>