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: add admin panel and display teams #175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions front/front/package-lock.json

This file was deleted.

29 changes: 26 additions & 3 deletions front/src/components/Drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
<v-img :src="userPicture"></v-img>
</v-list-item-avatar>

<v-list-item-title>{{user.displayName || user.email}}</v-list-item-title>
<v-list-item-title>{{
user.displayName || user.email
}}</v-list-item-title>
</v-list-item>

<v-divider></v-divider>
<v-list dense nav>
<template v-for="item in items">
<v-list-item :key="item.title" v-if="canDisplay(item)" link :to="item.href">
<v-list-item
:key="item.title"
v-if="canDisplay(item)"
link
:to="item.href"
>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
Expand All @@ -31,6 +38,19 @@
</v-list>

<template v-slot:append>
<v-list-item
link
to="/admin"
v-if="isAdmin"
>
<v-list-item-icon>
<v-icon color="warning">mdi-application-cog</v-icon>
</v-list-item-icon>

<v-list-item-content>
<v-list-item-title>Administration</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item link to="/logout" v-if="user">
<v-list-item-icon>
<v-icon color="error">mdi-logout</v-icon>
Expand Down Expand Up @@ -63,12 +83,15 @@ export default {
}
},
computed: {
...mapState([ 'organizationId', 'assignedTeamId' ]),
...mapState([ 'organizationId', 'assignedTeamId', 'role' ]),
user() {
return this.$store.getters.user;
},
userPicture() {
return this.user.photoURL || `https://eu.ui-avatars.com/api/?name=${this.user.email}`
},
isAdmin() {
return this.user && this.role && this.role.includes('admin')
}
},
methods: {
Expand Down
28 changes: 28 additions & 0 deletions front/src/router/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Dashboard from '../views/admin/Dashboard.vue';
import Organizations from '../views/admin/Organizations.vue';
import Teams from '../views/admin/Teams.vue';

const adminRoutes = [
{
path: '',
name: 'dashboard',
component: Dashboard,
},
{
path: 'organisations',
name: 'organisations',
Comment on lines +12 to +13
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
path: 'organisations',
name: 'organisations',
path: 'organizations',
name: 'organizations',

component: Organizations,
},
{
path: 'teams',
name: 'teams',
component: Teams,
},
{
path: 'users',
name: 'users',
component: Dashboard,
Copy link
Owner

Choose a reason for hiding this comment

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

component Dashboard for user ? typo or waiting for a future component ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For future admin and god user !

},
];

export default adminRoutes;
33 changes: 30 additions & 3 deletions front/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
import firebase from '@/firebase/init';
import store from '@/store';
import Home from '../views/Home.vue';
import Login from '../views/Login.vue';
import Register from '../views/Register.vue';
import About from '../views/About.vue';
import Faq from '../views/Faq.vue';
import Logout from '../views/Logout.vue';
import firebase from '@/firebase/init';
import store from '@/store';
import adminRoutes from './admin';
import Admin from '../views/Admin.vue';


Vue.use(VueRouter);

const routes = [
{
path: '/admin',
name: 'admin',
meta: {
requireAuth: true,
requireAdmin: true,
requireOrganization: false,
requireTeam: false,
},
component: Admin,
children: [...adminRoutes],
},
{
path: '/',
name: 'home',
Expand Down Expand Up @@ -112,9 +127,21 @@ const router = new VueRouter({
});

router.beforeEach(async (to, from, next) => {

const requireAuth = to.matched.some((record) => record.meta.requireAuth);
const requireTeam = to.matched.some((record) => record.meta.requireTeam);
const requireAdmin = to.matched.some((record) => record.meta.requireAdmin);

if (requireAdmin) {
if (
store.state &&
store.state.role &&
store.state.role.includes('admin')
) {
next();
} else {
next('/');
}
}

// When accessing a page that need an organization and no user, then login
if (requireAuth && !(await firebase.getCurrentUser())) {
Expand Down
11 changes: 10 additions & 1 deletion front/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default new Vuex.Store({
status: null,
error: null,
assignedTeamId: null,
organizationId: null
organizationId: null,
role: null,
},
mutations: {
setUser(state, payload) {
Expand All @@ -41,6 +42,10 @@ export default new Vuex.Store({

setOrganizationId(state, payload) {
state.organizationId = payload;
},

setRole(state, payload) {
state.role = payload;
}
},
actions: {
Expand All @@ -52,6 +57,10 @@ export default new Vuex.Store({
.doc(userId)
.onSnapshot(snapshot => {
this.userMetadata = snapshot.data();
commit(
'setRole',
this.userMetadata?.role
);
commit(
'setAssignedTeamId',
this.userMetadata?.assignedTeamId
Expand Down
32 changes: 32 additions & 0 deletions front/src/views/Admin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="admin">
<v-tabs fixed-tabs>
<v-tab v-for="li in links" :key="li.link" :to="`/admin/${li.link}`" :disabled="li.isDisabled">
{{ li.label }}
</v-tab>
</v-tabs>
<router-view />
</div>
</template>

<script>

export default {
name: 'admin',
data() {
return {
links: [
{ link: '', label: 'Dashboard' },
{ link: 'organisations', label: 'Organisations', isDisabled: true },
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
{ link: 'organisations', label: 'Organisations', isDisabled: true },
{ link: 'organizations', label: 'Organisations', isDisabled: true },

{ link: 'teams', label: 'Teams', isDisabled: false },
{ link: 'users', label: 'Users', isDisabled: true },
Comment on lines +19 to +22
Copy link
Owner

Choose a reason for hiding this comment

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

do you think it is posible to reuse the array from router/admin.js to avoid rewriting this array ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure and it will be different array for admin and god

]
}
},
components: {
},
created(){

}
Comment on lines +26 to +30
Copy link
Owner

Choose a reason for hiding this comment

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

can we delete them ?

}
</script>
42 changes: 42 additions & 0 deletions front/src/views/admin/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<section class="dashboard">
<v-skeleton-loader
class="mx-auto"
min-width="300"
type="card"
></v-skeleton-loader>
<v-skeleton-loader
class="mx-auto"
min-width="300"
type="card"
></v-skeleton-loader>
</section>
</template>

<script>

export default {
name: "dashboard",
components: {
},
data() {
return {
};
},
beforeCreate() {
},
watch: {
},
methods: {
}
Comment on lines +20 to +31
Copy link
Owner

Choose a reason for hiding this comment

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

useless ?

}
</script>

<style scoped lang="scss">
.dashboard {
display: flex;
justify-content: space-between;
align-items: center;
padding: 25px;
}
</style>
22 changes: 22 additions & 0 deletions front/src/views/admin/Organizations.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div class="d-flex">
<img src="" alt="" />
</div>
</template>

<script>

export default {
name: "organisations",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
name: "organisations",
name: "organizations",

components: {
},
data() {
return {

};
},
Comment on lines +11 to +17
Copy link
Owner

Choose a reason for hiding this comment

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

useless ?

}
</script>

<style scoped lang="scss">
</style>
Loading