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
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
51 changes: 40 additions & 11 deletions apps/ui/pages/admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<Container class="flex flex-col items-center">
<ContentBlock class="w-full mt-3" title="User management">
<h2>User List ({{ userCount }})</h2>
<Pagination
:currentPage="currentPage"
:totalPages="totalPages"
@update="updateCurrentPage"
/>
<Table>
<template #head>
<TableHeadRow>
Expand Down Expand Up @@ -36,26 +41,50 @@ definePageMeta({
middleware: "admin-only",
});

const { data, error } = await useFetch<IAdminResponse>("/api/graphql", {
method: "post",
body: {
query: `{ _admin { users { email, settings, {key, value} } userCount } }`,
},
const LIMIT = 20;
const currentPage = ref(1);
const offset = computed(() => {
return currentPage.value > 1 ? `, offset: ${currentPage.value * LIMIT}` : "";
});
if (error.value) {
console.log("Error loading users: ", error.value);
// todo handle error see catalogue error page

const users = ref<IUser[]>([]);
const userCount = ref(0);
const totalPages = ref(0);
getUsers();

function updateCurrentPage(newPage: number) {
currentPage.value = newPage;
getUsers();
}

const users = computed(() => data.value?.data._admin.users || []);
const userCount = computed(() => data.value?.data._admin.userCount ?? 0);
async function getUsers() {
const { data, error } = await useFetch<IAdminResponse>("/api/graphql", {
method: "post",
body: {
query: `{ _admin { users(limit: ${LIMIT}${offset.value}) { email, settings, {key, value} } userCount } }`,
},
});
if (error.value) {
console.log("Error loading users: ", error.value);
// todo handle error see catalogue error page
}
users.value = data.value?.data._admin.users || [];
userCount.value = data.value?.data._admin.userCount ?? 0;
const divided = userCount.value / LIMIT;
totalPages.value =
userCount.value % LIMIT > 0 ? Math.floor(divided) + 1 : divided;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should should work, but by keeping the useFetch at the page level and using the 'refresh' or computed there is no need for a separate getUsers func and the setup code . This has the added value of exposing the dat, status, error refs at the page level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds cool, didn't get it to work that way though with the pagination.


interface IAdminResponse {
data: {
_admin: {
users: { email: string; settings: ISetting[] }[];
users: IUser[];
userCount: number;
};
};
}
interface IUser {
email: string;
settings: ISetting[];
}
</script>