From 3e984d059c05cd63b1475ee6f222bfcc43c7d7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Wed, 1 Jan 2025 15:22:02 +0100 Subject: [PATCH] Improve model and add roles --- helpers/database.go | 5 ++--- models/people.go | 2 ++ models/roles.go | 15 +++++++++++++++ models/sections.go | 16 ++++++---------- models/users.go | 32 +++++++------------------------- 5 files changed, 32 insertions(+), 38 deletions(-) create mode 100644 models/roles.go diff --git a/helpers/database.go b/helpers/database.go index cd4591c..5be5534 100644 --- a/helpers/database.go +++ b/helpers/database.go @@ -37,11 +37,10 @@ func connectDatabase() (*gorm.DB, error) { err = database.AutoMigrate( &models.User{}, - &models.ParentSection{}, &models.Section{}, + &models.Role{}, + &models.UserRoles{}, &models.Person{}, - &models.ManageSection{}, - &models.ManageParentSection{}, &models.List{}, &models.ListItem{}, ) diff --git a/models/people.go b/models/people.go index c095ba9..8cab6a0 100644 --- a/models/people.go +++ b/models/people.go @@ -4,6 +4,8 @@ import "gorm.io/gorm" type Person struct { gorm.Model + IsMember bool + IsContact bool FirstName string LastName string Email string diff --git a/models/roles.go b/models/roles.go new file mode 100644 index 0000000..6739803 --- /dev/null +++ b/models/roles.go @@ -0,0 +1,15 @@ +package models + +import "gorm.io/gorm" + +type Role struct { + gorm.Model + Name string + ShowPerson bool + CreatePerson bool + EditPerson bool + ShowArchivedPerson bool + ArchivePerson bool + RestorePerson bool + ExportData bool +} diff --git a/models/sections.go b/models/sections.go index 9d7453e..a1ea7e2 100644 --- a/models/sections.go +++ b/models/sections.go @@ -2,16 +2,12 @@ package models import "gorm.io/gorm" -type ParentSection struct { - gorm.Model - Name string - ShortName string -} - type Section struct { gorm.Model - Name string - ShortName string - ParentSectionID uint - ParentSection ParentSection + Name string + ShortName string + ParentSectionID uint + ParentSection *Section + ContainsMembers bool + ContainsContacts bool } diff --git a/models/users.go b/models/users.go index deff81b..004c190 100644 --- a/models/users.go +++ b/models/users.go @@ -17,30 +17,12 @@ type User struct { SkipWelcome bool } -type ManageSection struct { +type UserRoles struct { gorm.Model - UserID uint - User User - SectionID uint - Section Section - ShowPerson bool - CreatePerson bool - EditPerson bool - ShowArchivedPerson bool - ArchivePerson bool - UnarchivePerson bool -} - -type ManageParentSection struct { - gorm.Model - UserID uint - User User - ParentSectionID uint - ParentSection ParentSection - ShowPerson bool - CreatePerson bool - EditPerson bool - ShowArchivedPerson bool - ArchivePerson bool - UnarchivePerson bool + UserID uint + User User + RoleID uint + Role Role + SectionID uint + Section Section }