Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var tableIndexes = map[string][]string{
"reservations": []string{"email", "name"},
"threads": []string{"owner"},
"tokens": []string{"owner"},
"attachments": []string{"owner"},
}

// List of names of databases
Expand Down
63 changes: 63 additions & 0 deletions db/table_attachments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package db

import (
"github.com/lavab/api/models"

"github.com/dancannon/gorethink"
)

type AttachmentsTable struct {
RethinkCRUD
Emails *EmailsTable
}

func (a *AttachmentsTable) GetAttachment(id string) (*models.Attachment, error) {
var result models.Attachment

if err := a.FindFetchOne(id, &result); err != nil {
return nil, err
}

return &result, nil
}

func (a *AttachmentsTable) GetOwnedBy(id string) ([]*models.Attachment, error) {
var result []*models.Attachment

err := a.WhereAndFetch(map[string]interface{}{
"owner": id,
}, &result)
if err != nil {
return nil, err
}

return result, nil
}

func (a *AttachmentsTable) DeleteOwnedBy(id string) error {
return a.Delete(map[string]interface{}{
"owner": id,
})
}

func (a *AttachmentsTable) GetEmailAttachments(id string) ([]*models.Attachment, error) {
email, err := a.Emails.GetEmail(id)
if err != nil {
return nil, err
}

query, err := a.Emails.GetTable().Filter(func(row gorethink.Term) gorethink.Term {
return gorethink.Expr(email.AttachmentIDs).Contains(row.Field("id"))
}).GetAll().Run(a.Emails.GetSession())
if err != nil {
return nil, err
}

var result []*models.Attachment
err = query.All(&result)
if err != nil {
return nil, err
}

return result, nil
}
2 changes: 2 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
Emails *db.EmailsTable
// Labels is the global instance of LabelsTable
Labels *db.LabelsTable
// Attachments is the global instance of AttachmentsTable
Attachments *db.AttachmentsTable
// Factors contains all currently registered factors
Factors map[string]factor.Factor
// NATS is the encoded connection to the NATS queue
Expand Down
8 changes: 4 additions & 4 deletions models/file.go → models/attachment.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package models

// File is an encrypted file stored by Lavaboom
type File struct {
// Attachment is an encrypted file stored by Lavaboom
type Attachment struct {
Encrypted
Resource

// Mime is the Internet media type of the file
// Mime is the Internet media type of the attachment
// Format: "type/subtype" – more info: en.wikipedia.org/wiki/Internet_media_type
Mime string `json:"mime" gorethink:"mime"`
MIME string `json:"mime" gorethink:"mime"`

// Size is the size of the file in bytes i.e. len(file.Data)
Size int `json:"size" gorethink:"size"`
Expand Down
17 changes: 11 additions & 6 deletions routes/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ func AccountsGet(c web.C, w http.ResponseWriter, r *http.Request) {

// AccountsUpdateRequest contains the input for the AccountsUpdate endpoint.
type AccountsUpdateRequest struct {
AltEmail string `json:"alt_email" schema:"alt_email"`
CurrentPassword string `json:"current_password" schema:"current_password"`
NewPassword string `json:"new_password" schema:"new_password"`
FactorType string `json:"factor_type" schema:"factor_type"`
FactorValue []string `json:"factor_value" schema:"factor_value"`
Token string `json:"token" schema:"token"`
AltEmail string `json:"alt_email" schema:"alt_email"`
CurrentPassword string `json:"current_password" schema:"current_password"`
NewPassword string `json:"new_password" schema:"new_password"`
FactorType string `json:"factor_type" schema:"factor_type"`
FactorValue []string `json:"factor_value" schema:"factor_value"`
Token string `json:"token" schema:"token"`
AppData interface{} `json:"app_data" schema:"app_data"`
}

// AccountsUpdateResponse contains the result of the AccountsUpdate request.
Expand Down Expand Up @@ -511,6 +512,10 @@ func AccountsUpdate(c web.C, w http.ResponseWriter, r *http.Request) {
user.AltEmail = input.AltEmail
}

if input.AppData != nil {
user.AppData = input.AppData
}

if input.FactorType != "" {
// Check if such factor exists
if _, exists := env.Factors[input.FactorType]; !exists {
Expand Down
Loading