Add document classification
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -28,15 +28,16 @@ import (
|
||||
|
||||
type (
|
||||
Document struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
Title string `db:"title"`
|
||||
DocumentType DocumentType `db:"document_type"`
|
||||
CurrentPublishedVersion *int `db:"current_published_version"`
|
||||
TrustCenterVisibility TrustCenterVisibility `db:"trust_center_visibility"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
Title string `db:"title"`
|
||||
DocumentType DocumentType `db:"document_type"`
|
||||
Classification DocumentClassification `db:"classification"`
|
||||
CurrentPublishedVersion *int `db:"current_published_version"`
|
||||
TrustCenterVisibility TrustCenterVisibility `db:"trust_center_visibility"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
Documents []*Document
|
||||
@@ -68,6 +69,7 @@ SELECT
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
@@ -150,6 +152,7 @@ SELECT
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
@@ -200,6 +203,7 @@ SELECT
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
@@ -249,6 +253,7 @@ INSERT INTO
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
@@ -261,6 +266,7 @@ VALUES (
|
||||
@owner_id,
|
||||
@title,
|
||||
@document_type,
|
||||
@classification,
|
||||
@current_published_version,
|
||||
@trust_center_visibility,
|
||||
@created_at,
|
||||
@@ -275,6 +281,7 @@ VALUES (
|
||||
"owner_id": p.OwnerID,
|
||||
"title": p.Title,
|
||||
"document_type": p.DocumentType,
|
||||
"classification": p.Classification,
|
||||
"current_published_version": p.CurrentPublishedVersion,
|
||||
"trust_center_visibility": p.TrustCenterVisibility,
|
||||
"created_at": p.CreatedAt,
|
||||
@@ -334,6 +341,7 @@ SET
|
||||
current_published_version = @current_published_version,
|
||||
owner_id = @owner_id,
|
||||
document_type = @document_type,
|
||||
classification = @classification,
|
||||
trust_center_visibility = @trust_center_visibility,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
@@ -350,6 +358,7 @@ WHERE
|
||||
"current_published_version": p.CurrentPublishedVersion,
|
||||
"owner_id": p.OwnerID,
|
||||
"document_type": p.DocumentType,
|
||||
"classification": p.Classification,
|
||||
"trust_center_visibility": p.TrustCenterVisibility,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
@@ -427,6 +436,7 @@ WITH plcs AS (
|
||||
p.owner_id,
|
||||
p.title,
|
||||
p.document_type,
|
||||
p.classification,
|
||||
p.current_published_version,
|
||||
p.trust_center_visibility,
|
||||
p.created_at,
|
||||
@@ -445,6 +455,7 @@ SELECT
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
@@ -543,6 +554,7 @@ WITH plcs AS (
|
||||
p.owner_id,
|
||||
p.title,
|
||||
p.document_type,
|
||||
p.classification,
|
||||
p.current_published_version,
|
||||
p.trust_center_visibility,
|
||||
p.created_at,
|
||||
@@ -562,6 +574,7 @@ SELECT
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
classification,
|
||||
current_published_version,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
|
||||
49
pkg/coredata/document_classification.go
Normal file
49
pkg/coredata/document_classification.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DocumentClassification string
|
||||
|
||||
const (
|
||||
DocumentClassificationPublic DocumentClassification = "PUBLIC"
|
||||
DocumentClassificationInternal DocumentClassification = "INTERNAL"
|
||||
DocumentClassificationConfidential DocumentClassification = "CONFIDENTIAL"
|
||||
DocumentClassificationSecret DocumentClassification = "SECRET"
|
||||
)
|
||||
|
||||
func (dc DocumentClassification) String() string {
|
||||
switch dc {
|
||||
case DocumentClassificationPublic:
|
||||
return "PUBLIC"
|
||||
case DocumentClassificationInternal:
|
||||
return "INTERNAL"
|
||||
case DocumentClassificationConfidential:
|
||||
return "CONFIDENTIAL"
|
||||
case DocumentClassificationSecret:
|
||||
return "SECRET"
|
||||
}
|
||||
panic(fmt.Errorf("invalid DocumentClassification value: %s", string(dc)))
|
||||
}
|
||||
|
||||
// Scan implements the sql.Scanner interface for database deserialization.
|
||||
func (dc *DocumentClassification) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
sv, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to scan DocumentClassification: %v", value)
|
||||
}
|
||||
|
||||
*dc = DocumentClassification(sv)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value implements the driver.Valuer interface for database serialization.
|
||||
func (dc DocumentClassification) Value() (driver.Value, error) {
|
||||
return string(dc), nil
|
||||
}
|
||||
@@ -28,17 +28,18 @@ import (
|
||||
|
||||
type (
|
||||
DocumentVersion struct {
|
||||
ID gid.GID `db:"id"`
|
||||
DocumentID gid.GID `db:"document_id"`
|
||||
Title string `db:"title"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
VersionNumber int `db:"version_number"`
|
||||
Content string `db:"content"`
|
||||
Changelog string `db:"changelog"`
|
||||
Status DocumentStatus `db:"status"`
|
||||
PublishedAt *time.Time `db:"published_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ID gid.GID `db:"id"`
|
||||
DocumentID gid.GID `db:"document_id"`
|
||||
Title string `db:"title"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
VersionNumber int `db:"version_number"`
|
||||
Classification DocumentClassification `db:"classification"`
|
||||
Content string `db:"content"`
|
||||
Changelog string `db:"changelog"`
|
||||
Status DocumentStatus `db:"status"`
|
||||
PublishedAt *time.Time `db:"published_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
DocumentVersions []*DocumentVersion
|
||||
@@ -58,6 +59,7 @@ SELECT
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -116,6 +118,7 @@ SELECT
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -165,6 +168,7 @@ INSERT INTO document_versions (
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -178,6 +182,7 @@ VALUES (
|
||||
@title,
|
||||
@owner_id,
|
||||
@version_number,
|
||||
@classification,
|
||||
@content,
|
||||
@changelog,
|
||||
@status,
|
||||
@@ -192,6 +197,7 @@ VALUES (
|
||||
"title": p.Title,
|
||||
"owner_id": p.OwnerID,
|
||||
"version_number": p.VersionNumber,
|
||||
"classification": p.Classification,
|
||||
"content": p.Content,
|
||||
"changelog": p.Changelog,
|
||||
"status": p.Status,
|
||||
@@ -221,6 +227,7 @@ SELECT
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -272,6 +279,7 @@ SELECT
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -321,6 +329,7 @@ SELECT
|
||||
title,
|
||||
owner_id,
|
||||
version_number,
|
||||
classification,
|
||||
content,
|
||||
changelog,
|
||||
status,
|
||||
@@ -372,6 +381,7 @@ UPDATE document_versions SET
|
||||
status = @status,
|
||||
content = @content,
|
||||
published_at = @published_at,
|
||||
classification = @classification,
|
||||
updated_at = @updated_at
|
||||
WHERE %s
|
||||
AND id = @document_version_id
|
||||
@@ -387,6 +397,7 @@ WHERE %s
|
||||
"status": p.Status,
|
||||
"content": p.Content,
|
||||
"published_at": p.PublishedAt,
|
||||
"classification": p.Classification,
|
||||
"updated_at": p.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
12
pkg/coredata/migrations/20251018T081657Z.sql
Normal file
12
pkg/coredata/migrations/20251018T081657Z.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE TYPE document_classification AS ENUM (
|
||||
'PUBLIC',
|
||||
'INTERNAL',
|
||||
'CONFIDENTIAL',
|
||||
'SECRET'
|
||||
);
|
||||
|
||||
ALTER TABLE documents ADD COLUMN classification document_classification NOT NULL DEFAULT 'CONFIDENTIAL';
|
||||
ALTER TABLE documents ALTER COLUMN classification DROP DEFAULT;
|
||||
|
||||
ALTER TABLE document_versions ADD COLUMN classification document_classification NOT NULL DEFAULT 'CONFIDENTIAL';
|
||||
ALTER TABLE document_versions ALTER COLUMN classification DROP DEFAULT;
|
||||
Reference in New Issue
Block a user