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 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
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
16 changes: 4 additions & 12 deletions apps/settings/src/components/Members.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
<MessageError v-if="graphqlError">{{ graphqlError }}</MessageError>
<MessageSuccess v-if="success">{{ success }}</MessageSuccess>
</div>
<div
v-if="
session &&
(session.email == 'admin' ||
(session.roles && session.roles.length > 0))
"
>
<div v-if="session?.email === 'admin' || session?.roles?.length">
<h5 class="card-title">Manage members</h5>
<p>Use table below to add, edit or remove members</p>
<form v-if="canEdit" class="form-inline">
Expand Down Expand Up @@ -109,13 +103,11 @@ export default {
loading: false,
};
},

computed: {
canEdit() {
return (
this.session != null &&
(this.session.email == "admin" ||
this.session.roles.includes("Manager"))
this.session?.email === "admin" ||
this.session?.roles.includes("Manager")
);
},
},
Expand All @@ -130,7 +122,7 @@ export default {
`mutation drop($member:[String]){drop(members:$member){message}}`,
{ member: name }
)
.then((data) => {
.then(() => {
this.loadMembers();
})
.catch((error) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/tailwind-components/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function showModal() {
visible.value = true;
}

const closeModal = (returnVal?: string) => {
const closeModal = (_returnVal?: string) => {
visible.value = false;
};

Expand All @@ -20,6 +20,7 @@ defineExpose({
visible,
});
</script>

<template>
<section
v-show="visible"
Expand Down
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
1 change: 0 additions & 1 deletion apps/tailwind-components/components/Table.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<table class="w-full table-auto">
<thead>
Expand Down
1 change: 0 additions & 1 deletion apps/tailwind-components/components/TableCell.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- eslint-disable vue/multi-word-component-names -->
<script setup>
defineProps({
allowLineBreak: {
Expand Down
1 change: 0 additions & 1 deletion apps/tailwind-components/components/TableRow.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<tr class="sm:hover:bg-blue-50 sm:hover:cursor-pointer">
<slot></slot>
Expand Down
2 changes: 1 addition & 1 deletion apps/tailwind-components/components/input/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script lang="ts" setup>
defineProps<{
value: string;
value: string | boolean;
}>();

const modelValue = defineModel<string>();
Expand Down
6 changes: 3 additions & 3 deletions apps/tailwind-components/components/input/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div
class="flex justify-start align-center"
v-for="option in radioOptions"
:key="option.value"
:key="JSON.stringify(option.value)"
>
<InputRadio
:id="`${id}-radio-group-${option.value}`"
Expand Down Expand Up @@ -41,7 +41,7 @@

<script lang="ts" setup>
interface RadioOptionsDataIF {
value: string;
value: string | boolean;
label?: string;
checked?: boolean | undefined;
}
Expand All @@ -57,7 +57,7 @@ withDefaults(
}
);

const modelValue = defineModel<string>();
const modelValue = defineModel<string | boolean>();

function resetModelValue() {
modelValue.value = "";
Expand Down
2 changes: 0 additions & 2 deletions apps/tailwind-components/components/input/Select.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script setup lang="ts">
import type { N } from "vitest/dist/reporters-MmQN-57K.js";

withDefaults(
defineProps<{
id: string;
Expand Down
35 changes: 19 additions & 16 deletions apps/tailwind-components/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
modules: ['@nuxtjs/tailwindcss', '@nuxt/test-utils/module'],
modules: ["@nuxtjs/tailwindcss", "@nuxt/test-utils/module"],
tailwindcss: {
cssPath: '~/assets/css/main.css',
configPath: '~/tailwind.config.js'
cssPath: "~/assets/css/main.css",
configPath: "~/tailwind.config.js",
},

ssr: process.env.NUXT_PUBLIC_IS_SSR === 'false' ? false : true,
ssr: process.env.NUXT_PUBLIC_IS_SSR === "false" ? false : true,

router: {
options: process.env.NUXT_PUBLIC_IS_SSR === 'false' ? {
hashMode: true
} : {}
options:
process.env.NUXT_PUBLIC_IS_SSR === "false"
? {
hashMode: true,
}
: {},
},

nitro: {
prerender: {
ignore: ['/_tailwind/']
}
ignore: ["/_tailwind/"],
},
},

app: {
head: {
htmlAttrs: {
'data-theme': ''
}
}
"data-theme": "",
},
},
},

components: [
Expand All @@ -36,16 +39,16 @@ export default defineNuxtConfig({
},
{
path: "~/components/viz",
pathPrefix: false
pathPrefix: false,
},
"~/components",
],

runtimeConfig: {
public: {
apiBase: "https://emx2.dev.molgenis.org/", // "http://localhost:8080/",
apiBase: "http://localhost:8080/",
},
},

compatibilityDate: '2024-08-23',
})
compatibilityDate: "2024-08-23",
});
21 changes: 11 additions & 10 deletions apps/tailwind-components/pages/Button.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@

<h2 class="text-2xl">Icons</h2>
<div class="flex gap-4">
<Button type="primary" size="medium" icon="filter" iconPosition="left"
>Filter</Button
>
<Button type="primary" size="small" icon="filter" iconPosition="right"
>Filter</Button
>
<Button type="secondary" size="small" icon="star" iconPosition="left"
>Star</Button
>
<Button type="primary" size="medium" icon="filter" iconPosition="left">
Filter
</Button>
<Button type="primary" size="small" icon="filter" iconPosition="right">
Filter
</Button>
<Button type="secondary" size="small" icon="star" iconPosition="left">
Star
</Button>
<Button
type="secondary"
size="small"
icon="CaretDown"
iconPosition="right"
>CaretDown</Button
>
CaretDown
</Button>
</div>
</div>
</template>
1 change: 1 addition & 0 deletions apps/tailwind-components/pages/Modal.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function showModal() {

let sectionCount = ref(0);
</script>

<template>
<button
@click="showModal"
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);
});
11 changes: 8 additions & 3 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 @@ -21,8 +21,8 @@ useHead({
return `${titleChunk} | ${config.public.siteTitle}`;
} else if (titleChunk) {
return titleChunk;
} else if (config.public.siteTitle) {
return config.public.siteTitle as string;
// } else if (config.public.siteTitle) {
chinook25 marked this conversation as resolved.
Show resolved Hide resolved
// return config.public.siteTitle as string;
} else {
return "Emx2";
}
Expand Down Expand Up @@ -67,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
Loading