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

Project sharing #5158

Merged
merged 8 commits into from
Oct 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { computed, ref } from 'vue';
import { exportProjectAsFile } from '@/services/project';
import { AcceptedExtensions } from '@/types/common';
import { MenuItem } from 'primevue/menuitem';
import useAuthStore from '@/stores/auth';

const props = defineProps<{ project: Project | null }>();

Expand All @@ -26,8 +27,8 @@ const { isShareDialogVisible, isRemoveDialogVisible, isProjectConfigDialogVisibl
const isCopying = ref(false);

const menu = ref();
const renameMenuItem = {
label: 'Edit project details',
const editDetailsMenuItem = {
label: 'Edit details',
icon: 'pi pi-pencil',
command: () => {
isProjectConfigDialogVisible.value = true;
Expand All @@ -41,14 +42,14 @@ const shareMenuItem = {
}
};
const removeMenuItem = {
label: 'Remove',
label: 'Delete',
icon: 'pi pi-trash',
command: () => {
isRemoveDialogVisible.value = true;
}
};
const copyMenuItem = {
label: 'Copy this project',
label: 'Copy',
icon: 'pi pi-clone',
command: async () => {
if (props.project) {
Expand Down Expand Up @@ -80,19 +81,20 @@ const downloadMenuItem = {
}
};

const separatorMenuItem = { separator: true };
const projectMenuItems = computed(() => {
const items: MenuItem[] = [];
if (props.project?.publicProject || props.project?.userPermission === 'creator') {
items.push(copyMenuItem);
items.push(downloadMenuItem);
}
if (props.project?.userPermission === 'creator') {
items.push(renameMenuItem, shareMenuItem, separatorMenuItem, removeMenuItem);
// Basic access to public and reader project
const items: MenuItem[] = [copyMenuItem, downloadMenuItem];

// Creator/Editor of the project
if (['creator', 'writer'].includes(props.project?.userPermission ?? '')) {
items.push(editDetailsMenuItem, shareMenuItem);
}
if (props.project?.userPermission === 'writer') {
items.push(renameMenuItem);

// Creator of the project, or an admin
if (props.project?.userPermission === 'creator' || useAuthStore().isAdmin) {
items.push(removeMenuItem);
}

return items;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const userMenuItems = ref([
command: () => {
router.push(RoutePath.UserAdmin);
},
visible: auth.user?.roles.some((r) => r.name === 'ADMIN')
visible: auth.isAdmin
},
{
label: 'Logout',
Expand Down
11 changes: 6 additions & 5 deletions packages/client/hmi-client/src/page/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@
</section>
<section class="projects">
<div v-if="!isLoadingProjects && isEmpty(searchedAndFilterProjects)" class="no-projects">
<Vue3Lottie :animationData="EmptySeed" :height="200" :width="200"></Vue3Lottie>
<!--
<img src="@assets/svg/seed.svg" alt="" />
-->
<Vue3Lottie :animationData="EmptySeed" :height="200" :width="200" />
<template v-if="tab.title === TabTitles.MyProjects">
<p class="mt-4">
Get started by creating a
Expand Down Expand Up @@ -232,7 +229,11 @@ const viewOptions = ref([
const myFilteredSortedProjects = computed(() => {
const projects = useProjects().allProjects.value;
if (!projects) return [];
const myProjects = projects.filter(({ userPermission }) => ['creator', 'writer'].includes(userPermission ?? ''));
const myProjects = projects.filter(
({ userPermission, publicProject }) =>
// I can edit the project, or I can view the project and it's not public
['creator', 'writer'].includes(userPermission ?? '') || (userPermission === 'reader' && !publicProject)
);
return filterAndSortProjects(myProjects);
});

Expand Down
9 changes: 8 additions & 1 deletion packages/client/hmi-client/src/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { User } from '@/types/Types';
import axios, { AxiosHeaders } from 'axios';
import { computed, ref } from 'vue';
import { createOidc, Oidc } from 'oidc-spa';
import { RoleType } from '@/types/Types';

/**
* Main store used for authentication
Expand Down Expand Up @@ -70,6 +71,11 @@ const useAuthStore = defineStore('auth', () => {
await loadUserModel();
};

const isAdmin = computed(() => {
if (!user.value) return false;
return user.value?.roles.some((r) => r.name === RoleType.Admin);
});

return {
login,
logout,
Expand All @@ -78,7 +84,8 @@ const useAuthStore = defineStore('auth', () => {
updateUser,
loadUserModel,
userInitials,
init
init,
isAdmin
};
});

Expand Down