π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Delete account, bugs fixes, modal, security
Smaug67392aab7ab4806e
diff --git a/backend/app/app.go b/backend/app/app.goindex 0ec5a8eb..00cca90f 100644--- a/backend/app/app.go+++ b/backend/app/app.go@@ -37,6 +37,7 @@ type Services struct {Document services.DocumentServiceCategory services.CategoryServiceRessource services.RessourceService+ Minio services.MinioService}type App struct {@@ -60,6 +61,7 @@ func InitApp(config Config) *App {Document: services.NewDocumentService(app.DB),Category: services.NewCategoryService(app.DB),Ressource: services.NewRessourceService(app.DB),+ Minio: services.NewMinioService(app.MinioClient),}Migrate(&config)diff --git a/backend/controllers/users.controller.go b/backend/controllers/users.controller.goindex 2926577a..6b8d50eb 100644--- a/backend/controllers/users.controller.go+++ b/backend/controllers/users.controller.go@@ -216,6 +216,11 @@ func (ctr *Controller) DeleteUser(c *gin.Context) (int, any) {if err != nil {return http.StatusUnauthorized, err}+ // Delete uploaded files+ err = ctr.app.Services.Minio.DeleteAllFromUser(id)+ if err != nil {+ return http.StatusInternalServerError, err+ }err = ctr.app.Services.User.DeleteUser(id)if err != nil {diff --git a/backend/services/category.service.go b/backend/services/category.service.goindex 1a11dce5..30496e9d 100644--- a/backend/services/category.service.go+++ b/backend/services/category.service.go@@ -19,7 +19,7 @@ func NewCategoryService(db *sql.DB) CategoryService {}func (s *Service) GetAllCategories(userId types.Snowflake) ([]*models.Category, error) {- var categories []*models.Category+ var categories = make([]*models.Category, 0)rows, err := s.db.Query("SELECT * FROM categories WHERE author_id = ? ORDER BY `order`", userId)if err != nil {return nil, errdiff --git a/backend/services/document.service.go b/backend/services/document.service.goindex da4f068c..5f1267d8 100644--- a/backend/services/document.service.go+++ b/backend/services/document.service.go@@ -20,7 +20,7 @@ func NewDocumentService(db *sql.DB) DocumentService {}func (s *Service) GetAllDocuments(userId types.Snowflake) ([]*models.Document, error) {- var documents []*models.Document+ var documents = make([]*models.Document, 0)rows, err := s.db.Query("SELECT id, name, description, tags, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ? ORDER BY name", userId)if err != nil {return nil, err@@ -48,7 +48,7 @@ func (s *Service) GetAllDocuments(userId types.Snowflake) ([]*models.Document, e}func (s *Service) GetAllDocumentBackup(author_id types.Snowflake) ([]*models.Document, error) {- var documents []*models.Document+ var documents = make([]*models.Document, 0)rows, err := s.db.Query("SELECT id, name, description, tags, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ?", author_id)if err != nil {return nil, errdiff --git a/backend/services/minio.service.go b/backend/services/minio.service.gonew file mode 100644index 00000000..c3a107ac--- /dev/null+++ b/backend/services/minio.service.go@@ -0,0 +1,43 @@+package services++import (+ "alexandrie/types"+ "context"+ "fmt"+ "os"++ "github.com/minio/minio-go/v7"+)++type MinioService interface {+ DeleteAllFromUser(userId types.Snowflake) error+}++func NewMinioService(minio *minio.Client) MinioService {+ return &Service{minio: minio}+}++// DeleteAllFromUser+// @Summary Delete all files from a user+// @Security Authenfification: Auth, Self+// @Param id prefix in the bucket+func (s *Service) DeleteAllFromUser(userId types.Snowflake) error {+ prefix := fmt.Sprintf("%d/", userId)+ ctx := context.Background()+ objectCh := s.minio.ListObjects(ctx, os.Getenv("MINIO_BUCKET"), minio.ListObjectsOptions{+ Prefix: prefix,+ Recursive: true,+ })++ // Delete each object+ for object := range objectCh {+ if object.Err != nil {+ return object.Err+ }+ err := s.minio.RemoveObject(ctx, os.Getenv("MINIO_BUCKET"), object.Key, minio.RemoveObjectOptions{})+ if err != nil {+ return fmt.Errorf("failed to delete object: %v", err)+ }+ }+ return nil+}diff --git a/backend/services/ressource.service.go b/backend/services/ressource.service.goindex 4b056a92..eb042ba0 100644--- a/backend/services/ressource.service.go+++ b/backend/services/ressource.service.go@@ -19,7 +19,7 @@ func NewRessourceService(db *sql.DB) RessourceService {}func (s *Service) GetAllUploadsByUserId(userId types.Snowflake) ([]*models.Ressource, error) {- var ressources []*models.Ressource+ var ressources = make([]*models.Ressource, 0)rows, err := s.db.Query("SELECT * from ressources WHERE author_id = ?", userId)if err != nil {return nil, errdiff --git a/backend/services/services.go b/backend/services/services.goindex 0e39bfe1..a68b436d 100644--- a/backend/services/services.go+++ b/backend/services/services.go@@ -1,9 +1,14 @@package services-import "database/sql"+import (+ "database/sql"++ "github.com/minio/minio-go/v7"+)type Service struct {- db *sql.DB+ db *sql.DB+ minio *minio.Client}func New(db *sql.DB) *Service {diff --git a/backend/services/user.service.go b/backend/services/user.service.goindex 735c5a10..68971021 100644--- a/backend/services/user.service.go+++ b/backend/services/user.service.go@@ -22,7 +22,7 @@ func NewUserService(db *sql.DB) UserService {}func (s *Service) GetAllUsers() ([]*models.User, error) {- var users []*models.User+ var users = make([]*models.User, 0)rows, err := s.db.Query("SELECT id, username, firstname, lastname, role, avatar, email, created_timestamp, updated_timestamp FROM users")if err != nil {return nil, errdiff --git a/frontend/composables/ModalBus.ts b/frontend/composables/ModalBus.tsindex b365821f..14542073 100644--- a/frontend/composables/ModalBus.ts+++ b/frontend/composables/ModalBus.ts@@ -22,5 +22,5 @@ export function useModal() {}export class Modal {- constructor(public component: any, public props: any, public onClose: () => void = () => {}) {}+ constructor(public component: any, public props: any = {}, public onClose: () => void = () => {}) {}}diff --git a/frontend/pages/dashboard/settings/_modals/DeleteAccountModal.vue b/frontend/pages/dashboard/settings/_modals/DeleteAccountModal.vuenew file mode 100644index 00000000..8adfa5d2--- /dev/null+++ b/frontend/pages/dashboard/settings/_modals/DeleteAccountModal.vue@@ -0,0 +1,55 @@+<template>+ <div class="modal">+ <h3>Delete account</h3>+ <p>Are you sure you want to delete your account ?</p>+ <p style="opacity: 0.7">This action is irreversible</p>+ <p v-if="time > 0">Please wait {{ time }} seconds before confirming</p>+ <div class="footer">+ <AppButton @click="emit('close')" type="secondary">Cancel</AppButton>+ <AppButton @click="deleteAccount" :disabled="time > 0" type="danger">Confirm</AppButton>+ </div>+ </div>+</template>++<script setup lang="ts">+import { onMounted, onBeforeUnmount, ref } from 'vue';++const time = ref(15);+const emit = defineEmits(['close']);++let interval: NodeJS.Timeout;++onMounted(() => {+ interval = setInterval(() => {+ if (time.value > 0) time.value--;+ else clearInterval(interval);+ }, 1000);+});++onBeforeUnmount(() => {+ if (interval) clearInterval(interval);+});+function deleteAccount() {+ useUserStore()+ .deleteAccount()+ .then(() => {+ useNotifications().add({ type: 'success', title: 'Account deleted' });+ emit('close');+ setTimeout(() => {+ useUserStore().post_logout();+ useRouter().push('/');+ }, 1000);+ })+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));+}+</script>++<style scoped lang="scss">+.modal {+ min-width: 500px;+}+.warn {+ color: $red-dark;+ opacity: 0.7;+}+</style>diff --git a/frontend/pages/dashboard/settings/_views/security.vue b/frontend/pages/dashboard/settings/_views/security.vueindex 55636771..0b8c056a 100644--- a/frontend/pages/dashboard/settings/_views/security.vue+++ b/frontend/pages/dashboard/settings/_views/security.vue@@ -33,11 +33,24 @@<AppButton type="danger">Change password</AppButton></form><h2>Danger</h2>+ <div>+ You can log out from all devices or log out from this device. <br />+ Be careful, if you log out from all devices, you will be redirected to the login page. Please save your work before.+ </div><AppButton type="danger" @click="logoutUser">Log out</AppButton><AppButton type="danger" @click="logoutUserAll">Log out from all devices</AppButton>+ <h2>Delete account <tag blue>New</tag></h2>+ <div>+ You can delete your account. <br />+ Be careful, if you delete your account, you will lose all your data and you will not be able to recover it.+ <br />+ <strong>This action is irreversible.</strong>+ </div>+ <AppButton type="danger" @click="openDeleteModal">Delete account</AppButton></template><script setup lang="ts">+import DeleteAccountModal from '../_modals/DeleteAccountModal.vue';import { parseUserAgent } from '~/helpers/utils';const store = useUserStore();const passwordValue = ref('');@@ -57,6 +70,7 @@ const changePassword = async () => {}).catch(e => useNotifications().add({ type: 'error', title: 'Error during password saving', message: e.message }));};+const openDeleteModal = () => useModal().add(new Modal(shallowRef(DeleteAccountModal)));</script><style scoped lang="scss">diff --git a/frontend/pages/dashboard/settings/index.vue b/frontend/pages/dashboard/settings/index.vueindex de80f486..adfd8739 100644--- a/frontend/pages/dashboard/settings/index.vue+++ b/frontend/pages/dashboard/settings/index.vue@@ -1,5 +1,5 @@<template>- <div :class="{ 'modal-mask': !isMobile() }">+ <div :class="{ 'modal-mask': !isMobile() }" style="z-index: 100"><div class="component"><nav><span>Account settings</span>diff --git a/frontend/stores/user.store.ts b/frontend/stores/user.store.tsindex f82c0e8f..1b926fe2 100644--- a/frontend/stores/user.store.ts+++ b/frontend/stores/user.store.ts@@ -80,6 +80,16 @@ export const useUserStore = defineStore('user', {} else reject(request.message);});},+ deleteAccount() {+ return new Promise(async (resolve, reject) => {+ if (!this.user) return;+ const request = await makeRequest(`users/${this.user.id}`, 'DELETE', {});+ if (request.status === 'success') {+ this.user = undefined;+ return resolve(true);+ } else reject(request.message);+ });+ },post_logout() {this.user = undefined;if (import.meta.client) localStorage.removeItem('isLoggedIn');