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
@@ -7,6 +7,21 @@
|
||||
/>
|
||||
|
||||
<breadcrumbs base="/files" />
|
||||
<section v-if="fileStore.req?.isDir" class="workspace-overview">
|
||||
<div>
|
||||
<span class="eyebrow">{{ t("sso.workspace") }}</span>
|
||||
<h1>
|
||||
{{
|
||||
route.path.replace(/\/+$/, "") === "/files"
|
||||
? t("sidebar.myFiles")
|
||||
: fileStore.req.name
|
||||
}}
|
||||
</h1>
|
||||
</div>
|
||||
<span class="workspace-count">{{
|
||||
t("sso.itemsCount", { count: fileStore.req.items?.length || 0 })
|
||||
}}</span>
|
||||
</section>
|
||||
<errors v-if="error" :errorCode="error.status" />
|
||||
<component v-else-if="currentView" :is="currentView"></component>
|
||||
<div v-else>
|
||||
|
||||
+25
-132
@@ -1,139 +1,32 @@
|
||||
<template>
|
||||
<div id="login" :class="{ recaptcha: recaptcha }">
|
||||
<form @submit="submit">
|
||||
<img :src="logoURL" alt="File Browser" />
|
||||
<h1>{{ name }}</h1>
|
||||
<p v-if="reason != null" class="logout-message">
|
||||
{{ t(`login.logout_reasons.${reason}`) }}
|
||||
</p>
|
||||
<div v-if="error !== ''" class="wrong">{{ error }}</div>
|
||||
|
||||
<input
|
||||
autofocus
|
||||
class="input input--block"
|
||||
type="text"
|
||||
autocapitalize="off"
|
||||
v-model="username"
|
||||
:placeholder="t('login.username')"
|
||||
/>
|
||||
<input
|
||||
class="input input--block"
|
||||
type="password"
|
||||
v-model="password"
|
||||
:placeholder="t('login.password')"
|
||||
/>
|
||||
<input
|
||||
class="input input--block"
|
||||
v-if="createMode"
|
||||
type="password"
|
||||
v-model="passwordConfirm"
|
||||
:placeholder="t('login.passwordConfirm')"
|
||||
/>
|
||||
|
||||
<div v-if="recaptcha" id="recaptcha"></div>
|
||||
<input
|
||||
class="button button--block"
|
||||
type="submit"
|
||||
:value="createMode ? t('login.signup') : t('login.submit')"
|
||||
/>
|
||||
|
||||
<p @click="toggleMode" v-if="signup">
|
||||
{{ createMode ? t("login.loginInstead") : t("login.createAnAccount") }}
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<main class="sso-welcome">
|
||||
<div class="sso-symbol" aria-hidden="true">
|
||||
<i class="material-icons">folder_open</i>
|
||||
</div>
|
||||
<span class="eyebrow">FILE WORKSPACE</span>
|
||||
<h1>{{ name }}</h1>
|
||||
<p>{{ $t("sso.description") }}</p>
|
||||
<button class="button sso-signin" @click="signIn">
|
||||
<i class="material-icons">login</i>{{ $t("sso.signIn") }}
|
||||
</button>
|
||||
<small>{{ $t("sso.managed") }}</small>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { StatusError } from "@/api/utils";
|
||||
import * as auth from "@/utils/auth";
|
||||
import {
|
||||
name,
|
||||
logoURL,
|
||||
recaptcha,
|
||||
recaptchaKey,
|
||||
signup,
|
||||
} from "@/utils/constants";
|
||||
import { inject, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
// Define refs
|
||||
const createMode = ref<boolean>(false);
|
||||
const error = ref<string>("");
|
||||
const username = ref<string>("");
|
||||
const password = ref<string>("");
|
||||
const passwordConfirm = ref<string>("");
|
||||
|
||||
import { onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { name, baseURL } from "@/utils/constants";
|
||||
import { startLogin } from "@/utils/auth";
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n({});
|
||||
// Define functions
|
||||
const toggleMode = () => (createMode.value = !createMode.value);
|
||||
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
const reason = route.query["logout-reason"] ?? null;
|
||||
|
||||
const submit = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const redirect = (route.query.redirect || "/files/") as string;
|
||||
|
||||
let captcha = "";
|
||||
if (recaptcha) {
|
||||
captcha = window.grecaptcha.getResponse();
|
||||
|
||||
if (captcha === "") {
|
||||
error.value = t("login.wrongCredentials");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (createMode.value) {
|
||||
if (password.value !== passwordConfirm.value) {
|
||||
error.value = t("login.passwordsDontMatch");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (createMode.value) {
|
||||
await auth.signup(username.value, password.value);
|
||||
}
|
||||
|
||||
await auth.login(username.value, password.value, captcha);
|
||||
router.push({ path: redirect });
|
||||
} catch (e: any) {
|
||||
// console.error(e);
|
||||
if (e instanceof StatusError) {
|
||||
if (e.status === 409) {
|
||||
error.value = t("login.usernameTaken");
|
||||
} else if (e.status === 403) {
|
||||
error.value = t("login.wrongCredentials");
|
||||
} else if (e.status === 400) {
|
||||
const match = e.message.match(/minimum length is (\d+)/);
|
||||
if (match) {
|
||||
error.value = t("login.passwordTooShort", { min: match[1] });
|
||||
} else {
|
||||
error.value = e.message;
|
||||
}
|
||||
} else {
|
||||
$showError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Run hooks
|
||||
function signIn() {
|
||||
startLogin(
|
||||
baseURL +
|
||||
(typeof route.query.redirect === "string"
|
||||
? route.query.redirect
|
||||
: "/files/")
|
||||
);
|
||||
}
|
||||
onMounted(() => {
|
||||
if (!recaptcha) return;
|
||||
|
||||
window.grecaptcha.ready(function () {
|
||||
window.grecaptcha.render("recaptcha", {
|
||||
sitekey: recaptchaKey,
|
||||
});
|
||||
});
|
||||
if (route.query.redirect && !route.query["logged-out"]) signIn();
|
||||
});
|
||||
</script>
|
||||
@@ -34,24 +34,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" v-if="user?.perm.admin">
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.sunsetTitle") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>{{ t("settings.sunsetBody") }}</p>
|
||||
<p>
|
||||
<a
|
||||
href="https://github.com/filebrowser/filebrowser#security"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>{{ t("settings.sunsetLink") }}</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading">
|
||||
<h2 class="message delayed">
|
||||
<div class="spinner">
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
/>
|
||||
</header-bar>
|
||||
|
||||
<breadcrumbs :base="'/share/' + hash" />
|
||||
<breadcrumbs :base="'/s/' + hash" />
|
||||
|
||||
<div v-if="layoutStore.loading">
|
||||
<h2 class="message delayed" style="padding-top: 3em !important">
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
import { files as api } from "@/api";
|
||||
import buttons from "@/utils/buttons";
|
||||
import url from "@/utils/url";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import ace, { Ace, version as ace_version } from "ace-builds";
|
||||
import "ace-builds/src-noconflict/ext-language_tools";
|
||||
import modelist from "ace-builds/src-noconflict/ext-modelist";
|
||||
@@ -92,7 +93,7 @@ import HeaderBar from "@/components/header/HeaderBar.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { getEditorTheme } from "@/utils/theme";
|
||||
import { getEditorTheme } from "@/utils/editor-theme";
|
||||
import { marked } from "marked";
|
||||
import markedKatex from "marked-katex-extension";
|
||||
import { inject, onBeforeUnmount, onMounted, ref, watchEffect } from "vue";
|
||||
@@ -172,10 +173,7 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
ace.config.set(
|
||||
"basePath",
|
||||
`https://cdn.jsdelivr.net/npm/ace-builds@${ace_version}/src-min-noconflict/`
|
||||
);
|
||||
ace.config.set("basePath", `${baseURL}/static/ace/${ace_version}/`);
|
||||
|
||||
if (!layoutStore.loading) {
|
||||
initEditor(fileContent);
|
||||
@@ -222,6 +220,7 @@ const initEditor = (fileContent: string) => {
|
||||
editor.value = ace.edit("editor", {
|
||||
value: fileContent,
|
||||
showPrintMargin: false,
|
||||
useWorker: false,
|
||||
readOnly: fileStore.req?.type === "textImmutable",
|
||||
theme: getEditorTheme(authStore.user?.aceEditorTheme ?? ""),
|
||||
mode: modelist.getModeForPath(fileStore.req!.name).mode,
|
||||
|
||||
@@ -205,7 +205,7 @@ import { useI18n } from "vue-i18n";
|
||||
// Prevents browser memory issues with large files
|
||||
const CSV_MAX_SIZE = 5 * 1024 * 1024;
|
||||
|
||||
const location = useStorage("book-progress", 0, undefined, {
|
||||
const location = useStorage<string | number>("book-progress", 0, undefined, {
|
||||
serializer: {
|
||||
read: (v) => JSON.parse(v),
|
||||
write: (v) => JSON.stringify(v),
|
||||
@@ -218,7 +218,7 @@ const size = useStorage("book-size", 120, undefined, {
|
||||
},
|
||||
});
|
||||
|
||||
const locationChange = (epubcifi: number) => {
|
||||
const locationChange = (epubcifi: string) => {
|
||||
location.value = epubcifi;
|
||||
};
|
||||
let rendition: Rendition | null = null;
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>
|
||||
<input type="checkbox" v-model="settings.signup" />
|
||||
{{ t("settings.allowSignup") }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="checkbox" v-model="settings.createUserDir" />
|
||||
{{ t("settings.createUserDir") }}
|
||||
@@ -32,18 +27,6 @@
|
||||
/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="minimumPasswordLength">{{
|
||||
t("settings.minimumPasswordLength")
|
||||
}}</label>
|
||||
<vue-number-input
|
||||
controls
|
||||
v-model.number="settings.minimumPasswordLength"
|
||||
id="minimumPasswordLength"
|
||||
:min="1"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<h3>{{ t("settings.rules") }}</h3>
|
||||
<p class="small">{{ t("settings.globalRules") }}</p>
|
||||
<rules v-model:rules="settings.rules" />
|
||||
|
||||
@@ -51,53 +51,6 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div v-if="!noAuth" class="column">
|
||||
<form
|
||||
class="card"
|
||||
v-if="!authStore.user?.lockPassword"
|
||||
@submit="updatePassword"
|
||||
>
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.changePassword") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<input
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.newPassword')"
|
||||
v-model="password"
|
||||
name="password"
|
||||
/>
|
||||
<input
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.newPasswordConfirm')"
|
||||
v-model="passwordConf"
|
||||
name="passwordConf"
|
||||
/>
|
||||
<input
|
||||
v-if="isCurrentPasswordRequired"
|
||||
:class="passwordClass"
|
||||
type="password"
|
||||
:placeholder="t('settings.currentPassword')"
|
||||
v-model="currentPassword"
|
||||
name="current_password"
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<input
|
||||
class="button button--flat"
|
||||
type="submit"
|
||||
name="submitPassword"
|
||||
:value="t('buttons.update')"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -107,9 +60,8 @@ import { useLayoutStore } from "@/stores/layout";
|
||||
import { users as api } from "@/api";
|
||||
import AceEditorTheme from "@/components/settings/AceEditorTheme.vue";
|
||||
import Languages from "@/components/settings/Languages.vue";
|
||||
import { computed, inject, onMounted, ref } from "vue";
|
||||
import { inject, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { authMethod, noAuth } from "@/utils/constants";
|
||||
|
||||
const layoutStore = useLayoutStore();
|
||||
const authStore = useAuthStore();
|
||||
@@ -118,10 +70,6 @@ const { t } = useI18n();
|
||||
const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
const password = ref<string>("");
|
||||
const passwordConf = ref<string>("");
|
||||
const currentPassword = ref<string>("");
|
||||
const isCurrentPasswordRequired = ref<boolean>(false);
|
||||
const hideDotfiles = ref<boolean>(false);
|
||||
const singleClick = ref<boolean>(false);
|
||||
const redirectAfterCopyMove = ref<boolean>(false);
|
||||
@@ -129,20 +77,6 @@ const dateFormat = ref<boolean>(false);
|
||||
const locale = ref<string>("");
|
||||
const aceEditorTheme = ref<string>("");
|
||||
|
||||
const passwordClass = computed(() => {
|
||||
const baseClass = "input input--block";
|
||||
|
||||
if (password.value === "" && passwordConf.value === "") {
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
if (password.value === passwordConf.value) {
|
||||
return `${baseClass} input--green`;
|
||||
}
|
||||
|
||||
return `${baseClass} input--red`;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
layoutStore.loading = true;
|
||||
if (authStore.user === null) return false;
|
||||
@@ -153,38 +87,10 @@ onMounted(async () => {
|
||||
dateFormat.value = authStore.user.dateFormat;
|
||||
aceEditorTheme.value = authStore.user.aceEditorTheme;
|
||||
layoutStore.loading = false;
|
||||
isCurrentPasswordRequired.value = authMethod == "json";
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
const updatePassword = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (
|
||||
password.value !== passwordConf.value ||
|
||||
password.value === "" ||
|
||||
currentPassword.value === "" ||
|
||||
authStore.user === null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = {
|
||||
...authStore.user,
|
||||
id: authStore.user.id,
|
||||
password: password.value,
|
||||
};
|
||||
await api.update(data, ["password"], currentPassword.value);
|
||||
authStore.updateUser(data);
|
||||
$showSuccess(t("settings.passwordUpdated"));
|
||||
} catch (e: any) {
|
||||
$showError(e);
|
||||
} finally {
|
||||
password.value = passwordConf.value = "";
|
||||
}
|
||||
};
|
||||
const updateSettings = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -5,28 +5,19 @@
|
||||
<div class="card">
|
||||
<div class="card-title">
|
||||
<h2>{{ t("settings.users") }}</h2>
|
||||
<router-link to="/settings/users/new"
|
||||
><button class="button">
|
||||
{{ t("buttons.new") }}
|
||||
</button></router-link
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="card-content full">
|
||||
<table>
|
||||
<tr>
|
||||
<th>{{ t("settings.username") }}</th>
|
||||
<th>{{ t("settings.admin") }}</th>
|
||||
|
||||
<th>{{ t("settings.scope") }}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<tr v-for="user in users" :key="user.id">
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<i v-if="user.perm.admin" class="material-icons">done</i
|
||||
><i v-else class="material-icons">close</i>
|
||||
</td>
|
||||
<td>{{ user.displayName || user.username }}</td>
|
||||
<td>{{ user.scope }}</td>
|
||||
<td class="small">
|
||||
<router-link :to="'/settings/users/' + user.id"
|
||||
|
||||
Reference in new issue
Block a user