document

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package document defines a document struct and contains logic for working with these documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStringSliceValue

func GetStringSliceValue(in map[string]any, key string) ([]string, error)

func GetStringValue

func GetStringValue(in map[string]any, key string) (string, error)

Types

type CustomDocTypeField

type CustomDocTypeField struct {
	// DisplayName is the display name of the custom document-type field.
	DisplayName string `json:"displayName"`

	// Type is the type of the custom document-type field. It is used by the
	// frontend to display the proper input component.
	// Valid values: "PEOPLE", "STRING".
	Type string `json:"type"`
}

type CustomField

type CustomField struct {
	// Name is the name of the custom field.
	// TODO: consolidate with DisplayName and make corresponding frontend changes
	//   to support this.
	Name string `json:"name"`

	// DisplayName is the display name of the custom field.
	DisplayName string `json:"displayName"`

	// Type is the type of the custom field. It is used by the frontend to display
	// the proper input component.
	// Valid values: "PEOPLE", "STRING".
	Type string `json:"type"`

	// Value is the value of the custom field.
	Value any
}

type Document

type Document struct {
	// ObjectID is the Google Drive file ID for the document.
	ObjectID string `json:"objectID,omitempty"`

	// Title is the title of the document. It does not contain the document number
	// (e.g., "TF-123").
	Title string `json:"title,omitempty"`

	// DocType is the type of document (e.g., "RFC", "PRD").
	DocType string `json:"docType,omitempty"`

	// DocNumber is a unique document identifier containing a product/area
	// abbreviation and a unique number (e.g., "TF-123").
	DocNumber string `json:"docNumber,omitempty"`

	// AppCreated should be set to true if the document was created through this
	// application, and false if created directly in Google Docs and indexed
	// afterwards.
	AppCreated bool `json:"appCreated,omitempty"`

	// ApprovedBy is a slice of email address strings for users that have approved
	// the document.
	ApprovedBy []string `json:"approvedBy,omitempty"`

	// Approvers is a slice of email address strings for users whose approvals
	// are requested for the document.
	Approvers []string `json:"approvers,omitempty"`

	// ChangesRequestedBy is a slice of email address strings for users that have
	// requested changes for the document.
	ChangesRequestedBy []string `json:"changesRequestedBy,omitempty"`

	// Contributors is a slice of email address strings for users who have
	// contributed to the document.
	Contributors []string `json:"contributors,omitempty"`

	// Content is the plaintext content of the document.
	Content string `json:"content,omitempty"`

	// Created is the UTC time of document creation, in a "Jan 2, 2006" string
	// format.
	Created string `json:"created,omitempty"`

	// CreatedTime is the time of document creation, in Unix time.
	CreatedTime int64 `json:"createdTime,omitempty"`

	// CustomEditableFields are all document-type-specific fields that are
	// editable.
	CustomEditableFields map[string]CustomDocTypeField `json:"customEditableFields,omitempty"`

	// CustomFields are custom fields that contain values too.
	// TODO: consolidate with CustomEditableFields.
	CustomFields []CustomField `json:"customFields,omitempty"`

	// FileRevisions is a map of file revision IDs to custom names.
	FileRevisions map[string]string `json:"fileRevisions,omitempty"`

	// TODO: LinkedDocs is not used yet.
	LinkedDocs []string `json:"linkedDocs,omitempty"`

	// Locked is true if the document is locked for editing.
	Locked bool `json:"locked,omitempty"`

	// MetaTags contains metadata tags that can be used for filtering in Algolia.
	MetaTags []string `json:"_tags,omitempty"`

	// Created is the time that the document was last modified, in Unix time.
	ModifiedTime int64 `json:"modifiedTime,omitempty"`

	// Owners is a slice of email address strings for document owners. Hermes
	// generally only uses the first element as the document owner, but this is a
	// slice for historical reasons as some HashiCorp documents have had multiple
	// owners in the past.
	Owners []string `json:"owners,omitempty"`

	// OwnerPhotos is a slice of URL strings for the profile photos of the
	// document owners (in the same order as the Owners field).
	OwnerPhotos []string `json:"ownerPhotos,omitempty"`

	// Product is the product or area that the document relates to.
	Product string `json:"product,omitempty"`

	// Summary is a summary of the document.
	Summary string `json:"summary,omitempty"`

	// Status is the status of the document (e.g., "WIP", "In-Review", "Approved",
	// "Obsolete").
	Status string `json:"status,omitempty"`

	// Tags is a slice of tags to help users discover the document based on their
	// interests.
	Tags []string `json:"tags,omitempty"`

	// ThumbnailLink is a URL string for the document thumbnail image.
	ThumbnailLink string `json:"thumbnailLink,omitempty"`
}

func NewFromAlgoliaObject

func NewFromAlgoliaObject(
	in map[string]any, docTypes []*config.DocumentType) (*Document, error)

NewFromAlgoliaObject creates a document from a document Algolia object.

func NewFromDatabaseModel

func NewFromDatabaseModel(
	model models.Document, reviews models.DocumentReviews,
) (*Document, error)

NewFromDatabaseModel creates a document from a document database model.

func (*Document) DeleteFileRevision

func (d *Document) DeleteFileRevision(revisionID string)

func (*Document) ReplaceHeader

func (doc *Document) ReplaceHeader(
	baseURL string, isDraft bool, s *gw.Service) error

func (*Document) SetFileRevision

func (d *Document) SetFileRevision(revisionID, revisionName string)

func (Document) ToAlgoliaObject

func (d Document) ToAlgoliaObject(
	removeCustomEditableFields bool) (map[string]any, error)

ToAlgoliaObject converts a document to a document Algolia object.

func (Document) ToDatabaseModels

func (d Document) ToDatabaseModels(
	docTypes []*config.DocumentType, products []*config.Product,
) (
	models.Document, models.DocumentReviews, error,
)

ToDatabaseModels converts a document to a document and document reviews database records.

func (*Document) UpsertCustomField

func (d *Document) UpsertCustomField(cf CustomField) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL