Skip to content

Commit 1f95711

Browse files
committed
Rename media things to attachments
1 parent e1ec059 commit 1f95711

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

core/models/orgs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (o *Org) StoreAttachment(ctx context.Context, rt *runtime.Runtime, filename
187187

188188
path := o.attachmentPath(prefix, filename)
189189

190-
url, err := rt.MediaStorage.Put(ctx, path, contentType, contentBytes)
190+
url, err := rt.AttachmentStorage.Put(ctx, path, contentType, contentBytes)
191191
if err != nil {
192192
return "", errors.Wrapf(err, "unable to store attachment content")
193193
}

core/models/orgs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestStoreAttachment(t *testing.T) {
7171
attachment, err := org.StoreAttachment(context.Background(), rt, "668383ba-387c-49bc-b164-1213ac0ea7aa.jpg", "image/jpeg", image)
7272
require.NoError(t, err)
7373

74-
assert.Equal(t, utils.Attachment("image/jpeg:_test_media_storage/media/1/6683/83ba/668383ba-387c-49bc-b164-1213ac0ea7aa.jpg"), attachment)
74+
assert.Equal(t, utils.Attachment("image/jpeg:_test_attachments_storage/attachments/1/6683/83ba/668383ba-387c-49bc-b164-1213ac0ea7aa.jpg"), attachment)
7575

7676
// err trying to read from same reader again
7777
_, err = org.StoreAttachment(context.Background(), rt, "668383ba-387c-49bc-b164-1213ac0ea7aa.jpg", "image/jpeg", image)

mailroom.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,22 @@ func (mr *Mailroom) Start() error {
129129
if err != nil {
130130
return err
131131
}
132-
mr.rt.MediaStorage = storage.NewS3(s3Client, mr.rt.Config.S3MediaBucket, c.S3Region, s3.BucketCannedACLPublicRead, 32)
132+
mr.rt.AttachmentStorage = storage.NewS3(s3Client, mr.rt.Config.S3MediaBucket, c.S3Region, s3.BucketCannedACLPublicRead, 32)
133133
mr.rt.SessionStorage = storage.NewS3(s3Client, mr.rt.Config.S3SessionBucket, c.S3Region, s3.ObjectCannedACLPrivate, 32)
134134
} else {
135-
mr.rt.MediaStorage = storage.NewFS("_storage", 0766)
135+
mr.rt.AttachmentStorage = storage.NewFS("_storage", 0766)
136136
mr.rt.SessionStorage = storage.NewFS("_storage", 0766)
137137
}
138138

139-
// test our media storage
139+
// test our attachment storage
140140
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
141-
err = mr.rt.MediaStorage.Test(ctx)
141+
err = mr.rt.AttachmentStorage.Test(ctx)
142142
cancel()
143143

144144
if err != nil {
145-
log.WithError(err).Error(mr.rt.MediaStorage.Name() + " media storage not available")
145+
log.WithError(err).Error(mr.rt.AttachmentStorage.Name() + " attachment storage not available")
146146
} else {
147-
log.Info(mr.rt.MediaStorage.Name() + " media storage ok")
147+
log.Info(mr.rt.AttachmentStorage.Name() + " attachment storage ok")
148148
}
149149

150150
ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)

runtime/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewDefaultConfig() *Config {
109109
S3Endpoint: "https://s3.amazonaws.com",
110110
S3Region: "us-east-1",
111111
S3MediaBucket: "mailroom-media",
112-
S3MediaPrefix: "/media/",
112+
S3MediaPrefix: "/attachments/",
113113
S3SessionBucket: "mailroom-sessions",
114114
S3SessionPrefix: "/",
115115
S3DisableSSL: false,

runtime/runtime.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
// Runtime represents the set of services required to run many Mailroom functions. Used as a wrapper for
1111
// those services to simplify call signatures but not create a direct dependency to Mailroom or Server
1212
type Runtime struct {
13-
DB *sqlx.DB
14-
ReadonlyDB *sqlx.DB
15-
RP *redis.Pool
16-
ES *elastic.Client
17-
MediaStorage storage.Storage
18-
SessionStorage storage.Storage
19-
Config *Config
13+
DB *sqlx.DB
14+
ReadonlyDB *sqlx.DB
15+
RP *redis.Pool
16+
ES *elastic.Client
17+
AttachmentStorage storage.Storage
18+
SessionStorage storage.Storage
19+
Config *Config
2020
}

services/tickets/mailgun/testdata/receive.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
},
302302
"db_assertions": [
303303
{
304-
"query": "select count(*) from msgs_msg where direction = 'O' AND uuid = '5802813d-6c58-4292-8228-9728778b6c98' AND attachments = '{text/plain:https:///_test_media_storage/media/1/8720/f157/8720f157-ca1c-432f-9c0b-2014ddc77094.txt,image/jpeg:https:///_test_media_storage/media/1/c34b/6c7d/c34b6c7d-fa06-4563-92a3-d648ab64bccb.jpg}'",
304+
"query": "select count(*) from msgs_msg where direction = 'O' AND uuid = '5802813d-6c58-4292-8228-9728778b6c98' AND attachments = '{text/plain:https:///_test_attachments_storage/attachments/1/8720/f157/8720f157-ca1c-432f-9c0b-2014ddc77094.txt,image/jpeg:https:///_test_attachments_storage/attachments/1/c34b/6c7d/c34b6c7d-fa06-4563-92a3-d648ab64bccb.jpg}'",
305305
"count": 1
306306
},
307307
{

services/tickets/rocketchat/testdata/event_callback.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
},
193193
"db_assertions": [
194194
{
195-
"query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{text/plain:https:///_test_media_storage/media/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'",
195+
"query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{text/plain:https:///_test_attachments_storage/attachments/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'",
196196
"count": 1
197197
}
198198
]

services/tickets/utils_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func TestSendReply(t *testing.T) {
131131

132132
assert.Equal(t, "I'll get back to you", msg.Text())
133133
assert.Equal(t, testdata.Cathy.ID, msg.ContactID())
134-
assert.Equal(t, []utils.Attachment{"image/jpeg:https:///_test_media_storage/media/1/e718/7099/e7187099-7d38-4f60-955c-325957214c42.jpg"}, msg.Attachments())
135-
assert.FileExists(t, "_test_media_storage/media/1/e718/7099/e7187099-7d38-4f60-955c-325957214c42.jpg")
134+
assert.Equal(t, []utils.Attachment{"image/jpeg:https:///_test_attachments_storage/attachments/1/e718/7099/e7187099-7d38-4f60-955c-325957214c42.jpg"}, msg.Attachments())
135+
assert.FileExists(t, "_test_attachments_storage/attachments/1/e718/7099/e7187099-7d38-4f60-955c-325957214c42.jpg")
136136

137137
// try with file that can't be read (i.e. same file again which is already closed)
138138
_, err = tickets.SendReply(ctx, rt, modelTicket, "I'll get back to you", []*tickets.File{image})

services/tickets/zendesk/service_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestOpenAndForward(t *testing.T) {
114114
dbTicket,
115115
flows.MsgUUID("ca5607f0-cba8-4c94-9cd5-c4fbc24aa767"),
116116
"It's urgent",
117-
[]utils.Attachment{utils.Attachment("image/jpg:http://myfiles.com/media/0123/attachment1.jpg")},
117+
[]utils.Attachment{utils.Attachment("image/jpg:http://myfiles.com/attachments/0123/attachment1.jpg")},
118118
logger.Log,
119119
)
120120

services/tickets/zendesk/testdata/channelback.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"db_assertions": [
6868
{
69-
"query": "select count(*) from msgs_msg where direction = 'O' and text = 'Like this' and attachments = '{text/plain:https:///_test_media_storage/media/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'",
69+
"query": "select count(*) from msgs_msg where direction = 'O' and text = 'Like this' and attachments = '{text/plain:https:///_test_attachments_storage/attachments/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'",
7070
"count": 1
7171
}
7272
]

testsuite/testsuite.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
var _db *sqlx.DB
3232

33-
const MediaStorageDir = "_test_media_storage"
33+
const AttachmentStorageDir = "_test_attachments_storage"
3434
const SessionStorageDir = "_test_session_storage"
3535

3636
// Refresh is our type for the pieces of org assets we want fresh (not cached)
@@ -67,13 +67,13 @@ func Get() (context.Context, *runtime.Runtime, *sqlx.DB, *redis.Pool) {
6767
db := getDB()
6868
rp := getRP()
6969
rt := &runtime.Runtime{
70-
DB: db,
71-
ReadonlyDB: db,
72-
RP: rp,
73-
ES: nil,
74-
MediaStorage: storage.NewFS(MediaStorageDir, 0766),
75-
SessionStorage: storage.NewFS(SessionStorageDir, 0766),
76-
Config: runtime.NewDefaultConfig(),
70+
DB: db,
71+
ReadonlyDB: db,
72+
RP: rp,
73+
ES: nil,
74+
AttachmentStorage: storage.NewFS(AttachmentStorageDir, 0766),
75+
SessionStorage: storage.NewFS(SessionStorageDir, 0766),
76+
Config: runtime.NewDefaultConfig(),
7777
}
7878

7979
logrus.SetLevel(logrus.DebugLevel)
@@ -176,7 +176,7 @@ func resetRedis() {
176176

177177
// clears our storage for tests
178178
func resetStorage() {
179-
must(os.RemoveAll(MediaStorageDir))
179+
must(os.RemoveAll(AttachmentStorageDir))
180180
must(os.RemoveAll(SessionStorageDir))
181181
}
182182

0 commit comments

Comments
 (0)