Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): add user role management #4248

Draft
wants to merge 83 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
63b758d
feat(admin): add user role management
chinook25 Sep 23, 2024
092408a
wip: admin page tries request
chinook25 Sep 23, 2024
4509030
wip: use useFetch (not working)
chinook25 Sep 24, 2024
4a69b28
wip: now it retrieves!
chinook25 Sep 24, 2024
a4b5171
wip: retrieve tokens
chinook25 Sep 24, 2024
7612f38
wip: add murmurs
chinook25 Sep 24, 2024
faf3f5b
Merge branch 'master' into feat/admin-role-management
chinook25 Sep 25, 2024
20477dc
wip: use useFetch
chinook25 Sep 25, 2024
239fe1e
wip: pagination working
chinook25 Sep 26, 2024
3981a51
wip: limit 20
chinook25 Sep 26, 2024
bebe5dc
wip: correct next page
chinook25 Sep 27, 2024
f11b42d
wip: add roles to user
chinook25 Oct 1, 2024
b57ab94
wip: add column to db
chinook25 Oct 1, 2024
9090611
wip rename
chinook25 Oct 1, 2024
7e678c9
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 1, 2024
15c32fb
now with correct query
chinook25 Oct 1, 2024
7449963
adding roles to sql
chinook25 Oct 1, 2024
c49169a
Merge branch 'master' into feat/admin-role-management
mswertz Oct 1, 2024
1b428a0
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 2, 2024
cd45861
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 3, 2024
78b2e47
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 4, 2024
086705d
wip: trying to retrieve roles, almost there?
chinook25 Oct 4, 2024
0bf018a
wip: remove unused code
chinook25 Oct 4, 2024
d7b20b5
chore: format
chinook25 Oct 4, 2024
de1e694
chore: format
chinook25 Oct 4, 2024
f2f245d
feat: retrieving roles works
chinook25 Oct 4, 2024
32aabc7
chore: remove roles from user
chinook25 Oct 4, 2024
1163a05
chore: remove unused type
chinook25 Oct 4, 2024
dddad76
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 7, 2024
7bfe0eb
chore: move load roles function
chinook25 Oct 7, 2024
f94833b
feat: split result into schema and role
chinook25 Oct 7, 2024
3201621
chore: minor refactor
chinook25 Oct 7, 2024
7da5b8b
fix: warnings
chinook25 Oct 7, 2024
c488c17
chore: nicer role and token display
chinook25 Oct 7, 2024
793e626
chore: refactor
chinook25 Oct 8, 2024
c059219
feat: add delete and update functions
chinook25 Oct 8, 2024
f7d8962
minor chagne
chinook25 Oct 8, 2024
6c71ff9
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 8, 2024
d73c913
feat: can add users
chinook25 Oct 8, 2024
534e7df
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 9, 2024
3380177
merge master
chinook25 Oct 9, 2024
30279c2
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 9, 2024
2cc3874
chore: add comments
chinook25 Oct 9, 2024
9dc7425
feat: show enabled; wip: start with edit user modal
chinook25 Oct 10, 2024
ae6f00b
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 14, 2024
0204c24
feat: put create user in modal
chinook25 Oct 14, 2024
27a700a
feat:retrieve roles
chinook25 Oct 15, 2024
4434a7d
chore: move functions to util file
chinook25 Oct 16, 2024
c6bed32
feat: show tokens in modal
chinook25 Oct 16, 2024
a7820f6
feat: add dis-/en-able button
chinook25 Oct 16, 2024
55fa5b6
chore: tsing
chinook25 Oct 16, 2024
eb03b44
chore: move edit user modal to component
chinook25 Oct 17, 2024
1ae772e
feat?: wip edit user
chinook25 Oct 17, 2024
bcbb249
feat: interface to add/remove roles and remove tokens
chinook25 Oct 17, 2024
a5d7c20
edit password field
chinook25 Oct 17, 2024
67946f0
Merge branch 'master' into feat/admin-role-management
chinook25 Oct 22, 2024
e216d99
wip: adding update user endpoint
chinook25 Oct 22, 2024
1d92672
wip: making update user endpoint
chinook25 Oct 23, 2024
b44047d
wip: gql query correct?
chinook25 Oct 23, 2024
5641f8c
update pass
chinook25 Oct 24, 2024
372a54c
feat: can commit user changes;fix: disabled user toggles correctly
chinook25 Oct 25, 2024
6f75747
Merge branch 'master' into feat/admin-role-management
chinook25 Nov 4, 2024
6883c43
feat: can now save enabling;update list on save
chinook25 Nov 4, 2024
e2e38c0
feat: make role api better
chinook25 Nov 5, 2024
c6a71b6
Merge branch 'master' into feat/admin-role-management
chinook25 Nov 7, 2024
875b9d0
wip: adding role api
chinook25 Nov 7, 2024
e5f61ab
fix: import
chinook25 Nov 7, 2024
0f4df76
feat: can add and remove roles!
chinook25 Nov 7, 2024
20480e7
feat: can now update existing roles
chinook25 Nov 7, 2024
e25daca
chore:refactor
chinook25 Nov 7, 2024
5a5d70c
Merge branch 'master' into feat/admin-role-management
chinook25 Nov 11, 2024
40286b9
test: add working start of test
chinook25 Nov 12, 2024
bca1285
chore: basic test
chinook25 Nov 12, 2024
4314bca
test: basic change test
chinook25 Nov 12, 2024
31ec18e
test: basic change test
chinook25 Nov 12, 2024
bc21da8
chore: test updateUser
chinook25 Nov 13, 2024
9e3b520
chore: improve cov
chinook25 Nov 13, 2024
d09a101
chore: refactor to make sonarcloud happy
chinook25 Nov 13, 2024
60842d5
chore: refactor to make sonarcloud happy
chinook25 Nov 13, 2024
f8d2ec1
chore: refactor to make sonarcloud happy
chinook25 Nov 13, 2024
6f33ba6
chore: more sonarring
chinook25 Nov 13, 2024
b8f192b
chore: remove dead code
chinook25 Nov 13, 2024
732cb00
chore: undo remove code
chinook25 Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/tailwind-components/components/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const mainButtons = computed(() =>
const subButtons = computed(() =>
props.navigation.slice(props.maximumButtonShown)
);
const active = "underline";
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
</script>

<template>
Expand Down
8 changes: 4 additions & 4 deletions apps/tailwind-components/server/routes/[schema]/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { joinURL } from "ufo";
import { createConsola } from "consola";

export default defineEventHandler((event) => {
const config = useRuntimeConfig(event);
const logger = createConsola({ level: config.logLevel?? 3 });
const config = useRuntimeConfig(event);
const logger = createConsola({ level: config.logLevel ?? 3 });
logger.info("proxy schema gql request : ", event.path);
if (event.method === "POST") {
readBody(event).then((body) => {
if (body.query) {
logger.debug( body.query);
logger.debug(body.query);
}
if (body.variables) {
logger.debug(body.variables);
Expand All @@ -17,6 +17,6 @@ export default defineEventHandler((event) => {
}
const schema = getRouterParam(event, "schema") || "";
logger.info("to : ", joinURL(config.public.apiBase, schema, "graphql"));
const target = joinURL(config.public.apiBase, schema,"graphql");
const target = joinURL(config.public.apiBase, schema, "graphql");
return proxyRequest(event, target);
});
15 changes: 11 additions & 4 deletions apps/ui/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const config = useRuntimeConfig();
const route = useRoute();
const { data: session } = await useSession();
console.log("session form defaiult layout: ", session.value);
console.log("session form default layout: ", session.value);

const faviconHref = config.public.emx2Theme
? `/_nuxt-styles/img/${config.public.emx2Theme}.ico`
Expand All @@ -11,16 +11,18 @@ const faviconHref = config.public.emx2Theme
useHead({
htmlAttrs: {
"data-theme":
(route.query.theme as string) || config.public.emx2Theme || "",
(route.query.theme as string) ||
(config.public.emx2Theme as string) ||
"",
},
link: [{ rel: "icon", href: faviconHref }],
titleTemplate: (titleChunk) => {
if (titleChunk && config.public.siteTitle) {
return `${titleChunk} | ${config.public.siteTitle}`;
} else if (titleChunk) {
return titleChunk;
} else if (config.public.siteTitle) {
return config.public.siteTitle;
// } else if (config.public.siteTitle) {
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
// return config.public.siteTitle;
} else {
return "Emx2";
}
Expand Down Expand Up @@ -65,6 +67,11 @@ const navigation = computed(() => {
<Navigation :navigation="navigation" />
</template>
<template #account>
<HeaderButton
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
label="Admin"
icon="Database"
@click="navigateTo({ path: '/admin/' })"
/>
<HeaderButton
:label="isSignedIn ? 'Account' : 'Signin'"
icon="user"
Expand Down
14 changes: 7 additions & 7 deletions apps/ui/middleware/adminOnly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default defineNuxtRouteMiddleware(async (to, from) => {
const {data: session} = await useSession();
const isAdmin = computed(() => session.value.email === "admin");
if (!isAdmin.value) {
return navigateTo('/login')
}
})
export default defineNuxtRouteMiddleware(async (_to, _from) => {
const { data: session } = await useSession();
const isAdmin = computed(() => session.value.email === "admin");
if (!isAdmin.value) {
return navigateTo("/login");
}
});
6 changes: 4 additions & 2 deletions apps/ui/pages/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ async function signout() {
type="primary"
size="medium"
@click="signout"
>Sign out</Button
>
Sign out
</Button>
<Button
v-else
type="primary"
size="medium"
@click="navigateTo('/login')"
>Sign in</Button
>
Sign in
</Button>
</div>
chinook25 marked this conversation as resolved.
Show resolved Hide resolved

<div class="mt-3">{{ errorMsg }}</div>
Expand Down
45 changes: 45 additions & 0 deletions apps/ui/pages/admin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<PageHeader title="Admin Tools" />
<Container class="flex flex-col items-center">
<ContentBlock class="w-full mt-3" title="User management">
<h2>User List</h2>
<Table>
<template #head>
<TableHeadRow>
<TableHead>name</TableHead>
<TableHead>description</TableHead>
</TableHeadRow>
</template>
<template #body>
<TableRow v-for="user in users">
<TableCell>{{ user.userName }}</TableCell>
<TableCell>{{ user }}</TableCell>
</TableRow>
</template>
</Table>
</ContentBlock>
</Container>
</template>

<script lang="ts">
import { request } from "graphql-request";
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
definePageMeta({
middleware: "admin-only",
});

const users = ref<Record<string, any>[]>([]);
const userCount = ref(0);

getUsers();

async function getUsers() {
const result: any = await request(
"graphql",
`{_admin{users{email},userCount}}`
).catch((error) => {
console.log("Error loading users: ", error);
});
users.value = result?._admin?.users || [];
userCount.value = result?._admin?.userCount ?? 0;
}
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
</script>
Loading