New column for encrypted data in preparation for full text search
This commit is contained in:
parent
b7c5a91c06
commit
57180e986e
3 changed files with 56 additions and 19 deletions
68
node.go
68
node.go
|
|
@ -21,6 +21,8 @@ type Node struct {
|
|||
Files []File
|
||||
Complete bool
|
||||
Level int
|
||||
|
||||
ContentEncrypted string `db:"content_encrypted" json:"-"`
|
||||
}
|
||||
|
||||
func (session Session) NodeTree(startNodeID int) (nodes []Node, err error) {// {{{
|
||||
|
|
@ -142,6 +144,7 @@ func (session Session) Node(nodeID int) (node Node, err error) {// {{{
|
|||
COALESCE(crypto_key_id, 0) AS crypto_key_id,
|
||||
name,
|
||||
content,
|
||||
content_encrypted,
|
||||
0 AS level
|
||||
FROM node
|
||||
WHERE
|
||||
|
|
@ -157,6 +160,7 @@ func (session Session) Node(nodeID int) (node Node, err error) {// {{{
|
|||
COALESCE(n.crypto_key_id, 0) AS crypto_key_id,
|
||||
n.name,
|
||||
'' AS content,
|
||||
'' AS content_encrypted,
|
||||
r.level + 1 AS level
|
||||
FROM node n
|
||||
INNER JOIN recurse r ON n.parent_id = r.id AND r.level = 0
|
||||
|
|
@ -193,8 +197,13 @@ func (session Session) Node(nodeID int) (node Node, err error) {// {{{
|
|||
node.ParentID = row.ParentID
|
||||
node.CryptoKeyID = row.CryptoKeyID
|
||||
node.Name = row.Name
|
||||
node.Content = row.Content
|
||||
node.Complete = true
|
||||
|
||||
if node.CryptoKeyID > 0 {
|
||||
node.Content = row.ContentEncrypted
|
||||
} else {
|
||||
node.Content = row.Content
|
||||
}
|
||||
}
|
||||
|
||||
if row.Level == 1 {
|
||||
|
|
@ -287,23 +296,46 @@ func (session Session) CreateNode(parentID int, name string) (node Node, err err
|
|||
return
|
||||
}// }}}
|
||||
func (session Session) UpdateNode(nodeID int, content string, cryptoKeyID int) (err error) {// {{{
|
||||
_, err = db.Exec(`
|
||||
UPDATE node
|
||||
SET
|
||||
content = $1,
|
||||
crypto_key_id = CASE $2::int
|
||||
WHEN 0 THEN NULL
|
||||
ELSE $2
|
||||
END
|
||||
WHERE
|
||||
id = $3 AND
|
||||
user_id = $4
|
||||
`,
|
||||
content,
|
||||
cryptoKeyID,
|
||||
nodeID,
|
||||
session.UserID,
|
||||
)
|
||||
if cryptoKeyID > 0 {
|
||||
_, err = db.Exec(`
|
||||
UPDATE node
|
||||
SET
|
||||
content = '',
|
||||
content_encrypted = $1,
|
||||
crypto_key_id = CASE $2::int
|
||||
WHEN 0 THEN NULL
|
||||
ELSE $2
|
||||
END
|
||||
WHERE
|
||||
id = $3 AND
|
||||
user_id = $4
|
||||
`,
|
||||
content,
|
||||
cryptoKeyID,
|
||||
nodeID,
|
||||
session.UserID,
|
||||
)
|
||||
} else {
|
||||
_, err = db.Exec(`
|
||||
UPDATE node
|
||||
SET
|
||||
content = $1,
|
||||
content_encrypted = '',
|
||||
crypto_key_id = CASE $2::int
|
||||
WHEN 0 THEN NULL
|
||||
ELSE $2
|
||||
END
|
||||
WHERE
|
||||
id = $3 AND
|
||||
user_id = $4
|
||||
`,
|
||||
content,
|
||||
cryptoKeyID,
|
||||
nodeID,
|
||||
session.UserID,
|
||||
)
|
||||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func (session Session) RenameNode(nodeID int, name string) (err error) {// {{{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue