opnform-host-nginx/client/components/pages/admin/AddUserToWorkspace.vue

87 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<form
v-if="isWorkspaceAdmin"
class="my-2"
@submit.prevent="addUser"
>
<text-input
v-model="newUser"
name="email"
label="Email"
:required="true"
:disabled="disabled"
placeholder="Add a new user by email"
/>
<select-input
v-model="newUserRole"
name="newUserRole"
:options="roleOptions"
:disabled="disabled"
placeholder="Select User Role"
label="Role"
:required="true"
/>
<div class="flex justify-center mt-2">
<UButton
type="submit"
:disabled="disabled"
:loading="addingUsersState"
icon="i-heroicons-envelope"
>
Invite User
</UButton>
</div>
</form>
</template>
<script setup>
const props = defineProps({
isWorkspaceAdmin: {},
disabled: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['fetchUsers'])
const workspacesStore = useWorkspacesStore()
const roleOptions = [
{name: "User", value: "user"},
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
{name: "Admin", value: "admin"},
{name: "Read Only", value: "readonly"}
]
const newUser = ref("")
const newUserRole = ref("user")
const addingUsersState = ref(false)
const addUser = () => {
if (!newUser.value) return
addingUsersState.value = true
opnFetch(
"/open/workspaces/" + workspacesStore.currentId + "/users/add",
{
method: "POST",
body: {
email: newUser.value,
role: newUserRole.value,
},
}
).then((data) => {
newUser.value = ""
newUserRole.value = "user"
useAlert().success(data.message)
emit("fetchUsers")
}).catch((error) => {
useAlert().error("There was an error adding user: " + error.data.message)
}).finally(() => {
addingUsersState.value = false
})
}
</script>