mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +00:00
Improve user settings (#2087)
Make the user settings tabbed as well, currently only holding "Settings" (language) and "API". Can be extended with user secrets (#1739) etc. later. ![Screenshot 2023-08-02 at 09-56-00 Woodpecker](https://github.com/woodpecker-ci/woodpecker/assets/80460567/15d82800-8a4d-47fe-aa77-33462f63585e) ![Screenshot 2023-08-02 at 09-56-05 Woodpecker](https://github.com/woodpecker-ci/woodpecker/assets/80460567/de2640be-144c-4190-adb6-56d43a38bdda) --------- Co-authored-by: Robert Kaussow <xoxys@rknet.org>
This commit is contained in:
parent
cbbf5a0c19
commit
d09c418941
10 changed files with 190 additions and 156 deletions
2
web/components.d.ts
vendored
2
web/components.d.ts
vendored
|
@ -101,6 +101,8 @@ declare module '@vue/runtime-core' {
|
||||||
Tab: typeof import('./src/components/layout/scaffold/Tab.vue')['default']
|
Tab: typeof import('./src/components/layout/scaffold/Tab.vue')['default']
|
||||||
Tabs: typeof import('./src/components/layout/scaffold/Tabs.vue')['default']
|
Tabs: typeof import('./src/components/layout/scaffold/Tabs.vue')['default']
|
||||||
TextField: typeof import('./src/components/form/TextField.vue')['default']
|
TextField: typeof import('./src/components/form/TextField.vue')['default']
|
||||||
|
UserAPITab: typeof import('./src/components/user/UserAPITab.vue')['default']
|
||||||
|
UserGeneralTab: typeof import('./src/components/user/UserGeneralTab.vue')['default']
|
||||||
Warning: typeof import('./src/components/atomic/Warning.vue')['default']
|
Warning: typeof import('./src/components/atomic/Warning.vue')['default']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,16 +425,27 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"user": {
|
"user": {
|
||||||
|
"settings": {
|
||||||
"settings": "User Settings",
|
"settings": "User Settings",
|
||||||
"oauth_error": "Error while authenticating against OAuth provider",
|
"general": {
|
||||||
"internal_error": "Some internal error occurred",
|
"general": "General",
|
||||||
"access_denied": "You are not allowed to login",
|
"language": "Language"
|
||||||
|
},
|
||||||
|
"api": {
|
||||||
|
"api": "API",
|
||||||
|
"desc": "Personal Access Token and API usage",
|
||||||
"token": "Personal Access Token",
|
"token": "Personal Access Token",
|
||||||
"shell_setup": "Shell setup",
|
"shell_setup": "Shell setup",
|
||||||
"api_usage": "Example API Usage",
|
"api_usage": "Example API Usage",
|
||||||
"cli_usage": "Example CLI Usage",
|
"cli_usage": "Example CLI Usage",
|
||||||
"dl_cli": "Download CLI",
|
"dl_cli": "Download CLI",
|
||||||
"shell_setup_before": "do shell setup steps before",
|
"shell_setup_before": "do shell setup steps before",
|
||||||
"reset_token": "Reset token"
|
"reset_token": "Reset token",
|
||||||
|
"swagger_ui": "Swagger UI",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"oauth_error": "Error while authenticating against OAuth provider",
|
||||||
|
"internal_error": "Some internal error occurred",
|
||||||
|
"access_denied": "You are not allowed to login",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
<!-- Active Pipelines Indicator -->
|
<!-- Active Pipelines Indicator -->
|
||||||
<ActivePipelines v-if="user" class="navbar-icon" />
|
<ActivePipelines v-if="user" class="navbar-icon" />
|
||||||
<!-- User Avatar -->
|
<!-- User Avatar -->
|
||||||
<IconButton v-if="user" :to="{ name: 'user' }" :title="$t('user.settings')" class="navbar-icon !p-1.5">
|
<IconButton v-if="user" :to="{ name: 'user' }" :title="$t('user.settings.settings')" class="navbar-icon !p-1.5">
|
||||||
<img v-if="user && user.avatar_url" class="rounded-md" :src="`${user.avatar_url}`" />
|
<img v-if="user && user.avatar_url" class="rounded-md" :src="`${user.avatar_url}`" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<!-- Login Button -->
|
<!-- Login Button -->
|
||||||
|
|
95
web/src/components/user/UserAPITab.vue
Normal file
95
web/src/components/user/UserAPITab.vue
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<template>
|
||||||
|
<Panel>
|
||||||
|
<div class="flex flex-row border-b mb-4 pb-4 items-center dark:border-wp-background-100">
|
||||||
|
<div class="ml-2">
|
||||||
|
<h1 class="text-xl text-wp-text-100">{{ $t('user.settings.api.api') }}</h1>
|
||||||
|
<p class="text-sm text-wp-text-alt-100">{{ $t('user.settings.api.desc') }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<div class="flex items-center mb-2">
|
||||||
|
<div class="flex flex-row items-center text-wp-text-100 font-bold">
|
||||||
|
<label>{{ $t('user.settings.api.token') }}</label>
|
||||||
|
</div>
|
||||||
|
<Button class="ml-auto" :text="$t('user.settings.api.reset_token')" @click="resetToken" />
|
||||||
|
</div>
|
||||||
|
<pre class="code-box">{{ token }}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<div class="flex items-center text-wp-text-100 font-bold mb-2">
|
||||||
|
<label>{{ $t('user.settings.api.shell_setup') }}</label>
|
||||||
|
</div>
|
||||||
|
<pre class="code-box">{{ usageWithShell }}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<div class="flex items-center mb-2">
|
||||||
|
<div class="flex items-center text-wp-text-100 font-bold">
|
||||||
|
<label>{{ $t('user.settings.api.api_usage') }}</label>
|
||||||
|
</div>
|
||||||
|
<a
|
||||||
|
v-if="enableSwagger"
|
||||||
|
:href="`${address}/swagger/index.html`"
|
||||||
|
target="_blank"
|
||||||
|
class="ml-4 text-wp-link-100 hover:text-wp-link-200"
|
||||||
|
>{{ $t('user.settings.api.swagger_ui') }}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<pre class="code-box">{{ usageWithCurl }}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<div class="flex items-center mb-2">
|
||||||
|
<div class="flex items-center text-wp-text-100 font-bold">
|
||||||
|
<label>{{ $t('user.settings.api.cli_usage') }}</label>
|
||||||
|
</div>
|
||||||
|
<a :href="cliDownload" target="_blank" class="ml-4 text-wp-link-100 hover:text-wp-link-200">{{
|
||||||
|
$t('user.settings.api.dl_cli')
|
||||||
|
}}</a>
|
||||||
|
</div>
|
||||||
|
<pre class="code-box">{{ usageWithCli }}</pre>
|
||||||
|
</div>
|
||||||
|
</Panel>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import Button from '~/components/atomic/Button.vue';
|
||||||
|
import useApiClient from '~/compositions/useApiClient';
|
||||||
|
import useConfig from '~/compositions/useConfig';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
const { enableSwagger } = useConfig();
|
||||||
|
|
||||||
|
const apiClient = useApiClient();
|
||||||
|
const token = ref<string | undefined>();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
token.value = await apiClient.getToken();
|
||||||
|
});
|
||||||
|
|
||||||
|
const address = `${window.location.protocol}//${window.location.host}`; // port is included in location.host
|
||||||
|
|
||||||
|
const usageWithShell = computed(() => {
|
||||||
|
let usage = `export WOODPECKER_SERVER="${address}"\n`;
|
||||||
|
usage += `export WOODPECKER_TOKEN="${token.value}"\n`;
|
||||||
|
return usage;
|
||||||
|
});
|
||||||
|
|
||||||
|
const usageWithCurl = `# ${t(
|
||||||
|
'user.settings.api.shell_setup_before',
|
||||||
|
)}\ncurl -i \${WOODPECKER_SERVER}/api/user -H "Authorization: Bearer \${WOODPECKER_TOKEN}"`;
|
||||||
|
|
||||||
|
const usageWithCli = `# ${t('user.settings.api.shell_setup_before')}\nwoodpecker info`;
|
||||||
|
|
||||||
|
const cliDownload = 'https://github.com/woodpecker-ci/woodpecker/releases';
|
||||||
|
|
||||||
|
const resetToken = async () => {
|
||||||
|
token.value = await apiClient.resetToken();
|
||||||
|
window.location.href = `${address}/logout`;
|
||||||
|
};
|
||||||
|
</script>
|
48
web/src/components/user/UserGeneralTab.vue
Normal file
48
web/src/components/user/UserGeneralTab.vue
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<template>
|
||||||
|
<Panel>
|
||||||
|
<div class="flex flex-row border-b mb-4 pb-4 items-center dark:border-wp-background-100">
|
||||||
|
<h1 class="ml-2 text-xl text-wp-text-100">{{ $t('user.settings.general.general') }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col mt-2 mb-4">
|
||||||
|
<div class="flex items-center text-wp-text-100 font-bold mb-2">
|
||||||
|
<label>{{ $t('user.settings.general.language') }}</label>
|
||||||
|
</div>
|
||||||
|
<SelectField v-model="selectedLocale" :options="localeOptions" />
|
||||||
|
</div>
|
||||||
|
</Panel>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { useLocalStorage } from '@vueuse/core';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import TimeAgo from 'javascript-time-ago';
|
||||||
|
import { SUPPORTED_LOCALES } from 'virtual:vue-i18n-supported-locales';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import SelectField from '~/components/form/SelectField.vue';
|
||||||
|
import { setI18nLanguage } from '~/compositions/useI18n';
|
||||||
|
|
||||||
|
const { locale } = useI18n();
|
||||||
|
|
||||||
|
const localeOptions = computed(() =>
|
||||||
|
SUPPORTED_LOCALES.map((supportedLocale) => ({
|
||||||
|
value: supportedLocale,
|
||||||
|
text: new Intl.DisplayNames(supportedLocale, { type: 'language' }).of(supportedLocale) || supportedLocale,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
const storedLocale = useLocalStorage('woodpecker:locale', locale.value);
|
||||||
|
const selectedLocale = computed<string>({
|
||||||
|
async set(_selectedLocale) {
|
||||||
|
await setI18nLanguage(_selectedLocale);
|
||||||
|
storedLocale.value = _selectedLocale;
|
||||||
|
dayjs.locale(_selectedLocale);
|
||||||
|
TimeAgo.setDefaultLocale(_selectedLocale);
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return storedLocale.value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -131,22 +131,10 @@ const routes: RouteRecordRaw[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/admin',
|
path: '/admin',
|
||||||
component: (): Component => import('~/views/RouterView.vue'),
|
|
||||||
meta: { authentication: 'required' },
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
name: 'admin',
|
|
||||||
component: (): Component => import('~/views/admin/Admin.vue'),
|
|
||||||
props: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'settings',
|
|
||||||
name: 'admin-settings',
|
name: 'admin-settings',
|
||||||
component: (): Component => import('~/views/admin/AdminSettings.vue'),
|
component: (): Component => import('~/views/admin/AdminSettings.vue'),
|
||||||
props: true,
|
props: true,
|
||||||
},
|
meta: { authentication: 'required' },
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,114 +1,21 @@
|
||||||
<template>
|
<template>
|
||||||
<Scaffold>
|
<Scaffold enable-tabs>
|
||||||
<template #title>{{ $t('user.settings') }}</template>
|
<template #title>{{ $t('user.settings.settings') }}</template>
|
||||||
<template #titleActions><Button :text="$t('logout')" :to="`${address}/logout`" /></template>
|
<template #titleActions><Button :text="$t('logout')" :to="`${address}/logout`" /></template>
|
||||||
<div class="space-y-4 flex flex-col">
|
<Tab id="general" :title="$t('user.settings.general.general')">
|
||||||
<SelectField v-model="selectedLocale" :options="localeOptions" />
|
<UserGeneralTab />
|
||||||
|
</Tab>
|
||||||
<div>
|
<Tab id="api" :title="$t('user.settings.api.api')">
|
||||||
<div class="flex items-center mb-2">
|
<UserAPITab />
|
||||||
<h2 class="text-lg text-wp-text-100">{{ $t('user.token') }}</h2>
|
</Tab>
|
||||||
<Button class="ml-4" :text="$t('user.reset_token')" @click="resetToken" />
|
|
||||||
</div>
|
|
||||||
<pre class="code-box">{{ token }}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h2 class="text-lg text-wp-text-100">{{ $t('user.shell_setup') }}</h2>
|
|
||||||
<pre class="code-box">{{ usageWithShell }}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<h2 class="text-lg text-wp-text-100">{{ $t('user.api_usage') }}</h2>
|
|
||||||
<a
|
|
||||||
v-if="enableSwagger"
|
|
||||||
:href="`${address}/swagger/index.html`"
|
|
||||||
target="_blank"
|
|
||||||
class="ml-4 text-wp-link-100 hover:text-wp-link-200"
|
|
||||||
>Swagger UI</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<pre class="code-box">{{ usageWithCurl }}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<h2 class="text-lg text-wp-text-100">{{ $t('user.cli_usage') }}</h2>
|
|
||||||
<a :href="cliDownload" target="_blank" class="ml-4 text-wp-link-100 hover:text-wp-link-200">{{
|
|
||||||
$t('user.dl_cli')
|
|
||||||
}}</a>
|
|
||||||
</div>
|
|
||||||
<pre class="code-box">{{ usageWithCli }}</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Scaffold>
|
</Scaffold>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useLocalStorage } from '@vueuse/core';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import TimeAgo from 'javascript-time-ago';
|
|
||||||
import { SUPPORTED_LOCALES } from 'virtual:vue-i18n-supported-locales';
|
|
||||||
import { computed, onMounted, ref } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
|
|
||||||
import Button from '~/components/atomic/Button.vue';
|
|
||||||
import SelectField from '~/components/form/SelectField.vue';
|
|
||||||
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';
|
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';
|
||||||
import useApiClient from '~/compositions/useApiClient';
|
import Tab from '~/components/layout/scaffold/Tab.vue';
|
||||||
import useConfig from '~/compositions/useConfig';
|
import UserAPITab from '~/components/user/UserAPITab.vue';
|
||||||
import { setI18nLanguage } from '~/compositions/useI18n';
|
import UserGeneralTab from '~/components/user/UserGeneralTab.vue';
|
||||||
|
|
||||||
const { t, locale } = useI18n();
|
const address = `${window.location.protocol}//${window.location.host}`; // port is included in location.host
|
||||||
const { enableSwagger } = useConfig();
|
|
||||||
|
|
||||||
const apiClient = useApiClient();
|
|
||||||
const token = ref<string | undefined>();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
token.value = await apiClient.getToken();
|
|
||||||
});
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
const address = `${location.protocol}//${location.host}`; // port is included in location.host
|
|
||||||
|
|
||||||
const usageWithShell = computed(() => {
|
|
||||||
let usage = `export WOODPECKER_SERVER="${address}"\n`;
|
|
||||||
usage += `export WOODPECKER_TOKEN="${token.value}"\n`;
|
|
||||||
return usage;
|
|
||||||
});
|
|
||||||
|
|
||||||
const usageWithCurl = `# ${t(
|
|
||||||
'user.shell_setup_before',
|
|
||||||
)}\ncurl -i \${WOODPECKER_SERVER}/api/user -H "Authorization: Bearer \${WOODPECKER_TOKEN}"`;
|
|
||||||
|
|
||||||
const usageWithCli = `# ${t('user.shell_setup_before')}\nwoodpecker info`;
|
|
||||||
|
|
||||||
const cliDownload = 'https://github.com/woodpecker-ci/woodpecker/releases';
|
|
||||||
|
|
||||||
const localeOptions = computed(() =>
|
|
||||||
SUPPORTED_LOCALES.map((supportedLocale) => ({
|
|
||||||
value: supportedLocale,
|
|
||||||
text: new Intl.DisplayNames(supportedLocale, { type: 'language' }).of(supportedLocale) || supportedLocale,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
const storedLocale = useLocalStorage('woodpecker:locale', locale.value);
|
|
||||||
const selectedLocale = computed<string>({
|
|
||||||
async set(_selectedLocale) {
|
|
||||||
await setI18nLanguage(_selectedLocale);
|
|
||||||
storedLocale.value = _selectedLocale;
|
|
||||||
dayjs.locale(_selectedLocale);
|
|
||||||
TimeAgo.setDefaultLocale(_selectedLocale);
|
|
||||||
},
|
|
||||||
get() {
|
|
||||||
return storedLocale.value;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const resetToken = async () => {
|
|
||||||
token.value = await apiClient.resetToken();
|
|
||||||
window.location.href = `${address}/logout`;
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<template>
|
|
||||||
<div class="flex m-auto">Administration</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { defineComponent, onMounted } from 'vue';
|
|
||||||
|
|
||||||
import useAuthentication from '~/compositions/useAuthentication';
|
|
||||||
import router from '~/router';
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'Admin',
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
const authentication = useAuthentication();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
if (!authentication.user || !authentication.user.admin) {
|
|
||||||
await router.replace({ name: 'home' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<template #titleActions>
|
<template #titleActions>
|
||||||
<IconButton
|
<IconButton
|
||||||
v-if="orgPermissions.admin"
|
v-if="!org.is_user && orgPermissions.admin"
|
||||||
icon="settings"
|
icon="settings"
|
||||||
:to="{ name: 'org-settings' }"
|
:to="{ name: 'org-settings' }"
|
||||||
:title="$t('org.settings.settings')"
|
:title="$t('org.settings.settings')"
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<template #titleActions>
|
<template #titleActions>
|
||||||
<IconButton
|
<IconButton
|
||||||
v-if="orgPermissions.admin"
|
v-if="!org.is_user && orgPermissions.admin"
|
||||||
:to="{ name: 'repo-settings' }"
|
:to="{ name: 'repo-settings' }"
|
||||||
:title="$t('org.settings.settings')"
|
:title="$t('org.settings.settings')"
|
||||||
icon="settings"
|
icon="settings"
|
||||||
|
@ -41,7 +41,14 @@ provide('org-permissions', orgPermissions);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
org.value = await apiClient.getOrg(orgId.value);
|
org.value = await apiClient.getOrg(orgId.value);
|
||||||
|
if (org.value.is_user) {
|
||||||
|
orgPermissions.value = {
|
||||||
|
member: true,
|
||||||
|
admin: true,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
orgPermissions.value = await apiClient.getOrgPermissions(org.value.id);
|
orgPermissions.value = await apiClient.getOrgPermissions(org.value.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(load);
|
onMounted(load);
|
||||||
|
|
Loading…
Reference in a new issue