feat: add SSO workspace, named shares and Debian release tooling
This commit is contained in:
1 parent
833d908884
commit
87bc33e675
106 files changed
+4160
-5637
No files matched your search
@@ -1,211 +1,74 @@
|
||||
<template>
|
||||
<errors v-if="error" :errorCode="error.status" />
|
||||
<div class="row" v-else-if="!layoutStore.loading">
|
||||
<div class="column">
|
||||
<form @submit="save" class="card">
|
||||
<div class="card-title">
|
||||
<h2 v-if="user?.id === 0">{{ $t("settings.newUser") }}</h2>
|
||||
<h2 v-else>{{ $t("settings.user") }} {{ user?.username }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content" v-if="user">
|
||||
<user-form
|
||||
v-model:user="user"
|
||||
v-model:createUserDir="createUserDir"
|
||||
:isDefault="false"
|
||||
:isNew="isNew"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<button
|
||||
v-if="!isNew"
|
||||
@click.prevent="deletePrompt"
|
||||
type="button"
|
||||
class="button button--flat button--red"
|
||||
:aria-label="$t('buttons.delete')"
|
||||
:title="$t('buttons.delete')"
|
||||
>
|
||||
{{ $t("buttons.delete") }}
|
||||
</button>
|
||||
<router-link to="/settings/users">
|
||||
<button
|
||||
class="button button--flat button--grey"
|
||||
:aria-label="$t('buttons.cancel')"
|
||||
:title="$t('buttons.cancel')"
|
||||
>
|
||||
{{ $t("buttons.cancel") }}
|
||||
</button>
|
||||
</router-link>
|
||||
<input
|
||||
class="button button--flat"
|
||||
type="submit"
|
||||
:value="$t('buttons.save')"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<form v-else-if="user" class="card" @submit.prevent="save">
|
||||
<div class="card-title">
|
||||
<h2>{{ user.displayName || user.username }}</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<p class="field-hint">{{ $t("sso.managed") }}</p>
|
||||
<label for="user-scope">{{ $t("settings.scope") }}</label>
|
||||
<input
|
||||
id="user-scope"
|
||||
class="input input--block"
|
||||
v-model="user.scope"
|
||||
required
|
||||
/>
|
||||
<p v-for="permission in permissions" :key="permission">
|
||||
<label
|
||||
><input type="checkbox" v-model="user.perm[permission]" />
|
||||
{{ $t("settings.perm." + permission) }}</label
|
||||
>
|
||||
</p>
|
||||
<rules v-model:rules="user.rules" />
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<router-link to="/settings/users" class="button button--flat">{{
|
||||
$t("buttons.cancel")
|
||||
}}</router-link
|
||||
><button class="button" :disabled="saving">
|
||||
{{ $t("buttons.save") }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { users as api, settings } from "@/api";
|
||||
import UserForm from "@/components/settings/UserForm.vue";
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import { computed, inject, onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { ref, onMounted, inject } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { users as api } from "@/api";
|
||||
import { StatusError } from "@/api/utils";
|
||||
import { authMethod } from "@/utils/constants";
|
||||
import { logout } from "@/utils/auth";
|
||||
|
||||
const error = ref<StatusError>();
|
||||
const originalUser = ref<IUser>();
|
||||
const user = ref<IUser>();
|
||||
const createUserDir = ref<boolean>(false);
|
||||
const isCurrentPasswordRequired = ref<boolean>(false);
|
||||
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const layoutStore = useLayoutStore();
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import Rules from "@/components/settings/Rules.vue";
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
});
|
||||
|
||||
const isNew = computed(() => route.path === "/settings/users/new");
|
||||
|
||||
watch(route, () => fetchData());
|
||||
watch(user, () => {
|
||||
if (!user.value?.perm.admin) return;
|
||||
user.value.lockPassword = false;
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
layoutStore.loading = true;
|
||||
|
||||
const user = ref<IUser>();
|
||||
const error = ref<StatusError>();
|
||||
const saving = ref(false);
|
||||
const showError = inject<IToastError>("$showError")!;
|
||||
const showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
const permissions = [
|
||||
"create",
|
||||
"rename",
|
||||
"modify",
|
||||
"delete",
|
||||
"share",
|
||||
"download",
|
||||
] as const;
|
||||
onMounted(async () => {
|
||||
try {
|
||||
if (isNew.value) {
|
||||
const { defaults, createUserDir: _createUserDir } = await settings.get();
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
createUserDir.value = _createUserDir;
|
||||
user.value = {
|
||||
...defaults,
|
||||
username: "",
|
||||
password: "",
|
||||
rules: [],
|
||||
lockPassword: false,
|
||||
id: 0,
|
||||
};
|
||||
} else {
|
||||
const { authMethod } = await settings.get();
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
const id = Array.isArray(route.params.id)
|
||||
? route.params.id.join("")
|
||||
: route.params.id;
|
||||
user.value = { ...(await api.get(parseInt(id))) };
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
error.value = err;
|
||||
}
|
||||
user.value = await api.get(Number(route.params.id));
|
||||
} catch (e) {
|
||||
error.value = e as StatusError;
|
||||
}
|
||||
});
|
||||
async function save() {
|
||||
if (!user.value || saving.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await api.update(user.value, ["scope", "perm", "rules"]);
|
||||
showSuccess("Saved");
|
||||
} catch (e) {
|
||||
showError(e as Error);
|
||||
} finally {
|
||||
layoutStore.loading = false;
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const deletePrompt = () => {
|
||||
if (isCurrentPasswordRequired.value) {
|
||||
layoutStore.showHover({
|
||||
prompt: "current-password",
|
||||
confirm: (event: Event, currentPassword: string) => {
|
||||
event.preventDefault();
|
||||
layoutStore.closeHovers();
|
||||
deleteUser(currentPassword);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
layoutStore.showHover({
|
||||
prompt: "deleteUser",
|
||||
confirm: () => deleteUser(""),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const deleteUser = async (currentPassword: string) => {
|
||||
if (!user.value) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await api.remove(user.value.id, currentPassword);
|
||||
if (user.value.id == authStore.user?.id) {
|
||||
logout();
|
||||
} else {
|
||||
router.push({ path: "/settings/users" });
|
||||
}
|
||||
$showSuccess(t("settings.userDeleted"));
|
||||
} catch (err) {
|
||||
if (err instanceof StatusError) {
|
||||
err.status === 403 ? $showError(t("errors.forbidden")) : $showError(err);
|
||||
} else if (err instanceof Error) {
|
||||
$showError(err);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const save = (event: Event) => {
|
||||
event.preventDefault();
|
||||
if (isCurrentPasswordRequired.value) {
|
||||
layoutStore.showHover({
|
||||
prompt: "current-password",
|
||||
confirm: (event: Event, currentPassword: string) => {
|
||||
event.preventDefault();
|
||||
layoutStore.closeHovers();
|
||||
send(currentPassword);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
send("");
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const send = async (currentPassword: string) => {
|
||||
if (!user.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNew.value) {
|
||||
const newUser: IUser = {
|
||||
...originalUser?.value,
|
||||
...user.value,
|
||||
};
|
||||
|
||||
const loc = await api.create(newUser, currentPassword);
|
||||
router.push({ path: loc || "/settings/users" });
|
||||
$showSuccess(t("settings.userCreated"));
|
||||
} else {
|
||||
await api.update(user.value, ["all"], currentPassword);
|
||||
|
||||
if (user.value.id === authStore.user?.id) {
|
||||
authStore.updateUser(user.value);
|
||||
}
|
||||
|
||||
$showSuccess(t("settings.userUpdated"));
|
||||
}
|
||||
} catch (e: any) {
|
||||
$showError(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user