Skip to content

Commit 0ea2258

Browse files
feat(GODT-2617): Allow change send ability on GPA server addresses
1 parent d2fbf42 commit 0ea2258

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

server/backend/address.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ import (
77
)
88

99
type address struct {
10-
addrID string
11-
email string
12-
order int
13-
status proton.AddressStatus
14-
addrType proton.AddressType
15-
keys []key
10+
addrID string
11+
email string
12+
order int
13+
status proton.AddressStatus
14+
addrType proton.AddressType
15+
keys []key
16+
allowSend bool
1617
}
1718

1819
func (add *address) toAddress() proton.Address {
1920
return proton.Address{
2021
ID: add.addrID,
2122
Email: add.email,
2223

23-
Send: true,
24+
Send: proton.Bool(add.allowSend),
2425
Receive: true,
2526
Status: add.status,
2627
Type: add.addrType,

server/backend/backend.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,32 @@ func (b *Backend) RemoveUserKey(userID, keyID string) error {
209209
}
210210

211211
func (b *Backend) CreateAddress(userID, email string, password []byte, withKey bool, status proton.AddressStatus, addrType proton.AddressType) (string, error) {
212-
return b.createAddress(userID, email, password, withKey, status, addrType, false)
212+
return b.createAddress(userID, email, password, withKey, status, addrType, false, true)
213213
}
214214

215215
func (b *Backend) CreateAddressAsUpdate(userID, email string, password []byte, withKey bool, status proton.AddressStatus, addrType proton.AddressType) (string, error) {
216-
return b.createAddress(userID, email, password, withKey, status, addrType, true)
216+
return b.createAddress(userID, email, password, withKey, status, addrType, true, true)
217217
}
218218

219-
func (b *Backend) createAddress(userID, email string, password []byte, withKey bool, status proton.AddressStatus, addrType proton.AddressType, issueUpdateInsteadOfCreate bool) (string, error) {
219+
func (b *Backend) CreateAddressWithSendDisabled(
220+
userID, email string,
221+
password []byte,
222+
withKey bool,
223+
status proton.AddressStatus,
224+
addrType proton.AddressType,
225+
) (string, error) {
226+
return b.createAddress(userID, email, password, withKey, status, addrType, false, false)
227+
}
228+
229+
func (b *Backend) createAddress(
230+
userID, email string,
231+
password []byte,
232+
withKey bool,
233+
status proton.AddressStatus,
234+
addrType proton.AddressType,
235+
issueUpdateInsteadOfCreate bool,
236+
allowSend bool,
237+
) (string, error) {
220238
return withAcc(b, userID, func(acc *account) (string, error) {
221239
var keys []key
222240

@@ -257,12 +275,13 @@ func (b *Backend) createAddress(userID, email string, password []byte, withKey b
257275
addressID := uuid.NewString()
258276

259277
acc.addresses[addressID] = &address{
260-
addrID: addressID,
261-
email: email,
262-
order: len(acc.addresses) + 1,
263-
status: status,
264-
addrType: addrType,
265-
keys: keys,
278+
addrID: addressID,
279+
email: email,
280+
order: len(acc.addresses) + 1,
281+
status: status,
282+
addrType: addrType,
283+
keys: keys,
284+
allowSend: allowSend,
266285
}
267286

268287
var update update
@@ -295,6 +314,18 @@ func (b *Backend) ChangeAddressType(userID, addrId string, addrType proton.Addre
295314
})
296315
}
297316

317+
func (b *Backend) ChangeAddressAllowSend(userID, addrId string, allowSend bool) error {
318+
return b.withAcc(userID, func(acc *account) error {
319+
for _, addr := range acc.addresses {
320+
if addr.addrID == addrId {
321+
addr.allowSend = allowSend
322+
return nil
323+
}
324+
}
325+
return fmt.Errorf("no addrID matching %s for user %s", addrId, userID)
326+
})
327+
}
328+
298329
func (b *Backend) CreateAddressKey(userID, addrID string, password []byte) error {
299330
return b.withAcc(userID, func(acc *account) error {
300331
token, err := crypto.RandomToken(32)

server/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ func (s *Server) CreateAddressAsUpdate(userID, email string, password []byte) (s
155155
return s.b.CreateAddressAsUpdate(userID, email, password, true, proton.AddressStatusEnabled, proton.AddressTypeOriginal)
156156
}
157157

158+
func (s *Server) ChangeAddressAllowSend(userID, addrID string, allowSend bool) error {
159+
return s.b.ChangeAddressAllowSend(userID, addrID, allowSend)
160+
}
161+
158162
func (s *Server) ChangeAddressType(userID, addrId string, addrType proton.AddressType) error {
159163
return s.b.ChangeAddressType(userID, addrId, addrType)
160164
}

0 commit comments

Comments
 (0)